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