createsliver.py 2.93 KB
Newer Older
1 2
#! /usr/bin/env python
#
3
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
4
# 
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# {{{GENIPUBLIC-LICENSE
# 
# GENI Public License
# 
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
# 
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
# 
# }}}
29 30 31 32 33 34 35 36
#

#
#
import sys
import pwd
import getopt
import os
Leigh B. Stoller's avatar
Leigh B. Stoller committed
37
import time
38 39
import re

40 41
ACCEPTSLICENAME=1

42
debug    = 0
43 44
impotent = 0
dokeys   = 1
45

46
execfile( "test-common.py" )
47

48
if len(REQARGS) > 1:
49 50
    Usage()
    sys.exit( 1 )
51
elif len(REQARGS) == 1:
52
    try:
53
        rspecfile = open(REQARGS[0])
54 55 56 57 58 59 60
        rspec = rspecfile.read()
        rspecfile.close()
    except IOError, e:
        print >> sys.stderr, args[ 0 ] + ": " + e.strerror
        sys.exit( 1 )
else:
    rspec = "<rspec xmlns=\"http://protogeni.net/resources/rspec/0.1\"> " +\
61
            " <node virtual_id=\"geni1\" "+\
Leigh B. Stoller's avatar
Leigh B. Stoller committed
62 63
            "       virtualization_type=\"emulab-vnode\" " +\
            "       startup_command=\"/bin/ls > /tmp/foo\"> " +\
64 65 66
            " </node>" +\
            "</rspec>"    

67 68 69
#
# Get a credential for myself, that allows me to do things at the SA.
#
70
mycredential = get_self_credential()
71 72
print "Got my SA credential"

73 74 75
#
# Lookup my ssh keys.
#
76 77 78
if dokeys:
    params = {}
    params["credential"] = mycredential
79
    rval,response = do_method_retry("sa", "GetKeys", params)
80 81
    if rval:
        Fatal("Could not get my keys")
82
    pass
83

84
#
85
# Lookup slice and get credential.
86
#
87
myslice = resolve_slice( SLICENAME, mycredential )
88 89 90 91

print "Asking for slice credential for " + SLICENAME
slicecredential = get_slice_credential( myslice, mycredential )
print "Got the slice credential"
92 93 94 95

#
# Create the sliver.
#
96
print "Creating the Sliver ..."
97
params = {}
98
params["credentials"] = (slicecredential,)
99
params["slice_urn"]   = myslice["urn"]
100
params["rspec"]       = rspec
101 102 103
if dokeys:
    params["keys"]        = mykeys
    pass
104
params["impotent"]    = impotent
105
rval,response = do_method_retry("cm", "CreateSliver", params)
106
if rval:
107
    Fatal("Could not create sliver")
108
    pass
109 110
sliver,manifest = response["value"]
print "Created the sliver"
111
#print str(manifest)
112