cloudstack: cs_sshkeypair: add account and domain support

reviewable/pr18780/r1
Rene Moser 10 years ago
parent 8afc822d0c
commit 95305f4ea9

@ -23,6 +23,7 @@ DOCUMENTATION = '''
module: cs_sshkeypair
short_description: Manages SSH keys on Apache CloudStack based clouds.
description:
- Create, register and remove SSH keys.
- If no key was found and no public key was provided and a new SSH
private/public key pair will be created and the private key will be returned.
version_added: '2.0'
@ -32,6 +33,16 @@ options:
description:
- Name of public key.
required: true
domain:
description:
- Domain the public key is related to.
required: false
default: null
account:
description:
- Account the public key is related to.
required: false
default: null
project:
description:
- Name of the project the public key to be registered in.
@ -111,9 +122,10 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
def register_ssh_key(self, public_key):
ssh_key = self.get_ssh_key()
args = {}
args['projectid'] = self.get_project_id()
args['domainid'] = self.get_domain('id')
args['account'] = self.get_account('name')
args['projectid'] = self.get_project('id')
args['name'] = self.module.params.get('name')
res = None
@ -143,7 +155,9 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
if not ssh_key:
self.result['changed'] = True
args = {}
args['projectid'] = self.get_project_id()
args['domainid'] = self.get_domain('id')
args['account'] = self.get_account('name')
args['projectid'] = self.get_project('id')
args['name'] = self.module.params.get('name')
if not self.module.check_mode:
res = self.cs.createSSHKeyPair(**args)
@ -156,8 +170,10 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
if ssh_key:
self.result['changed'] = True
args = {}
args['domainid'] = self.get_domain('id')
args['account'] = self.get_account('name')
args['projectid'] = self.get_project('id')
args['name'] = self.module.params.get('name')
args['projectid'] = self.get_project_id()
if not self.module.check_mode:
res = self.cs.deleteSSHKeyPair(**args)
return ssh_key
@ -166,7 +182,9 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
def get_ssh_key(self):
if not self.ssh_key:
args = {}
args['projectid'] = self.get_project_id()
args['domainid'] = self.get_domain('id')
args['account'] = self.get_account('name')
args['projectid'] = self.get_project('id')
args['name'] = self.module.params.get('name')
ssh_keys = self.cs.listSSHKeyPairs(**args)
@ -179,10 +197,8 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
if ssh_key:
if 'fingerprint' in ssh_key:
self.result['fingerprint'] = ssh_key['fingerprint']
if 'name' in ssh_key:
self.result['name'] = ssh_key['name']
if 'privatekey' in ssh_key:
self.result['private_key'] = ssh_key['privatekey']
return self.result
@ -196,8 +212,10 @@ class AnsibleCloudStackSshKey(AnsibleCloudStack):
def main():
module = AnsibleModule(
argument_spec = dict(
name = dict(required=True, default=None),
name = dict(required=True),
public_key = dict(default=None),
domain = dict(default=None),
account = dict(default=None),
project = dict(default=None),
state = dict(choices=['present', 'absent'], default='present'),
api_key = dict(default=None),

Loading…
Cancel
Save