From 6b5a7d942d0bfe8ae4485abe3738b0a9d1b5c384 Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Wed, 12 Oct 2016 12:54:26 +0100 Subject: [PATCH] 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 --- library/neutron | 24 +++++++++++++++++++ .../notes/get-networks-e241137620c2280d.yaml | 9 +++++++ 2 files changed, 33 insertions(+) create mode 100644 releasenotes/notes/get-networks-e241137620c2280d.yaml diff --git a/library/neutron b/library/neutron index 7237364..e41a6fa 100644 --- a/library/neutron +++ b/library/neutron @@ -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( diff --git a/releasenotes/notes/get-networks-e241137620c2280d.yaml b/releasenotes/notes/get-networks-e241137620c2280d.yaml new file mode 100644 index 0000000..6a2e7a4 --- /dev/null +++ b/releasenotes/notes/get-networks-e241137620c2280d.yaml @@ -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.