cloudstack: cs_instance: add domain and account
This commit is contained in:
parent
8afc822d0c
commit
c5514e0618
1 changed files with 57 additions and 12 deletions
|
@ -106,6 +106,16 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: []
|
default: []
|
||||||
aliases: [ 'security_group' ]
|
aliases: [ 'security_group' ]
|
||||||
|
domain:
|
||||||
|
description:
|
||||||
|
- Domain the instance is related to.
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
|
account:
|
||||||
|
description:
|
||||||
|
- Account the instance is related to.
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
project:
|
project:
|
||||||
description:
|
description:
|
||||||
- Name of the project the instance to be deployed in.
|
- Name of the project the instance to be deployed in.
|
||||||
|
@ -252,6 +262,16 @@ ssh_key:
|
||||||
returned: success
|
returned: success
|
||||||
type: string
|
type: string
|
||||||
sample: key@work
|
sample: key@work
|
||||||
|
domain:
|
||||||
|
description: Domain the instance is related to.
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample: example domain
|
||||||
|
account:
|
||||||
|
description: Account the instance is related to.
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample: example account
|
||||||
project:
|
project:
|
||||||
description: Name of project the instance is related to.
|
description: Name of project the instance is related to.
|
||||||
returned: success
|
returned: success
|
||||||
|
@ -352,8 +372,15 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
if template and iso:
|
if template and iso:
|
||||||
self.module.fail_json(msg="Template are ISO are mutually exclusive.")
|
self.module.fail_json(msg="Template are ISO are mutually exclusive.")
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
if template:
|
if template:
|
||||||
templates = self.cs.listTemplates(templatefilter='executable')
|
args['templatefilter'] = 'executable'
|
||||||
|
templates = self.cs.listTemplates(**args)
|
||||||
if templates:
|
if templates:
|
||||||
for t in templates['template']:
|
for t in templates['template']:
|
||||||
if template in [ t['displaytext'], t['name'], t['id'] ]:
|
if template in [ t['displaytext'], t['name'], t['id'] ]:
|
||||||
|
@ -361,7 +388,8 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
self.module.fail_json(msg="Template '%s' not found" % template)
|
self.module.fail_json(msg="Template '%s' not found" % template)
|
||||||
|
|
||||||
elif iso:
|
elif iso:
|
||||||
isos = self.cs.listIsos()
|
args['isofilter'] = 'executable'
|
||||||
|
isos = self.cs.listIsos(**args)
|
||||||
if isos:
|
if isos:
|
||||||
for i in isos['iso']:
|
for i in isos['iso']:
|
||||||
if iso in [ i['displaytext'], i['name'], i['id'] ]:
|
if iso in [ i['displaytext'], i['name'], i['id'] ]:
|
||||||
|
@ -375,7 +403,10 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
if not disk_offering:
|
if not disk_offering:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
disk_offerings = self.cs.listDiskOfferings()
|
args = {}
|
||||||
|
args['domainid'] = self.get_domain('id')
|
||||||
|
|
||||||
|
disk_offerings = self.cs.listDiskOfferings(**args)
|
||||||
if disk_offerings:
|
if disk_offerings:
|
||||||
for d in disk_offerings['diskoffering']:
|
for d in disk_offerings['diskoffering']:
|
||||||
if disk_offering in [ d['displaytext'], d['name'], d['id'] ]:
|
if disk_offering in [ d['displaytext'], d['name'], d['id'] ]:
|
||||||
|
@ -388,9 +419,12 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
if not instance:
|
if not instance:
|
||||||
instance_name = self.module.params.get('name')
|
instance_name = self.module.params.get('name')
|
||||||
|
|
||||||
args = {}
|
args = {}
|
||||||
args['projectid'] = self.get_project_id()
|
args['account'] = self.get_account('name')
|
||||||
args['zoneid'] = self.get_zone_id()
|
args['domainid'] = self.get_domain('id')
|
||||||
|
args['projectid'] = self.get_project('id')
|
||||||
|
args['zoneid'] = self.get_zone('id')
|
||||||
|
|
||||||
instances = self.cs.listVirtualMachines(**args)
|
instances = self.cs.listVirtualMachines(**args)
|
||||||
if instances:
|
if instances:
|
||||||
for v in instances['virtualmachine']:
|
for v in instances['virtualmachine']:
|
||||||
|
@ -405,9 +439,12 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
if not network_names:
|
if not network_names:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
args = {}
|
args = {}
|
||||||
args['zoneid'] = self.get_zone_id()
|
args['account'] = self.get_account('name')
|
||||||
args['projectid'] = self.get_project_id()
|
args['domainid'] = self.get_domain('id')
|
||||||
|
args['projectid'] = self.get_project('id')
|
||||||
|
args['zoneid'] = self.get_zone('id')
|
||||||
|
|
||||||
networks = self.cs.listNetworks(**args)
|
networks = self.cs.listNetworks(**args)
|
||||||
if not networks:
|
if not networks:
|
||||||
self.module.fail_json(msg="No networks available")
|
self.module.fail_json(msg="No networks available")
|
||||||
|
@ -458,9 +495,11 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
|
|
||||||
args = {}
|
args = {}
|
||||||
args['templateid'] = self.get_template_or_iso_id()
|
args['templateid'] = self.get_template_or_iso_id()
|
||||||
args['zoneid'] = self.get_zone_id()
|
args['zoneid'] = self.get_zone('id')
|
||||||
args['serviceofferingid'] = self.get_service_offering_id()
|
args['serviceofferingid'] = self.get_service_offering_id()
|
||||||
args['projectid'] = self.get_project_id()
|
args['account'] = self.get_account('name')
|
||||||
|
args['domainid'] = self.get_domain('id')
|
||||||
|
args['projectid'] = self.get_project('id')
|
||||||
args['diskofferingid'] = self.get_disk_offering_id()
|
args['diskofferingid'] = self.get_disk_offering_id()
|
||||||
args['networkids'] = self.get_network_ids()
|
args['networkids'] = self.get_network_ids()
|
||||||
args['hypervisor'] = self.get_hypervisor()
|
args['hypervisor'] = self.get_hypervisor()
|
||||||
|
@ -503,7 +542,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
args_ssh_key = {}
|
args_ssh_key = {}
|
||||||
args_ssh_key['id'] = instance['id']
|
args_ssh_key['id'] = instance['id']
|
||||||
args_ssh_key['keypair'] = self.module.params.get('ssh_key')
|
args_ssh_key['keypair'] = self.module.params.get('ssh_key')
|
||||||
args_ssh_key['projectid'] = self.get_project_id()
|
args_ssh_key['projectid'] = self.get_project('id')
|
||||||
|
|
||||||
if self._has_changed(args_service_offering, instance) or \
|
if self._has_changed(args_service_offering, instance) or \
|
||||||
self._has_changed(args_instance_update, instance) or \
|
self._has_changed(args_instance_update, instance) or \
|
||||||
|
@ -668,6 +707,10 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
self.result['display_name'] = instance['displayname']
|
self.result['display_name'] = instance['displayname']
|
||||||
if 'group' in instance:
|
if 'group' in instance:
|
||||||
self.result['group'] = instance['group']
|
self.result['group'] = instance['group']
|
||||||
|
if 'domain' in instance:
|
||||||
|
self.result['domain'] = instance['domain']
|
||||||
|
if 'account' in instance:
|
||||||
|
self.result['account'] = instance['account']
|
||||||
if 'project' in instance:
|
if 'project' in instance:
|
||||||
self.result['project'] = instance['project']
|
self.result['project'] = instance['project']
|
||||||
if 'publicip' in instance:
|
if 'publicip' in instance:
|
||||||
|
@ -732,6 +775,8 @@ def main():
|
||||||
hypervisor = dict(default=None),
|
hypervisor = dict(default=None),
|
||||||
security_groups = dict(type='list', aliases=[ 'security_group' ], default=[]),
|
security_groups = dict(type='list', aliases=[ 'security_group' ], default=[]),
|
||||||
affinity_groups = dict(type='list', aliases=[ 'affinity_group' ], default=[]),
|
affinity_groups = dict(type='list', aliases=[ 'affinity_group' ], default=[]),
|
||||||
|
domain = dict(default=None),
|
||||||
|
account = dict(default=None),
|
||||||
project = dict(default=None),
|
project = dict(default=None),
|
||||||
user_data = dict(default=None),
|
user_data = dict(default=None),
|
||||||
zone = dict(default=None),
|
zone = dict(default=None),
|
||||||
|
|
Loading…
Reference in a new issue