Skip to content

Commit

Permalink
cs_vlan_ip_range: implement pod argument (#20)
Browse files Browse the repository at this point in the history
* cs_vlan_ip_range: implement pod argument

* add changelog fragment
  • Loading branch information
resmo authored Aug 15, 2020
1 parent 9c09963 commit 518f19b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/20-cs_vlan_ip_range_pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- cs_vlan_ip_range - Added support to specify pod name (https://github.com/ngine-io/ansible-collection-cloudstack/pull/20)
13 changes: 13 additions & 0 deletions plugins/module_utils/cloudstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,19 @@ def get_project(self, key=None):
return self._get_by_key(key, self.project)
self.fail_json(msg="project '%s' not found" % project)

def get_pod(self, key=None):
pod_name = self.module.params.get('pod')
if not pod_name:
return None
args = {
'name': pod_name,
'zoneid': self.get_zone(key='id'),
}
pods = self.query_api('listPods', **args)
if pods:
return self._get_by_key(key, pods['pod'][0])
self.module.fail_json(msg="Pod %s not found" % pod_name)

def get_ip_address(self, key=None):
if self.ip_address:
return self._get_by_key(key, self.ip_address)
Expand Down
10 changes: 0 additions & 10 deletions plugins/modules/cs_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,6 @@ def _get_common_cluster_args(self):
args['allocationstate'] = state.capitalize()
return args

def get_pod(self, key=None):
args = {
'name': self.module.params.get('pod'),
'zoneid': self.get_zone(key='id'),
}
pods = self.query_api('listPods', **args)
if pods:
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')))

def get_cluster(self):
if not self.cluster:
args = {}
Expand Down
13 changes: 0 additions & 13 deletions plugins/modules/cs_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,6 @@ def __init__(self, module):
}
self.host = None

def get_pod(self, key=None):
pod_name = self.module.params.get('pod')
if not pod_name:
return None
args = {
'name': pod_name,
'zoneid': self.get_zone(key='id'),
}
pods = self.query_api('listPods', **args)
if pods:
return self._get_by_key(key, pods['pod'][0])
self.module.fail_json(msg="Pod %s not found" % pod_name)

def get_cluster(self, key=None):
cluster_name = self.module.params.get('cluster')
if not cluster_name:
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/cs_vlan_ip_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
- The ID or VID of the network.
- If not specified, will be defaulted to the vlan of the network.
type: str
pod:
description:
- Name of the pod.
type: str
state:
description:
- State of the network ip range.
Expand Down Expand Up @@ -312,6 +316,7 @@ def create_vlan_ip_range(self):
'networkid': self.get_network(key='id'),
'forvirtualnetwork': self.module.params.get('for_virtual_network'),
'forsystemvms': self.module.params.get('for_system_vms'),
'podid': self.get_pod(key='id'),
}
if self.module.params.get('physical_network'):
args['physicalnetworkid'] = self.get_physical_network(key='id')
Expand Down Expand Up @@ -358,6 +363,7 @@ def main():
domain=dict(type='str'),
account=dict(type='str'),
project=dict(type='str'),
pod=dict(type='str'),
for_virtual_network=dict(type='bool', default=False),
for_system_vms=dict(type='bool', default=False),
))
Expand Down

0 comments on commit 518f19b

Please sign in to comment.