Do not exclude flake8 checker for devstack directory
There are some python files here that we should be running the flake8 on. This patch updates those files to pass flake8 and enables the checking. Change-Id: I73b76d2911daaf85282c9f77143f943805a33b03
This commit is contained in:
parent
01ad2eb932
commit
8cf544e62b
@ -13,16 +13,16 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
import base64
|
import base64
|
||||||
|
import jsonutils
|
||||||
|
import optparse
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class NSXClient(object):
|
class NSXClient(object):
|
||||||
""" Base NSX REST client """
|
"""Base NSX REST client"""
|
||||||
API_VERSION = "v1"
|
API_VERSION = "v1"
|
||||||
|
|
||||||
def __init__(self, host, username, password, *args, **kwargs):
|
def __init__(self, host, username, password, *args, **kwargs):
|
||||||
@ -103,7 +103,7 @@ class NSXClient(object):
|
|||||||
"""
|
"""
|
||||||
self.__set_url(endpoint=endpoint)
|
self.__set_url(endpoint=endpoint)
|
||||||
response = requests.put(self.url, headers=self.headers,
|
response = requests.put(self.url, headers=self.headers,
|
||||||
verify=self.verify, data=json.dumps(body))
|
verify=self.verify, data=jsonutils.dumps(body))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def delete(self, endpoint=None, params=None):
|
def delete(self, endpoint=None, params=None):
|
||||||
@ -121,7 +121,8 @@ class NSXClient(object):
|
|||||||
"""
|
"""
|
||||||
self.__set_url(endpoint=endpoint)
|
self.__set_url(endpoint=endpoint)
|
||||||
response = requests.post(self.url, headers=self.headers,
|
response = requests.post(self.url, headers=self.headers,
|
||||||
verify=self.verify, data=json.dumps(body))
|
verify=self.verify,
|
||||||
|
data=jsonutils.dumps(body))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_transport_zones(self):
|
def get_transport_zones(self):
|
||||||
@ -412,9 +413,8 @@ class NSXClient(object):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from optparse import OptionParser
|
|
||||||
|
|
||||||
parser = OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option("--mgr-ip", dest="mgr_ip", help="NSX Manager IP address")
|
parser.add_option("--mgr-ip", dest="mgr_ip", help="NSX Manager IP address")
|
||||||
parser.add_option("-u", "--username", default="admin", dest="username",
|
parser.add_option("-u", "--username", default="admin", dest="username",
|
||||||
help="NSX Manager username")
|
help="NSX Manager username")
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# Copyright 2015 VMware Inc
|
||||||
|
# All Rights Reserved
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Purpose: Sometimes NSXv backend are out of sync with OpenStack and all
|
Purpose: Sometimes NSXv backend are out of sync with OpenStack and all
|
||||||
@ -35,16 +49,17 @@ If you have any comment or find a bug, please contact
|
|||||||
Tong Liu <tongl@vmware.com>
|
Tong Liu <tongl@vmware.com>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
import base64
|
import base64
|
||||||
|
import jsonutils
|
||||||
|
import optparse
|
||||||
import requests
|
import requests
|
||||||
|
import sys
|
||||||
|
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
|
|
||||||
|
|
||||||
class VSMClient(object):
|
class VSMClient(object):
|
||||||
""" Base VSM REST client """
|
"""Base VSM REST client """
|
||||||
API_VERSION = "2.0"
|
API_VERSION = "2.0"
|
||||||
|
|
||||||
def __init__(self, host, username, password, *args, **kwargs):
|
def __init__(self, host, username, password, *args, **kwargs):
|
||||||
@ -136,16 +151,17 @@ class VSMClient(object):
|
|||||||
self.__set_url(endpoint=endpoint)
|
self.__set_url(endpoint=endpoint)
|
||||||
self.__set_headers()
|
self.__set_headers()
|
||||||
response = requests.post(self.url, headers=self.headers,
|
response = requests.post(self.url, headers=self.headers,
|
||||||
verify=self.verify, data=json.dumps(body))
|
verify=self.verify,
|
||||||
|
data=jsonutils.dumps(body))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_vdn_scope_id(self):
|
def get_vdn_scope_id(self):
|
||||||
"""
|
"""
|
||||||
Retrieve existing network scope id
|
Retrieve existing network scope id
|
||||||
"""
|
"""
|
||||||
self.__set_api_version('2.0');
|
self.__set_api_version('2.0')
|
||||||
self.__set_endpoint("/vdn/scopes")
|
self.__set_endpoint("/vdn/scopes")
|
||||||
response = self.get();
|
response = self.get()
|
||||||
if len(response.json()['allScopes']) == 0:
|
if len(response.json()['allScopes']) == 0:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -154,7 +170,7 @@ class VSMClient(object):
|
|||||||
def query_all_logical_switches(self):
|
def query_all_logical_switches(self):
|
||||||
lswitches = []
|
lswitches = []
|
||||||
self.__set_api_version('2.0')
|
self.__set_api_version('2.0')
|
||||||
vdn_scope_id = self.get_vdn_scope_id();
|
vdn_scope_id = self.get_vdn_scope_id()
|
||||||
if not vdn_scope_id:
|
if not vdn_scope_id:
|
||||||
return lswitches
|
return lswitches
|
||||||
endpoint = "/vdn/scopes/%s/virtualwires" % (vdn_scope_id)
|
endpoint = "/vdn/scopes/%s/virtualwires" % (vdn_scope_id)
|
||||||
@ -164,10 +180,10 @@ class VSMClient(object):
|
|||||||
paging_info = response.json()['dataPage']['pagingInfo']
|
paging_info = response.json()['dataPage']['pagingInfo']
|
||||||
page_size = int(paging_info['pageSize'])
|
page_size = int(paging_info['pageSize'])
|
||||||
total_count = int(paging_info['totalCount'])
|
total_count = int(paging_info['totalCount'])
|
||||||
print "There are total %s logical switches and page size is %s" % (
|
print ("There are total %s logical switches and page size is %s" % (
|
||||||
total_count, page_size)
|
total_count, page_size))
|
||||||
pages = ceil(total_count, page_size)
|
pages = ceil(total_count, page_size)
|
||||||
print "Total pages: %s" % pages
|
print ("Total pages: %s" % pages)
|
||||||
for i in range(0, pages):
|
for i in range(0, pages):
|
||||||
start_index = page_size * i
|
start_index = page_size * i
|
||||||
params = {'startindex': start_index}
|
params = {'startindex': start_index}
|
||||||
@ -178,16 +194,16 @@ class VSMClient(object):
|
|||||||
return lswitches
|
return lswitches
|
||||||
|
|
||||||
def cleanup_logical_switch(self):
|
def cleanup_logical_switch(self):
|
||||||
print "Cleaning up logical switches on NSX manager"
|
print ("Cleaning up logical switches on NSX manager")
|
||||||
lswitches = self.query_all_logical_switches()
|
lswitches = self.query_all_logical_switches()
|
||||||
print "There are total %s logical switches" % len(lswitches)
|
print ("There are total %s logical switches" % len(lswitches))
|
||||||
for ls in lswitches:
|
for ls in lswitches:
|
||||||
print "\nDeleting logical switch %s (%s) ..." % (ls['name'],
|
print ("\nDeleting logical switch %s (%s) ..." % (ls['name'],
|
||||||
ls['objectId'])
|
ls['objectId']))
|
||||||
endpoint = '/vdn/virtualwires/%s' % ls['objectId']
|
endpoint = '/vdn/virtualwires/%s' % ls['objectId']
|
||||||
response = self.delete(endpoint=endpoint)
|
response = self.delete(endpoint=endpoint)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print "ERROR: response status code %s" % response.status_code
|
print ("ERROR: response status code %s" % response.status_code)
|
||||||
|
|
||||||
def query_all_firewall_sections(self):
|
def query_all_firewall_sections(self):
|
||||||
firewall_sections = []
|
firewall_sections = []
|
||||||
@ -201,23 +217,23 @@ class VSMClient(object):
|
|||||||
firewall_sections = [s for s in l3_sections if s['name'] !=
|
firewall_sections = [s for s in l3_sections if s['name'] !=
|
||||||
"Default Section Layer3"]
|
"Default Section Layer3"]
|
||||||
else:
|
else:
|
||||||
print "ERROR: wrong response status code! Exiting..."
|
print ("ERROR: wrong response status code! Exiting...")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
return firewall_sections
|
return firewall_sections
|
||||||
|
|
||||||
def cleanup_firewall_section(self):
|
def cleanup_firewall_section(self):
|
||||||
print "\n\nCleaning up firewall sections on NSX manager"
|
print ("\n\nCleaning up firewall sections on NSX manager")
|
||||||
l3_sections = self.query_all_firewall_sections()
|
l3_sections = self.query_all_firewall_sections()
|
||||||
print "There are total %s firewall sections" % len(l3_sections)
|
print ("There are total %s firewall sections" % len(l3_sections))
|
||||||
for l3sec in l3_sections:
|
for l3sec in l3_sections:
|
||||||
print "\nDeleting firewall section %s (%s) ..." % (l3sec['name'],
|
print ("\nDeleting firewall section %s (%s) ..." % (l3sec['name'],
|
||||||
l3sec['id'])
|
l3sec['id']))
|
||||||
endpoint = '/firewall/globalroot-0/config/layer3sections/%s' % \
|
endpoint = '/firewall/globalroot-0/config/layer3sections/%s' % \
|
||||||
l3sec['id']
|
l3sec['id']
|
||||||
response = self.delete(endpoint=endpoint)
|
response = self.delete(endpoint=endpoint)
|
||||||
if response.status_code != 204:
|
if response.status_code != 204:
|
||||||
print "ERROR: response status code %s" % response.status_code
|
print ("ERROR: response status code %s" % response.status_code)
|
||||||
|
|
||||||
def query_all_security_groups(self):
|
def query_all_security_groups(self):
|
||||||
security_groups = []
|
security_groups = []
|
||||||
@ -228,7 +244,7 @@ class VSMClient(object):
|
|||||||
if response.status_code is 200:
|
if response.status_code is 200:
|
||||||
sg_all = response.json()
|
sg_all = response.json()
|
||||||
else:
|
else:
|
||||||
print "ERROR: wrong response status code! Exiting..."
|
print ("ERROR: wrong response status code! Exiting...")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
# Remove Activity Monitoring Data Collection, which is not
|
# Remove Activity Monitoring Data Collection, which is not
|
||||||
# related to any security group created by OpenStack
|
# related to any security group created by OpenStack
|
||||||
@ -237,17 +253,17 @@ class VSMClient(object):
|
|||||||
return security_groups
|
return security_groups
|
||||||
|
|
||||||
def cleanup_security_group(self):
|
def cleanup_security_group(self):
|
||||||
print "\n\nCleaning up security groups on NSX manager"
|
print ("\n\nCleaning up security groups on NSX manager")
|
||||||
security_groups = self.query_all_security_groups()
|
security_groups = self.query_all_security_groups()
|
||||||
print "There are total %s security groups" % len(security_groups)
|
print ("There are total %s security groups" % len(security_groups))
|
||||||
for sg in security_groups:
|
for sg in security_groups:
|
||||||
print "\nDeleting security group %s (%s) ..." % (sg['name'],
|
print ("\nDeleting security group %s (%s) ..." % (sg['name'],
|
||||||
sg['objectId'])
|
sg['objectId']))
|
||||||
endpoint = '/services/securitygroup/%s' % sg['objectId']
|
endpoint = '/services/securitygroup/%s' % sg['objectId']
|
||||||
params = {'force': self.force}
|
params = {'force': self.force}
|
||||||
response = self.delete(endpoint=endpoint, params=params)
|
response = self.delete(endpoint=endpoint, params=params)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print "ERROR: response status code %s" % response.status_code
|
print ("ERROR: response status code %s" % response.status_code)
|
||||||
|
|
||||||
def query_all_spoofguard_policies(self):
|
def query_all_spoofguard_policies(self):
|
||||||
self.__set_api_version('4.0')
|
self.__set_api_version('4.0')
|
||||||
@ -255,7 +271,7 @@ class VSMClient(object):
|
|||||||
# Query all spoofguard policies
|
# Query all spoofguard policies
|
||||||
response = self.get()
|
response = self.get()
|
||||||
if response.status_code is not 200:
|
if response.status_code is not 200:
|
||||||
print "ERROR: Faield to get spoofguard policies"
|
print ("ERROR: Faield to get spoofguard policies")
|
||||||
return
|
return
|
||||||
sgp_all = response.json()
|
sgp_all = response.json()
|
||||||
policies = [sgp for sgp in sgp_all['policies'] if
|
policies = [sgp for sgp in sgp_all['policies'] if
|
||||||
@ -263,15 +279,15 @@ class VSMClient(object):
|
|||||||
return policies
|
return policies
|
||||||
|
|
||||||
def cleanup_spoofguard_policies(self):
|
def cleanup_spoofguard_policies(self):
|
||||||
print "\n\nCleaning up spoofguard policies"
|
print ("\n\nCleaning up spoofguard policies")
|
||||||
policies = self.query_all_spoofguard_policies()
|
policies = self.query_all_spoofguard_policies()
|
||||||
print "There are total %s policies" % len(policies)
|
print ("There are total %s policies" % len(policies))
|
||||||
for spg in policies:
|
for spg in policies:
|
||||||
print "\nDeleting spoofguard policy %s (%s) ..." % (spg['name'],
|
print ("\nDeleting spoofguard policy %s (%s) ..." %
|
||||||
spg['policyId'])
|
(spg['name'], spg['policyId']))
|
||||||
endpoint = '/services/spoofguard/policies/%s' % spg['policyId']
|
endpoint = '/services/spoofguard/policies/%s' % spg['policyId']
|
||||||
response = self.delete(endpoint=endpoint)
|
response = self.delete(endpoint=endpoint)
|
||||||
print "Response code: %s" % response.status_code
|
print ("Response code: %s" % response.status_code)
|
||||||
|
|
||||||
def query_all_edges(self):
|
def query_all_edges(self):
|
||||||
edges = []
|
edges = []
|
||||||
@ -282,10 +298,10 @@ class VSMClient(object):
|
|||||||
paging_info = response.json()['edgePage']['pagingInfo']
|
paging_info = response.json()['edgePage']['pagingInfo']
|
||||||
page_size = int(paging_info['pageSize'])
|
page_size = int(paging_info['pageSize'])
|
||||||
total_count = int(paging_info['totalCount'])
|
total_count = int(paging_info['totalCount'])
|
||||||
print "There are total %s edges and page size is %s" % (
|
print ("There are total %s edges and page size is %s" % (
|
||||||
total_count, page_size)
|
total_count, page_size))
|
||||||
pages = ceil(total_count, page_size)
|
pages = ceil(total_count, page_size)
|
||||||
print "Total pages: %s" % pages
|
print ("Total pages: %s" % pages)
|
||||||
for i in range(0, pages):
|
for i in range(0, pages):
|
||||||
start_index = page_size * i
|
start_index = page_size * i
|
||||||
params = {'startindex': start_index}
|
params = {'startindex': start_index}
|
||||||
@ -296,14 +312,15 @@ class VSMClient(object):
|
|||||||
return edges
|
return edges
|
||||||
|
|
||||||
def cleanup_edge(self):
|
def cleanup_edge(self):
|
||||||
print "\n\nCleaning up edges on NSX manager"
|
print ("\n\nCleaning up edges on NSX manager")
|
||||||
edges = self.query_all_edges()
|
edges = self.query_all_edges()
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
print "\nDeleting edge %s (%s) ..." % (edge['name'], edge['id'])
|
print ("\nDeleting edge %s (%s) ..." % (edge['name'], edge['id']))
|
||||||
endpoint = '/edges/%s' % edge['id']
|
endpoint = '/edges/%s' % edge['id']
|
||||||
response = self.delete(endpoint=endpoint)
|
response = self.delete(endpoint=endpoint)
|
||||||
if response.status_code != 204:
|
if response.status_code != 204:
|
||||||
print "ERROR: response status code %s" % response.status_code
|
print ("ERROR: response status code %s" %
|
||||||
|
response.status_code)
|
||||||
|
|
||||||
def cleanup_all(self):
|
def cleanup_all(self):
|
||||||
self.cleanup_firewall_section()
|
self.cleanup_firewall_section()
|
||||||
@ -322,9 +339,8 @@ def ceil(a, b):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from optparse import OptionParser
|
|
||||||
|
|
||||||
parser = OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option("--vsm-ip", dest="vsm_ip", help="NSX Manager IP address")
|
parser.add_option("--vsm-ip", dest="vsm_ip", help="NSX Manager IP address")
|
||||||
parser.add_option("-u", "--username", default="admin", dest="username",
|
parser.add_option("-u", "--username", default="admin", dest="username",
|
||||||
help="NSX Manager username")
|
help="NSX Manager username")
|
||||||
@ -333,10 +349,10 @@ if __name__ == "__main__":
|
|||||||
parser.add_option("-f", "--force", dest="force", action="store_true",
|
parser.add_option("-f", "--force", dest="force", action="store_true",
|
||||||
help="Force cleanup option")
|
help="Force cleanup option")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
print "vsm-ip: %s" % options.vsm_ip
|
print ("vsm-ip: %s" % options.vsm_ip)
|
||||||
print "username: %s" % options.username
|
print ("username: %s" % options.username)
|
||||||
print "password: %s" % options.password
|
print ("password: %s" % options.password)
|
||||||
print "force: %s" % options.force
|
print ("force: %s" % options.force)
|
||||||
|
|
||||||
# Get VSM REST client
|
# Get VSM REST client
|
||||||
if options.force:
|
if options.force:
|
||||||
|
2
tox.ini
2
tox.ini
@ -82,7 +82,7 @@ commands = python setup.py build_sphinx
|
|||||||
ignore = E125,E126,E128,E129,E265,H305,H307,H402,H404,H405,H904
|
ignore = E125,E126,E128,E129,E265,H305,H307,H402,H404,H405,H904
|
||||||
show-source = true
|
show-source = true
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,.ropeproject,devstack
|
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,.ropeproject
|
||||||
|
|
||||||
[testenv:pylint]
|
[testenv:pylint]
|
||||||
deps =
|
deps =
|
||||||
|
Loading…
Reference in New Issue
Block a user