mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: remove CloudStackException dep for several modules (#26874)
* cloudstack: cs_affinitygroup: remove CloudStackException dependency * cloudstack: cs_domain: remove CloudStackException dependency * cloudstack: cs_firewall: remove CloudStackException dependency * cloudstack: cs_host: remove CloudStackException dependency * cloudstack: cs_instancegroup: remove CloudStackException dependency * cloudstack: cs_pod: remove CloudStackException dependency * cloudstack: cs_configuration: remove CloudStackException dependency, fix pep8 * cloudstack: cs_cluster: remove CloudStackException dependency * cloudstack: cs_network_acl: remove CloudStackException dependency * cloudstack: cs_network_acl_rule: remove CloudStackException dependency * cloudstack: cs_zone_facts: remove CloudStackException dependency * cloudstack: cs_zone: remove CloudStackException dependency * cloudstack: cs_vpn_gateway: remove CloudStackException dependency * cloudstack: cs_vpc: remove CloudStackException dependency * cloudstack: cs_sshkeypair: remove CloudStackException dependency * cloudstack: cs_role: remove CloudStackException dependency * cloudstack: cs_ip_address: remove CloudStackException dependency * cloudstack: cs_ip_staticnat: remove CloudStackException dependency * cloudstack: cs_resourcelimit: remove CloudStackException dependency * cloudstack: cs_region: remove CloudStackException dependency * cloudstack: cs_project: remove CloudStackException dependency * cloudstack: cs_network: remove CloudStackException dependency * cloudstack: cs_loadbalancer_rule_member: remove CloudStackException dependency * cloudstack: cs_loadbalancer_rule: remove CloudStackException dependency * cloudstack: cs_iso: remove CloudStackException dependency
This commit is contained in:
parent
e228c7d021
commit
30ad30c470
26 changed files with 333 additions and 595 deletions
|
@ -131,7 +131,6 @@ account:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -155,7 +154,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
|
|||
'domainid': self.get_domain(key='id'),
|
||||
'name': self.module.params.get('name'),
|
||||
}
|
||||
affinity_groups = self.cs.listAffinityGroups(**args)
|
||||
affinity_groups = self.query_api('listAffinityGroups', **args)
|
||||
if affinity_groups:
|
||||
self.affinity_group = affinity_groups['affinitygroup'][0]
|
||||
return self.affinity_group
|
||||
|
@ -163,7 +162,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
|
|||
def get_affinity_type(self):
|
||||
affinity_type = self.module.params.get('affinty_type')
|
||||
|
||||
affinity_types = self.cs.listAffinityGroupTypes()
|
||||
affinity_types = self.query_api('listAffinityGroupTypes', )
|
||||
if affinity_types:
|
||||
if not affinity_type:
|
||||
return affinity_types['affinityGroupType'][0]['type']
|
||||
|
@ -187,10 +186,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
|
|||
'domainid': self.get_domain(key='id'),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createAffinityGroup(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createAffinityGroup', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if res and poll_async:
|
||||
|
@ -209,10 +205,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
|
|||
'domainid': self.get_domain(key='id'),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteAffinityGroup(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteAffinityGroup', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if res and poll_async:
|
||||
|
@ -239,7 +232,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_ag = AnsibleCloudStackAffinityGroup(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -250,9 +242,6 @@ def main():
|
|||
|
||||
result = acs_ag.get_result(affinity_group)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -234,7 +234,6 @@ pod:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
CS_HYPERVISORS
|
||||
|
@ -273,7 +272,7 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
|
|||
'name': self.module.params.get('pod'),
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
pods = self.cs.listPods(**args)
|
||||
pods = self.query_api('listPods', **args)
|
||||
if pods:
|
||||
return self._get_by_key(key, pods['pod'][0])
|
||||
self.module.fail_json(msg="Pod %s not found in zone %s" % (self.module.params.get('pod'), self.get_zone(key='name')))
|
||||
|
@ -285,13 +284,13 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
|
|||
uuid = self.module.params.get('id')
|
||||
if uuid:
|
||||
args['id'] = uuid
|
||||
clusters = self.cs.listClusters(**args)
|
||||
clusters = self.query_api('listClusters', **args)
|
||||
if clusters:
|
||||
self.cluster = clusters['cluster'][0]
|
||||
return self.cluster
|
||||
|
||||
args['name'] = self.module.params.get('name')
|
||||
clusters = self.cs.listClusters(**args)
|
||||
clusters = self.query_api('listClusters', **args)
|
||||
if clusters:
|
||||
self.cluster = clusters['cluster'][0]
|
||||
# fix different return from API then request argument given
|
||||
|
@ -335,7 +334,7 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
|
|||
|
||||
cluster = None
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.addCluster(**args)
|
||||
res = self.query_api('addCluster', **args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
# API returns a list as result CLOUDSTACK-9205
|
||||
|
@ -355,10 +354,9 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateCluster(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateCluster', **args)
|
||||
cluster = res['cluster']
|
||||
|
||||
return cluster
|
||||
|
||||
def absent_cluster(self):
|
||||
|
@ -369,10 +367,10 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
|
|||
args = {
|
||||
'id': cluster['id'],
|
||||
}
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteCluster(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('deleteCluster', **args)
|
||||
|
||||
return cluster
|
||||
|
||||
|
||||
|
@ -406,7 +404,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_cluster = AnsibleCloudStackCluster(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -417,9 +414,6 @@ def main():
|
|||
|
||||
result = acs_cluster.get_result(cluster)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -153,8 +153,13 @@ storage:
|
|||
sample: storage01
|
||||
'''
|
||||
|
||||
# import cloudstack common
|
||||
from ansible.module_utils.cloudstack import *
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
||||
|
||||
class AnsibleCloudStackConfiguration(AnsibleCloudStack):
|
||||
|
||||
|
@ -169,32 +174,31 @@ class AnsibleCloudStackConfiguration(AnsibleCloudStack):
|
|||
self.account = None
|
||||
self.cluster = None
|
||||
|
||||
|
||||
def _get_common_configuration_args(self):
|
||||
args = {}
|
||||
args['name'] = self.module.params.get('name')
|
||||
args['accountid'] = self.get_account(key='id')
|
||||
args['storageid'] = self.get_storage(key='id')
|
||||
args['zoneid'] = self.get_zone(key='id')
|
||||
args['clusterid'] = self.get_cluster(key='id')
|
||||
args = {
|
||||
'name': self.module.params.get('name'),
|
||||
'accountid': self.get_account(key='id'),
|
||||
'storageid': self.get_storage(key='id'),
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
'clusterid': self.get_cluster(key='id'),
|
||||
}
|
||||
return args
|
||||
|
||||
|
||||
def get_zone(self, key=None):
|
||||
# make sure we do net use the default zone
|
||||
zone = self.module.params.get('zone')
|
||||
if zone:
|
||||
return super(AnsibleCloudStackConfiguration, self).get_zone(key=key)
|
||||
|
||||
|
||||
def get_cluster(self, key=None):
|
||||
if not self.cluster:
|
||||
cluster_name = self.module.params.get('cluster')
|
||||
if not cluster_name:
|
||||
return None
|
||||
args = {}
|
||||
args['name'] = cluster_name
|
||||
clusters = self.cs.listClusters(**args)
|
||||
args = {
|
||||
'name': cluster_name,
|
||||
}
|
||||
clusters = self.query_api('listClusters', **args)
|
||||
if clusters:
|
||||
self.cluster = clusters['cluster'][0]
|
||||
self.result['cluster'] = self.cluster['name']
|
||||
|
@ -202,15 +206,15 @@ class AnsibleCloudStackConfiguration(AnsibleCloudStack):
|
|||
self.module.fail_json(msg="Cluster %s not found." % cluster_name)
|
||||
return self._get_by_key(key=key, my_dict=self.cluster)
|
||||
|
||||
|
||||
def get_storage(self, key=None):
|
||||
if not self.storage:
|
||||
storage_pool_name = self.module.params.get('storage')
|
||||
if not storage_pool_name:
|
||||
return None
|
||||
args = {}
|
||||
args['name'] = storage_pool_name
|
||||
storage_pools = self.cs.listStoragePools(**args)
|
||||
args = {
|
||||
'name': storage_pool_name,
|
||||
}
|
||||
storage_pools = self.query_api('listStoragePools', **args)
|
||||
if storage_pools:
|
||||
self.storage = storage_pools['storagepool'][0]
|
||||
self.result['storage'] = self.storage['name']
|
||||
|
@ -218,24 +222,21 @@ class AnsibleCloudStackConfiguration(AnsibleCloudStack):
|
|||
self.module.fail_json(msg="Storage pool %s not found." % storage_pool_name)
|
||||
return self._get_by_key(key=key, my_dict=self.storage)
|
||||
|
||||
|
||||
def get_configuration(self):
|
||||
configuration = None
|
||||
args = self._get_common_configuration_args()
|
||||
configurations = self.cs.listConfigurations(**args)
|
||||
configurations = self.query_api('listConfigurations', **args)
|
||||
if not configurations:
|
||||
self.module.fail_json(msg="Configuration %s not found." % args['name'])
|
||||
configuration = configurations['configuration'][0]
|
||||
return configuration
|
||||
|
||||
|
||||
def get_value(self):
|
||||
value = str(self.module.params.get('value'))
|
||||
if value in ('True', 'False'):
|
||||
value = value.lower()
|
||||
return value
|
||||
|
||||
|
||||
def present_configuration(self):
|
||||
configuration = self.get_configuration()
|
||||
args = self._get_common_configuration_args()
|
||||
|
@ -243,13 +244,10 @@ class AnsibleCloudStackConfiguration(AnsibleCloudStack):
|
|||
if self.has_changed(args, configuration, ['value']):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateConfiguration(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateConfiguration', **args)
|
||||
configuration = res['configuration']
|
||||
return configuration
|
||||
|
||||
|
||||
def get_result(self, configuration):
|
||||
self.result = super(AnsibleCloudStackConfiguration, self).get_result(configuration)
|
||||
if self.account:
|
||||
|
@ -259,15 +257,16 @@ class AnsibleCloudStackConfiguration(AnsibleCloudStack):
|
|||
self.result['zone'] = self.zone['name']
|
||||
return self.result
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = cs_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
name=dict(required=True),
|
||||
value=dict(type='str', required=True),
|
||||
zone = dict(default=None),
|
||||
storage = dict(default=None),
|
||||
cluster = dict(default=None),
|
||||
account = dict(default=None),
|
||||
zone=dict(),
|
||||
storage=dict(),
|
||||
cluster=dict(),
|
||||
account=dict(),
|
||||
domain=dict(default='ROOT')
|
||||
))
|
||||
|
||||
|
@ -277,17 +276,11 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_configuration = AnsibleCloudStackConfiguration(module)
|
||||
configuration = acs_configuration.present_configuration()
|
||||
result = acs_configuration.get_result(configuration)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -114,7 +114,6 @@ network_domain:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -149,7 +148,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
|
|||
'listall': True
|
||||
}
|
||||
|
||||
domains = self.cs.listDomains(**args)
|
||||
domains = self.query_api('listDomains', **args)
|
||||
if domains:
|
||||
for d in domains['domain']:
|
||||
if path == d['path'].lower():
|
||||
|
@ -194,9 +193,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
|
|||
'networkdomain': self.module.params.get('network_domain')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createDomain(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createDomain', **args)
|
||||
domain = res['domain']
|
||||
return domain
|
||||
|
||||
|
@ -208,9 +205,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
|
|||
if self.has_changed(args, domain):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateDomain(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateDomain', **args)
|
||||
domain = res['domain']
|
||||
return domain
|
||||
|
||||
|
@ -224,10 +219,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
|
|||
'id': domain['id'],
|
||||
'cleanup': self.module.params.get('clean_up')
|
||||
}
|
||||
res = self.cs.deleteDomain(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteDomain', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -251,7 +243,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_dom = AnsibleCloudStackDomain(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -262,9 +253,6 @@ def main():
|
|||
|
||||
result = acs_dom.get_result(domain)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -226,7 +226,6 @@ network:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -276,12 +275,12 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
|
|||
args['networkid'] = self.get_network(key='id')
|
||||
if not args['networkid']:
|
||||
self.module.fail_json(msg="missing required argument for type egress: network")
|
||||
firewall_rules = self.cs.listEgressFirewallRules(**args)
|
||||
firewall_rules = self.query_api('listEgressFirewallRules', **args)
|
||||
else:
|
||||
args['ipaddressid'] = self.get_ip_address('id')
|
||||
if not args['ipaddressid']:
|
||||
self.module.fail_json(msg="missing required argument for type ingress: ip_address")
|
||||
firewall_rules = self.cs.listFirewallRules(**args)
|
||||
firewall_rules = self.query_api('listFirewallRules', **args)
|
||||
|
||||
if firewall_rules and 'firewallrule' in firewall_rules:
|
||||
for rule in firewall_rules['firewallrule']:
|
||||
|
@ -342,13 +341,10 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
|
|||
if not self.module.check_mode:
|
||||
if fw_type == 'egress':
|
||||
args['networkid'] = self.get_network(key='id')
|
||||
res = self.cs.createEgressFirewallRule(**args)
|
||||
res = self.query_api('createEgressFirewallRule', **args)
|
||||
else:
|
||||
args['ipaddressid'] = self.get_ip_address('id')
|
||||
res = self.cs.createFirewallRule(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createFirewallRule', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -372,12 +368,9 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
|
|||
fw_type = self.module.params.get('type')
|
||||
if not self.module.check_mode:
|
||||
if fw_type == 'egress':
|
||||
res = self.cs.deleteEgressFirewallRule(**args)
|
||||
res = self.query_api('deleteEgressFirewallRule', **args)
|
||||
else:
|
||||
res = self.cs.deleteFirewallRule(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteFirewallRule', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -433,7 +426,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_fw = AnsibleCloudStackFirewall(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -444,9 +436,6 @@ def main():
|
|||
|
||||
result = acs_fw.get_result(fw_rule)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -349,7 +349,6 @@ zone:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
CS_HYPERVISORS
|
||||
|
@ -415,7 +414,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'name': pod_name,
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
pods = self.cs.listPods(**args)
|
||||
pods = self.query_api('listPods', **args)
|
||||
if pods:
|
||||
return self._get_by_key(key, pods['pod'][0])
|
||||
self.module.fail_json(msg="Pod %s not found" % pod_name)
|
||||
|
@ -428,7 +427,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'name': cluster_name,
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
clusters = self.cs.listClusters(**args)
|
||||
clusters = self.query_api('listClusters', **args)
|
||||
if clusters:
|
||||
return self._get_by_key(key, clusters['cluster'][0])
|
||||
self.module.fail_json(msg="Cluster %s not found" % cluster_name)
|
||||
|
@ -447,7 +446,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
args = {
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
res = self.cs.listHosts(**args)
|
||||
res = self.query_api('listHosts', **args)
|
||||
if res:
|
||||
for h in res['host']:
|
||||
if name in [h['ipaddress'], h['name']]:
|
||||
|
@ -530,9 +529,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'hosttags': self.get_host_tags(),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
host = self.cs.addHost(**args)
|
||||
if 'errortext' in host:
|
||||
self.module.fail_json(msg="Failed: '%s'" % host['errortext'])
|
||||
host = self.query_api('addHost', **args)
|
||||
host = host['host'][0]
|
||||
return host
|
||||
|
||||
|
@ -549,9 +546,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
if self.has_changed(args, host):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
host = self.cs.updateHost(**args)
|
||||
if 'errortext' in host:
|
||||
self.module.fail_json(msg="Failed: '%s'" % host['errortext'])
|
||||
host = self.query_api('updateHost', **args)
|
||||
host = host['host']
|
||||
|
||||
return host
|
||||
|
@ -566,9 +561,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
if not self.module.check_mode:
|
||||
res = self.enable_maintenance(host)
|
||||
if res:
|
||||
res = self.cs.deleteHost(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteHost', **args)
|
||||
return host
|
||||
|
||||
def enable_maintenance(self, host):
|
||||
|
@ -578,9 +571,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'id': host['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.prepareHostForMaintenance(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('prepareHostForMaintenance', **args)
|
||||
self.poll_job(res, 'host')
|
||||
host = self._poll_for_maintenance()
|
||||
return host
|
||||
|
@ -592,9 +583,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
|||
'id': host['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.cancelHostMaintenance(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('cancelHostMaintenance', **args)
|
||||
host = self.poll_job(res, 'host')
|
||||
return host
|
||||
|
||||
|
@ -638,7 +627,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_host = AnsibleCloudStackHost(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -649,9 +637,6 @@ def main():
|
|||
|
||||
result = acs_host.get_result(host)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -110,7 +110,6 @@ project:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -133,7 +132,7 @@ class AnsibleCloudStackInstanceGroup(AnsibleCloudStack):
|
|||
'domainid': self.get_domain('id'),
|
||||
'projectid': self.get_project('id'),
|
||||
}
|
||||
instance_groups = self.cs.listInstanceGroups(**args)
|
||||
instance_groups = self.query_api('listInstanceGroups', **args)
|
||||
if instance_groups:
|
||||
for g in instance_groups['instancegroup']:
|
||||
if name in [g['name'], g['id']]:
|
||||
|
@ -153,9 +152,7 @@ class AnsibleCloudStackInstanceGroup(AnsibleCloudStack):
|
|||
'projectid': self.get_project('id'),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createInstanceGroup(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createInstanceGroup', **args)
|
||||
instance_group = res['instancegroup']
|
||||
return instance_group
|
||||
|
||||
|
@ -164,9 +161,7 @@ class AnsibleCloudStackInstanceGroup(AnsibleCloudStack):
|
|||
if instance_group:
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteInstanceGroup(id=instance_group['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('deleteInstanceGroup', id=instance_group['id'])
|
||||
return instance_group
|
||||
|
||||
|
||||
|
@ -186,7 +181,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_ig = AnsibleCloudStackInstanceGroup(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -197,9 +191,6 @@ def main():
|
|||
|
||||
result = acs_ig.get_result(instance_group)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -135,7 +135,6 @@ domain:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -178,8 +177,6 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
|
|||
ip_address = None
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.associateIpAddress(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -196,8 +193,7 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.disassociateIpAddress(id=ip_address['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
self.poll_job(res, 'ipaddress')
|
||||
|
@ -227,7 +223,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_ip_address = AnsibleCloudStackIPAddress(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -237,10 +232,6 @@ def main():
|
|||
ip_address = acs_ip_address.associate_ip_address()
|
||||
|
||||
result = acs_ip_address.get_result(ip_address)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -275,7 +275,6 @@ tags:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -333,9 +332,7 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
|||
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.registerIso(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('registerIso', **args)
|
||||
self.iso = res['iso'][0]
|
||||
return self.iso
|
||||
|
||||
|
@ -367,9 +364,7 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
|||
args['zoneid'] = -1
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateIso(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateIso', **args)
|
||||
self.iso = res['iso']
|
||||
return self.iso
|
||||
|
||||
|
@ -391,7 +386,7 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
|||
if not checksum:
|
||||
args['name'] = self.module.params.get('name')
|
||||
|
||||
isos = self.cs.listIsos(**args)
|
||||
isos = self.query_api('listIsos', **args)
|
||||
if isos:
|
||||
if not checksum:
|
||||
self.iso = isos['iso'][0]
|
||||
|
@ -416,9 +411,7 @@ class AnsibleCloudStackIso(AnsibleCloudStack):
|
|||
args['zoneid'] = self.get_zone(key='id')
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteIso(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteIso', **args)
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
self.poll_job(res, 'iso')
|
||||
|
@ -466,7 +459,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_iso = AnsibleCloudStackIso(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -476,10 +468,6 @@ def main():
|
|||
iso = acs_iso.present_iso()
|
||||
|
||||
result = acs_iso.get_result(iso)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -225,7 +225,6 @@ state:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -248,7 +247,7 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
}
|
||||
|
||||
def get_rule(self, **kwargs):
|
||||
rules = self.cs.listLoadBalancerRules(**kwargs)
|
||||
rules = self.query_api('listLoadBalancerRules', **kwargs)
|
||||
if rules:
|
||||
return rules['loadbalancerrule'][0]
|
||||
|
||||
|
@ -263,16 +262,12 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
}
|
||||
|
||||
def present_lb_rule(self):
|
||||
missing_params = []
|
||||
for required_params in [
|
||||
required_params = [
|
||||
'algorithm',
|
||||
'private_port',
|
||||
'public_port',
|
||||
]:
|
||||
if not self.module.params.get(required_params):
|
||||
missing_params.append(required_params)
|
||||
if missing_params:
|
||||
self.module.fail_json(msg="missing required arguments: %s" % ','.join(missing_params))
|
||||
]
|
||||
self.module.fail_on_missing_params(required_params=required_params)
|
||||
|
||||
args = self._get_common_args()
|
||||
rule = self.get_rule(**args)
|
||||
|
@ -297,9 +292,7 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
'description': self.module.params.get('description'),
|
||||
'protocol': self.module.params.get('protocol'),
|
||||
})
|
||||
res = self.cs.createLoadBalancerRule(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createLoadBalancerRule', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -315,9 +308,7 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
if self.has_changed(args, rule):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateLoadBalancerRule(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateLoadBalancerRule', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -330,12 +321,11 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
|
|||
if rule:
|
||||
self.result['changed'] = True
|
||||
if rule and not self.module.check_mode:
|
||||
res = self.cs.deleteLoadBalancerRule(id=rule['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteLoadBalancerRule', id=rule['id'])
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
res = self.poll_job(res, 'loadbalancer')
|
||||
self.poll_job(res, 'loadbalancer')
|
||||
return rule
|
||||
|
||||
|
||||
|
@ -366,7 +356,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_lb_rule = AnsibleCloudStackLBRule(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -376,10 +365,6 @@ def main():
|
|||
rule = acs_lb_rule.present_lb_rule()
|
||||
|
||||
result = acs_lb_rule.get_result(rule)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -207,7 +207,6 @@ state:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -238,7 +237,7 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
if self.module.params.get('ip_address'):
|
||||
args['publicipid'] = self.get_ip_address(key='id')
|
||||
|
||||
rules = self.cs.listLoadBalancerRules(**args)
|
||||
rules = self.query_api('listLoadBalancerRules', **args)
|
||||
if rules:
|
||||
if len(rules['loadbalancerrule']) > 1:
|
||||
self.module.fail_json(msg="More than one rule having name %s. Please pass 'ip_address' as well." % args['name'])
|
||||
|
@ -253,9 +252,7 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
}
|
||||
|
||||
def _get_members_of_rule(self, rule):
|
||||
res = self.cs.listLoadBalancerRuleInstances(id=rule['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('listLoadBalancerRuleInstances', id=rule['id'])
|
||||
return res.get('loadbalancerruleinstance', [])
|
||||
|
||||
def _ensure_members(self, operation):
|
||||
|
@ -283,7 +280,7 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
return rule
|
||||
|
||||
args = self._get_common_args()
|
||||
vms = self.cs.listVirtualMachines(**args)
|
||||
vms = self.query_api('listVirtualMachines', **args)
|
||||
to_change_ids = []
|
||||
for name in to_change:
|
||||
for vm in vms.get('virtualmachine', []):
|
||||
|
@ -301,8 +298,7 @@ class AnsibleCloudStackLBRuleMember(AnsibleCloudStack):
|
|||
id=rule['id'],
|
||||
virtualmachineids=to_change_ids,
|
||||
)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
self.poll_job(res)
|
||||
|
@ -344,7 +340,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_lb_rule_member = AnsibleCloudStackLBRuleMember(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -354,10 +349,6 @@ def main():
|
|||
rule = acs_lb_rule_member.add_members()
|
||||
|
||||
result = acs_lb_rule_member.get_result(rule)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -326,7 +326,6 @@ network_offering:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -363,7 +362,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
|
|||
'zoneid': self.get_zone(key='id')
|
||||
}
|
||||
|
||||
network_offerings = self.cs.listNetworkOfferings(**args)
|
||||
network_offerings = self.query_api('listNetworkOfferings', **args)
|
||||
if network_offerings:
|
||||
for no in network_offerings['networkoffering']:
|
||||
if network_offering in [no['name'], no['displaytext'], no['id']]:
|
||||
|
@ -388,7 +387,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
|
|||
'account': self.get_account(key='name'),
|
||||
'domainid': self.get_domain(key='id')
|
||||
}
|
||||
networks = self.cs.listNetworks(**args)
|
||||
networks = self.query_api('listNetworks', **args)
|
||||
if networks:
|
||||
for n in networks['network']:
|
||||
if network in [n['name'], n['displaytext'], n['id']]:
|
||||
|
@ -411,10 +410,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
|
|||
if self.has_changed(args, network):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
network = self.cs.updateNetwork(**args)
|
||||
|
||||
if 'errortext' in network:
|
||||
self.module.fail_json(msg="Failed: '%s'" % network['errortext'])
|
||||
network = self.query_api('updateNetwork', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if network and poll_async:
|
||||
|
@ -446,10 +442,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
|
|||
})
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createNetwork(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createNetwork', **args)
|
||||
|
||||
network = res['network']
|
||||
return network
|
||||
|
@ -470,10 +463,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
|
|||
}
|
||||
|
||||
if not self.module.check_mode:
|
||||
network = self.cs.restartNetwork(**args)
|
||||
|
||||
if 'errortext' in network:
|
||||
self.module.fail_json(msg="Failed: '%s'" % network['errortext'])
|
||||
network = self.query_api('restartNetwork', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if network and poll_async:
|
||||
|
@ -490,14 +480,11 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
|
|||
}
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteNetwork(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteNetwork', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if res and poll_async:
|
||||
res = self.poll_job(res, 'network')
|
||||
self.poll_job(res, 'network')
|
||||
return network
|
||||
|
||||
|
||||
|
@ -539,7 +526,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_network = AnsibleCloudStackNetwork(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -553,10 +539,6 @@ def main():
|
|||
network = acs_network.present_network()
|
||||
|
||||
result = acs_network.get_result(network)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,6 @@ zone:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -139,7 +138,7 @@ class AnsibleCloudStackNetworkAcl(AnsibleCloudStack):
|
|||
'name': self.module.params.get('name'),
|
||||
'vpcid': self.get_vpc(key='id'),
|
||||
}
|
||||
network_acls = self.cs.listNetworkACLLists(**args)
|
||||
network_acls = self.query_api('listNetworkACLLists', **args)
|
||||
if network_acls:
|
||||
return network_acls['networkacllist'][0]
|
||||
return None
|
||||
|
@ -154,9 +153,7 @@ class AnsibleCloudStackNetworkAcl(AnsibleCloudStack):
|
|||
'vpcid': self.get_vpc(key='id')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createNetworkACLList(**args)
|
||||
if 'errortext' in res:
|
||||
self.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createNetworkACLList', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -172,9 +169,7 @@ class AnsibleCloudStackNetworkAcl(AnsibleCloudStack):
|
|||
'id': network_acl['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteNetworkACLList(**args)
|
||||
if 'errortext' in res:
|
||||
self.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteNetworkACLList', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -203,7 +198,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_network_acl = AnsibleCloudStackNetworkAcl(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -214,9 +208,6 @@ def main():
|
|||
|
||||
result = acs_network_acl.get_result(network_acl)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -285,7 +285,6 @@ zone:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -317,7 +316,7 @@ class AnsibleCloudStackNetworkAclRule(AnsibleCloudStack):
|
|||
'domainid': self.get_domain(key='id'),
|
||||
'projectid': self.get_project(key='id'),
|
||||
}
|
||||
network_acl_rules = self.cs.listNetworkACLs(**args)
|
||||
network_acl_rules = self.query_api('listNetworkACLs', **args)
|
||||
for acl_rule in network_acl_rules.get('networkacl', []):
|
||||
if acl_rule['number'] == self.module.params.get('rule_position'):
|
||||
return acl_rule
|
||||
|
@ -358,9 +357,7 @@ class AnsibleCloudStackNetworkAclRule(AnsibleCloudStack):
|
|||
'id': network_acl_rule['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteNetworkACL(**args)
|
||||
if 'errortext' in res:
|
||||
self.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteNetworkACL', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -384,9 +381,7 @@ class AnsibleCloudStackNetworkAclRule(AnsibleCloudStack):
|
|||
'cidrlist': self.module.params.get('cidr'),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createNetworkACL(**args)
|
||||
if 'errortext' in res:
|
||||
self.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createNetworkACL', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -410,9 +405,7 @@ class AnsibleCloudStackNetworkAclRule(AnsibleCloudStack):
|
|||
if self.has_changed(args, network_acl_rule):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateNetworkACLItem(**args)
|
||||
if 'errortext' in res:
|
||||
self.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateNetworkACLItem', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -470,7 +463,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_network_acl_rule = AnsibleCloudStackNetworkAclRule(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -481,9 +473,6 @@ def main():
|
|||
|
||||
result = acs_network_acl_rule.get_result(network_acl_rule)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -158,7 +158,6 @@ zone:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -199,14 +198,14 @@ class AnsibleCloudStackPod(AnsibleCloudStack):
|
|||
if uuid:
|
||||
args['id'] = uuid
|
||||
args['zoneid'] = self.get_zone(key='id')
|
||||
pods = self.cs.listPods(**args)
|
||||
pods = self.query_api('listPods', **args)
|
||||
if pods:
|
||||
self.pod = pods['pod'][0]
|
||||
return self.pod
|
||||
|
||||
args['name'] = self.module.params.get('name')
|
||||
args['zoneid'] = self.get_zone(key='id')
|
||||
pods = self.cs.listPods(**args)
|
||||
pods = self.query_api('listPods', **args)
|
||||
if pods:
|
||||
self.pod = pods['pod'][0]
|
||||
return self.pod
|
||||
|
@ -231,9 +230,7 @@ class AnsibleCloudStackPod(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
args = self._get_common_pod_args()
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createPod(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createPod', **args)
|
||||
pod = res['pod']
|
||||
return pod
|
||||
|
||||
|
@ -246,9 +243,7 @@ class AnsibleCloudStackPod(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updatePod(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updatePod', **args)
|
||||
pod = res['pod']
|
||||
return pod
|
||||
|
||||
|
@ -261,9 +256,7 @@ class AnsibleCloudStackPod(AnsibleCloudStack):
|
|||
'id': pod['id']
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deletePod(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('deletePod', **args)
|
||||
return pod
|
||||
|
||||
|
||||
|
@ -286,7 +279,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_pod = AnsibleCloudStackPod(module)
|
||||
state = module.params.get('state')
|
||||
if state in ['absent']:
|
||||
|
@ -296,9 +288,6 @@ def main():
|
|||
|
||||
result = acs_pod.get_result(pod)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -149,7 +149,6 @@ tags:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -165,7 +164,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|||
'account': self.get_account(key='name'),
|
||||
'domainid': self.get_domain(key='id')
|
||||
}
|
||||
projects = self.cs.listProjects(**args)
|
||||
projects = self.query_api('listProjects', **args)
|
||||
if projects:
|
||||
for p in projects['project']:
|
||||
if project.lower() in [p['name'].lower(), p['id']]:
|
||||
|
@ -193,10 +192,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|||
if self.has_changed(args, project):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
project = self.cs.updateProject(**args)
|
||||
|
||||
if 'errortext' in project:
|
||||
self.module.fail_json(msg="Failed: '%s'" % project['errortext'])
|
||||
project = self.query_api('updateProject', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if project and poll_async:
|
||||
|
@ -213,10 +209,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|||
'domainid': self.get_domain('id')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
project = self.cs.createProject(**args)
|
||||
|
||||
if 'errortext' in project:
|
||||
self.module.fail_json(msg="Failed: '%s'" % project['errortext'])
|
||||
project = self.query_api('createProject', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if project and poll_async:
|
||||
|
@ -234,12 +227,9 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|||
}
|
||||
if not self.module.check_mode:
|
||||
if state == 'suspended':
|
||||
project = self.cs.suspendProject(**args)
|
||||
project = self.query_api('suspendProject', **args)
|
||||
else:
|
||||
project = self.cs.activateProject(**args)
|
||||
|
||||
if 'errortext' in project:
|
||||
self.module.fail_json(msg="Failed: '%s'" % project['errortext'])
|
||||
project = self.query_api('activateProject', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if project and poll_async:
|
||||
|
@ -255,10 +245,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|||
'id': project['id']
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteProject(**args)
|
||||
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteProject', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if res and poll_async:
|
||||
|
@ -284,7 +271,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_project = AnsibleCloudStackProject(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -298,10 +284,6 @@ def main():
|
|||
project = acs_project.present_project()
|
||||
|
||||
result = acs_project.get_result(project)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -106,7 +106,6 @@ portable_ip_service_enabled:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -124,7 +123,7 @@ class AnsibleCloudStackRegion(AnsibleCloudStack):
|
|||
|
||||
def get_region(self):
|
||||
id = self.module.params.get('id')
|
||||
regions = self.cs.listRegions(id=id)
|
||||
regions = self.query_api('listRegions', id=id)
|
||||
if regions:
|
||||
return regions['region'][0]
|
||||
return None
|
||||
|
@ -145,9 +144,7 @@ class AnsibleCloudStackRegion(AnsibleCloudStack):
|
|||
'endpoint': self.module.params.get('endpoint')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.addRegion(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('addRegion', **args)
|
||||
region = res['region']
|
||||
return region
|
||||
|
||||
|
@ -160,9 +157,7 @@ class AnsibleCloudStackRegion(AnsibleCloudStack):
|
|||
if self.has_changed(args, region):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateRegion(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateRegion', **args)
|
||||
region = res['region']
|
||||
return region
|
||||
|
||||
|
@ -171,9 +166,7 @@ class AnsibleCloudStackRegion(AnsibleCloudStack):
|
|||
if region:
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.removeRegion(id=region['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('removeRegion', id=region['id'])
|
||||
return region
|
||||
|
||||
|
||||
|
@ -195,7 +188,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_region = AnsibleCloudStackRegion(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -205,10 +197,6 @@ def main():
|
|||
region = acs_region.present_region()
|
||||
|
||||
result = acs_region.get_result(region)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -124,7 +124,6 @@ project:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_required_together,
|
||||
cs_argument_spec
|
||||
)
|
||||
|
@ -186,8 +185,6 @@ class AnsibleCloudStackResourceLimit(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateResourceLimit(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
resource_limit = res['resourcelimit']
|
||||
return resource_limit
|
||||
|
||||
|
@ -202,9 +199,9 @@ def main():
|
|||
argument_spec.update(dict(
|
||||
resource_type=dict(required=True, choices=RESOURCE_TYPES.keys(), aliases=['type']),
|
||||
limit=dict(default=-1, aliases=['max'], type='int'),
|
||||
domain=dict(default=None),
|
||||
account=dict(default=None),
|
||||
project=dict(default=None),
|
||||
domain=dict(),
|
||||
account=dict(),
|
||||
project=dict(),
|
||||
))
|
||||
|
||||
module = AnsibleModule(
|
||||
|
@ -213,14 +210,9 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_resource_limit = AnsibleCloudStackResourceLimit(module)
|
||||
resource_limit = acs_resource_limit.update_resource_limit()
|
||||
result = acs_resource_limit.get_result(resource_limit)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -108,7 +108,11 @@ role_type:
|
|||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import AnsibleCloudStack, CloudStackException, cs_argument_spec, cs_required_together
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
||||
|
||||
class AnsibleCloudStackRole(AnsibleCloudStack):
|
||||
|
@ -125,14 +129,14 @@ class AnsibleCloudStackRole(AnsibleCloudStack):
|
|||
args = {
|
||||
'id': uuid,
|
||||
}
|
||||
roles = self.cs.listRoles(**args)
|
||||
roles = self.query_api('listRoles', **args)
|
||||
if roles:
|
||||
return roles['role'][0]
|
||||
else:
|
||||
args = {
|
||||
'name': self.module.params.get('name'),
|
||||
}
|
||||
roles = self.cs.listRoles(**args)
|
||||
roles = self.query_api('listRoles', **args)
|
||||
if roles:
|
||||
return roles['role'][0]
|
||||
return None
|
||||
|
@ -153,9 +157,7 @@ class AnsibleCloudStackRole(AnsibleCloudStack):
|
|||
'description': self.module.params.get('description'),
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createRole(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createRole', **args)
|
||||
role = res['role']
|
||||
return role
|
||||
|
||||
|
@ -168,9 +170,8 @@ class AnsibleCloudStackRole(AnsibleCloudStack):
|
|||
if self.has_changed(args, role):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateRole(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateRole', **args)
|
||||
|
||||
# The API as in 4.9 does not return an updated role yet
|
||||
if 'role' not in res:
|
||||
role = self.get_role()
|
||||
|
@ -186,18 +187,16 @@ class AnsibleCloudStackRole(AnsibleCloudStack):
|
|||
'id': role['id'],
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteRole(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('deleteRole', **args)
|
||||
return role
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = cs_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
uuid=dict(default=None, aliases=['id']),
|
||||
uuid=dict(aliases=['id']),
|
||||
name=dict(required=True),
|
||||
description=dict(default=None),
|
||||
description=dict(),
|
||||
role_type=dict(choices=['User', 'DomainAdmin', 'ResourceAdmin', 'Admin'], default='User'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
))
|
||||
|
@ -208,7 +207,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_role = AnsibleCloudStackRole(module)
|
||||
state = module.params.get('state')
|
||||
if state == 'absent':
|
||||
|
@ -218,9 +216,6 @@ def main():
|
|||
|
||||
result = acs_role.get_result(role)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,6 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_required_together,
|
||||
cs_argument_spec
|
||||
)
|
||||
|
@ -150,7 +149,7 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
|
|||
args['publickey'] = public_key
|
||||
if not self.module.check_mode:
|
||||
args['name'] = name
|
||||
res = self.cs.registerSSHKeyPair(**args)
|
||||
res = self.query_api('registerSSHKeyPair', **args)
|
||||
else:
|
||||
fingerprint = self._get_ssh_fingerprint(public_key)
|
||||
if ssh_key['fingerprint'] != fingerprint:
|
||||
|
@ -158,26 +157,26 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
|
|||
if not self.module.check_mode:
|
||||
# delete the ssh key with matching name but wrong fingerprint
|
||||
args['name'] = name
|
||||
self.cs.deleteSSHKeyPair(**args)
|
||||
self.query_api('deleteSSHKeyPair', **args)
|
||||
|
||||
elif ssh_key['name'].lower() != name.lower():
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
# delete the ssh key with matching fingerprint but wrong name
|
||||
args['name'] = ssh_key['name']
|
||||
self.cs.deleteSSHKeyPair(**args)
|
||||
self.query_api('deleteSSHKeyPair', **args)
|
||||
# First match for key retrievment will be the fingerprint.
|
||||
# We need to make another lookup if there is a key with identical name.
|
||||
self.ssh_key = None
|
||||
ssh_key = self.get_ssh_key()
|
||||
if ssh_key['fingerprint'] != fingerprint:
|
||||
args['name'] = name
|
||||
self.cs.deleteSSHKeyPair(**args)
|
||||
self.query_api('deleteSSHKeyPair', **args)
|
||||
|
||||
if not self.module.check_mode and self.result['changed']:
|
||||
args['publickey'] = public_key
|
||||
args['name'] = name
|
||||
res = self.cs.registerSSHKeyPair(**args)
|
||||
res = self.query_api('registerSSHKeyPair', **args)
|
||||
|
||||
if res and 'keypair' in res:
|
||||
ssh_key = res['keypair']
|
||||
|
@ -191,7 +190,7 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
|
|||
args = self._get_common_args()
|
||||
args['name'] = self.module.params.get('name')
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createSSHKeyPair(**args)
|
||||
res = self.query_api('createSSHKeyPair', **args)
|
||||
ssh_key = res['keypair']
|
||||
return ssh_key
|
||||
|
||||
|
@ -202,7 +201,7 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
|
|||
args = self._get_common_args()
|
||||
args['name'] = name or self.module.params.get('name')
|
||||
if not self.module.check_mode:
|
||||
self.cs.deleteSSHKeyPair(**args)
|
||||
self.query_api('deleteSSHKeyPair', **args)
|
||||
return ssh_key
|
||||
|
||||
def _get_common_args(self):
|
||||
|
@ -219,14 +218,14 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
|
|||
# Query by fingerprint of the public key
|
||||
args_fingerprint = self._get_common_args()
|
||||
args_fingerprint['fingerprint'] = self._get_ssh_fingerprint(public_key)
|
||||
ssh_keys = self.cs.listSSHKeyPairs(**args_fingerprint)
|
||||
ssh_keys = self.query_api('listSSHKeyPairs', **args_fingerprint)
|
||||
if ssh_keys and 'sshkeypair' in ssh_keys:
|
||||
self.ssh_key = ssh_keys['sshkeypair'][0]
|
||||
# When key has not been found by fingerprint, use the name
|
||||
if not self.ssh_key:
|
||||
args_name = self._get_common_args()
|
||||
args_name['name'] = self.module.params.get('name')
|
||||
ssh_keys = self.cs.listSSHKeyPairs(**args_name)
|
||||
ssh_keys = self.query_api('listSSHKeyPairs', **args_name)
|
||||
if ssh_keys and 'sshkeypair' in ssh_keys:
|
||||
self.ssh_key = ssh_keys['sshkeypair'][0]
|
||||
return self.ssh_key
|
||||
|
@ -258,7 +257,6 @@ def main():
|
|||
if not HAS_LIB_SSHPUBKEYS:
|
||||
module.fail_json(msg="python library sshpubkeys required: pip install sshpubkeys")
|
||||
|
||||
try:
|
||||
acs_sshkey = AnsibleCloudStackSshKey(module)
|
||||
state = module.params.get('state')
|
||||
if state in ['absent']:
|
||||
|
@ -271,10 +269,6 @@ def main():
|
|||
ssh_key = acs_sshkey.create_ssh_key()
|
||||
|
||||
result = acs_sshkey.get_result(ssh_key)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -160,7 +160,6 @@ domain:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -186,9 +185,7 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
'networkid': self.get_network(key='id')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.enableStaticNat(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('enableStaticNat', **args)
|
||||
|
||||
# reset ip address and query new values
|
||||
self.ip_address = None
|
||||
|
@ -207,13 +204,10 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
if self.has_changed(args, ip_address, ['vmguestip', 'virtualmachineid']):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.disableStaticNat(ipaddressid=ip_address['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('disableStaticNat', ipaddressid=ip_address['id'])
|
||||
self.poll_job(res, 'staticnat')
|
||||
res = self.cs.enableStaticNat(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
|
||||
self.query_api('enableStaticNat', **args)
|
||||
|
||||
# reset ip address and query new values
|
||||
self.ip_address = None
|
||||
|
@ -233,9 +227,8 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
|
|||
if ip_address['isstaticnat']:
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.disableStaticNat(ipaddressid=ip_address['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('disableStaticNat', ipaddressid=ip_address['id'])
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
self.poll_job(res, 'staticnat')
|
||||
|
@ -264,7 +257,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_static_nat = AnsibleCloudStackStaticNat(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -275,9 +267,6 @@ def main():
|
|||
|
||||
result = acs_static_nat.get_result(ip_address)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -210,7 +210,6 @@ tags:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -242,7 +241,7 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
else:
|
||||
args['isdefault'] = True
|
||||
|
||||
vpc_offerings = self.cs.listVPCOfferings(**args)
|
||||
vpc_offerings = self.query_api('listVPCOfferings', **args)
|
||||
if vpc_offerings:
|
||||
self.vpc_offering = vpc_offerings['vpcoffering'][0]
|
||||
return self._get_by_key(key, self.vpc_offering)
|
||||
|
@ -257,7 +256,7 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
'projectid': self.get_project(key='id'),
|
||||
'zoneid': self.get_zone(key='id'),
|
||||
}
|
||||
vpcs = self.cs.listVPCs(**args)
|
||||
vpcs = self.query_api('listVPCs', **args)
|
||||
if vpcs:
|
||||
vpc_name = self.module.params.get('name')
|
||||
for v in vpcs['vpc']:
|
||||
|
@ -276,9 +275,7 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
args = {
|
||||
'id': vpc['id'],
|
||||
}
|
||||
res = self.cs.restartVPC(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('restartVPC', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -310,9 +307,7 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
}
|
||||
self.result['diff']['after'] = args
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createVPC(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createVPC', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -327,9 +322,7 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
if self.has_changed(args, vpc):
|
||||
self.result['changed'] = True
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateVPC(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateVPC', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -342,9 +335,7 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
self.result['diff']['before'] = vpc
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteVPC(id=vpc['id'])
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteVPC', id=vpc['id'])
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -378,7 +369,6 @@ def main():
|
|||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
try:
|
||||
acs_vpc = AnsibleCloudStackVpc(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -391,9 +381,6 @@ def main():
|
|||
|
||||
result = acs_vpc.get_result(vpc)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -121,7 +121,6 @@ project:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together
|
||||
)
|
||||
|
@ -142,7 +141,7 @@ class AnsibleCloudStackVpnGateway(AnsibleCloudStack):
|
|||
'domainid': self.get_domain(key='id'),
|
||||
'projectid': self.get_project(key='id')
|
||||
}
|
||||
vpn_gateways = self.cs.listVpnGateways(**args)
|
||||
vpn_gateways = self.query_api('listVpnGateways', **args)
|
||||
if vpn_gateways:
|
||||
return vpn_gateways['vpngateway'][0]
|
||||
return None
|
||||
|
@ -158,9 +157,7 @@ class AnsibleCloudStackVpnGateway(AnsibleCloudStack):
|
|||
'projectid': self.get_project(key='id')
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createVpnGateway(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createVpnGateway', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -176,9 +173,7 @@ class AnsibleCloudStackVpnGateway(AnsibleCloudStack):
|
|||
'id': vpn_gateway['id']
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteVpnGateway(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('deleteVpnGateway', **args)
|
||||
|
||||
poll_async = self.module.params.get('poll_async')
|
||||
if poll_async:
|
||||
|
@ -211,7 +206,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_vpn_gw = AnsibleCloudStackVpnGateway(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -222,9 +216,6 @@ def main():
|
|||
|
||||
result = acs_vpn_gw.get_result(vpn_gateway)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -234,7 +234,6 @@ tags:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
cs_required_together,
|
||||
)
|
||||
|
@ -289,13 +288,13 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
uuid = self.module.params.get('id')
|
||||
if uuid:
|
||||
args['id'] = uuid
|
||||
zones = self.cs.listZones(**args)
|
||||
zones = self.query_api('listZones', **args)
|
||||
if zones:
|
||||
self.zone = zones['zone'][0]
|
||||
return self.zone
|
||||
|
||||
args['name'] = self.module.params.get('name')
|
||||
zones = self.cs.listZones(**args)
|
||||
zones = self.query_api('listZones', **args)
|
||||
if zones:
|
||||
self.zone = zones['zone'][0]
|
||||
return self.zone
|
||||
|
@ -322,9 +321,7 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
|
||||
zone = None
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.createZone(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('createZone', **args)
|
||||
zone = res['zone']
|
||||
return zone
|
||||
|
||||
|
@ -338,9 +335,7 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
self.result['changed'] = True
|
||||
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.updateZone(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
res = self.query_api('updateZone', **args)
|
||||
zone = res['zone']
|
||||
return zone
|
||||
|
||||
|
@ -353,9 +348,8 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
'id': zone['id']
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteZone(**args)
|
||||
if 'errortext' in res:
|
||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||
self.query_api('deleteZone', **args)
|
||||
|
||||
return zone
|
||||
|
||||
|
||||
|
@ -386,7 +380,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
try:
|
||||
acs_zone = AnsibleCloudStackZone(module)
|
||||
|
||||
state = module.params.get('state')
|
||||
|
@ -397,9 +390,6 @@ def main():
|
|||
|
||||
result = acs_zone.get_result(zone)
|
||||
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ cloudstack_zone.tags:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.cloudstack import (
|
||||
AnsibleCloudStack,
|
||||
CloudStackException,
|
||||
cs_argument_spec,
|
||||
)
|
||||
|
||||
|
@ -197,11 +196,8 @@ def main():
|
|||
supports_check_mode=False,
|
||||
)
|
||||
|
||||
try:
|
||||
cs_zone_facts = AnsibleCloudStackZoneFacts(module=module).run()
|
||||
cs_facts_result = dict(changed=False, ansible_facts=cs_zone_facts)
|
||||
except CloudStackException as e:
|
||||
module.fail_json(msg='CloudStackException: %s' % str(e))
|
||||
|
||||
module.exit_json(**cs_facts_result)
|
||||
|
||||
|
|
|
@ -83,7 +83,6 @@ lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py
|
|||
lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork_facts.py
|
||||
lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py
|
||||
lib/ansible/modules/cloud/cloudscale/cloudscale_server.py
|
||||
lib/ansible/modules/cloud/cloudstack/cs_configuration.py
|
||||
lib/ansible/modules/cloud/cloudstack/cs_instance.py
|
||||
lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py
|
||||
lib/ansible/modules/cloud/cloudstack/cs_nic.py
|
||||
|
|
Loading…
Reference in a new issue