From 5fc83959c6fc0cf15f9917c80d9ad265b1493c4b Mon Sep 17 00:00:00 2001 From: changzhi1990 Date: Wed, 6 Jan 2016 18:18:11 +0800 Subject: [PATCH] Change position of stethoclient and fix bugs when check vlan --- requirements.txt | 1 + setup.py | 7 +++-- stetho/stethoclient/README.rst | 5 ---- .../{stethoclient => }/__init__.py | 0 .../{stethoclient => }/agent_api.py | 28 +++++++++++++++++++ .../{stethoclient => }/constants.py | 0 .../stethoclient/{stethoclient => }/shell.py | 0 .../{stethoclient => }/strutils.py | 0 8 files changed, 33 insertions(+), 8 deletions(-) delete mode 100644 stetho/stethoclient/README.rst rename stetho/stethoclient/{stethoclient => }/__init__.py (100%) rename stetho/stethoclient/{stethoclient => }/agent_api.py (90%) rename stetho/stethoclient/{stethoclient => }/constants.py (100%) rename stetho/stethoclient/{stethoclient => }/shell.py (100%) rename stetho/stethoclient/{stethoclient => }/strutils.py (100%) diff --git a/requirements.txt b/requirements.txt index 7d1af9d..3a92f0e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ jsonrpclib netaddr mock +cliff diff --git a/setup.py b/setup.py index 968b7ca..7a5f93f 100644 --- a/setup.py +++ b/setup.py @@ -14,14 +14,15 @@ # under the License. import sys + from setuptools import setup, find_packages + # In CentOS6.5, the version of python is 2.6, and in CentOS7 the version of # python is 2.7. So we can according by the python version to put the # stetho-agent script to the right place. # # If in CentOS6.5, the init script should be placed in "/etc/init.d/" # If in CentOS7, the init script should be placed in "/etc/systemd/system/" -# CENTOS6 = '/etc/init.d/' CENTOS7 = '/etc/systemd/system/' CENTOS6_SCRIPT = 'etc/init.d/stetho-agent' @@ -43,12 +44,12 @@ setup(name='stetho', url = "https://www.ustack.com", data_files=[ ('/etc/stetho', ['etc/stetho.conf']), - (AGENT_INIT_SCRIPT, [SCRIPT_LOCATION]), + (AGENT_INIT_SCRIPT, [SCRIPT_LOCATION]), ], entry_points={ 'console_scripts': [ - 'stetho = stetho.stethoclient.stethoclient.shell:main', + 'stetho = stetho.stethoclient.shell:main', 'stetho-agent = stetho.agent.agent:main', ] } diff --git a/stetho/stethoclient/README.rst b/stetho/stethoclient/README.rst deleted file mode 100644 index 0acf63c..0000000 --- a/stetho/stethoclient/README.rst +++ /dev/null @@ -1,5 +0,0 @@ -====================== - Running Stethoclient -====================== - -This is a client library for stetho built on the Stetho API. It provides a Python API (the stethoclient module) and a command-line tool (stetho). diff --git a/stetho/stethoclient/stethoclient/__init__.py b/stetho/stethoclient/__init__.py similarity index 100% rename from stetho/stethoclient/stethoclient/__init__.py rename to stetho/stethoclient/__init__.py diff --git a/stetho/stethoclient/stethoclient/agent_api.py b/stetho/stethoclient/agent_api.py similarity index 90% rename from stetho/stethoclient/stethoclient/agent_api.py rename to stetho/stethoclient/agent_api.py index c32d9af..14166da 100644 --- a/stetho/stethoclient/stethoclient/agent_api.py +++ b/stetho/stethoclient/agent_api.py @@ -112,6 +112,9 @@ class SetUpLink(Lister): # Get Link info res = server.get_interface(parsed_args.interface) self.log.debug('Response is %s' % res) + if res['code'] == 1: + Logger.log_fail(res['message']) + sys.exit() if res['code'] == 0: return (('Field', 'Value'), ((k, v) for k, v in res['data'].items())) @@ -139,6 +142,9 @@ class GetInterface(Lister): try: res = server.get_interface(parsed_args.interface) self.log.debug('Response is %s' % res) + if res['code'] == 1: + Logger.log_fail(res['message']) + sys.exit() if res['code'] == 0: return (('Field', 'Value'), ((k, v) for k, v in res['data'].items())) @@ -173,6 +179,9 @@ class AddVlanToInterface(Lister): new_interface = parsed_args.interface + '.' + parsed_args.vlan_id res = server.get_interface(new_interface) self.log.debug('Response is %s' % res) + if res['code'] == 1: + Logger.log_fail(res['message']) + sys.exit() if res['code'] == 0: return (('Field', 'Value'), ((k, v) for k, v in res['data'].items())) @@ -205,6 +214,9 @@ class AgentPing(Lister): timeout=parsed_args.timeout, interface=parsed_args.interface) self.log.debug('Response is %s' % res) + if res['code'] == 1: + Logger.log_fail(res['message']) + sys.exit() if res['code'] == 0: return (('Destination', 'Packet Loss (%)'), ((k, v) for k, v in res['data'].items())) @@ -232,6 +244,9 @@ class CheckPortsOnBr(Lister): res = server.check_ports_on_br(parsed_args.bridge, parsed_args.port) self.log.debug('Response is %s' % res) + if res['code'] == 1: + Logger.log_fail(res['message']) + sys.exit() if res['code'] == 0: return (('Port', 'Exists'), ((k, v) for k, v in res['data'].items())) @@ -258,6 +273,19 @@ class CheckVlanInterface(Lister): serverB = setup_server(parsed_args.agentB) try: interface = parsed_args.interface + '.' + parsed_args.vlan_id + # First of all, check the interface if exists + resA = serverA.get_interface(interface) + resB = serverB.get_interface(interface) + if resA['code'] == 1: + msg = "Agent: %s has no interface named %s!" % ( + parsed_args.agentA, interface) + Logger.log_fail(msg) + sys.exit() + if resB['code'] == 1: + msg = "Agent: %s has no interface named %s!" % ( + parsed_args.agentB, interface) + Logger.log_fail(msg) + sys.exit() # add vlan interface in each agent resA = serverA.add_vlan_to_interface(parsed_args.interface, parsed_args.vlan_id) diff --git a/stetho/stethoclient/stethoclient/constants.py b/stetho/stethoclient/constants.py similarity index 100% rename from stetho/stethoclient/stethoclient/constants.py rename to stetho/stethoclient/constants.py diff --git a/stetho/stethoclient/stethoclient/shell.py b/stetho/stethoclient/shell.py similarity index 100% rename from stetho/stethoclient/stethoclient/shell.py rename to stetho/stethoclient/shell.py diff --git a/stetho/stethoclient/stethoclient/strutils.py b/stetho/stethoclient/strutils.py similarity index 100% rename from stetho/stethoclient/stethoclient/strutils.py rename to stetho/stethoclient/strutils.py