cloudstack: move duplicate common code to utils
This commit is contained in:
parent
35b699b99c
commit
b85b4de4e9
2 changed files with 0 additions and 56 deletions
|
@ -227,33 +227,6 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
|
|||
'privateendport': 'private_end_port',
|
||||
}
|
||||
self.portforwarding_rule = None
|
||||
self.vm_default_nic = None
|
||||
|
||||
|
||||
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_portforwarding_rule(self):
|
||||
|
|
|
@ -160,35 +160,6 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
'ipaddress': 'ip_address',
|
||||
'vmipaddress': 'vm_guest_ip',
|
||||
}
|
||||
self.vm_default_nic = None
|
||||
|
||||
|
||||
# TODO: move it to cloudstack utils, also used in cs_portforward
|
||||
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)
|
||||
|
||||
|
||||
# TODO: move it to cloudstack utils, also used in cs_portforward
|
||||
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 create_static_nat(self, ip_address):
|
||||
|
|
Loading…
Add table
Reference in a new issue