def main(): if len(sys.argv) != 2: print "FAIL: nodeid not provided!" return -1 nodeid = sys.argv[1] hm = HenManager() if (hm.power(sys.argv[1], "poweroff") < 0): print "FAIL: hm.power(%s, \"poweroff\") failed (cause unknown)!"\ % nodeid return -1 time.sleep(2) (sts, output) = hm.powerSilent(sys.argv[1], "status") if (sts < 0): print "FAIL: hm.power(%s, \"status\") returned: %s" % (nodeid, output) return -1 if (output == "on"): print "FAIL: hm.power(%s, \"status\") says the node is still on!" \ % nodeid return -1 if (output == "off"): print "SUCCESS: hm.power(%s, \"poweroff\") succeeded." % nodeid return 0 print "FAIL: hm.power(%s, \"status\") returned: %s" % (nodeid, output) return -1
def main(): if len(sys.argv) != 2: print "FAIL: nodeid not provided!" return -1 nodeid = sys.argv[1] hm = HenManager() if (hm.power(sys.argv[1], "poweroff") < 0): print "FAIL: hm.power(%s, \"poweroff\") failed (cause unknown)!"\ % nodeid return -1 time.sleep(2) (sts, output) = hm.powerSilent(sys.argv[1], "status") if (sts < 0): print "FAIL: hm.power(%s, \"status\") returned: %s" % (nodeid, output) return -1 if (output == "on"): print "FAIL: hm.power(%s, \"status\") says the node is still on!" \ % nodeid return -1 if (output == "off"): print "SUCCESS: hm.power(%s, \"poweroff\") succeeded." % nodeid return 0 print "FAIL: hm.power(%s, \"status\") returned: %s" % (nodeid, output) return -1
########################################################################################### # Main execution ########################################################################################### print "Content-Type: text/html" print "" print "" manager = HenManager() nodes = manager.getNodes("all") form = cgi.FieldStorage() if form.has_key("id"): pass else: sys.exit() nodeid = form["id"].value for nodeTypeDictionary in nodes.values(): for node in nodeTypeDictionary.values(): if (nodeid == node.getNodeID()): print "<p>" print "power status of " manager.power(nodeid,"status") print "</p>" sys.exit()
sys.path.append("/usr/local/hen/lib/") from henmanager import HenManager ########################################################################################### # Main execution ########################################################################################### print "Content-Type: text/html" print "" print "" manager = HenManager() nodes = manager.getNodes("all") form = cgi.FieldStorage() if form.has_key("id"): pass else: sys.exit() nodeid = form["id"].value for nodeTypeDictionary in nodes.values(): for node in nodeTypeDictionary.values(): if (nodeid == node.getNodeID()): print "<p>" print "power status of " manager.power(nodeid, "status") print "</p>" sys.exit()