cloudstack: cs_staticnat: fix VPC support (#22626)
- Fix the VPC support by adding network to create and update methods - Fix pep8
This commit is contained in:
parent
a227a4ebb4
commit
38b9f055d7
1 changed files with 37 additions and 35 deletions
|
@ -55,7 +55,7 @@ options:
|
|||
version_added: "2.2"
|
||||
vpc:
|
||||
description:
|
||||
- Name of the VPC.
|
||||
- VPC the network related to.
|
||||
required: false
|
||||
default: null
|
||||
version_added: "2.3"
|
||||
|
@ -157,8 +157,13 @@ domain:
|
|||
sample: example domain
|
||||
'''
|
||||
|
||||
# import cloudstack common
|
||||
from ansible.module_utils.cloudstack import *
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
||||
|
||||
class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
||||
|
@ -172,14 +177,14 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
'vmipaddress': 'vm_guest_ip',
|
||||
}
|
||||
|
||||
|
||||
def create_static_nat(self, ip_address):
|
||||
self.result['changed'] = True
|
||||
args = {}
|
||||
args['virtualmachineid'] = self.get_vm(key='id')
|
||||
args['ipaddressid'] = ip_address['id']
|
||||
args['vmguestip'] = self.get_vm_guest_ip()
|
||||
args['networkid'] = self.get_network(key='id')
|
||||
args = {
|
||||
'virtualmachineid': self.get_vm(key='id'),
|
||||
'ipaddressid': ip_address['id'],
|
||||
'vmguestip': self.get_vm_guest_ip(),
|
||||
'networkid': self.get_network(key='id')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.enableStaticNat(**args)
|
||||
if 'errortext' in res:
|
||||
|
@ -190,14 +195,14 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
ip_address = self.get_ip_address()
|
||||
return ip_address
|
||||
|
||||
|
||||
def update_static_nat(self, ip_address):
|
||||
args = {}
|
||||
args['virtualmachineid'] = self.get_vm(key='id')
|
||||
args['ipaddressid'] = ip_address['id']
|
||||
args['vmguestip'] = self.get_vm_guest_ip()
|
||||
|
||||
# make an alias, so we can use _has_changed()
|
||||
args = {
|
||||
'virtualmachineid': self.get_vm(key='id'),
|
||||
'ipaddressid': ip_address['id'],
|
||||
'vmguestip': self.get_vm_guest_ip(),
|
||||
'networkid': self.get_network(key='id')
|
||||
}
|
||||
# make an alias, so we can use has_changed()
|
||||
ip_address['vmguestip'] = ip_address['vmipaddress']
|
||||
if self.has_changed(args, ip_address, ['vmguestip', 'virtualmachineid']):
|
||||
self.result['changed'] = True
|
||||
|
@ -215,7 +220,6 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
ip_address = self.get_ip_address()
|
||||
return ip_address
|
||||
|
||||
|
||||
def present_static_nat(self):
|
||||
ip_address = self.get_ip_address()
|
||||
if not ip_address['isstaticnat']:
|
||||
|
@ -224,7 +228,6 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
ip_address = self.update_static_nat(ip_address)
|
||||
return ip_address
|
||||
|
||||
|
||||
def absent_static_nat(self):
|
||||
ip_address = self.get_ip_address()
|
||||
if ip_address['isstaticnat']:
|
||||
|
@ -243,15 +246,15 @@ def main():
|
|||
argument_spec = cs_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
ip_address=dict(required=True),
|
||||
vm = dict(default=None),
|
||||
vm_guest_ip = dict(default=None),
|
||||
network = dict(default=None),
|
||||
vpc = dict(default=None),
|
||||
vm=dict(),
|
||||
vm_guest_ip=dict(),
|
||||
network=dict(),
|
||||
vpc=dict(),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
zone = dict(default=None),
|
||||
domain = dict(default=None),
|
||||
account = dict(default=None),
|
||||
project = dict(default=None),
|
||||
zone=dict(),
|
||||
domain=dict(),
|
||||
account=dict(),
|
||||
project=dict(),
|
||||
poll_async=dict(type='bool', default=True),
|
||||
))
|
||||
|
||||
|
@ -277,7 +280,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue