X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=cmdline%2FeditRecord.py;h=f138f136583569a2f2b72b8f1a214637b5853df1;hb=4eb1bb57c22a78d8cf652a68085e6f00cc2e2460;hp=74d5d5879fce948739f6d1e410b85f1e57dfa4cc;hpb=b2344721149cb64667c88b63cdc3adb62ccf3530;p=sfa.git diff --git a/cmdline/editRecord.py b/cmdline/editRecord.py index 74d5d587..f138f136 100644 --- a/cmdline/editRecord.py +++ b/cmdline/editRecord.py @@ -6,12 +6,16 @@ from __future__ import with_statement import sys import os, os.path import getopt -from util.cert import Keypair, Certificate -from util.credential import Credential -from util.geniclient import GeniClient -from util.record import GeniRecord -from util.gid import GID - +import tempfile +from geni.util.cert import Keypair, Certificate +from geni.util.credential import Credential +from geni.util.geniclient import GeniClient +from geni.util.record import GeniRecord +from geni.util.gid import GID +from geni.util.gid import create_uuid + +gidhrn = None +gidkeyfile = None infile = None outfile = None gidfile = None @@ -23,7 +27,7 @@ type = None dump = False researcher = [] -long_opts = ["infile=", "outfile=", "email=", "ip=", "dns=", "gidfile=", "hrn=", "type=", "addresearcher=", "delresearcher=", "dump"] +long_opts = ["infile=", "outfile=", "email=", "ip=", "dns=", "gidfile=", "gidhrn=", "gidkeyfile=", "hrn=", "type=", "addresearcher=", "delresearcher=", "dump"] def showhelp(): print "syntax: editRecord.py " @@ -32,6 +36,8 @@ def showhelp(): print " --outfile ... write record to file" print " --dump ... dump record to stdout" print " --gidfile ... load gid from file" + print " --gidhrn ... name to use when creating gid" + print " --gidkeyfile ... key to use when creating gid" print " --hrn ... set hrn" print " --type ... set type (user|slice|sa|ma|...)" print " --email ... user: set email address" @@ -40,11 +46,27 @@ def showhelp(): print " --addresearcher ... slice: add researcher" print " --delresearcher ... slice: delete researcher" +def load_publickey_string(fn): + f = file(fn,"r") + key_string = f.read() + + # if the filename is a private key file, then extract the public key + if "PRIVATE KEY" in key_string: + outfn = tempfile.mktemp() + cmd = "openssl rsa -in " + fn + " -pubout -outform PEM -out " + outfn + os.system(cmd) + f = file(outfn, "r") + key_string = f.read() + os.remove(outfn) + + return key_string + def process_options(): global infile, outfile global email, ip, dns, gidfile, hrn, type global researcher global dump + global gidkeyfile, gidhrn (options, args) = getopt.getopt(sys.argv[1:], '', long_opts) for opt in options: @@ -66,6 +88,10 @@ def process_options(): dns = val elif name == "--gidfile": gidfile = val + elif name == "--gidhrn": + gidhrn = val + elif name == "--gidkeyfile": + gidkeyfile = val elif name == "--hrn": hrn = val elif name == "--type": @@ -86,7 +112,7 @@ def errorcheck(record): print "Warning: unknown record type" if not record.name: print "Warning: unknown record name" - if not record.gid: + if (not record.gid) and (not ("create_gid" in geni_info)): print "Warning: unknown record gid" if record.type == "user": @@ -152,6 +178,19 @@ def main(): gid = GID(string=gid_str) record.set_gid(gid) + if gidhrn or gidkeyfile: + if not gidhrn: + print "must use --gidkeyfile with --gidhrn" + sys.exit(-1) + if not gidkeyfile: + print "must use --gidhrn with --gidkeyfile" + sys.exit(-1) + + geni_info = record.get_geni_info() + geni_info["create_gid"] = True + geni_info["create_gid_hrn"] = gidhrn + geni_info["create_gid_key"] = load_publickey_string(gidkeyfile) + if researcher: update_list(geni_info, "researcher", researcher)