mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Fix tabs and spaces in OpenStack modules.
This commit is contained in:
parent
e5c2d0b247
commit
9c5d6f11f0
11 changed files with 472 additions and 471 deletions
80
library/cloud/quantum_floating_ip
Executable file → Normal file
80
library/cloud/quantum_floating_ip
Executable file → Normal file
|
@ -110,24 +110,24 @@ def _get_quantum_client(module, kwargs):
|
|||
quantum = client.Client('2.0', **kwargs)
|
||||
except Exception as e:
|
||||
module.fail_json(msg = "Error in connecting to quantum: %s " % e.message)
|
||||
return quantum
|
||||
return quantum
|
||||
|
||||
def _get_server_state(module, nova):
|
||||
server_info = None
|
||||
server = None
|
||||
try:
|
||||
for server in nova.servers.list():
|
||||
if server:
|
||||
info = server._info
|
||||
if info['name'] == module.params['instance_name']:
|
||||
if info['status'] != 'ACTIVE' and module.params['state'] == 'present':
|
||||
module.fail_json( msg="The VM is available but not Active. state:" + info['status'])
|
||||
server_info = info
|
||||
break
|
||||
if server:
|
||||
info = server._info
|
||||
if info['name'] == module.params['instance_name']:
|
||||
if info['status'] != 'ACTIVE' and module.params['state'] == 'present':
|
||||
module.fail_json( msg="The VM is available but not Active. state:" + info['status'])
|
||||
server_info = info
|
||||
break
|
||||
except Exception as e:
|
||||
module.fail_json(msg = "Error in getting the server list: %s" % e.message)
|
||||
return server_info, server
|
||||
|
||||
module.fail_json(msg = "Error in getting the server list: %s" % e.message)
|
||||
return server_info, server
|
||||
|
||||
def _get_port_info(quantum, module, instance_id):
|
||||
kwargs = {
|
||||
'device_id': instance_id,
|
||||
|
@ -139,7 +139,7 @@ def _get_port_info(quantum, module, instance_id):
|
|||
if not ports['ports']:
|
||||
return None, None
|
||||
return ports['ports'][0]['fixed_ips'][0]['ip_address'], ports['ports'][0]['id']
|
||||
|
||||
|
||||
def _get_floating_ip(module, quantum, fixed_ip_address):
|
||||
kwargs = {
|
||||
'fixed_ip_address': fixed_ip_address
|
||||
|
@ -154,13 +154,13 @@ def _get_floating_ip(module, quantum, fixed_ip_address):
|
|||
|
||||
def _create_floating_ip(quantum, module, port_id, net_id):
|
||||
kwargs = {
|
||||
'port_id': port_id,
|
||||
'floating_network_id': net_id
|
||||
'port_id': port_id,
|
||||
'floating_network_id': net_id
|
||||
}
|
||||
try:
|
||||
result = quantum.create_floatingip({'floatingip': kwargs})
|
||||
result = quantum.create_floatingip({'floatingip': kwargs})
|
||||
except Exception as e:
|
||||
module.fail_json( msg = "There was an error in updating the floating ip address: %s" % e.message)
|
||||
module.fail_json( msg = "There was an error in updating the floating ip address: %s" % e.message)
|
||||
module.exit_json( changed = True, result = result, public_ip=result['floatingip']['floating_ip_address'] )
|
||||
|
||||
def _get_net_id(quantum, module):
|
||||
|
@ -189,43 +189,43 @@ def _update_floating_ip(quantum, module, port_id, floating_ip_id):
|
|||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
login_username = dict(default='admin'),
|
||||
login_password = dict(required=True),
|
||||
login_tenant_name = dict(required='True'),
|
||||
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
|
||||
region_name = dict(default=None),
|
||||
network_name = dict(required=True),
|
||||
instance_name = dict(required=True),
|
||||
state = dict(default='present', choices=['absent', 'present'])
|
||||
argument_spec = dict(
|
||||
login_username = dict(default='admin'),
|
||||
login_password = dict(required=True),
|
||||
login_tenant_name = dict(required='True'),
|
||||
auth_url = dict(default='http://127.0.0.1:35357/v2.0/'),
|
||||
region_name = dict(default=None),
|
||||
network_name = dict(required=True),
|
||||
instance_name = dict(required=True),
|
||||
state = dict(default='present', choices=['absent', 'present'])
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
try:
|
||||
nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
|
||||
module.params['login_tenant_name'], module.params['auth_url'], service_type='compute')
|
||||
quantum = _get_quantum_client(module, module.params)
|
||||
nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
|
||||
module.params['login_tenant_name'], module.params['auth_url'], service_type='compute')
|
||||
quantum = _get_quantum_client(module, module.params)
|
||||
except Exception as e:
|
||||
module.fail_json( msg = " Error in authenticating to nova: %s" % e.message)
|
||||
|
||||
module.fail_json( msg = " Error in authenticating to nova: %s" % e.message)
|
||||
|
||||
server_info, server_obj = _get_server_state(module, nova)
|
||||
if not server_info:
|
||||
module.fail_json( msg = " The instance name provided cannot be found")
|
||||
module.fail_json( msg = " The instance name provided cannot be found")
|
||||
fixed_ip, port_id = _get_port_info(quantum, module, server_info['id'])
|
||||
if not port_id:
|
||||
module.fail_json(msg = "Cannot find a port for this instance, maybe fixed ip is not assigned")
|
||||
module.fail_json(msg = "Cannot find a port for this instance, maybe fixed ip is not assigned")
|
||||
floating_id, floating_ip = _get_floating_ip(module, quantum, fixed_ip)
|
||||
if module.params['state'] == 'present':
|
||||
if floating_ip:
|
||||
module.exit_json(changed = False, public_ip=floating_ip)
|
||||
net_id = _get_net_id(quantum, module)
|
||||
if floating_ip:
|
||||
module.exit_json(changed = False, public_ip=floating_ip)
|
||||
net_id = _get_net_id(quantum, module)
|
||||
if not net_id:
|
||||
module.fail_json(msg = "cannot find the network specified, please check")
|
||||
_create_floating_ip(quantum, module, port_id, net_id)
|
||||
module.fail_json(msg = "cannot find the network specified, please check")
|
||||
_create_floating_ip(quantum, module, port_id, net_id)
|
||||
|
||||
if module.params['state'] == 'absent':
|
||||
if floating_ip:
|
||||
_update_floating_ip(quantum, module, None, floating_id)
|
||||
if floating_ip:
|
||||
_update_floating_ip(quantum, module, None, floating_id)
|
||||
module.exit_json(changed=False)
|
||||
# this is magic, see lib/ansible/module.params['common.py
|
||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue