cloudstack: use get_or_fallback() from cloudstack utils

This commit is contained in:
Rene Moser 2015-07-19 15:09:49 +02:00
parent 6c9410dce9
commit 8e6e9c782b
6 changed files with 14 additions and 59 deletions

View file

@ -216,18 +216,12 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
self.firewall_rule = None self.firewall_rule = None
def get_end_port(self):
if self.module.params.get('end_port'):
return self.module.params.get('end_port')
return self.module.params.get('start_port')
def get_firewall_rule(self): def get_firewall_rule(self):
if not self.firewall_rule: if not self.firewall_rule:
cidr = self.module.params.get('cidr') cidr = self.module.params.get('cidr')
protocol = self.module.params.get('protocol') protocol = self.module.params.get('protocol')
start_port = self.module.params.get('start_port') start_port = self.module.params.get('start_port')
end_port = self.get_end_port() end_port = self.get_or_fallback('end_port', 'start_port')
icmp_code = self.module.params.get('icmp_code') icmp_code = self.module.params.get('icmp_code')
icmp_type = self.module.params.get('icmp_type') icmp_type = self.module.params.get('icmp_type')
fw_type = self.module.params.get('type') fw_type = self.module.params.get('type')
@ -328,7 +322,7 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
args['cidrlist'] = self.module.params.get('cidr') args['cidrlist'] = self.module.params.get('cidr')
args['protocol'] = self.module.params.get('protocol') args['protocol'] = self.module.params.get('protocol')
args['startport'] = self.module.params.get('start_port') args['startport'] = self.module.params.get('start_port')
args['endport'] = self.get_end_port() args['endport'] = self.get_or_fallback('end_port', 'start_port')
args['icmptype'] = self.module.params.get('icmp_type') args['icmptype'] = self.module.params.get('icmp_type')
args['icmpcode'] = self.module.params.get('icmp_code') args['icmpcode'] = self.module.params.get('icmp_code')

View file

@ -500,13 +500,6 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
return user_data return user_data
def get_display_name(self):
display_name = self.module.params.get('display_name')
if not display_name:
display_name = self.module.params.get('name')
return display_name
def deploy_instance(self): def deploy_instance(self):
self.result['changed'] = True self.result['changed'] = True
@ -555,7 +548,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
args_instance_update = {} args_instance_update = {}
args_instance_update['id'] = instance['id'] args_instance_update['id'] = instance['id']
args_instance_update['group'] = self.module.params.get('group') args_instance_update['group'] = self.module.params.get('group')
args_instance_update['displayname'] = self.get_display_name() args_instance_update['displayname'] = self.get_or_fallback('display_name', 'name')
args_instance_update['userdata'] = self.get_user_data() args_instance_update['userdata'] = self.get_user_data()
args_instance_update['ostypeid'] = self.get_os_type(key='id') args_instance_update['ostypeid'] = self.get_os_type(key='id')

View file

@ -335,13 +335,6 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
self.network = None self.network = None
def get_or_fallback(self, key=None, fallback_key=None):
value = self.module.params.get(key)
if not value:
value = self.module.params.get(fallback_key)
return value
def get_vpc(self, key=None): def get_vpc(self, key=None):
vpc = self.module.params.get('vpc') vpc = self.module.params.get('vpc')
if not vpc: if not vpc:

View file

@ -217,18 +217,6 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
self.vm_default_nic = None self.vm_default_nic = None
def get_public_end_port(self):
if not self.module.params.get('public_end_port'):
return self.module.params.get('public_port')
return self.module.params.get('public_end_port')
def get_private_end_port(self):
if not self.module.params.get('private_end_port'):
return self.module.params.get('private_port')
return self.module.params.get('private_end_port')
def get_vm_guest_ip(self): def get_vm_guest_ip(self):
vm_guest_ip = self.module.params.get('vm_guest_ip') vm_guest_ip = self.module.params.get('vm_guest_ip')
default_nic = self.get_vm_default_nic() default_nic = self.get_vm_default_nic()
@ -259,9 +247,9 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
if not self.portforwarding_rule: if not self.portforwarding_rule:
protocol = self.module.params.get('protocol') protocol = self.module.params.get('protocol')
public_port = self.module.params.get('public_port') public_port = self.module.params.get('public_port')
public_end_port = self.get_public_end_port() public_end_port = self.get_or_fallback('public_end_port', 'public_port')
private_port = self.module.params.get('private_port') private_port = self.module.params.get('private_port')
private_end_port = self.get_private_end_port() private_end_port = self.get_or_fallback('private_end_port', 'private_port')
args = {} args = {}
args['ipaddressid'] = self.get_ip_address(key='id') args['ipaddressid'] = self.get_ip_address(key='id')
@ -290,9 +278,9 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
args = {} args = {}
args['protocol'] = self.module.params.get('protocol') args['protocol'] = self.module.params.get('protocol')
args['publicport'] = self.module.params.get('public_port') args['publicport'] = self.module.params.get('public_port')
args['publicendport'] = self.get_public_end_port() args['publicendport'] = self.get_or_fallback('public_end_port', 'public_port')
args['privateport'] = self.module.params.get('private_port') args['privateport'] = self.module.params.get('private_port')
args['privateendport'] = self.get_private_end_port() args['privateendport'] = self.get_or_fallback('private_end_port', 'private_port')
args['openfirewall'] = self.module.params.get('open_firewall') args['openfirewall'] = self.module.params.get('open_firewall')
args['vmguestip'] = self.get_vm_guest_ip() args['vmguestip'] = self.get_vm_guest_ip()
args['ipaddressid'] = self.get_ip_address(key='id') args['ipaddressid'] = self.get_ip_address(key='id')
@ -312,9 +300,9 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
args = {} args = {}
args['protocol'] = self.module.params.get('protocol') args['protocol'] = self.module.params.get('protocol')
args['publicport'] = self.module.params.get('public_port') args['publicport'] = self.module.params.get('public_port')
args['publicendport'] = self.get_public_end_port() args['publicendport'] = self.get_or_fallback('public_end_port', 'public_port')
args['privateport'] = self.module.params.get('private_port') args['privateport'] = self.module.params.get('private_port')
args['privateendport'] = self.get_private_end_port() args['privateendport'] = self.get_or_fallback('private_end_port', 'private_port')
args['openfirewall'] = self.module.params.get('open_firewall') args['openfirewall'] = self.module.params.get('open_firewall')
args['vmguestip'] = self.get_vm_guest_ip() args['vmguestip'] = self.get_vm_guest_ip()
args['ipaddressid'] = self.get_ip_address(key='id') args['ipaddressid'] = self.get_ip_address(key='id')

View file

@ -148,13 +148,6 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
self.project = None self.project = None
def get_displaytext(self):
displaytext = self.module.params.get('displaytext')
if not displaytext:
displaytext = self.module.params.get('name')
return displaytext
def get_project(self): def get_project(self):
if not self.project: if not self.project:
project = self.module.params.get('name') project = self.module.params.get('name')
@ -184,7 +177,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
def update_project(self, project): def update_project(self, project):
args = {} args = {}
args['id'] = project['id'] args['id'] = project['id']
args['displaytext'] = self.get_displaytext() args['displaytext'] = self.get_or_fallback('displaytext', 'name')
if self._has_changed(args, project): if self._has_changed(args, project):
self.result['changed'] = True self.result['changed'] = True
@ -205,7 +198,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
args = {} args = {}
args['name'] = self.module.params.get('name') args['name'] = self.module.params.get('name')
args['displaytext'] = self.get_displaytext() args['displaytext'] = self.get_or_fallback('displaytext', 'name')
args['account'] = self.get_account('name') args['account'] = self.get_account('name')
args['domainid'] = self.get_domain('id') args['domainid'] = self.get_domain('id')

View file

@ -222,18 +222,12 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack):
and cidr == rule['cidr'] and cidr == rule['cidr']
def get_end_port(self):
if self.module.params.get('end_port'):
return self.module.params.get('end_port')
return self.module.params.get('start_port')
def _get_rule(self, rules): def _get_rule(self, rules):
user_security_group_name = self.module.params.get('user_security_group') user_security_group_name = self.module.params.get('user_security_group')
cidr = self.module.params.get('cidr') cidr = self.module.params.get('cidr')
protocol = self.module.params.get('protocol') protocol = self.module.params.get('protocol')
start_port = self.module.params.get('start_port') start_port = self.module.params.get('start_port')
end_port = self.get_end_port() end_port = self.get_or_fallback('end_port', 'start_port')
icmp_code = self.module.params.get('icmp_code') icmp_code = self.module.params.get('icmp_code')
icmp_type = self.module.params.get('icmp_type') icmp_type = self.module.params.get('icmp_type')
@ -291,7 +285,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack):
args['protocol'] = self.module.params.get('protocol') args['protocol'] = self.module.params.get('protocol')
args['startport'] = self.module.params.get('start_port') args['startport'] = self.module.params.get('start_port')
args['endport'] = self.get_end_port() args['endport'] = self.get_or_fallback('end_port', 'start_port')
args['icmptype'] = self.module.params.get('icmp_type') args['icmptype'] = self.module.params.get('icmp_type')
args['icmpcode'] = self.module.params.get('icmp_code') args['icmpcode'] = self.module.params.get('icmp_code')
args['projectid'] = self.get_project('id') args['projectid'] = self.get_project('id')