����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: cs_pod
short_description: Manages pods on Apache CloudStack based clouds.
description:
- Create, update, delete pods.
author: René Moser (@resmo)
version_added: 0.1.0
options:
name:
description:
- Name of the pod.
type: str
required: true
id:
description:
- uuid of the existing pod.
type: str
start_ip:
description:
- Starting IP address for the Pod.
- Required on I(state=present)
type: str
end_ip:
description:
- Ending IP address for the Pod.
type: str
netmask:
description:
- Netmask for the Pod.
- Required on I(state=present)
type: str
gateway:
description:
- Gateway for the Pod.
- Required on I(state=present)
type: str
zone:
description:
- Name of the zone in which the pod belongs to.
type: str
required: true
state:
description:
- State of the pod.
type: str
default: present
choices: [ present, enabled, disabled, absent ]
extends_documentation_fragment:
- ngine_io.cloudstack.cloudstack
'''
EXAMPLES = '''
- name: Ensure a pod is present
ngine_io.cloudstack.cs_pod:
name: pod1
zone: ch-zrh-ix-01
start_ip: 10.100.10.101
gateway: 10.100.10.1
netmask: 255.255.255.0
- name: Ensure a pod is disabled
ngine_io.cloudstack.cs_pod:
name: pod1
zone: ch-zrh-ix-01
state: disabled
- name: Ensure a pod is enabled
ngine_io.cloudstack.cs_pod:
name: pod1
zone: ch-zrh-ix-01
state: enabled
- name: Ensure a pod is absent
ngine_io.cloudstack.cs_pod:
name: pod1
zone: ch-zrh-ix-01
state: absent
'''
RETURN = '''
---
id:
description: UUID of the pod.
returned: success
type: str
sample: 04589590-ac63-4ffc-93f5-b698b8ac38b6
name:
description: Name of the pod.
returned: success
type: str
sample: pod01
start_ip:
description: Starting IP of the pod.
returned: success
type: str
sample: 10.100.1.101
end_ip:
description: Ending IP of the pod.
returned: success
type: str
sample: 10.100.1.254
netmask:
description: Netmask of the pod.
returned: success
type: str
sample: 255.255.255.0
gateway:
description: Gateway of the pod.
returned: success
type: str
sample: 10.100.1.1
allocation_state:
description: State of the pod.
returned: success
type: str
sample: Enabled
zone:
description: Name of zone the pod is in.
returned: success
type: str
sample: ch-gva-2
'''
from ansible.module_utils.basic import AnsibleModule
from ..module_utils.cloudstack import (AnsibleCloudStack, cs_argument_spec,
cs_required_together)
class AnsibleCloudStackPod(AnsibleCloudStack):
def __init__(self, module):
super(AnsibleCloudStackPod, self).__init__(module)
self.returns = {
'endip': 'end_ip',
'startip': 'start_ip',
'gateway': 'gateway',
'netmask': 'netmask',
'allocationstate': 'allocation_state',
}
self.pod = None
def _get_common_pod_args(self):
args = {
'name': self.module.params.get('name'),
'zoneid': self.get_zone(key='id'),
'startip': self.module.params.get('start_ip'),
'endip': self.module.params.get('end_ip'),
'netmask': self.module.params.get('netmask'),
'gateway': self.module.params.get('gateway')
}
state = self.module.params.get('state')
if state in ['enabled', 'disabled']:
args['allocationstate'] = state.capitalize()
return args
def get_pod(self):
if not self.pod:
args = {
'zoneid': self.get_zone(key='id')
}
uuid = self.module.params.get('id')
if uuid:
args['id'] = uuid
else:
args['name'] = self.module.params.get('name')
pods = self.query_api('listPods', **args)
if pods:
for pod in pods['pod']:
if not args['name']:
self.pod = self._transform_ip_list(pod)
break
elif args['name'] == pod['name']:
self.pod = self._transform_ip_list(pod)
break
return self.pod
def present_pod(self):
pod = self.get_pod()
if pod:
pod = self._update_pod()
else:
pod = self._create_pod()
return pod
def _create_pod(self):
required_params = [
'start_ip',
'netmask',
'gateway',
]
self.module.fail_on_missing_params(required_params=required_params)
pod = None
self.result['changed'] = True
args = self._get_common_pod_args()
if not self.module.check_mode:
res = self.query_api('createPod', **args)
pod = res['pod']
return pod
def _update_pod(self):
pod = self.get_pod()
args = self._get_common_pod_args()
args['id'] = pod['id']
if self.has_changed(args, pod):
self.result['changed'] = True
if not self.module.check_mode:
res = self.query_api('updatePod', **args)
pod = res['pod']
return pod
def absent_pod(self):
pod = self.get_pod()
if pod:
self.result['changed'] = True
args = {
'id': pod['id']
}
if not self.module.check_mode:
self.query_api('deletePod', **args)
return pod
def _transform_ip_list(self, resource):
""" Workaround for 4.11 return API break """
keys = ['endip', 'startip']
if resource:
for key in keys:
if key in resource and isinstance(resource[key], list):
resource[key] = resource[key][0]
return resource
def get_result(self, resource):
resource = self._transform_ip_list(resource)
super(AnsibleCloudStackPod, self).get_result(resource)
return self.result
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
id=dict(),
name=dict(required=True),
gateway=dict(),
netmask=dict(),
start_ip=dict(),
end_ip=dict(),
zone=dict(required=True),
state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
))
module = AnsibleModule(
argument_spec=argument_spec,
required_together=cs_required_together(),
supports_check_mode=True
)
acs_pod = AnsibleCloudStackPod(module)
state = module.params.get('state')
if state in ['absent']:
pod = acs_pod.absent_pod()
else:
pod = acs_pod.present_pod()
result = acs_pod.get_result(pod)
module.exit_json(**result)
if __name__ == '__main__':
main()
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 0 B | 0644 |
|
| cs_account.py | File | 13.02 KB | 0644 |
|
| cs_affinitygroup.py | File | 6.37 KB | 0644 |
|
| cs_cluster.py | File | 10.71 KB | 0644 |
|
| cs_configuration.py | File | 7.77 KB | 0644 |
|
| cs_disk_offering.py | File | 11.04 KB | 0644 |
|
| cs_domain.py | File | 6.39 KB | 0644 |
|
| cs_facts.py | File | 7.48 KB | 0644 |
|
| cs_firewall.py | File | 13.35 KB | 0644 |
|
| cs_host.py | File | 17.08 KB | 0644 |
|
| cs_image_store.py | File | 6.87 KB | 0644 |
|
| cs_instance.py | File | 40.2 KB | 0644 |
|
| cs_instance_info.py | File | 11.64 KB | 0644 |
|
| cs_instance_nic.py | File | 7.33 KB | 0644 |
|
| cs_instance_nic_secondaryip.py | File | 7.41 KB | 0644 |
|
| cs_instance_password_reset.py | File | 3.87 KB | 0644 |
|
| cs_instancegroup.py | File | 4.66 KB | 0644 |
|
| cs_ip_address.py | File | 8.3 KB | 0644 |
|
| cs_iso.py | File | 12.65 KB | 0644 |
|
| cs_loadbalancer_rule.py | File | 10.25 KB | 0644 |
|
| cs_loadbalancer_rule_member.py | File | 9.1 KB | 0644 |
|
| cs_network.py | File | 18.44 KB | 0644 |
|
| cs_network_acl.py | File | 5.01 KB | 0644 |
|
| cs_network_acl_rule.py | File | 13.9 KB | 0644 |
|
| cs_network_offering.py | File | 15.52 KB | 0644 |
|
| cs_physical_network.py | File | 14.51 KB | 0644 |
|
| cs_pod.py | File | 7.1 KB | 0644 |
|
| cs_portforward.py | File | 12.46 KB | 0644 |
|
| cs_project.py | File | 7.3 KB | 0644 |
|
| cs_region.py | File | 4.65 KB | 0644 |
|
| cs_resourcelimit.py | File | 5.31 KB | 0644 |
|
| cs_role.py | File | 5.11 KB | 0644 |
|
| cs_role_permission.py | File | 9.53 KB | 0644 |
|
| cs_router.py | File | 9.76 KB | 0644 |
|
| cs_securitygroup.py | File | 5.1 KB | 0644 |
|
| cs_securitygroup_rule.py | File | 12.48 KB | 0644 |
|
| cs_service_offering.py | File | 17.56 KB | 0644 |
|
| cs_snapshot_policy.py | File | 10.31 KB | 0644 |
|
| cs_sshkeypair.py | File | 8.17 KB | 0644 |
|
| cs_staticnat.py | File | 6.65 KB | 0644 |
|
| cs_storage_pool.py | File | 14.88 KB | 0644 |
|
| cs_template.py | File | 23.38 KB | 0644 |
|
| cs_traffic_type.py | File | 9.89 KB | 0644 |
|
| cs_user.py | File | 11.46 KB | 0644 |
|
| cs_vlan_ip_range.py | File | 10.81 KB | 0644 |
|
| cs_vmsnapshot.py | File | 7.6 KB | 0644 |
|
| cs_volume.py | File | 16.71 KB | 0644 |
|
| cs_vpc.py | File | 11.02 KB | 0644 |
|
| cs_vpc_offering.py | File | 9.69 KB | 0644 |
|
| cs_vpn_connection.py | File | 10.14 KB | 0644 |
|
| cs_vpn_customer_gateway.py | File | 10.54 KB | 0644 |
|
| cs_vpn_gateway.py | File | 5.33 KB | 0644 |
|
| cs_zone.py | File | 9.64 KB | 0644 |
|
| cs_zone_info.py | File | 5.27 KB | 0644 |
|