cloudstack: cs_portforward: implement vpc support (#19044)

* cloudstack: cs_portforward: implement vpc support

* cloudstack: cs_portforward: add vpc and network to returns

* cloudstack: cs_portforward: networkid must not be used for rule listing

* cloudstack: fail for get_network when vpc but no network name

This seem to be a global pattern for get_network, we want to enforce a
network name to be set if a vpn param is given.

This is used for cs_portforward.

* cloudstack: cs_portforward: doc: fix defaults for vpc, network
pull/18616/merge
René Moser 8 years ago committed by GitHub
parent 577d0e43ba
commit a6f887ce6e

@ -274,6 +274,9 @@ class AnsibleCloudStack(object):
network = self.module.params.get('network')
if not network:
vpc_name = self.get_vpc(key='name')
if vpc_name:
self.module.fail_json(msg="Could not find network for VPC '%s' due missing argument: network" % vpc_name)
return None
args = {
@ -383,6 +386,7 @@ class AnsibleCloudStack(object):
'domainid': self.get_domain(key='id'),
'projectid': self.get_project(key='id'),
'zoneid': self.get_zone(key='id'),
'networkid': self.get_network(key='id'),
'vpcid': vpc_id,
}
vms = self.cs.listVirtualMachines(**args)

@ -84,6 +84,18 @@ options:
- VM guest NIC secondary IP address for the port forwarding rule.
required: false
default: false
network:
description:
- Name of the network.
required: false
default: null
version_added: "2.3"
vpc:
description:
- Name of the VPC.
required: false
default: null
version_added: "2.3"
domain:
description:
- Domain the C(vm) is related to.
@ -205,6 +217,18 @@ vm_guest_ip:
returned: success
type: string
sample: 10.101.65.152
vpc:
description: Name of the VPC.
version_added: "2.3"
returned: success
type: string
sample: my_vpc
network:
description: Name of the network.
version_added: "2.3"
returned: success
type: string
sample: dmz
'''
# import cloudstack common
@ -279,6 +303,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
args['virtualmachineid'] = self.get_vm(key='id')
args['account'] = self.get_account(key='name')
args['domainid'] = self.get_domain(key='id')
args['networkid'] = self.get_network(key='id')
portforwarding_rule = None
self.result['changed'] = True
@ -300,6 +325,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
args['vmguestip'] = self.get_vm_guest_ip()
args['ipaddressid'] = self.get_ip_address(key='id')
args['virtualmachineid'] = self.get_vm(key='id')
args['networkid'] = self.get_network(key='id')
if self.has_changed(args, portforwarding_rule):
self.result['changed'] = True
@ -332,8 +358,16 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
def get_result(self, portforwarding_rule):
super(AnsibleCloudStackPortforwarding, self).get_result(portforwarding_rule)
network_name = self.get_network(key='name')
if network_name:
self.result['network'] = network_name
vpc_name = self.get_vpc(key='name')
if vpc_name:
self.result['vpc'] = vpc_name
if portforwarding_rule:
# Bad bad API does not always return int when it should.
for search_key, return_key in self.returns_to_int.items():
if search_key in portforwarding_rule:
self.result[return_key] = int(portforwarding_rule[search_key])
@ -353,6 +387,8 @@ def main():
open_firewall = dict(type='bool', default=False),
vm_guest_ip = dict(default=None),
vm = dict(default=None),
vpc = dict(default=None),
network = dict(default=None),
zone = dict(default=None),
domain = dict(default=None),
account = dict(default=None),

Loading…
Cancel
Save