|
|
@ -1,22 +1,9 @@
|
|
|
|
#!/usr/bin/python
|
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# (c) 2015, René Moser <mail@renemoser.net>
|
|
|
|
# Copyright (c) 2017, René Moser <mail@renemoser.net>
|
|
|
|
#
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# This file is part of Ansible
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|
|
|
'status': ['stableinterface'],
|
|
|
|
'status': ['stableinterface'],
|
|
|
@ -40,160 +27,129 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Display text of the network.
|
|
|
|
- Display text of the network.
|
|
|
|
- If not specified, C(name) will be used as C(display_text).
|
|
|
|
- If not specified, C(name) will be used as C(display_text).
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
network_offering:
|
|
|
|
network_offering:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Name of the offering for the network.
|
|
|
|
- Name of the offering for the network.
|
|
|
|
- Required if C(state=present).
|
|
|
|
- Required if C(state=present).
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
start_ip:
|
|
|
|
start_ip:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The beginning IPv4 address of the network belongs to.
|
|
|
|
- The beginning IPv4 address of the network belongs to.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
end_ip:
|
|
|
|
end_ip:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The ending IPv4 address of the network belongs to.
|
|
|
|
- The ending IPv4 address of the network belongs to.
|
|
|
|
- If not specified, value of C(start_ip) is used.
|
|
|
|
- If not specified, value of C(start_ip) is used.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
gateway:
|
|
|
|
gateway:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The gateway of the network.
|
|
|
|
- The gateway of the network.
|
|
|
|
- Required for shared networks and isolated networks when it belongs to a VPC.
|
|
|
|
- Required for shared networks and isolated networks when it belongs to a VPC.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
netmask:
|
|
|
|
netmask:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The netmask of the network.
|
|
|
|
- The netmask of the network.
|
|
|
|
- Required for shared networks and isolated networks when it belongs to a VPC.
|
|
|
|
- Required for shared networks and isolated networks when it belongs to a VPC.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
start_ipv6:
|
|
|
|
start_ipv6:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The beginning IPv6 address of the network belongs to.
|
|
|
|
- The beginning IPv6 address of the network belongs to.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
end_ipv6:
|
|
|
|
end_ipv6:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The ending IPv6 address of the network belongs to.
|
|
|
|
- The ending IPv6 address of the network belongs to.
|
|
|
|
- If not specified, value of C(start_ipv6) is used.
|
|
|
|
- If not specified, value of C(start_ipv6) is used.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
cidr_ipv6:
|
|
|
|
cidr_ipv6:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- CIDR of IPv6 network, must be at least /64.
|
|
|
|
- CIDR of IPv6 network, must be at least /64.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
gateway_ipv6:
|
|
|
|
gateway_ipv6:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The gateway of the IPv6 network.
|
|
|
|
- The gateway of the IPv6 network.
|
|
|
|
- Required for shared networks.
|
|
|
|
- Required for shared networks.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
vlan:
|
|
|
|
vlan:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The ID or VID of the network.
|
|
|
|
- The ID or VID of the network.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
vpc:
|
|
|
|
vpc:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Name of the VPC of the network.
|
|
|
|
- Name of the VPC of the network.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
isolated_pvlan:
|
|
|
|
isolated_pvlan:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The isolated private VLAN for this network.
|
|
|
|
- The isolated private VLAN for this network.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
clean_up:
|
|
|
|
clean_up:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Cleanup old network elements.
|
|
|
|
- Cleanup old network elements.
|
|
|
|
- Only considered on C(state=restarted).
|
|
|
|
- Only considered on C(state=restarted).
|
|
|
|
required: false
|
|
|
|
default: no
|
|
|
|
default: false
|
|
|
|
type: bool
|
|
|
|
acl_type:
|
|
|
|
acl_type:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Access control type.
|
|
|
|
- Access control type.
|
|
|
|
- Only considered on create.
|
|
|
|
- Only considered on create.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: account
|
|
|
|
default: account
|
|
|
|
choices: [ 'account', 'domain' ]
|
|
|
|
choices: [ account, domain ]
|
|
|
|
|
|
|
|
subdomain_access:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Defines whether to allow subdomains to use networks dedicated to their parent domain(s).
|
|
|
|
|
|
|
|
- Should be used with C(acl_type=domain).
|
|
|
|
|
|
|
|
- Only considered on create.
|
|
|
|
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
version_added: "2.5"
|
|
|
|
network_domain:
|
|
|
|
network_domain:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The network domain.
|
|
|
|
- The network domain.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
state:
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- State of the network.
|
|
|
|
- State of the network.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: present
|
|
|
|
default: present
|
|
|
|
choices: [ 'present', 'absent', 'restarted' ]
|
|
|
|
choices: [ present, absent, restarted ]
|
|
|
|
zone:
|
|
|
|
zone:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Name of the zone in which the network should be deployed.
|
|
|
|
- Name of the zone in which the network should be deployed.
|
|
|
|
- If not set, default zone is used.
|
|
|
|
- If not set, default zone is used.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
project:
|
|
|
|
project:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Name of the project the network to be deployed in.
|
|
|
|
- Name of the project the network to be deployed in.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
domain:
|
|
|
|
domain:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Domain the network is related to.
|
|
|
|
- Domain the network is related to.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
account:
|
|
|
|
account:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Account the network is related to.
|
|
|
|
- Account the network is related to.
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
poll_async:
|
|
|
|
poll_async:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Poll async jobs until job has finished.
|
|
|
|
- Poll async jobs until job has finished.
|
|
|
|
required: false
|
|
|
|
default: yes
|
|
|
|
default: true
|
|
|
|
type: bool
|
|
|
|
extends_documentation_fragment: cloudstack
|
|
|
|
extends_documentation_fragment: cloudstack
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
|
# create a network
|
|
|
|
- name: Create a network
|
|
|
|
- local_action:
|
|
|
|
local_action:
|
|
|
|
module: cs_network
|
|
|
|
module: cs_network
|
|
|
|
name: my network
|
|
|
|
name: my network
|
|
|
|
zone: gva-01
|
|
|
|
zone: gva-01
|
|
|
|
network_offering: DefaultIsolatedNetworkOfferingWithSourceNatService
|
|
|
|
network_offering: DefaultIsolatedNetworkOfferingWithSourceNatService
|
|
|
|
network_domain: example.com
|
|
|
|
network_domain: example.com
|
|
|
|
|
|
|
|
|
|
|
|
# update a network
|
|
|
|
- name: Update a network
|
|
|
|
- local_action:
|
|
|
|
local_action:
|
|
|
|
module: cs_network
|
|
|
|
module: cs_network
|
|
|
|
name: my network
|
|
|
|
name: my network
|
|
|
|
display_text: network of domain example.local
|
|
|
|
display_text: network of domain example.local
|
|
|
|
network_domain: example.local
|
|
|
|
network_domain: example.local
|
|
|
|
|
|
|
|
|
|
|
|
# restart a network with clean up
|
|
|
|
- name: Restart a network with clean up
|
|
|
|
- local_action:
|
|
|
|
local_action:
|
|
|
|
module: cs_network
|
|
|
|
module: cs_network
|
|
|
|
name: my network
|
|
|
|
name: my network
|
|
|
|
clean_up: yes
|
|
|
|
clean_up: yes
|
|
|
|
state: restared
|
|
|
|
state: restared
|
|
|
|
|
|
|
|
|
|
|
|
# remove a network
|
|
|
|
- name: Remove a network
|
|
|
|
- local_action:
|
|
|
|
local_action:
|
|
|
|
module: cs_network
|
|
|
|
module: cs_network
|
|
|
|
name: my network
|
|
|
|
name: my network
|
|
|
|
state: absent
|
|
|
|
state: absent
|
|
|
@ -503,6 +459,7 @@ def main():
|
|
|
|
isolated_pvlan=dict(),
|
|
|
|
isolated_pvlan=dict(),
|
|
|
|
clean_up=dict(type='bool', default=False),
|
|
|
|
clean_up=dict(type='bool', default=False),
|
|
|
|
network_domain=dict(),
|
|
|
|
network_domain=dict(),
|
|
|
|
|
|
|
|
subdomain_access=dict(type='bool'),
|
|
|
|
state=dict(choices=['present', 'absent', 'restarted'], default='present'),
|
|
|
|
state=dict(choices=['present', 'absent', 'restarted'], default='present'),
|
|
|
|
acl_type=dict(choices=['account', 'domain']),
|
|
|
|
acl_type=dict(choices=['account', 'domain']),
|
|
|
|
project=dict(),
|
|
|
|
project=dict(),
|
|
|
@ -524,10 +481,10 @@ def main():
|
|
|
|
acs_network = AnsibleCloudStackNetwork(module)
|
|
|
|
acs_network = AnsibleCloudStackNetwork(module)
|
|
|
|
|
|
|
|
|
|
|
|
state = module.params.get('state')
|
|
|
|
state = module.params.get('state')
|
|
|
|
if state in ['absent']:
|
|
|
|
if state == 'absent':
|
|
|
|
network = acs_network.absent_network()
|
|
|
|
network = acs_network.absent_network()
|
|
|
|
|
|
|
|
|
|
|
|
elif state in ['restarted']:
|
|
|
|
elif state == 'restarted':
|
|
|
|
network = acs_network.restart_network()
|
|
|
|
network = acs_network.restart_network()
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|