plabnode.in 1.81 KB
Newer Older
1
#!/usr/local/bin/python
2 3 4 5
# -*- python -*-

import sys
sys.path.append("@prefix@/lib")
6
import getopt
7
import libplab
Kirk Webb's avatar
 
Kirk Webb committed
8 9
import xmlrpclib
import time
10
import socket
Kirk Webb's avatar
 
Kirk Webb committed
11 12 13

TRIES = 3
SLEEPINT = 5
14 15

def usage(me):
16
    print "Usage: %s [ -vd ] { alloc | free } pid eid nodeid" % me
17 18 19
    sys.exit(1)

def main(args):
20
    me = args[0]
Kirk Webb's avatar
 
Kirk Webb committed
21 22
    alloctries = TRIES
    setuptries = TRIES
23

24
    try:
25 26 27
        command, pid, eid, nodeid = libplab.handleArgs(args[1:])
    except getopt.GetoptError:
        usage(me)
28
    except ValueError:
29
        usage(me)
30 31 32

    plab = libplab.Plab()
    slice = plab.loadSlice(pid, eid)
Kirk Webb's avatar
 
Kirk Webb committed
33

34
    if command == "alloc":
Kirk Webb's avatar
 
Kirk Webb committed
35
        node = slice.createNode(nodeid)
36
#        node.addKey("/root/.ssh/identity.pub")
Kirk Webb's avatar
 
Kirk Webb committed
37
        
Kirk Webb's avatar
 
Kirk Webb committed
38 39 40 41 42
        while 1:
            try:
                node.emulabify()
                # Note that vnode_setup boots the node
            except:
43
                print "Node setup failed on %s" % nodeid
Kirk Webb's avatar
 
Kirk Webb committed
44 45 46
            else:
                break

47 48 49 50 51 52 53 54 55 56 57
            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

Kirk Webb's avatar
 
Kirk Webb committed
58 59 60 61 62 63 64 65
    elif command == "renew":
        try:
            node = slice.loadNode(nodeid)
        except:
            print "renew: Node %s isn't allocated" % nodeid
            sys.exit(1)
        node.renew()

Kirk Webb's avatar
 
Kirk Webb committed
66
    elif command == "free":
67
        try:
Kirk Webb's avatar
 
Kirk Webb committed
68
            node = slice.loadNode(nodeid)
69
        except:
Kirk Webb's avatar
 
Kirk Webb committed
70 71
            print "free: Node %s wasn't really allocated" % nodeid
            sys.exit(1)
Kirk Webb's avatar
 
Kirk Webb committed
72

73
        node.free()
Kirk Webb's avatar
 
Kirk Webb committed
74

75 76 77 78 79
    else:
        usage(me)

if __name__ == "__main__":
    main(sys.argv)