Merge pull request #2388 from resmo/for-ansible-2.2

[2.2] cloudstack related changes for Ansible 2.2
reviewable/pr18780/r1
René Moser 9 years ago committed by GitHub
commit e596ad9294

@ -172,12 +172,6 @@ domain:
sample: ROOT sample: ROOT
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -196,28 +190,26 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
'domain_admin': 2, 'domain_admin': 2,
} }
def get_account_type(self): def get_account_type(self):
account_type = self.module.params.get('account_type') account_type = self.module.params.get('account_type')
return self.account_types[account_type] return self.account_types[account_type]
def get_account(self): def get_account(self):
if not self.account: if not self.account:
args = {} args = {
args['listall'] = True 'listall': True,
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
}
accounts = self.cs.listAccounts(**args) accounts = self.cs.listAccounts(**args)
if accounts: if accounts:
account_name = self.module.params.get('name') account_name = self.module.params.get('name')
for a in accounts['account']: for a in accounts['account']:
if account_name in [ a['name'] ]: if account_name == a['name']:
self.account = a self.account = a
break break
return self.account return self.account
def enable_account(self): def enable_account(self):
account = self.get_account() account = self.get_account()
if not account: if not account:
@ -225,10 +217,11 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
if account['state'].lower() != 'enabled': if account['state'].lower() != 'enabled':
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['id'] = account['id'] 'id': account['id'],
args['account'] = self.module.params.get('name') 'account': self.module.params.get('name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id')
}
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.enableAccount(**args) res = self.cs.enableAccount(**args)
if 'errortext' in res: if 'errortext' in res:
@ -236,15 +229,12 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
account = res['account'] account = res['account']
return account return account
def lock_account(self): def lock_account(self):
return self.lock_or_disable_account(lock=True) return self.lock_or_disable_account(lock=True)
def disable_account(self): def disable_account(self):
return self.lock_or_disable_account() return self.lock_or_disable_account()
def lock_or_disable_account(self, lock=False): def lock_or_disable_account(self, lock=False):
account = self.get_account() account = self.get_account()
if not account: if not account:
@ -254,14 +244,15 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
if lock and account['state'].lower() == 'disabled': if lock and account['state'].lower() == 'disabled':
account = self.enable_account() account = self.enable_account()
if lock and account['state'].lower() != 'locked' \ if (lock and account['state'].lower() != 'locked' or
or not lock and account['state'].lower() != 'disabled': not lock and account['state'].lower() != 'disabled'):
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['id'] = account['id'] 'id': account['id'],
args['account'] = self.module.params.get('name') 'account': self.module.params.get('name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
args['lock'] = lock 'lock': lock,
}
if not self.module.check_mode: if not self.module.check_mode:
account = self.cs.disableAccount(**args) account = self.cs.disableAccount(**args)
@ -270,42 +261,36 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
account = self._poll_job(account, 'account') account = self.poll_job(account, 'account')
return account return account
def present_account(self): def present_account(self):
missing_params = [] required_params = [
missing_params = []
for required_params in [
'email', 'email',
'username', 'username',
'password', 'password',
'first_name', 'first_name',
'last_name', 'last_name',
]: ]
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))
account = self.get_account() account = self.get_account()
if not account: if not account:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['account'] = self.module.params.get('name') 'account': self.module.params.get('name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
args['accounttype'] = self.get_account_type() 'accounttype': self.get_account_type(),
args['networkdomain'] = self.module.params.get('network_domain') 'networkdomain': self.module.params.get('network_domain'),
args['username'] = self.module.params.get('username') 'username': self.module.params.get('username'),
args['password'] = self.module.params.get('password') 'password': self.module.params.get('password'),
args['firstname'] = self.module.params.get('first_name') 'firstname': self.module.params.get('first_name'),
args['lastname'] = self.module.params.get('last_name') 'lastname': self.module.params.get('last_name'),
args['email'] = self.module.params.get('email') 'email': self.module.params.get('email'),
args['timezone'] = self.module.params.get('timezone') 'timezone': self.module.params.get('timezone')
}
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.createAccount(**args) res = self.cs.createAccount(**args)
if 'errortext' in res: if 'errortext' in res:
@ -313,7 +298,6 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
account = res['account'] account = res['account']
return account return account
def absent_account(self): def absent_account(self):
account = self.get_account() account = self.get_account()
if account: if account:
@ -327,15 +311,14 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
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, 'account') self.poll_job(res, 'account')
return account return account
def get_result(self, account): def get_result(self, account):
super(AnsibleCloudStackAccount, self).get_result(account) super(AnsibleCloudStackAccount, self).get_result(account)
if account: if account:
if 'accounttype' in account: if 'accounttype' in account:
for key,value in self.account_types.items(): for key, value in self.account_types.items():
if value == account['accounttype']: if value == account['accounttype']:
self.result['account_type'] = key self.result['account_type'] = key
break break
@ -345,18 +328,18 @@ class AnsibleCloudStackAccount(AnsibleCloudStack):
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),
state = dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'), state=dict(choices=['present', 'absent', 'enabled', 'disabled', 'locked', 'unlocked'], default='present'),
account_type = dict(choices=['user', 'root_admin', 'domain_admin'], default='user'), account_type=dict(choices=['user', 'root_admin', 'domain_admin'], default='user'),
network_domain = dict(default=None), network_domain=dict(default=None),
domain = dict(default='ROOT'), domain=dict(default='ROOT'),
email = dict(default=None), email=dict(default=None),
first_name = dict(default=None), first_name=dict(default=None),
last_name = dict(default=None), last_name=dict(default=None),
username = dict(default=None), username=dict(default=None),
password = dict(default=None, no_log=True), password=dict(default=None, no_log=True),
timezone = dict(default=None), timezone=dict(default=None),
poll_async = dict(type='bool', default=True), poll_async=dict(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -365,9 +348,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_acc = AnsibleCloudStackAccount(module) acs_acc = AnsibleCloudStackAccount(module)

@ -123,12 +123,6 @@ account:
sample: example account sample: example account
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -142,22 +136,20 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
} }
self.affinity_group = None self.affinity_group = None
def get_affinity_group(self): def get_affinity_group(self):
if not self.affinity_group: if not self.affinity_group:
args = {} args = {
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
args['account'] = self.get_account('name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain('id') 'domainid': self.get_domain(key='id'),
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
}
affinity_groups = self.cs.listAffinityGroups(**args) affinity_groups = self.cs.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
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')
@ -171,20 +163,19 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
return a['type'] return a['type']
self.module.fail_json(msg="affinity group type '%s' not found" % affinity_type) self.module.fail_json(msg="affinity group type '%s' not found" % affinity_type)
def create_affinity_group(self): def create_affinity_group(self):
affinity_group = self.get_affinity_group() affinity_group = self.get_affinity_group()
if not affinity_group: if not affinity_group:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
args['type'] = self.get_affinity_type() 'type': self.get_affinity_type(),
args['description'] = self.module.params.get('description') 'description': self.module.params.get('description'),
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
args['account'] = self.get_account('name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain('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.cs.createAffinityGroup(**args)
@ -193,21 +184,20 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
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:
affinity_group = self._poll_job(res, 'affinitygroup') affinity_group = self.poll_job(res, 'affinitygroup')
return affinity_group return affinity_group
def remove_affinity_group(self): def remove_affinity_group(self):
affinity_group = self.get_affinity_group() affinity_group = self.get_affinity_group()
if affinity_group: if affinity_group:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
args['account'] = self.get_account('name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain('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.cs.deleteAffinityGroup(**args)
@ -216,21 +206,21 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack):
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, 'affinitygroup') self.poll_job(res, 'affinitygroup')
return affinity_group return affinity_group
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),
affinty_type = dict(default=None), affinty_type=dict(default=None),
description = dict(default=None), description=dict(default=None),
state = dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
domain = dict(default=None), domain=dict(default=None),
account = dict(default=None), account=dict(default=None),
project = dict(default=None), project=dict(default=None),
poll_async = dict(type='bool', default=True), poll_async=dict(type='bool', default=True),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -239,9 +229,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_ag = AnsibleCloudStackAffinityGroup(module) acs_ag = AnsibleCloudStackAffinityGroup(module)

@ -226,15 +226,10 @@ pod:
sample: pod01 sample: pod01
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
class AnsibleCloudStackCluster(AnsibleCloudStack): class AnsibleCloudStackCluster(AnsibleCloudStack):
def __init__(self, module): def __init__(self, module):
@ -251,29 +246,27 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
} }
self.cluster = None self.cluster = None
def _get_common_cluster_args(self): def _get_common_cluster_args(self):
args = {} args = {
args['clustername'] = self.module.params.get('name') 'clustername': self.module.params.get('name'),
args['hypervisor'] = self.module.params.get('hypervisor') 'hypervisor': self.module.params.get('hypervisor'),
args['clustertype'] = self.module.params.get('cluster_type') 'clustertype': self.module.params.get('cluster_type'),
}
state = self.module.params.get('state') state = self.module.params.get('state')
if state in [ 'enabled', 'disabled']: if state in ['enabled', 'disabled']:
args['allocationstate'] = state.capitalize() args['allocationstate'] = state.capitalize()
return args return args
def get_pod(self, key=None): def get_pod(self, key=None):
args = {} args = {
args['name'] = self.module.params.get('pod') 'name': self.module.params.get('pod'),
args['zoneid'] = self.get_zone(key='id') 'zoneid': self.get_zone(key='id'),
}
pods = self.cs.listPods(**args) pods = self.cs.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')))
def get_cluster(self): def get_cluster(self):
if not self.cluster: if not self.cluster:
args = {} args = {}
@ -295,7 +288,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
self.cluster['clustername'] = self.cluster['name'] self.cluster['clustername'] = self.cluster['name']
return self.cluster return self.cluster
def present_cluster(self): def present_cluster(self):
cluster = self.get_cluster() cluster = self.get_cluster()
if cluster: if cluster:
@ -304,7 +296,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = self._create_cluster() cluster = self._create_cluster()
return cluster return cluster
def _create_cluster(self): def _create_cluster(self):
required_params = [ required_params = [
'cluster_type', 'cluster_type',
@ -343,7 +334,6 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = res['cluster'] cluster = res['cluster']
return cluster return cluster
def _update_cluster(self): def _update_cluster(self):
cluster = self.get_cluster() cluster = self.get_cluster()
@ -360,15 +350,14 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
cluster = res['cluster'] cluster = res['cluster']
return cluster return cluster
def absent_cluster(self): def absent_cluster(self):
cluster = self.get_cluster() cluster = self.get_cluster()
if cluster: if cluster:
self.result['changed'] = True self.result['changed'] = True
args = {} 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) res = self.cs.deleteCluster(**args)
if 'errortext' in res: if 'errortext' in res:
@ -379,25 +368,25 @@ class AnsibleCloudStackCluster(AnsibleCloudStack):
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),
zone = dict(default=None), zone=dict(default=None),
pod = dict(default=None), pod=dict(default=None),
cluster_type = dict(choices=['CloudManaged', 'ExternalManaged'], default=None), cluster_type=dict(choices=['CloudManaged', 'ExternalManaged'], default=None),
hypervisor = dict(choices=CS_HYPERVISORS, default=None), hypervisor=dict(choices=CS_HYPERVISORS, default=None),
state = dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'), state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
url = dict(default=None), url=dict(default=None),
username = dict(default=None), username=dict(default=None),
password = dict(default=None, no_log=True), password=dict(default=None, no_log=True),
guest_vswitch_name = dict(default=None), guest_vswitch_name=dict(default=None),
guest_vswitch_type = dict(choices=['vmwaresvs', 'vmwaredvs'], default=None), guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
public_vswitch_name = dict(default=None), public_vswitch_name=dict(default=None),
public_vswitch_type = dict(choices=['vmwaresvs', 'vmwaredvs'], default=None), public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None),
vms_ip_address = dict(default=None), vms_ip_address=dict(default=None),
vms_username = dict(default=None), vms_username=dict(default=None),
vms_password = dict(default=None, no_log=True), vms_password=dict(default=None, no_log=True),
ovm3_cluster = dict(default=None), ovm3_cluster=dict(default=None),
ovm3_pool = dict(default=None), ovm3_pool=dict(default=None),
ovm3_vip = dict(default=None), ovm3_vip=dict(default=None),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -406,9 +395,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_cluster = AnsibleCloudStackCluster(module) acs_cluster = AnsibleCloudStackCluster(module)

@ -148,12 +148,6 @@ storage:
sample: storage01 sample: storage01
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -278,9 +272,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_configuration = AnsibleCloudStackConfiguration(module) acs_configuration = AnsibleCloudStackConfiguration(module)
configuration = acs_configuration.present_configuration() configuration = acs_configuration.present_configuration()

@ -106,12 +106,6 @@ network_domain:
sample: example.local sample: example.local
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -207,7 +201,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
args['id'] = domain['id'] args['id'] = domain['id']
args['networkdomain'] = self.module.params.get('network_domain') args['networkdomain'] = self.module.params.get('network_domain')
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.cs.updateDomain(**args)
@ -233,7 +227,7 @@ class AnsibleCloudStackDomain(AnsibleCloudStack):
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, 'domain') res = self.poll_job(res, 'domain')
return domain return domain
@ -254,9 +248,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_dom = AnsibleCloudStackDomain(module) acs_dom = AnsibleCloudStackDomain(module)

@ -210,12 +210,6 @@ network:
sample: my_network sample: my_network
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -337,7 +331,7 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
firewall_rule = self._poll_job(res, 'firewallrule') firewall_rule = self.poll_job(res, 'firewallrule')
return firewall_rule return firewall_rule
@ -361,7 +355,7 @@ class AnsibleCloudStackFirewall(AnsibleCloudStack):
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, 'firewallrule') res = self.poll_job(res, 'firewallrule')
return firewall_rule return firewall_rule
@ -413,9 +407,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_fw = AnsibleCloudStackFirewall(module) acs_fw = AnsibleCloudStackFirewall(module)

@ -396,12 +396,6 @@ instance_name:
import base64 import base64
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -672,7 +666,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
instance = self._poll_job(instance, 'virtualmachine') instance = self.poll_job(instance, 'virtualmachine')
return instance return instance
@ -682,7 +676,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
args_service_offering['id'] = instance['id'] args_service_offering['id'] = instance['id']
if self.module.params.get('service_offering'): if self.module.params.get('service_offering'):
args_service_offering['serviceofferingid'] = self.get_service_offering_id() args_service_offering['serviceofferingid'] = self.get_service_offering_id()
service_offering_changed = self._has_changed(args_service_offering, instance) service_offering_changed = self.has_changed(args_service_offering, instance)
# Instance data # Instance data
args_instance_update = {} args_instance_update = {}
@ -693,7 +687,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
args_instance_update['group'] = self.module.params.get('group') args_instance_update['group'] = self.module.params.get('group')
if self.module.params.get('display_name'): if self.module.params.get('display_name'):
args_instance_update['displayname'] = self.module.params.get('display_name') args_instance_update['displayname'] = self.module.params.get('display_name')
instance_changed = self._has_changed(args_instance_update, instance) instance_changed = self.has_changed(args_instance_update, instance)
# SSH key data # SSH key data
args_ssh_key = {} args_ssh_key = {}
@ -701,7 +695,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
args_ssh_key['projectid'] = self.get_project(key='id') args_ssh_key['projectid'] = self.get_project(key='id')
if self.module.params.get('ssh_key'): if self.module.params.get('ssh_key'):
args_ssh_key['keypair'] = self.module.params.get('ssh_key') args_ssh_key['keypair'] = self.module.params.get('ssh_key')
ssh_key_changed = self._has_changed(args_ssh_key, instance) ssh_key_changed = self.has_changed(args_ssh_key, instance)
security_groups_changed = self.security_groups_has_changed() security_groups_changed = self.security_groups_has_changed()
@ -721,7 +715,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
# Ensure VM has stopped # Ensure VM has stopped
instance = self.stop_instance() instance = self.stop_instance()
instance = self._poll_job(instance, 'virtualmachine') instance = self.poll_job(instance, 'virtualmachine')
self.instance = instance self.instance = instance
# Change service offering # Change service offering
@ -748,7 +742,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
if 'errortext' in instance: if 'errortext' in instance:
self.module.fail_json(msg="Failed: '%s'" % instance['errortext']) self.module.fail_json(msg="Failed: '%s'" % instance['errortext'])
instance = self._poll_job(instance, 'virtualmachine') instance = self.poll_job(instance, 'virtualmachine')
self.instance = instance self.instance = instance
# Start VM again if it was running before # Start VM again if it was running before
@ -781,7 +775,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
instance = self._poll_job(res, 'virtualmachine') instance = self.poll_job(res, 'virtualmachine')
return instance return instance
@ -804,7 +798,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
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, 'virtualmachine') res = self.poll_job(res, 'virtualmachine')
return instance return instance
@ -825,7 +819,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
instance = self._poll_job(instance, 'virtualmachine') instance = self.poll_job(instance, 'virtualmachine')
return instance return instance
@ -846,7 +840,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
instance = self._poll_job(instance, 'virtualmachine') instance = self.poll_job(instance, 'virtualmachine')
return instance return instance
@ -864,7 +858,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
instance = self._poll_job(instance, 'virtualmachine') instance = self.poll_job(instance, 'virtualmachine')
elif instance['state'].lower() in [ 'stopping', 'stopped' ]: elif instance['state'].lower() in [ 'stopping', 'stopped' ]:
instance = self.start_instance() instance = self.start_instance()
@ -885,7 +879,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
instance = self._poll_job(res, 'virtualmachine') instance = self.poll_job(res, 'virtualmachine')
return instance return instance
@ -962,9 +956,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_instance = AnsibleCloudStackInstance(module) acs_instance = AnsibleCloudStackInstance(module)

@ -178,12 +178,6 @@ cloudstack_instance.instance_name:
import base64 import base64
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -270,9 +264,6 @@ def main():
supports_check_mode=False, supports_check_mode=False,
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
cs_instance_facts = AnsibleCloudStackInstanceFacts(module=module).run() cs_instance_facts = AnsibleCloudStackInstanceFacts(module=module).run()
cs_facts_result = dict(changed=False, ansible_facts=cs_instance_facts) cs_facts_result = dict(changed=False, ansible_facts=cs_instance_facts)
module.exit_json(**cs_facts_result) module.exit_json(**cs_facts_result)

@ -102,12 +102,6 @@ project:
sample: example project sample: example project
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -185,9 +179,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_ig = AnsibleCloudStackInstanceGroup(module) acs_ig = AnsibleCloudStackInstanceGroup(module)

@ -127,13 +127,6 @@ domain:
sample: example domain sample: example domain
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -209,7 +202,7 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
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, 'ipaddress') res = self.poll_job(res, 'ipaddress')
ip_address = res ip_address = res
return ip_address return ip_address
@ -228,7 +221,7 @@ class AnsibleCloudStackIPAddress(AnsibleCloudStack):
self.module.fail_json(msg="Failed: '%s'" % res['errortext']) 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')
return ip_address return ip_address
@ -252,9 +245,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_ip_address = AnsibleCloudStackIPAddress(module) acs_ip_address = AnsibleCloudStackIPAddress(module)

@ -197,12 +197,6 @@ project:
sample: example project sample: example project
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -319,9 +313,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_iso = AnsibleCloudStackIso(module) acs_iso = AnsibleCloudStackIso(module)

@ -217,12 +217,6 @@ state:
sample: "Add" sample: "Add"
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -333,7 +327,7 @@ class AnsibleCloudStackLBRule(AnsibleCloudStack):
self.module.fail_json(msg="Failed: '%s'" % res['errortext']) 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') res = self.poll_job(res, 'loadbalancer')
return rule return rule
@ -364,9 +358,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_lb_rule = AnsibleCloudStackLBRule(module) acs_lb_rule = AnsibleCloudStackLBRule(module)

@ -200,12 +200,6 @@ state:
sample: "Add" sample: "Add"
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -344,9 +338,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_lb_rule_member = AnsibleCloudStackLBRuleMember(module) acs_lb_rule_member = AnsibleCloudStackLBRuleMember(module)

@ -318,12 +318,6 @@ network_offering:
sample: DefaultIsolatedNetworkOfferingWithSourceNatService sample: DefaultIsolatedNetworkOfferingWithSourceNatService
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -428,7 +422,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
args = self._get_args() args = self._get_args()
args['id'] = network['id'] args['id'] = network['id']
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.cs.updateNetwork(**args)
@ -438,7 +432,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
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:
network = self._poll_job(network, 'network') network = self.poll_job(network, 'network')
return network return network
@ -496,7 +490,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
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:
network = self._poll_job(network, 'network') network = self.poll_job(network, 'network')
return network return network
@ -516,7 +510,7 @@ class AnsibleCloudStackNetwork(AnsibleCloudStack):
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') res = self.poll_job(res, 'network')
return network return network
@ -560,9 +554,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_network = AnsibleCloudStackNetwork(module) acs_network = AnsibleCloudStackNetwork(module)

@ -150,12 +150,6 @@ zone:
sample: ch-gva-2 sample: ch-gva-2
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -286,9 +280,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_pod = AnsibleCloudStackPod(module) acs_pod = AnsibleCloudStackPod(module)
state = module.params.get('state') state = module.params.get('state')

@ -203,12 +203,6 @@ vm_guest_ip:
sample: 10.101.65.152 sample: 10.101.65.152
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -233,33 +227,6 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
'privateendport': 'private_end_port', 'privateendport': 'private_end_port',
} }
self.portforwarding_rule = None self.portforwarding_rule = None
self.vm_default_nic = None
def get_vm_guest_ip(self):
vm_guest_ip = self.module.params.get('vm_guest_ip')
default_nic = self.get_vm_default_nic()
if not vm_guest_ip:
return default_nic['ipaddress']
for secondary_ip in default_nic['secondaryip']:
if vm_guest_ip == secondary_ip['ipaddress']:
return vm_guest_ip
self.module.fail_json(msg="Secondary IP '%s' not assigned to VM" % vm_guest_ip)
def get_vm_default_nic(self):
if self.vm_default_nic:
return self.vm_default_nic
nics = self.cs.listNics(virtualmachineid=self.get_vm(key='id'))
if nics:
for n in nics['nic']:
if n['isdefault']:
self.vm_default_nic = n
return self.vm_default_nic
self.module.fail_json(msg="No default IP address of VM '%s' found" % self.module.params.get('vm'))
def get_portforwarding_rule(self): def get_portforwarding_rule(self):
@ -311,7 +278,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
portforwarding_rule = self.cs.createPortForwardingRule(**args) portforwarding_rule = self.cs.createPortForwardingRule(**args)
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
portforwarding_rule = self._poll_job(portforwarding_rule, 'portforwardingrule') portforwarding_rule = self.poll_job(portforwarding_rule, 'portforwardingrule')
return portforwarding_rule return portforwarding_rule
@ -326,7 +293,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
args['ipaddressid'] = self.get_ip_address(key='id') args['ipaddressid'] = self.get_ip_address(key='id')
args['virtualmachineid'] = self.get_vm(key='id') args['virtualmachineid'] = self.get_vm(key='id')
if self._has_changed(args, portforwarding_rule): if self.has_changed(args, portforwarding_rule):
self.result['changed'] = True self.result['changed'] = True
if not self.module.check_mode: if not self.module.check_mode:
# API broken in 4.2.1?, workaround using remove/create instead of update # API broken in 4.2.1?, workaround using remove/create instead of update
@ -335,7 +302,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
portforwarding_rule = self.cs.createPortForwardingRule(**args) portforwarding_rule = self.cs.createPortForwardingRule(**args)
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
portforwarding_rule = self._poll_job(portforwarding_rule, 'portforwardingrule') portforwarding_rule = self.poll_job(portforwarding_rule, 'portforwardingrule')
return portforwarding_rule return portforwarding_rule
@ -351,7 +318,7 @@ class AnsibleCloudStackPortforwarding(AnsibleCloudStack):
res = self.cs.deletePortForwardingRule(**args) res = self.cs.deletePortForwardingRule(**args)
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, 'portforwardingrule') self.poll_job(res, 'portforwardingrule')
return portforwarding_rule return portforwarding_rule
@ -391,9 +358,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_pf = AnsibleCloudStackPortforwarding(module) acs_pf = AnsibleCloudStackPortforwarding(module)
state = module.params.get('state') state = module.params.get('state')

@ -53,6 +53,13 @@ options:
- Account the project is related to. - Account the project is related to.
required: false required: false
default: null default: null
tags:
description:
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
- "If you want to delete all tags, set a empty list e.g. C(tags: [])."
required: false
default: null
version_added: "2.2"
poll_async: poll_async:
description: description:
- Poll async jobs until job has finished. - Poll async jobs until job has finished.
@ -66,6 +73,9 @@ EXAMPLES = '''
- local_action: - local_action:
module: cs_project module: cs_project
name: web name: web
tags:
- { key: admin, value: john }
- { key: foo, value: bar }
# Rename a project # Rename a project
- local_action: - local_action:
@ -131,12 +141,6 @@ tags:
sample: '[ { "key": "foo", "value": "bar" } ]' sample: '[ { "key": "foo", "value": "bar" } ]'
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -167,6 +171,10 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
project = self.create_project(project) project = self.create_project(project)
else: else:
project = self.update_project(project) project = self.update_project(project)
if project:
project = self.ensure_tags(resource=project, resource_type='project')
# refresh resource
self.project = project
return project return project
@ -175,7 +183,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
args['id'] = project['id'] args['id'] = project['id']
args['displaytext'] = self.get_or_fallback('display_text', 'name') args['displaytext'] = self.get_or_fallback('display_text', 'name')
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.cs.updateProject(**args)
@ -185,7 +193,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
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:
project = self._poll_job(project, 'project') project = self.poll_job(project, 'project')
return project return project
@ -206,15 +214,12 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
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:
project = self._poll_job(project, 'project') project = self.poll_job(project, 'project')
return project return project
def state_project(self, state=None): def state_project(self, state='active'):
project = self.get_project() project = self.present_project()
if not project:
self.module.fail_json(msg="No project named '%s' found." % self.module.params('name'))
if project['state'].lower() != state: if project['state'].lower() != state:
self.result['changed'] = True self.result['changed'] = True
@ -233,7 +238,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
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:
project = self._poll_job(project, 'project') project = self.poll_job(project, 'project')
return project return project
@ -253,7 +258,7 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
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, 'project') res = self.poll_job(res, 'project')
return project return project
@ -267,6 +272,7 @@ def main():
domain = dict(default=None), domain = dict(default=None),
account = dict(default=None), account = dict(default=None),
poll_async = dict(type='bool', default=True), poll_async = dict(type='bool', default=True),
tags=dict(type='list', aliases=['tag'], default=None),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -275,9 +281,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_project = AnsibleCloudStackProject(module) acs_project = AnsibleCloudStackProject(module)

@ -115,12 +115,6 @@ project:
sample: example project sample: example project
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -206,9 +200,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: 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()

@ -160,12 +160,6 @@ account:
sample: admin sample: admin
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -233,7 +227,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
router = self._poll_job(res, 'router') router = self.poll_job(res, 'router')
return router return router
def stop_router(self): def stop_router(self):
@ -254,7 +248,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
router = self._poll_job(res, 'router') router = self.poll_job(res, 'router')
return router return router
def reboot_router(self): def reboot_router(self):
@ -274,7 +268,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
router = self._poll_job(res, 'router') router = self.poll_job(res, 'router')
return router return router
def absent_router(self): def absent_router(self):
@ -293,7 +287,7 @@ class AnsibleCloudStackRouter(AnsibleCloudStack):
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, 'router') self.poll_job(res, 'router')
return router return router
@ -358,9 +352,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_router = AnsibleCloudStackRouter(module) acs_router = AnsibleCloudStackRouter(module)

@ -113,12 +113,6 @@ account:
sample: example account sample: example account
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -203,9 +197,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_sg = AnsibleCloudStackSecurityGroup(module) acs_sg = AnsibleCloudStackSecurityGroup(module)

@ -181,12 +181,6 @@ end_port:
sample: 80 sample: 80
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -329,7 +323,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack):
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:
security_group = self._poll_job(res, 'securitygroup') security_group = self.poll_job(res, 'securitygroup')
key = sg_type + "rule" # ingressrule / egressrule key = sg_type + "rule" # ingressrule / egressrule
if key in security_group: if key in security_group:
rule = security_group[key][0] rule = security_group[key][0]
@ -360,7 +354,7 @@ class AnsibleCloudStackSecurityGroupRule(AnsibleCloudStack):
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, 'securitygroup') res = self.poll_job(res, 'securitygroup')
return rule return rule
@ -405,9 +399,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_sg_rule = AnsibleCloudStackSecurityGroupRule(module) acs_sg_rule = AnsibleCloudStackSecurityGroupRule(module)

@ -99,13 +99,6 @@ private_key:
sample: "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCkeFYjI+4k8bWfIRMzp4pCzhlopNydbbwRu824P5ilD4ATWMUG\nvEtuCQ2Mp5k5Bma30CdYHgh2/SbxC5RxXSUKTUJtTKpoJUy8PAhb1nn9dnfkC2oU\naRVi9NRUgypTIZxMpgooHOxvAzWxbZCyh1W+91Ld3FNaGxTLqTgeevY84wIDAQAB\nAoGAcwQwgLyUwsNB1vmjWwE0QEmvHS4FlhZyahhi4hGfZvbzAxSWHIK7YUT1c8KU\n9XsThEIN8aJ3GvcoL3OAqNKRnoNb14neejVHkYRadhxqc0GVN6AUIyCqoEMpvhFI\nQrinM572ORzv5ffRjCTbvZcYlW+sqFKNo5e8pYIB8TigpFECQQDu7bg9vkvg8xPs\nkP1K+EH0vsR6vUfy+m3euXjnbJtiP7RoTkZk0JQMOmexgy1qQhISWT0e451wd62v\nJ7M0trl5AkEAsDivJnMIlCCCypwPN4tdNUYpe9dtidR1zLmb3SA7wXk5xMUgLZI9\ncWPjBCMt0KKShdDhQ+hjXAyKQLF7iAPuOwJABjdHCMwvmy2XwhrPjCjDRoPEBtFv\n0sFzJE08+QBZVogDwIbwy+SlRWArnHGmN9J6N+H8dhZD3U4vxZPJ1MBAOQJBAJxO\nCv1dt1Q76gbwmYa49LnWO+F+2cgRTVODpr5iYt5fOmBQQRRqzFkRMkFvOqn+KVzM\nQ6LKM6dn8BEl295vLhUCQQCVDWzoSk3GjL3sOjfAUTyAj8VAXM69llaptxWWySPM\nE9pA+8rYmHfohYFx7FD5/KWCO+sfmxTNB48X0uwyE8tO\n-----END RSA PRIVATE KEY-----\n" sample: "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIBAAKBgQCkeFYjI+4k8bWfIRMzp4pCzhlopNydbbwRu824P5ilD4ATWMUG\nvEtuCQ2Mp5k5Bma30CdYHgh2/SbxC5RxXSUKTUJtTKpoJUy8PAhb1nn9dnfkC2oU\naRVi9NRUgypTIZxMpgooHOxvAzWxbZCyh1W+91Ld3FNaGxTLqTgeevY84wIDAQAB\nAoGAcwQwgLyUwsNB1vmjWwE0QEmvHS4FlhZyahhi4hGfZvbzAxSWHIK7YUT1c8KU\n9XsThEIN8aJ3GvcoL3OAqNKRnoNb14neejVHkYRadhxqc0GVN6AUIyCqoEMpvhFI\nQrinM572ORzv5ffRjCTbvZcYlW+sqFKNo5e8pYIB8TigpFECQQDu7bg9vkvg8xPs\nkP1K+EH0vsR6vUfy+m3euXjnbJtiP7RoTkZk0JQMOmexgy1qQhISWT0e451wd62v\nJ7M0trl5AkEAsDivJnMIlCCCypwPN4tdNUYpe9dtidR1zLmb3SA7wXk5xMUgLZI9\ncWPjBCMt0KKShdDhQ+hjXAyKQLF7iAPuOwJABjdHCMwvmy2XwhrPjCjDRoPEBtFv\n0sFzJE08+QBZVogDwIbwy+SlRWArnHGmN9J6N+H8dhZD3U4vxZPJ1MBAOQJBAJxO\nCv1dt1Q76gbwmYa49LnWO+F+2cgRTVODpr5iYt5fOmBQQRRqzFkRMkFvOqn+KVzM\nQ6LKM6dn8BEl295vLhUCQQCVDWzoSk3GjL3sOjfAUTyAj8VAXM69llaptxWWySPM\nE9pA+8rYmHfohYFx7FD5/KWCO+sfmxTNB48X0uwyE8tO\n-----END RSA PRIVATE KEY-----\n"
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
try: try:
import sshpubkeys import sshpubkeys
has_lib_sshpubkeys = True has_lib_sshpubkeys = True
@ -221,9 +214,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
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")

@ -146,13 +146,6 @@ domain:
sample: example domain sample: example domain
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -167,35 +160,6 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
'ipaddress': 'ip_address', 'ipaddress': 'ip_address',
'vmipaddress': 'vm_guest_ip', 'vmipaddress': 'vm_guest_ip',
} }
self.vm_default_nic = None
# TODO: move it to cloudstack utils, also used in cs_portforward
def get_vm_guest_ip(self):
vm_guest_ip = self.module.params.get('vm_guest_ip')
default_nic = self.get_vm_default_nic()
if not vm_guest_ip:
return default_nic['ipaddress']
for secondary_ip in default_nic['secondaryip']:
if vm_guest_ip == secondary_ip['ipaddress']:
return vm_guest_ip
self.module.fail_json(msg="Secondary IP '%s' not assigned to VM" % vm_guest_ip)
# TODO: move it to cloudstack utils, also used in cs_portforward
def get_vm_default_nic(self):
if self.vm_default_nic:
return self.vm_default_nic
nics = self.cs.listNics(virtualmachineid=self.get_vm(key='id'))
if nics:
for n in nics['nic']:
if n['isdefault']:
self.vm_default_nic = n
return self.vm_default_nic
self.module.fail_json(msg="No default IP address of VM '%s' found" % self.module.params.get('vm'))
def create_static_nat(self, ip_address): def create_static_nat(self, ip_address):
@ -224,13 +188,13 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
# make an alias, so we can use _has_changed() # make an alias, so we can use _has_changed()
ip_address['vmguestip'] = ip_address['vmipaddress'] ip_address['vmguestip'] = ip_address['vmipaddress']
if self._has_changed(args, ip_address): 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.cs.disableStaticNat(ipaddressid=ip_address['id'])
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'])
self._poll_job(res, 'staticnat') self.poll_job(res, 'staticnat')
res = self.cs.enableStaticNat(**args) res = self.cs.enableStaticNat(**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'])
@ -260,7 +224,7 @@ class AnsibleCloudStackStaticNat(AnsibleCloudStack):
self.module.fail_json(msg="Failed: '%s'" % res['errortext']) 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')
return ip_address return ip_address
@ -285,9 +249,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_static_nat = AnsibleCloudStackStaticNat(module) acs_static_nat = AnsibleCloudStackStaticNat(module)

@ -375,12 +375,6 @@ project:
sample: Production sample: Production
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -482,7 +476,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
template = self._poll_job(template, 'template') template = self.poll_job(template, 'template')
return template return template
@ -570,7 +564,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
template = self._poll_job(template, 'template') template = self.poll_job(template, 'template')
return template return template
@ -593,7 +587,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
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, 'template') res = self.poll_job(res, 'template')
return template return template
@ -643,9 +637,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_tpl = AnsibleCloudStackTemplate(module) acs_tpl = AnsibleCloudStackTemplate(module)

@ -197,12 +197,6 @@ domain:
sample: ROOT sample: ROOT
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -303,7 +297,7 @@ class AnsibleCloudStackUser(AnsibleCloudStack):
poll_async = self.module.params.get('poll_async') poll_async = self.module.params.get('poll_async')
if poll_async: if poll_async:
user = self._poll_job(user, 'user') user = self.poll_job(user, 'user')
return user return user
@ -424,9 +418,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_acc = AnsibleCloudStackUser(module) acs_acc = AnsibleCloudStackUser(module)

@ -162,12 +162,6 @@ project:
sample: Production sample: Production
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -215,7 +209,7 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack):
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:
snapshot = self._poll_job(res, 'vmsnapshot') snapshot = self.poll_job(res, 'vmsnapshot')
return snapshot return snapshot
@ -232,7 +226,7 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack):
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, 'vmsnapshot') res = self.poll_job(res, 'vmsnapshot')
return snapshot return snapshot
@ -249,7 +243,7 @@ class AnsibleCloudStackVmSnapshot(AnsibleCloudStack):
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, 'vmsnapshot') res = self.poll_job(res, 'vmsnapshot')
return snapshot return snapshot
self.module.fail_json(msg="snapshot not found, could not revert VM") self.module.fail_json(msg="snapshot not found, could not revert VM")
@ -282,9 +276,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_vmsnapshot = AnsibleCloudStackVmSnapshot(module) acs_vmsnapshot = AnsibleCloudStackVmSnapshot(module)

@ -230,12 +230,6 @@ device_id:
sample: 1 sample: 1
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -469,9 +463,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_vol = AnsibleCloudStackVolume(module) acs_vol = AnsibleCloudStackVolume(module)

@ -226,12 +226,6 @@ tags:
sample: [ { "key": "foo", "value": "bar" } ] sample: [ { "key": "foo", "value": "bar" } ]
''' '''
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -386,9 +380,6 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
try: try:
acs_zone = AnsibleCloudStackZone(module) acs_zone = AnsibleCloudStackZone(module)

@ -138,12 +138,6 @@ cloudstack_zone.tags:
import base64 import base64
try:
from cs import CloudStack, CloudStackException, read_config
has_lib_cs = True
except ImportError:
has_lib_cs = False
# import cloudstack common # import cloudstack common
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import *
@ -197,9 +191,6 @@ def main():
supports_check_mode=False, supports_check_mode=False,
) )
if not has_lib_cs:
module.fail_json(msg="python library cs required: pip install cs")
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)
module.exit_json(**cs_facts_result) module.exit_json(**cs_facts_result)

Loading…
Cancel
Save