registerslice.py 2.73 KB
Newer Older
1 2
#! /usr/bin/env python
#
3
# GENIPUBLIC-COPYRIGHT
4
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# All rights reserved.
# 
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation.
#
# THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION.  THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
# FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#

#
#
import sys
import pwd
import getopt
import os
import re
import xmlrpclib
25
from M2Crypto import X509
26

27
ACCEPTSLICENAME=1
28
OtherUser = None
29

30
execfile( "test-common.py" )
31

32 33 34 35
if len(REQARGS) == 1:
    OtherUser = REQARGS[0]
    pass

36 37 38
#
# Get a credential for myself, that allows me to do things at the SA.
#
39
mycredential = get_self_credential()
40 41 42 43 44 45 46 47
print "Got my SA credential"

#
# Lookup slice, delete before proceeding.
#
params = {}
params["credential"] = mycredential
params["type"]       = "Slice"
48
params["hrn"]        = SLICENAME
49 50
rval,response = do_method("sa", "Resolve", params)
if rval == 0:
Leigh B. Stoller's avatar
Leigh B. Stoller committed
51
    print "Deleting previously registered slice";
52 53 54
    params = {}
    params["credential"] = mycredential
    params["type"]       = "Slice"
55
    params["hrn"]        = SLICENAME
56 57 58 59 60 61 62 63 64
    rval,response = do_method("sa", "Remove", params)
    if rval:
        Fatal("Could not remove slice record")
        pass
    pass

#
# Create a slice. 
#
65
print "Creating new slice called " + SLICENAME
66 67 68
params = {}
params["credential"] = mycredential
params["type"]       = "Slice"
69
params["hrn"]        = SLICENAME
70 71 72
rval,response = do_method("sa", "Register", params)
if rval:
    Fatal("Could not get my slice")
73 74
    print str(rval)
    print str(response)
75 76
    pass
myslice = response["value"]
77
print "New slice created: " + SLICEURN
78
if debug: print str(myslice)
79 80

#
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
# Lookup another user so we can bind them to the slice.
#
if OtherUser:
    params = {}
    params["hrn"]       = OtherUser;
    params["credential"] = mycredential
    params["type"]       = "User"
    rval,response = do_method("sa", "Resolve", params)
    if rval:
        Fatal("Could not resolve other user")
        pass
    user = response["value"]
    print "Found other user record at the SA, binding to slice ..."
    
    #
    # And bind the user to the slice so that he can get his own cred.
    #
    params = {}
    params["uuid"]       = user["uuid"]
    params["credential"] = myslice
    rval,response = do_method("sa", "BindToSlice", params)
    if rval:
        Fatal("Could not bind other user to slice")
        pass
    binding = response["value"]
    print "Bound other user to slice at the SA"
    pass