mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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):
|
||||
|
@ -166,20 +171,20 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
def __init__(self, module):
|
||||
super(AnsibleCloudStackStaticNat, self).__init__(module)
|
||||
self.returns = {
|
||||
'virtualmachinedisplayname': 'vm_display_name',
|
||||
'virtualmachinename': 'vm_name',
|
||||
'ipaddress': 'ip_address',
|
||||
'vmipaddress': 'vm_guest_ip',
|
||||
'virtualmachinedisplayname': 'vm_display_name',
|
||||
'virtualmachinename': 'vm_name',
|
||||
'ipaddress': 'ip_address',
|
||||
'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']:
|
||||
|
@ -242,17 +245,17 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
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),
|
||||
state = dict(choices=['present', 'absent'], default='present'),
|
||||
zone = dict(default=None),
|
||||
domain = dict(default=None),
|
||||
account = dict(default=None),
|
||||
project = dict(default=None),
|
||||
poll_async = dict(type='bool', default=True),
|
||||
ip_address=dict(required=True),
|
||||
vm=dict(),
|
||||
vm_guest_ip=dict(),
|
||||
network=dict(),
|
||||
vpc=dict(),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
zone=dict(),
|
||||
domain=dict(),
|
||||
account=dict(),
|
||||
project=dict(),
|
||||
poll_async=dict(type='bool', default=True),
|
||||
))
|
||||
|
||||
module = AnsibleModule(
|
||||
|
@ -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