|
|
@ -146,30 +146,33 @@ tags:
|
|
|
|
sample: '[ { "key": "foo", "value": "bar" } ]'
|
|
|
|
sample: '[ { "key": "foo", "value": "bar" } ]'
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
# import cloudstack common
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.cloudstack import *
|
|
|
|
from ansible.module_utils.cloudstack import (
|
|
|
|
|
|
|
|
AnsibleCloudStack,
|
|
|
|
|
|
|
|
CloudStackException,
|
|
|
|
|
|
|
|
cs_argument_spec,
|
|
|
|
|
|
|
|
cs_required_together
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_project(self):
|
|
|
|
def get_project(self):
|
|
|
|
if not self.project:
|
|
|
|
if not self.project:
|
|
|
|
project = self.module.params.get('name')
|
|
|
|
project = self.module.params.get('name')
|
|
|
|
|
|
|
|
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['account'] = self.get_account(key='name')
|
|
|
|
'account': self.get_account(key='name'),
|
|
|
|
args['domainid'] = self.get_domain(key='id')
|
|
|
|
'domainid': self.get_domain(key='id')
|
|
|
|
|
|
|
|
}
|
|
|
|
projects = self.cs.listProjects(**args)
|
|
|
|
projects = self.cs.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']]:
|
|
|
|
self.project = p
|
|
|
|
self.project = p
|
|
|
|
break
|
|
|
|
break
|
|
|
|
return self.project
|
|
|
|
return self.project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def present_project(self):
|
|
|
|
def present_project(self):
|
|
|
|
project = self.get_project()
|
|
|
|
project = self.get_project()
|
|
|
|
if not project:
|
|
|
|
if not project:
|
|
|
@ -182,12 +185,11 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
self.project = project
|
|
|
|
self.project = project
|
|
|
|
return project
|
|
|
|
return project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_project(self, project):
|
|
|
|
def update_project(self, project):
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['id'] = project['id']
|
|
|
|
'id': project['id'],
|
|
|
|
args['displaytext'] = self.get_or_fallback('display_text', 'name')
|
|
|
|
'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:
|
|
|
@ -201,16 +203,15 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
project = self.poll_job(project, 'project')
|
|
|
|
project = self.poll_job(project, 'project')
|
|
|
|
return project
|
|
|
|
return project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_project(self, project):
|
|
|
|
def create_project(self, project):
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['name'] = self.module.params.get('name')
|
|
|
|
'name': self.module.params.get('name'),
|
|
|
|
args['displaytext'] = self.get_or_fallback('display_text', 'name')
|
|
|
|
'displaytext': self.get_or_fallback('display_text', 'name'),
|
|
|
|
args['account'] = self.get_account('name')
|
|
|
|
'account': self.get_account('name'),
|
|
|
|
args['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.cs.createProject(**args)
|
|
|
|
|
|
|
|
|
|
|
@ -222,16 +223,15 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
project = self.poll_job(project, 'project')
|
|
|
|
project = self.poll_job(project, 'project')
|
|
|
|
return project
|
|
|
|
return project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def state_project(self, state='active'):
|
|
|
|
def state_project(self, state='active'):
|
|
|
|
project = self.present_project()
|
|
|
|
project = self.present_project()
|
|
|
|
|
|
|
|
|
|
|
|
if project['state'].lower() != state:
|
|
|
|
if project['state'].lower() != state:
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['id'] = project['id']
|
|
|
|
'id': project['id']
|
|
|
|
|
|
|
|
}
|
|
|
|
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.cs.suspendProject(**args)
|
|
|
@ -246,15 +246,14 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
project = self.poll_job(project, 'project')
|
|
|
|
project = self.poll_job(project, 'project')
|
|
|
|
return project
|
|
|
|
return project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def absent_project(self):
|
|
|
|
def absent_project(self):
|
|
|
|
project = self.get_project()
|
|
|
|
project = self.get_project()
|
|
|
|
if project:
|
|
|
|
if project:
|
|
|
|
self.result['changed'] = True
|
|
|
|
self.result['changed'] = True
|
|
|
|
|
|
|
|
|
|
|
|
args = {}
|
|
|
|
args = {
|
|
|
|
args['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.cs.deleteProject(**args)
|
|
|
|
|
|
|
|
|
|
|
@ -267,17 +266,16 @@ class AnsibleCloudStackProject(AnsibleCloudStack):
|
|
|
|
return project
|
|
|
|
return project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
display_text = dict(default=None),
|
|
|
|
display_text=dict(),
|
|
|
|
state = dict(choices=['present', 'absent', 'active', 'suspended' ], default='present'),
|
|
|
|
state=dict(choices=['present', 'absent', 'active', 'suspended'], default='present'),
|
|
|
|
domain = dict(default=None),
|
|
|
|
domain=dict(),
|
|
|
|
account = dict(default=None),
|
|
|
|
account=dict(),
|
|
|
|
poll_async = dict(type='bool', default=True),
|
|
|
|
poll_async=dict(type='bool', default=True),
|
|
|
|
tags=dict(type='list', aliases=['tag'], default=None),
|
|
|
|
tags=dict(type='list', aliases=['tag']),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
@ -306,7 +304,6 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|