Add get_networks command to neutron library

get_networks will return network information, and will fail if the
specified "net_name" network is not present.
If no "net_name" is specified the network information will be
returned without performing the check on the existence of "net_name"
network within neutron.

Change-Id: I01775c9b29e312cc6696ffdc708befc46d11bf52
This commit is contained in:
Andy McCrae 2016-10-12 12:54:26 +01:00 committed by Andy McCrae
parent 334604c209
commit 6b5a7d942d
2 changed files with 33 additions and 0 deletions

View File

@ -37,6 +37,7 @@ options:
- create_subnet
- create_router
- add_router_interface
- get_networks
required: True
openrc_path:
decription:
@ -123,6 +124,10 @@ EXAMPLES = """
openrc_path: /root/openrc
router_name: router
subnet_name: private-subnet
- name: Get network information
command: get_network
openrc_path: /root/openrc
net_name: public
"""
@ -158,6 +163,11 @@ COMMAND_MAP = {
'router_name',
'subnet_name'
]
},
'get_networks': {
'variables': [
'net_name'
]
}
}
@ -413,6 +423,20 @@ class ManageNeutron(object):
self.neutron.add_interface_router(router_id,
{'subnet_id': subnet_id})
def _get_networks(self, variables):
variables_dict = self._get_vars(variables)
net_name = variables_dict.pop('net_name')
if net_name:
network_id = self._get_resource_by_name('networks', net_name)
if not network_id:
self.failure(
error='Network not found',
rc=1,
msg='The specified network could not be found'
)
return self._facts('networks', self.neutron.list_networks())
def main():
module = AnsibleModule(

View File

@ -0,0 +1,9 @@
---
features:
- Add ``get_networks`` command to the neutron library.
This will return network information for all networks,
and fail if the specified ``net_name`` network is not
present. If no ``net_name`` is specified network
information will for all networks will be returned
without performing a check on an existing ``net_name``
network.