Skip to content

Commit

Permalink
F #247 Add IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
frousselet committed May 13, 2022
1 parent d688ed2 commit 53c523e
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 84 deletions.
20 changes: 20 additions & 0 deletions opennebula/resource_opennebula_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func nicComputedVMFields() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"computed_ip6_global": {
Type: schema.TypeString,
Computed: true,
},
"computed_ip6_link": {
Type: schema.TypeString,
Computed: true,
},
"computed_mac": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -727,6 +735,8 @@ func flattenNICComputed(nic shared.NIC) map[string]interface{} {
ip, _ := nic.Get(shared.IP)
mac, _ := nic.Get(shared.MAC)
physicalDevice, _ := nic.GetStr("PHYDEV")
ip6Global, _ := nic.GetStr("IP6_GLOBAL")
ip6Link, _ := nic.GetStr("IP6_LINK")
network, _ := nic.Get(shared.Network)

model, _ := nic.Get(shared.Model)
Expand All @@ -743,6 +753,8 @@ func flattenNICComputed(nic shared.NIC) map[string]interface{} {
"nic_id": nicID,
"network": network,
"computed_ip": ip,
"computed_ip6_global": ip6Global,
"computed_ip6_link": ip6Link,
"computed_mac": mac,
"computed_physical_device": physicalDevice,
"computed_model": model,
Expand All @@ -758,6 +770,12 @@ func flattenVMNICComputed(NICConfig map[string]interface{}, NIC shared.NIC) map[
if len(NICConfig["ip"].(string)) > 0 {
NICMap["ip"] = NICMap["computed_ip"]
}
if len(NICConfig["ip6_global"].(string)) > 0 {
NICMap["ip6_global"] = NICMap["computed_ip6_global"]
}
if len(NICConfig["ip6_link"].(string)) > 0 {
NICMap["ip6_link"] = NICMap["computed_ip6_link"]
}
if len(NICConfig["mac"].(string)) > 0 {
NICMap["mac"] = NICMap["computed_mac"]
}
Expand Down Expand Up @@ -1258,6 +1276,8 @@ func resourceOpennebulaVirtualMachineUpdate(d *schema.ResourceData, meta interfa
},
"network_id",
"ip",
"ip6Global",
"ip6Link",
"mac",
"security_groups",
"model",
Expand Down
195 changes: 111 additions & 84 deletions opennebula/resource_opennebula_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,8 @@ resource "opennebula_virtual_machine" "test" {
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
ip6_global = "2001:db8:abcd::1"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
timeout = 5
Expand Down Expand Up @@ -1444,10 +1446,14 @@ resource "opennebula_virtual_machine" "test" {
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
ip6_global = "2001:db8:abcd::1"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.132"
ip6_global = "2001:db8:abcd::2"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
timeout = 5
Expand All @@ -1464,37 +1470,42 @@ var testAccVirtualMachineTemplateConfigNICUpdate = testNICVNetResources + `
cpu = 0.1
context = {
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
}
os {
arch = "x86_64"
boot = ""
}
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
tags = {
env = "prod"
customer = "test"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
}
os {
arch = "x86_64"
boot = ""
}
tags = {
env = "prod"
customer = "test"
}
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
}
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.111"
}
timeout = 5
}
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
ip6_global = "2001:db8:abcd::1"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.111"
ip6_global = "2001:db8:abcd::2"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
timeout = 5
}
`

var testAccVirtualMachineTemplateConfigNICIPUpdate = testNICVNetResources + `
Expand All @@ -1503,42 +1514,46 @@ var testAccVirtualMachineTemplateConfigNICIPUpdate = testNICVNetResources + `
name = "test-virtual_machine"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
memory = 128
cpu = 0.1
context = {
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
}
os {
arch = "x86_64"
boot = ""
arch = "x86_64"
boot = ""
}
tags = {
env = "prod"
customer = "test"
env = "prod"
customer = "test"
}
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
}
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.112"
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
ip6_global = "2001:db8:abcd::1"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.112"
ip6_global = "2001:db8:abcd::2"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
timeout = 5
}
timeout = 5
}
`

var testAccVirtualMachineTemplateConfigMultipleNICs = testNICVNetResources + `
Expand All @@ -1547,50 +1562,62 @@ var testAccVirtualMachineTemplateConfigMultipleNICs = testNICVNetResources + `
name = "test-virtual_machine"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
memory = 128
cpu = 0.1
context = {
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
graphics {
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
type = "VNC"
listen = "0.0.0.0"
keymap = "en-us"
}
os {
arch = "x86_64"
boot = ""
arch = "x86_64"
boot = ""
}
tags = {
env = "prod"
customer = "test"
env = "prod"
customer = "test"
}
keep_nic_order = false
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.112"
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.112"
ip6_global = "2001:db8:abcd::1"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.132"
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.132"
ip6_global = "2001:db8:abcd::2"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.113"
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.113"
ip6_global = "2001:db8:abcd::3"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.133"
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.133"
ip6_global = "2001:db8:abcd::4"
ip6_link = "FE80::C000:1DFF:FEE0:0"
}
timeout = 5
}
}
`

var testAccVirtualMachineTemplateConfigMultipleNICsOrderedUpdate = testNICVNetResources + `
Expand All @@ -1599,11 +1626,11 @@ var testAccVirtualMachineTemplateConfigMultipleNICsOrderedUpdate = testNICVNetRe
name = "test-virtual_machine"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
memory = 128
cpu = 0.1
context = {
NETWORK = "YES"
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
Expand All @@ -1619,7 +1646,7 @@ var testAccVirtualMachineTemplateConfigMultipleNICsOrderedUpdate = testNICVNetRe
}
tags = {
env = "prod"
env = "prod"
customer = "test"
}
Expand Down Expand Up @@ -1651,11 +1678,11 @@ resource "opennebula_virtual_machine" "test" {
name = "test-virtual_machine"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
memory = 128
cpu = 0.1
context = {
NETWORK = "YES"
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
Expand All @@ -1671,7 +1698,7 @@ resource "opennebula_virtual_machine" "test" {
}
tags = {
env = "prod"
env = "prod"
customer = "test"
}
Expand All @@ -1687,11 +1714,11 @@ resource "opennebula_template" "template" {
name = "test-template"
group = "oneadmin"
permissions = "642"
memory = 128
cpu = 0.1
memory = 128
cpu = 0.1
context = {
NETWORK = "YES"
NETWORK = "YES"
SET_HOSTNAME = "$NAME"
}
Expand All @@ -1703,8 +1730,8 @@ resource "opennebula_template" "template" {
nic {
network_id = opennebula_virtual_network.network1.id
ip = "172.16.100.131"
model = "virtio"
ip = "172.16.100.131"
model = "virtio"
virtio_queues = "2"
}
Expand Down Expand Up @@ -1735,9 +1762,9 @@ resource "opennebula_virtual_machine" "test" {
template_id = opennebula_template.template.id
nic {
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.111"
model = "virtio"
network_id = opennebula_virtual_network.network2.id
ip = "172.16.100.111"
model = "virtio"
virtio_queues = "2"
}
Expand Down
Loading

0 comments on commit 53c523e

Please sign in to comment.