Flake8 update - library/neutron
This update fixes issues with linting such that it can now pass OpenStack hacking/flake8 checks. Change-Id: I06f037b84fe8c0a0dad9bbaaa117791ebdc16f7d Partial-Bug: 1440462
This commit is contained in:
parent
4c4fbe25c3
commit
864c8179a5
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = """
|
||||||
---
|
---
|
||||||
module: neutron
|
module: neutron
|
||||||
short_description:
|
short_description:
|
||||||
@ -62,9 +62,9 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Specify external_gateway_info when creating router
|
- Specify external_gateway_info when creating router
|
||||||
author: Hugh Saunders
|
author: Hugh Saunders
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = """
|
||||||
- name: Create private network
|
- name: Create private network
|
||||||
neutron:
|
neutron:
|
||||||
command: create_network
|
command: create_network
|
||||||
@ -104,12 +104,13 @@ EXAMPLES = '''
|
|||||||
openrc_path: /root/openrc
|
openrc_path: /root/openrc
|
||||||
router_name: router
|
router_name: router
|
||||||
subnet_name: private-subnet
|
subnet_name: private-subnet
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
import keystoneclient.v2_0.client as ksclient
|
import keystoneclient.v2_0.client as ksclient
|
||||||
from neutronclient.neutron import client as nclient
|
from neutronclient.neutron import client as nclient
|
||||||
|
|
||||||
|
|
||||||
COMMAND_MAP = {
|
COMMAND_MAP = {
|
||||||
'create_network': {
|
'create_network': {
|
||||||
'variables': [
|
'variables': [
|
||||||
@ -189,16 +190,13 @@ class ManageNeutron(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _facts(resource_type, resource_data):
|
def _facts(resource_type, resource_data):
|
||||||
"""Return a dict for our Ansible facts.
|
"""Return a dict for our Ansible facts."""
|
||||||
|
|
||||||
:param facts: ``dict`` Dict with data to return
|
|
||||||
"""
|
|
||||||
key = 'neutron_%s' % resource_type
|
key = 'neutron_%s' % resource_type
|
||||||
facts = {key: {}}
|
facts = {key: {}}
|
||||||
for f in resource_data[resource_type]:
|
for f in resource_data[resource_type]:
|
||||||
name = f['name']
|
res_name = f['name']
|
||||||
del f['name']
|
del f['name']
|
||||||
facts[key][name] = f
|
facts[key][res_name] = f
|
||||||
|
|
||||||
return facts
|
return facts
|
||||||
|
|
||||||
@ -236,17 +234,18 @@ class ManageNeutron(object):
|
|||||||
self.module.fail_json(msg=msg, rc=rc, err=error)
|
self.module.fail_json(msg=msg, rc=rc, err=error)
|
||||||
|
|
||||||
def _parse_openrc(self):
|
def _parse_openrc(self):
|
||||||
""" Get credentials from an openrc file """
|
"""Get credentials from an openrc file."""
|
||||||
openrc_path = self.module.params['openrc_path']
|
openrc_path = self.module.params['openrc_path']
|
||||||
line_re = re.compile('^export (?P<key>OS_\w*)=(?P<value>[^\n]*)')
|
line_re = re.compile('^export (?P<key>OS_\w*)=(?P<value>[^\n]*)')
|
||||||
with open(openrc_path) as openrc:
|
with open(openrc_path) as openrc:
|
||||||
matches = [line_re.match(l) for l in openrc]
|
matches = [line_re.match(l) for l in openrc]
|
||||||
return dict(
|
return dict(
|
||||||
(g.groupdict()['key'], g.groupdict()['value'])
|
(g.groupdict()['key'], g.groupdict()['value'])
|
||||||
for g in matches if g)
|
for g in matches if g
|
||||||
|
)
|
||||||
|
|
||||||
def _keystone_authenticate(self):
|
def _keystone_authenticate(self):
|
||||||
""" Authenticate with Keystone """
|
"""Authenticate with Keystone."""
|
||||||
openrc = self._parse_openrc()
|
openrc = self._parse_openrc()
|
||||||
self.keystone = ksclient.Client(username=openrc['OS_USERNAME'],
|
self.keystone = ksclient.Client(username=openrc['OS_USERNAME'],
|
||||||
password=openrc['OS_PASSWORD'],
|
password=openrc['OS_PASSWORD'],
|
||||||
@ -254,7 +253,7 @@ class ManageNeutron(object):
|
|||||||
auth_url=openrc['OS_AUTH_URL'])
|
auth_url=openrc['OS_AUTH_URL'])
|
||||||
|
|
||||||
def _init_neutron(self):
|
def _init_neutron(self):
|
||||||
""" Create neutron client object using token and url from keystone """
|
"""Create neutron client object using token and url from keystone."""
|
||||||
openrc = self._parse_openrc()
|
openrc = self._parse_openrc()
|
||||||
self.neutron = nclient.Client(
|
self.neutron = nclient.Client(
|
||||||
'2.0',
|
'2.0',
|
||||||
@ -280,7 +279,9 @@ class ManageNeutron(object):
|
|||||||
'provider_physical_network'
|
'provider_physical_network'
|
||||||
)
|
)
|
||||||
provider_network_type = variables_dict.pop('provider_network_type')
|
provider_network_type = variables_dict.pop('provider_network_type')
|
||||||
provider_segmentation_id = variables_dict.pop('provider_segmentation_id')
|
provider_segmentation_id = variables_dict.pop(
|
||||||
|
'provider_segmentation_id'
|
||||||
|
)
|
||||||
router_external = variables_dict.pop('router_external')
|
router_external = variables_dict.pop('router_external')
|
||||||
tenant_id = variables_dict.pop('tenant_id')
|
tenant_id = variables_dict.pop('tenant_id')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user