|
|
@ -37,12 +37,12 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Password of login user
|
|
|
|
- Password of login user
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
default: True
|
|
|
|
default: 'yes'
|
|
|
|
login_tenant_name:
|
|
|
|
login_tenant_name:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The tenant name of the login user
|
|
|
|
- The tenant name of the login user
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
default: True
|
|
|
|
default: 'yes'
|
|
|
|
auth_url:
|
|
|
|
auth_url:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- The keystone url for authentication
|
|
|
|
- The keystone url for authentication
|
|
|
@ -124,8 +124,8 @@ def _get_router_id(module, quantum):
|
|
|
|
|
|
|
|
|
|
|
|
def _get_net_id(quantum, module):
|
|
|
|
def _get_net_id(quantum, module):
|
|
|
|
kwargs = {
|
|
|
|
kwargs = {
|
|
|
|
'name': module.params['network_name'],
|
|
|
|
'name': module.params['network_name'],
|
|
|
|
'router:external': True
|
|
|
|
'router:external': True
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
networks = quantum.list_networks(**kwargs)
|
|
|
|
networks = quantum.list_networks(**kwargs)
|
|
|
@ -135,11 +135,10 @@ def _get_net_id(quantum, module):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
return networks['networks'][0]['id']
|
|
|
|
return networks['networks'][0]['id']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_port_id(quantum, module, router_id, network_id):
|
|
|
|
def _get_port_id(quantum, module, router_id, network_id):
|
|
|
|
kwargs = {
|
|
|
|
kwargs = {
|
|
|
|
'device_id': router_id,
|
|
|
|
'device_id': router_id,
|
|
|
|
'network_id': network_id,
|
|
|
|
'network_id': network_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ports = quantum.list_ports(**kwargs)
|
|
|
|
ports = quantum.list_ports(**kwargs)
|
|
|
@ -151,7 +150,7 @@ def _get_port_id(quantum, module, router_id, network_id):
|
|
|
|
|
|
|
|
|
|
|
|
def _add_gateway_router(quantum, module, router_id, network_id):
|
|
|
|
def _add_gateway_router(quantum, module, router_id, network_id):
|
|
|
|
kwargs = {
|
|
|
|
kwargs = {
|
|
|
|
'network_id': network_id
|
|
|
|
'network_id': network_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
quantum.add_gateway_router(router_id, kwargs)
|
|
|
|
quantum.add_gateway_router(router_id, kwargs)
|
|
|
@ -163,46 +162,47 @@ def _remove_gateway_router(quantum, module, router_id):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
quantum.remove_gateway_router(router_id)
|
|
|
|
quantum.remove_gateway_router(router_id)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg = "Error in removing gateway to router: %s" % e.message)
|
|
|
|
module.fail_json(msg = "Error in removing gateway to router: %s" % e.message)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
login_username = dict(default='admin'),
|
|
|
|
login_username = dict(default='admin'),
|
|
|
|
login_password = dict(required=True),
|
|
|
|
login_password = dict(required=True),
|
|
|
|
login_tenant_name = dict(required='True'),
|
|
|
|
login_tenant_name = dict(required='True'),
|
|
|
|
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
|
|
|
|
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
|
|
|
|
region_name = dict(default=None),
|
|
|
|
region_name = dict(default=None),
|
|
|
|
router_name = dict(required=True),
|
|
|
|
router_name = dict(required=True),
|
|
|
|
network_name = dict(required=True),
|
|
|
|
network_name = dict(required=True),
|
|
|
|
state = dict(default='present', choices=['absent', 'present']),
|
|
|
|
state = dict(default='present', choices=['absent', 'present']),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
quantum = _get_quantum_client(module, module.params)
|
|
|
|
quantum = _get_quantum_client(module, module.params)
|
|
|
|
router_id = _get_router_id(module, quantum)
|
|
|
|
router_id = _get_router_id(module, quantum)
|
|
|
|
|
|
|
|
|
|
|
|
if not router_id:
|
|
|
|
if not router_id:
|
|
|
|
module.fail_json(msg = "failed to get the router id, please check the router name")
|
|
|
|
module.fail_json(msg="failed to get the router id, please check the router name")
|
|
|
|
|
|
|
|
|
|
|
|
network_id = _get_net_id(quantum, module)
|
|
|
|
network_id = _get_net_id(quantum, module)
|
|
|
|
if not network_id:
|
|
|
|
if not network_id:
|
|
|
|
module.fail_json(msg = "failed to get the network id, please check the network name and make sure it is external")
|
|
|
|
module.fail_json(msg="failed to get the network id, please check the network name and make sure it is external")
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['state'] == 'present':
|
|
|
|
if module.params['state'] == 'present':
|
|
|
|
port_id = _get_port_id(quantum, module, router_id, network_id)
|
|
|
|
port_id = _get_port_id(quantum, module, router_id, network_id)
|
|
|
|
if not port_id:
|
|
|
|
if not port_id:
|
|
|
|
_add_gateway_router(quantum, module, router_id, network_id)
|
|
|
|
_add_gateway_router(quantum, module, router_id, network_id)
|
|
|
|
module.exit_json(changed = True, result = "created")
|
|
|
|
module.exit_json(changed=True, result="created")
|
|
|
|
module.exit_json(changed = False, result = "success")
|
|
|
|
module.exit_json(changed=False, result="success")
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['state'] == 'absent':
|
|
|
|
if module.params['state'] == 'absent':
|
|
|
|
port_id = _get_port_id(quantum, module, router_id, network_id)
|
|
|
|
port_id = _get_port_id(quantum, module, router_id, network_id)
|
|
|
|
if not port_id:
|
|
|
|
if not port_id:
|
|
|
|
module.exit_json(changed = False, result = "Success")
|
|
|
|
module.exit_json(changed=False, result="Success")
|
|
|
|
_remove_gateway_router(quantum, module, router_id)
|
|
|
|
_remove_gateway_router(quantum, module, router_id)
|
|
|
|
module.exit_json(changed = True, result = "Deleted")
|
|
|
|
module.exit_json(changed=True, result="Deleted")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# this is magic, see lib/ansible/module.params['common.py
|
|
|
|
# this is magic, see lib/ansible/module.params['common.py
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|