mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: cs_ip_address: implement VPC support (#3403)
This commit is contained in:
parent
93ebe0f7c1
commit
3c48b4a7a1
1 changed files with 18 additions and 44 deletions
|
@ -139,62 +139,34 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
|
||||||
'ipaddress': 'ip_address',
|
'ipaddress': 'ip_address',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#TODO: Add to parent class, duplicated in cs_network
|
|
||||||
def get_network(self, key=None, network=None):
|
|
||||||
if not network:
|
|
||||||
network = self.module.params.get('network')
|
|
||||||
|
|
||||||
if not network:
|
|
||||||
return None
|
|
||||||
|
|
||||||
args = {}
|
|
||||||
args['account'] = self.get_account('name')
|
|
||||||
args['domainid'] = self.get_domain('id')
|
|
||||||
args['projectid'] = self.get_project('id')
|
|
||||||
args['zoneid'] = self.get_zone('id')
|
|
||||||
|
|
||||||
networks = self.cs.listNetworks(**args)
|
|
||||||
if not networks:
|
|
||||||
self.module.fail_json(msg="No networks available")
|
|
||||||
|
|
||||||
for n in networks['network']:
|
|
||||||
if network in [ n['displaytext'], n['name'], n['id'] ]:
|
|
||||||
return self._get_by_key(key, n)
|
|
||||||
self.module.fail_json(msg="Network '%s' not found" % network)
|
|
||||||
|
|
||||||
|
|
||||||
#TODO: Merge changes here with parent class
|
|
||||||
def get_ip_address(self, key=None):
|
def get_ip_address(self, key=None):
|
||||||
if self.ip_address:
|
if self.ip_address:
|
||||||
return self._get_by_key(key, self.ip_address)
|
return self._get_by_key(key, self.ip_address)
|
||||||
|
|
||||||
ip_address = self.module.params.get('ip_address')
|
ip_address = self.module.params.get('ip_address')
|
||||||
if not ip_address:
|
args = {
|
||||||
self.module.fail_json(msg="IP address param 'ip_address' is required")
|
'ipaddress': self.module.params.get('ip_address'),
|
||||||
|
'account': self.get_account(key='name'),
|
||||||
args = {}
|
'domainid': self.get_domain(key='id'),
|
||||||
args['ipaddress'] = ip_address
|
'projectid': self.get_project(key='id'),
|
||||||
args['account'] = self.get_account(key='name')
|
'vpcid': self.get_vpc(key='id'),
|
||||||
args['domainid'] = self.get_domain(key='id')
|
}
|
||||||
args['projectid'] = self.get_project(key='id')
|
|
||||||
args['vpcid'] = self.get_vpc(key='id')
|
|
||||||
ip_addresses = self.cs.listPublicIpAddresses(**args)
|
ip_addresses = self.cs.listPublicIpAddresses(**args)
|
||||||
|
|
||||||
if ip_addresses:
|
if ip_addresses:
|
||||||
self.ip_address = ip_addresses['publicipaddress'][0]
|
self.ip_address = ip_addresses['publicipaddress'][0]
|
||||||
return self._get_by_key(key, self.ip_address)
|
return self._get_by_key(key, self.ip_address)
|
||||||
|
|
||||||
|
|
||||||
def associate_ip_address(self):
|
def associate_ip_address(self):
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
args = {}
|
args = {
|
||||||
args['account'] = self.get_account(key='name')
|
'account': self.get_account(key='name'),
|
||||||
args['domainid'] = self.get_domain(key='id')
|
'domainid': self.get_domain(key='id'),
|
||||||
args['projectid'] = self.get_project(key='id')
|
'projectid': self.get_project(key='id'),
|
||||||
args['networkid'] = self.get_network(key='id')
|
'networkid': self.get_network(key='id'),
|
||||||
args['zoneid'] = self.get_zone(key='id')
|
'zoneid': self.get_zone(key='id'),
|
||||||
ip_address = {}
|
}
|
||||||
|
ip_address = None
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.associateIpAddress(**args)
|
res = self.cs.associateIpAddress(**args)
|
||||||
if 'errortext' in res:
|
if 'errortext' in res:
|
||||||
|
@ -205,7 +177,6 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
|
||||||
ip_address = self.poll_job(res, 'ipaddress')
|
ip_address = self.poll_job(res, 'ipaddress')
|
||||||
return ip_address
|
return ip_address
|
||||||
|
|
||||||
|
|
||||||
def disassociate_ip_address(self):
|
def disassociate_ip_address(self):
|
||||||
ip_address = self.get_ip_address()
|
ip_address = self.get_ip_address()
|
||||||
if not ip_address:
|
if not ip_address:
|
||||||
|
@ -241,6 +212,9 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
required_together=cs_required_together(),
|
required_together=cs_required_together(),
|
||||||
|
required_if=[
|
||||||
|
('state', 'absent', ['ip_address']),
|
||||||
|
],
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue