Skip to content

Commit 24d1733

Browse files
authored
Allow passing cluster and pod details when deploying an VM (#105)
1 parent 6da2b06 commit 24d1733

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

plugins/modules/cs_instance.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@
135135
- Only considered when I(state=started) or instance is running.
136136
- Requires root admin privileges.
137137
type: str
138+
cluster:
139+
description:
140+
- Cluster on which an instance should be deployed or started on.
141+
- Only considered when I(state=started) or instance is running.
142+
- Requires root admin privileges.
143+
type: str
144+
pod:
145+
description:
146+
- Pod on which an instance should be deployed or started on.
147+
- Only considered when I(state=started) or instance is running.
148+
- Requires root admin privileges.
149+
type: str
138150
domain:
139151
description:
140152
- Domain the instance is related to.
@@ -469,11 +481,43 @@ def get_host_id(self):
469481
hosts = self.query_api('listHosts', **args)
470482
if hosts:
471483
for h in hosts['host']:
472-
if h['name'] == host_name:
484+
if host_name in [h['name'], h['id']]:
473485
return h['id']
474486

475487
self.fail_json(msg="Host '%s' not found" % host_name)
476488

489+
def get_cluster_id(self):
490+
cluster_name = self.module.params.get('cluster')
491+
if not cluster_name:
492+
return None
493+
494+
args = {
495+
'zoneid': self.get_zone(key='id')
496+
}
497+
clusters = self.query_api('listClusters', **args)
498+
if clusters:
499+
for c in clusters['cluster']:
500+
if cluster_name in [c['name'], c['id']]:
501+
return c['id']
502+
503+
self.fail_json(msg="Cluster '%s' not found" % cluster_name)
504+
505+
def get_pod_id(self):
506+
pod_name = self.module.params.get('pod')
507+
if not pod_name:
508+
return None
509+
510+
args = {
511+
'zoneid': self.get_zone(key='id')
512+
}
513+
pods = self.query_api('listPods', **args)
514+
if pods:
515+
for p in pods['pod']:
516+
if pod_name in [p['name'], p['id']]:
517+
return p['id']
518+
519+
self.fail_json(msg="Pod '%s' not found" % pod_name)
520+
477521
def get_template_or_iso(self, key=None):
478522
template = self.module.params.get('template')
479523
iso = self.module.params.get('iso')
@@ -740,6 +784,8 @@ def deploy_instance(self, start_vm=True):
740784
args['details'] = self.get_details()
741785
args['securitygroupnames'] = self.module.params.get('security_groups')
742786
args['hostid'] = self.get_host_id()
787+
args['clusterid'] = self.get_cluster_id()
788+
args['podid'] = self.get_pod_id()
743789

744790
template_iso = self.get_template_or_iso()
745791
if 'hypervisor' not in template_iso:
@@ -1038,6 +1084,8 @@ def main():
10381084
keyboard=dict(type='str', choices=['de', 'de-ch', 'es', 'fi', 'fr', 'fr-be', 'fr-ch', 'is', 'it', 'jp', 'nl-be', 'no', 'pt', 'uk', 'us']),
10391085
hypervisor=dict(),
10401086
host=dict(),
1087+
cluster=dict(),
1088+
pod=dict(),
10411089
security_groups=dict(type='list', elements='str', aliases=['security_group']),
10421090
affinity_groups=dict(type='list', elements='str', aliases=['affinity_group']),
10431091
domain=dict(),

0 commit comments

Comments
 (0)