2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 11:01:09 +00:00

Fix various client issues

Usage messages when no noderange, consistent use of the environment variables for login,
fix nodehealth when a troublesome sensor has a value.
This commit is contained in:
Jarrod Johnson 2015-03-25 17:19:58 -04:00
parent 0d893f8887
commit 093e9faec4
6 changed files with 40 additions and 8 deletions

View File

@ -28,7 +28,11 @@ import confluent.client as client
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
noderange = sys.argv[1]
try:
noderange = sys.argv[1]
except IndexError:
sys.stderr.write('Usage: {0} <noderange>\n'.format(sys.argv[0]))
sys.exit(1)
session = client.Command()
exitcode = 0
@ -53,9 +57,11 @@ for health in session.read('/noderange/{0}/health/hardware'.format(noderange)):
for sensor in health[node]['sensors']:
explanation = sensor['name'] + ':'
if sensor['value'] is not None:
explanation += sensor['value']
explanation += str(sensor['value'])
if sensor['units'] is not None:
explanation += sensor['units']
if sensor['states']:
explanation += ','
if sensor['states']:
explanation += ','.join(sensor['states'])
healthexplanations[node].append(explanation)

View File

@ -25,8 +25,12 @@ if path.startswith('/opt'):
import confluent.client as client
try:
noderange = sys.argv[1]
except IndexError:
sys.stderr.write('Usage: {0} <noderange> [on|off]\n'.format(sys.argv[0]))
sys.exit(1)
noderange = sys.argv[1]
identifystate = None
if len(sys.argv) > 2:
identifystate = sys.argv[2]

View File

@ -26,7 +26,14 @@ if path.startswith('/opt'):
import confluent.client as client
noderange = sys.argv[1]
try:
noderange = sys.argv[1]
except IndexError:
sys.stderr.write(
'Usage: {0} <noderange> ([status|on|off|shutdown|boot|reset]\n'.format(
sys.argv[0]))
sys.exit(1)
setstate = None
if len(sys.argv) > 2:
if setstate == 'softoff':

View File

@ -54,8 +54,11 @@ if options.numreadings:
repeatmode = options.numreadings
if options.interval is None:
options.interval = 1
noderange = args[0]
try:
noderange = args[0]
except IndexError:
argparser.print_usage()
sys.exit(1)
sensors = []
for sensorgroup in args[1:]:
for sensor in sensorgroup.split(','):

View File

@ -26,10 +26,18 @@ if path.startswith('/opt'):
import confluent.client as client
noderange = sys.argv[1]
try:
noderange = sys.argv[1]
except IndexError:
sys.stderr.write(
'Usage: {0} <noderange> [default|cd|network|setup|hd]\n'.format(
sys.argv[0]))
sys.exit(1)
bootdev = None
if len(sys.argv) > 2:
bootdev = sys.argv[2]
if bootdev in ('net', 'pxe'):
bootdev = 'network'
session = client.Command()
exitcode = 0
sys.exit(

View File

@ -43,7 +43,7 @@ def _parseserver(string):
class Command(object):
def __init__(self, server="/var/run/confluent/api.sock"):
def __init__(self, server=None):
self.connection = None
if server is None:
if 'CONFLUENT_HOST' in os.environ:
@ -62,6 +62,10 @@ class Command(object):
self.authenticated = True
else:
self.authenticated = False
if not self.authenticated and 'CONFLUENT_USER' in os.environ:
username = os.environ['CONFLUENT_USER']
passphrase = os.environ['CONFLUENT_PASSPHRASE']
self.authenticate(username, passphrase)
def authenticate(self, username, password):
tlvdata.send(self.connection,