Check to see existence of same named/location system before creation. (#2150)
This commit is contained in:
parent
009f5f716a
commit
f3d248de9a
1 changed files with 12 additions and 1 deletions
|
@ -225,6 +225,16 @@ except ImportError:
|
||||||
|
|
||||||
def create_virtual_instance(module):
|
def create_virtual_instance(module):
|
||||||
|
|
||||||
|
instances = vsManager.list_instances(
|
||||||
|
hostname = module.params.get('hostname'),
|
||||||
|
domain = module.params.get('domain'),
|
||||||
|
datacenter = module.params.get('datacenter')
|
||||||
|
)
|
||||||
|
|
||||||
|
if instances:
|
||||||
|
return False, None
|
||||||
|
|
||||||
|
|
||||||
# Check if OS or Image Template is provided (Can't be both, defaults to OS)
|
# Check if OS or Image Template is provided (Can't be both, defaults to OS)
|
||||||
if (module.params.get('os_code') != None and module.params.get('os_code') != ''):
|
if (module.params.get('os_code') != None and module.params.get('os_code') != ''):
|
||||||
module.params['image_id'] = ''
|
module.params['image_id'] = ''
|
||||||
|
@ -303,6 +313,7 @@ def cancel_instance(module):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
instance_id=dict(),
|
instance_id=dict(),
|
||||||
|
@ -338,7 +349,7 @@ def main():
|
||||||
|
|
||||||
elif module.params.get('state') == 'present':
|
elif module.params.get('state') == 'present':
|
||||||
(changed, instance) = create_virtual_instance(module)
|
(changed, instance) = create_virtual_instance(module)
|
||||||
if module.params.get('wait') == True:
|
if module.params.get('wait') == True and instance:
|
||||||
(changed, instance) = wait_for_instance(module, instance['id'])
|
(changed, instance) = wait_for_instance(module, instance['id'])
|
||||||
|
|
||||||
module.exit_json(changed=changed, instance=json.loads(json.dumps(instance, default=lambda o: o.__dict__)))
|
module.exit_json(changed=changed, instance=json.loads(json.dumps(instance, default=lambda o: o.__dict__)))
|
||||||
|
|
Loading…
Reference in a new issue