diff --git a/lib/ansible/modules/cloud/cloudstack/cs_vlan_ip_range.py b/lib/ansible/modules/cloud/cloudstack/cs_vlan_ip_range.py index c7f0f38b534..4d3983205bf 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_vlan_ip_range.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_vlan_ip_range.py @@ -22,7 +22,11 @@ options: network: description: - The network name or id. - required: true + - Required if I(for_virtual_network) and I(physical_network) are not set. + physical_network: + description: + - The physical network name or id. + type: str start_ip: description: - The beginning IPv4 address in the VLAN IP range. @@ -84,6 +88,8 @@ options: for_virtual_network: description: - true if VLAN is of Virtual type, false if Direct. + - If set to C(true) but neither I(physical_network) or I(network) is set CloudStack will try to add the + VLAN range to the Physical Network with a Public traffic type. type: bool default: false extends_documentation_fragment: cloudstack @@ -269,6 +275,8 @@ class AnsibleCloudStackVlanIpRange(AnsibleCloudStack): 'networkid': self.get_network(key='id'), 'forvirtualnetwork': self.module.params.get('for_virtual_network'), } + if self.module.params.get('physical_network'): + args['physicalnetworkid'] = self.get_physical_network(key='id') if not self.module.check_mode: res = self.query_api('createVlanIpRange', **args) @@ -296,7 +304,8 @@ class AnsibleCloudStackVlanIpRange(AnsibleCloudStack): def main(): argument_spec = cs_argument_spec() argument_spec.update(dict( - network=dict(type='str', required=True), + network=dict(type='str'), + physical_network=dict(type='str'), zone=dict(type='str'), start_ip=dict(type='str', required=True), end_ip=dict(type='str'), diff --git a/test/integration/targets/cs_vlan_ip_range/tasks/main.yml b/test/integration/targets/cs_vlan_ip_range/tasks/main.yml index 6fead98d2a0..48c663e5fe4 100644 --- a/test/integration/targets/cs_vlan_ip_range/tasks/main.yml +++ b/test/integration/targets/cs_vlan_ip_range/tasks/main.yml @@ -369,3 +369,67 @@ that: - ipr_net is successful - ipr_net is changed + +# Create a new zone - the default one is enabled +- name: assure zone for tests + cs_zone: + name: cs-test-zone + state: present + dns1: 8.8.8.8 + network_type: advanced + register: cszone + +- name: ensure the zone is disabled + cs_zone: + name: "{{ cszone.name }}" + state: disabled + +- name: setup a network for tests + cs_physical_network: + name: net01 + zone: "{{ cszone.name }}" + isolation_method: VLAN + broadcast_domain_range: ZONE + state: present + register: public_network + +- name: setup public network traffic + cs_traffic_type: + physical_network: "{{ public_network.name }}" + traffic_type: Public + kvm_networklabel: cloudbr1 + zone: "{{ public_network.zone }}" + +- name: test adding a public IP range + cs_vlan_ip_range: + end_ip: 10.0.3.250 + start_ip: 10.0.3.10 + zone: "{{ cszone.name }}" + netmask: 255.255.255.0 + for_virtual_network: 'yes' + gateway: 10.0.3.2 + vlan: untagged + register: public_range +- name: verify test adding a public IP range + assert: + that: + - public_range is successful + - public_range is changed + - public_range.physical_network == public_network.id + - public_range.vlan == 'vlan://untagged' + - public_range.gateway == '10.0.3.2' + - public_range.netmask == '255.255.255.0' + - public_range.zone == cszone.name + - public_range.start_ip == '10.0.3.10' + - public_range.end_ip == '10.0.3.250' + +- name: cleanup the network + cs_physical_network: + name: net01 + zone: "{{ cszone.name }}" + state: absent + +- name: cleanup the zone + cs_zone: + name: "{{ cszone.name }}" + state: absent \ No newline at end of file