Change position of stethoclient and fix bugs when check vlan

This commit is contained in:
changzhi1990 2016-01-06 18:18:11 +08:00
parent a96a7b442d
commit 5fc83959c6
8 changed files with 33 additions and 8 deletions

View File

@ -1,3 +1,4 @@
jsonrpclib
netaddr
mock
cliff

View File

@ -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',
]
}

View File

@ -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).

View File

@ -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)