Apply general code clean-up and fixes

* Removed unused generate_uuid method.
* Changed print statement from 2.x style to 3.x.
* Updated scrapy to scrapy-python3 in requirements.txt for py3
  compatibility.

Change-Id: I7255a57c85cde105bf83bf6de5e779b71a09f8ee
Closes-Bug: #1576396
This commit is contained in:
Tin Lam 2016-05-02 21:26:17 -05:00
parent 4eff227d1e
commit 352c65725d
5 changed files with 13 additions and 20 deletions

@ -3,5 +3,5 @@ jsonrpclib
netaddr netaddr
cliff cliff
oslo.config>=1.6.0 oslo.config>=1.6.0
scapy>=2.3.1 scapy-python3
pypcap pypcap

6
steth/stethclient/clients/neutron.py Normal file → Executable file

@ -24,7 +24,7 @@ try:
from neutronclient.v2_0 import client from neutronclient.v2_0 import client
from neutronclient.common import exceptions from neutronclient.common import exceptions
except ImportError: except ImportError:
print "Import neutronclient error. Please check it out." print("Import neutronclient error. Please check it out.")
sys.exit() sys.exit()
@ -42,10 +42,10 @@ def get_port_attr(port_id, attr):
try: try:
res = client.show_port(port_id) res = client.show_port(port_id)
except exceptions.NeutronClientException: except exceptions.NeutronClientException:
print 'Port %s Not Found.' % port_id print('Port %s Not Found.' % port_id)
return return
except KeyError: except KeyError:
print 'Port attr: %s Not Found.' % attr print('Port attr: %s Not Found.' % attr)
return return
return res['port'][attr] return res['port'][attr]

@ -93,12 +93,12 @@ def check_ip_and_fill(agent_type, net_prefix):
d[name_prefix + node] = net_prefix + node d[name_prefix + node] = net_prefix + node
agent_type.update(d) agent_type.update(d)
else: else:
print "%s is not IP!" % name_prefix + node print("%s is not IP!" % name_prefix + node)
def validate_and_parse_network_types(): def validate_and_parse_network_types():
if not cfg.CONF.network_types: if not cfg.CONF.network_types:
print 'You must fill network_types in config file!' print("You must fill network_types in config file!")
sys.exit() sys.exit()
for network_type in cfg.CONF.network_types: for network_type in cfg.CONF.network_types:
net_type, net_interface, net_prefix = network_type.split(':') net_type, net_interface, net_prefix = network_type.split(':')
@ -118,5 +118,6 @@ def validate_and_parse_network_types():
global STORAGE_INTERFACE global STORAGE_INTERFACE
STORAGE_INTERFACE = net_interface STORAGE_INTERFACE = net_interface
else: else:
print "Unkown network_types: %s" % network_type print("Unkown network_types: %s" % network_type)
validate_and_parse_network_types() validate_and_parse_network_types()

@ -75,7 +75,7 @@ def main(argv=sys.argv[1:]):
return StethShell(STETH_API_VERSION).run( return StethShell(STETH_API_VERSION).run(
map(utils.safe_decode, argv)) map(utils.safe_decode, argv))
except KeyboardInterrupt: except KeyboardInterrupt:
print "... terminating neutron client" print("... terminating neutron client")
return 1 return 1
except Exception as e: except Exception as e:
print(e) print(e)

@ -69,15 +69,15 @@ class Logger():
@staticmethod @staticmethod
def log_normal(info): def log_normal(info):
print Logger.OKBLUE + info + Logger.ENDC print(Logger.OKBLUE + info + Logger.ENDC)
@staticmethod @staticmethod
def log_high(info): def log_high(info):
print Logger.OKGREEN + info + Logger.ENDC print(Logger.OKGREEN + info + Logger.ENDC)
@staticmethod @staticmethod
def log_fail(info): def log_fail(info):
print Logger.FAIL + info + Logger.ENDC print(Logger.FAIL + info + Logger.ENDC)
LISTEN_PORT = 9698 LISTEN_PORT = 9698
@ -134,15 +134,7 @@ def get_ip_from_agent(node, net_type):
else: else:
return 1 return 1
except Exception as e: except Exception as e:
print "Can't get ip! Because: %s" % e print("Can't get ip! Because: %s" % e)
def generate_uuid():
"""Creates a random uuid string.
:returns: string
"""
return str(uuid.uuid4())
def _format_uuid_string(string): def _format_uuid_string(string):