def listShadow(options, host, shadow): result, data = elflet.request(host, '/shadow') if result: print '{0} shadows are registered'.format(len(data)) for name in data: print ' {0}'.format(name) return result, data
def changeConfig(data, host, password): data['commit'] = True result, rdata = elflet.request(host, '/manage/config', method=elflet.POST, data=data, password=password) if not result: print >> sys.stderr, \ "an error occurred while communicating with elflet: {0}" \ .format(rdata) sys.exit(1)
def getInformation(options, host): raw = (options.stat or options.rawOutput) path = '/manage/status' if options.stat else '/manage/config' result, rdata = elflet.request(host, path, method=elflet.GET) if result: if raw: print json.dumps(rdata, indent=4, sort_keys=True) else: printConfig(rdata) else: print >> sys.stderr, \ "an error occurred while communicating with elflet: {0}" \ .format(rdata) sys.exit(1)
def showStatus(options, host, shadow): result, data = elflet.request(host, '/shadow/{0}'.format(shadow)) if result: if options.raw: print json.dumps(data, indent=4, sort_keys=True) else: print 'Node Name: {0}'.format(data['NodeName']) print 'Shadow Name: {0}'.format(data['ShadowName']) print 'Power Status: {0}'.format('ON' if data['IsOn'] else 'OFF') if 'Attributes' in data: attrs = data['Attributes'] if len(attrs) > 0: print 'Atrributes:' maxkeylen = 0 for key in attrs: maxkeylen = max(maxkeylen, len(key)) fstr = ' {0:' + str(maxkeylen + 1) + 's}: {1}' for key in attrs: print fstr.format(key, attrs[key]) return result, data
def delDef(options, host, shadow): return elflet.request(host, '/shadowDefs/{0}'.format(shadow), method=elflet.DELETE, password=options.password)
def addDef(options, host, shadow): return elflet.request(host, '/shadowDefs/{0}'.format(shadow), method=elflet.POST, data=options.data, password=options.password)
def showDef(options, host, shadow): result, data = elflet.request(host, '/shadowDefs/{0}'.format(shadow)) if result: print json.dumps(data, indent=4, sort_keys=True) return result, data
def changeStatus(options, host, shadow): return elflet.request(host, '/shadow/{0}'.format(shadow), method=elflet.POST, data=options.data)