registerslice.py 2.67 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
# 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
22
import time
23 24 25
import os
import re
import xmlrpclib
26
from M2Crypto import X509
27

28
ACCEPTSLICENAME=1
29 30
OtherUser  = None
Expiration = (60 * 60 * 6)
31

32
execfile( "test-common.py" )
33

34 35 36 37
if len(REQARGS) == 1:
    OtherUser = REQARGS[0]
    pass

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

#
45
# Lookup slice.
46 47 48 49
#
params = {}
params["credential"] = mycredential
params["type"]       = "Slice"
50
params["hrn"]        = SLICENAME
51 52
rval,response = do_method("sa", "Resolve", params)
if rval == 0:
53 54
    print "Slice already exists."
    sys.exit(0)
55 56
    pass

57 58 59 60 61 62
#
# Set up expiration.
#
valid_until = time.strftime("%Y%m%dT%H:%M:%S",
                            time.gmtime(time.time() + Expiration))

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

#
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
# 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 = {}
Leigh B Stoller's avatar
Leigh B Stoller committed
101
    params["urn"]        = user["urn"]
102 103 104 105 106 107 108 109 110
    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