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

Include omitted changes from last commit

I did not include all intended changes in last
commit.
This commit is contained in:
Jarrod Johnson 2015-03-19 15:06:31 -04:00
parent 745679029c
commit 41698b2bad
4 changed files with 102 additions and 9 deletions

View File

@ -236,7 +236,8 @@ currchildren = None
def print_result(res):
if 'errorcode' in res:
if 'errorcode' in res or 'error' in res:
print res['error']
return
for key in res.iterkeys():
notes = []

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014 IBM Corporation
# Copyright 2015 Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -19,14 +19,22 @@ import os
import sys
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..'))
sys.path.append(path)
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
if path.startswith('/opt'):
sys.path.append(path)
import confluent.client as client
node = sys.argv[1]
noderange = sys.argv[1]
setstate = None
if len(sys.argv) > 2:
if setstate == 'softoff':
setstate = 'shutdown'
elif not sys.argv[2] in ('stat', 'state', 'status'):
setstate = sys.argv[2]
session = client.Command()
for res in session.read("/node/{0}/power/state".format(node)):
print("%s: %s" % (node, res['state']['value']))
exitcode = 0
sys.exit(
session.simple_noderange_command(noderange, '/power/state', setstate))

View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2015 Lenovo
#
# 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.
import os
import sys
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
if path.startswith('/opt'):
sys.path.append(path)
import confluent.client as client
noderange = sys.argv[1]
bootdev = None
if len(sys.argv) > 2:
bootdev = sys.argv[2]
session = client.Command()
exitcode = 0
sys.exit(
session.simple_noderange_command(noderange, '/boot/nextdevice', bootdev))

View File

@ -1,6 +1,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014 IBM Corporation
# Copyright 2015 Lenovo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -20,6 +21,7 @@ import hashlib
import os
import socket
import ssl
import sys
import confluent.tlvdata as tlvdata
SO_PASSCRED = 16
@ -43,8 +45,14 @@ class Command(object):
def __init__(self, server="/var/run/confluent/api.sock"):
self.connection = None
self.serverloc = server
if os.path.isabs(server) and os.path.exists(server):
if server is None:
if 'CONFLUENT_HOST' in os.environ:
self.serverloc = os.environ['CONFLUENT_HOST']
else:
self.serverloc = '/var/run/confluent/api.sock'
else:
self.serverloc = server
if os.path.isabs(self.serverloc) and os.path.exists(self.serverloc):
self._connect_unix()
else:
self._connect_tls()
@ -62,6 +70,43 @@ class Command(object):
if authdata['authpassed'] == 1:
self.authenticated = True
def handle_results(self, ikey, rc, res):
if 'error' in res and type(res['error']) in (str, unicode):
sys.stderr.write('Error: {0}\n'.format(res['error']))
if 'errorcode' in res:
return res['errorcode']
else:
return 1
for node in res:
if 'error' in res[node]:
sys.stderr.write('{0}: Error: {1}\n'.format(
node, res[node]['error']))
if 'errorcode' in res[node]:
rc |= res[node]['errorcode']
else:
rc |= 1
else:
print('{0}: {1}'.format(node, res[node][ikey]['value']))
return rc
def simple_noderange_command(self, noderange, resource, input=None):
rc = 0
if resource[0] == '/':
resource = resource[1:]
# The implicit key is the resource basename
ikey = resource.rpartition('/')[-1]
if input is None:
for res in self.read('/noderange/{0}/{1}'.format(
noderange, resource)):
rc = self.handle_results(ikey, rc, res)
else:
for res in self.update('/noderange/{0}/{1}'.format(
noderange, resource), {ikey: input}):
rc = self.handle_results(ikey, rc, res)
return rc
def read(self, path, parameters=None):
return send_request('retrieve', path, self.connection, parameters)
@ -155,3 +200,6 @@ def send_request(operation, path, server, parameters=None):
while '_requestdone' not in result:
yield result
result = tlvdata.recv(server)