cloudstack: move common code to module_utils (#17635)
This commit is contained in:
parent
4235bda192
commit
6247e7bc38
1 changed files with 27 additions and 0 deletions
|
@ -109,6 +109,7 @@ class AnsibleCloudStack(object):
|
|||
self.vpc = None
|
||||
self.zone = None
|
||||
self.vm = None
|
||||
self.vm_default_nic = None
|
||||
self.os_type = None
|
||||
self.hypervisor = None
|
||||
self.capabilities = None
|
||||
|
@ -287,6 +288,32 @@ class AnsibleCloudStack(object):
|
|||
return self._get_by_key(key, self.ip_address)
|
||||
|
||||
|
||||
def get_vm_guest_ip(self):
|
||||
vm_guest_ip = self.module.params.get('vm_guest_ip')
|
||||
default_nic = self.get_vm_default_nic()
|
||||
|
||||
if not vm_guest_ip:
|
||||
return default_nic['ipaddress']
|
||||
|
||||
for secondary_ip in default_nic['secondaryip']:
|
||||
if vm_guest_ip == secondary_ip['ipaddress']:
|
||||
return vm_guest_ip
|
||||
self.module.fail_json(msg="Secondary IP '%s' not assigned to VM" % vm_guest_ip)
|
||||
|
||||
|
||||
def get_vm_default_nic(self):
|
||||
if self.vm_default_nic:
|
||||
return self.vm_default_nic
|
||||
|
||||
nics = self.cs.listNics(virtualmachineid=self.get_vm(key='id'))
|
||||
if nics:
|
||||
for n in nics['nic']:
|
||||
if n['isdefault']:
|
||||
self.vm_default_nic = n
|
||||
return self.vm_default_nic
|
||||
self.module.fail_json(msg="No default IP address of VM '%s' found" % self.module.params.get('vm'))
|
||||
|
||||
|
||||
def get_vm(self, key=None):
|
||||
if self.vm:
|
||||
return self._get_by_key(key, self.vm)
|
||||
|
|
Loading…
Reference in a new issue