Skip to content

Commit

Permalink
add NIC configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigard committed Aug 11, 2017
1 parent 1479571 commit 5b2ccc2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 11 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
resource "ovirt_vm" "my_vm" {
name = "my_first_vm"
cluster = "Default"
template = "centos-7-b"
network_interface {
label = "eth0"
boot_proto = "static"
ip_address = "130.20.232.184"
gateway = "130.20.232.1"
}
provisioner "remote-exec" {
inline = [
"uptime"
]
}
}
2 changes: 1 addition & 1 deletion ovirt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func Provider() terraform.ResourceProvider {
}

func ConfigureProvider(d *schema.ResourceData) (interface{}, error) {
return ovirtapi.NewConnection(d.Get("url").(string), d.Get("username").(string), d.Get("password").(string), false)
return ovirtapi.NewConnection(d.Get("url").(string), d.Get("username").(string), d.Get("password").(string), true)
}
22 changes: 13 additions & 9 deletions ovirt/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ovirt

import (
"fmt"
"time"
"strconv"
"time"

"github.com/EMSL-MSC/ovirtapi"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -33,11 +33,11 @@ func resourceVM() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"network_interface" : {
"network_interface": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Resource {
Schema : map[string]*schema.Schema{
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"label": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -100,29 +100,33 @@ func resourceVMCreate(d *schema.ResourceData, meta interface{}) error {
Gateway: d.Get(prefix + ".gateway").(string),
},
BootProtocol: d.Get(prefix + ".boot_proto").(string),
OnBoot: strconv.FormatBool(d.Get(prefix + ".on_boot").(bool)),
Name: d.Get(prefix + ".label").(string),
OnBoot: strconv.FormatBool(d.Get(prefix + ".on_boot").(bool)),
Name: d.Get(prefix + ".label").(string),
}
if i == 0 {
d.SetConnInfo(map[string]string{
"host": d.Get(prefix + ".ip_address").(string),
})
}
}
newVM.Initialization.NICConfigurations = &ovirtapi.NICConfigurations{NICConfigurations}
newVM.Initialization.NICConfigurations = &ovirtapi.NICConfigurations{NICConfiguration: NICConfigurations}

err := newVM.Save()
if err != nil {
return err
}
d.SetId(newVM.ID)

for newVM.Status != "down" {
time.Sleep(time.Second)
newVM.Update()
}

newVM.Start("", "", "", "", "", nil)
d.SetId(newVM.ID)
err = newVM.Start("", "", "", "", "", nil)
if err != nil {
newVM.Delete()
return err
}
return nil
}

Expand Down

0 comments on commit 5b2ccc2

Please sign in to comment.