Check to see existence of same named/location system before creation. (#2150)

This commit is contained in:
kubilus1 2016-05-18 03:26:58 -04:00 committed by Matt Clay
parent 009f5f716a
commit f3d248de9a

View file

@ -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__)))