Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B-515: fix ignored vlan_id #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.4.2 (Unreleased)

BUG FIXES:

* resources/opennebula_virtual_network: allow to set a `vlan_id` for ovswitch (#515)

# 1.4.1 (Unreleased)

FEATURES:
Expand Down
20 changes: 12 additions & 8 deletions opennebula/resource_opennebula_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,19 @@ func generateVn(d *schema.ResourceData) (string, error) {
tpl.Add(vnk.Name, vnname)
tpl.Add(vnk.VNMad, vnmad)

if mandatoryVLAN(vnmad) {
if d.Get("automatic_vlan_id") == true {
tpl.Add("AUTOMATIC_VLAN_ID", "YES")
} else if vlanid, ok := d.GetOk("vlan_id"); ok {
tpl.Add(vnk.VlanID, vlanid.(string))
} else {
return "", fmt.Errorf("You must specify a 'vlan_id' or set the flag 'automatic_vlan_id'")
}
vlanSet := false
if d.Get("automatic_vlan_id").(bool) {
tpl.Add("AUTOMATIC_VLAN_ID", "YES")
vlanSet = true
} else if vlanid, ok := d.GetOk("vlan_id"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to OpenNebula docs on ovswitch vnets, automatic_vlan_id should be ignored in case vlan_id is defined (https://docs.opennebula.io/6.10/open_cluster_deployment/networking_setup/openvswitch.html#defining-open-vswitch-network). Meaning that, if both params are defined, vlan_id should have priority => vlan_id should be checked first

tpl.Add(vnk.VlanID, vlanid.(string))
vlanSet = true
}

if mandatoryVLAN(vnmad) && !vlanSet {
return "", fmt.Errorf("you must specify a 'vlan_id' or set the flag 'automatic_vlan_id'")
}

if vnbridge, ok := d.GetOk("bridge"); ok {
tpl.Add(vnk.Bridge, vnbridge.(string))
}
Expand Down
Loading