#!/usr/local/bin/python # -*- python -*- import sys sys.path.append("@prefix@/lib") import getopt import libplab import xmlrpclib import time import socket TRIES = 3 SLEEPINT = 5 def usage(me): print "Usage: %s [ -vd ] { alloc | free } pid eid nodeid" % me sys.exit(1) def main(args): me = args[0] alloctries = TRIES setuptries = TRIES try: command, pid, eid, nodeid = libplab.handleArgs(args[1:]) except getopt.GetoptError: usage(me) except ValueError: usage(me) plab = libplab.Plab() slice = plab.loadSlice(pid, eid) if command == "alloc": node = slice.createNode(nodeid) # node.addKey("/root/.ssh/identity.pub") while 1: try: node.emulabify() # Note that vnode_setup boots the node except: print "Node setup failed on %s" % nodeid else: break setuptries = setuptries - 1 if setuptries > 0: print "Sleeping for %s seconds and then retrying " \ "setup on %s" % (SLEEPINT, nodeid) time.sleep(SLEEPINT) else: print "Giving up after %s setup attempts on %s" % \ (TRIES, nodeid) node.free() raise elif command == "renew": try: node = slice.loadNode(nodeid) except: print "renew: Node %s isn't allocated" % nodeid sys.exit(1) node.renew() elif command == "free": try: node = slice.loadNode(nodeid) except: print "free: Node %s wasn't really allocated" % nodeid sys.exit(1) node.free() else: usage(me) if __name__ == "__main__": main(sys.argv)