sys.path.append('.')
import os, os.path
import tempfile
-import traceback
import socket
-import random
import datetime
-import zlib
import codecs
import pickle
from lxml import etree
from StringIO import StringIO
-from types import StringTypes, ListType
from optparse import OptionParser
-from sfa.client.client_helper import pg_users_arg, sfa_users_arg, sfa_to_pg_users_arg
+from sfa.client.client_helper import pg_users_arg, sfa_users_arg
from sfa.util.sfalogging import sfi_logger
from sfa.trust.certificate import Keypair, Certificate
from sfa.trust.gid import GID
from sfa.trust.credential import Credential
-from sfa.util.sfaticket import SfaTicket
+from sfa.trust.sfaticket import SfaTicket
from sfa.util.record import SfaRecord, UserRecord, SliceRecord, NodeRecord, AuthorityRecord
from sfa.rspecs.rspec import RSpec
from sfa.rspecs.rspec_converter import RSpecConverter
-from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn
+from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
from sfa.util.config import Config
from sfa.util.version import version_core
for record in recordList:
record = SfaRecord(dict=record)
f.write('<record hrn="' + record.get_name() + '" type="' + record.get_type() + '" />\n')
- f.write("</recordlist>\n");
+ f.write("</recordlist>\n")
f.close()
elif format == "hrnlist":
f = open(filename, "w")
parser.add_option("-d", "--delegate", dest="delegate", default=None,
action="store_true",
help="Include a credential delegated to the user's root"+\
- "authority in set of credentials for this call")
-
- # registy filter option
+ "authority in set of credentials for this call")
+
+ # registy filter option
if command in ("list", "show", "remove"):
parser.add_option("-t", "--type", dest="type", type="choice",
help="type filter ([all]|user|slice|authority|node|aggregate)",
help="output file format ([xml]|xmllist|hrnlist)", default="xml",
choices=("xml", "xmllist", "hrnlist"))
- if command in ("status"):
+ if command in ("status", "version"):
parser.add_option("-o", "--output", dest="file",
help="output dictionary to file", metavar="FILE", default=None)
parser.add_option("-F", "--fileformat", dest="fileformat", type="choice",
if args:
hrn = args[0]
gid = self._get_gid(hrn)
- self.logger.debug("Sfi.get_gid-> %s",gid.save_to_string(save_parents=True))
+ self.logger.debug("Sfi.get_gid-> %s" % gid.save_to_string(save_parents=True))
return gid
def _get_gid(self, hrn=None, type=None):
hrn = self.user
gidfile = os.path.join(self.options.sfi_dir, hrn + ".gid")
- print gidfile
gid = self.get_cached_gid(gidfile)
if not gid:
user_cred = self.get_user_cred()
version=server.GetVersion()
for (k,v) in version.iteritems():
print "%-20s: %s"%(k,v)
+ if opts.file:
+ save_variable_to_file(version, opts.file, opts.fileformat)
# list instantiated slices
def slices(self, opts, args):
else:
save_rspec_to_file(result, opts.file)
return
-
+
# created named slice with given rspec
def create(self, opts, args):
server = self.get_server_from_opts(opts)
server_version = self.get_cached_server_version(server)
slice_hrn = args[0]
- slice_urn = hrn_to_urn(slice_hrn, 'slice')
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
user_cred = self.get_user_cred()
slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
- creds = [slice_cred]
- if opts.delegate:
- delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority))
- creds.append(delegated_cred)
+
+ if hasattr(opts, 'aggregate') and opts.aggregate:
+ delegated_cred = None
+ else:
+ # delegate the cred to the callers root authority
+ delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority)+'.slicemanager')
+ #delegated_cred = self.delegate_cred(slice_cred, get_authority(slice_hrn))
+ #creds.append(delegated_cred)
+
rspec_file = self.get_rspec_file(args[1])
rspec = open(rspec_file).read()
- # need to pass along user keys to the aggregate.
+ # need to pass along user keys to the aggregate.
# users = [
# { urn: urn:publicid:IDN+emulab.net+user+alice
- # keys: [<ssh key A>, <ssh key B>]
+ # keys: [<ssh key A>, <ssh key B>]
# }]
users = []
slice_records = self.registry.Resolve(slice_urn, [user_cred.save_to_string(save_parents=True)])
user_hrns = slice_record['researcher']
user_urns = [hrn_to_urn(hrn, 'user') for hrn in user_hrns]
user_records = self.registry.Resolve(user_urns, [user_cred.save_to_string(save_parents=True)])
-
+
if 'sfa' not in server_version:
users = pg_users_arg(user_records)
rspec = RSpec(rspec)
rspec.filter({'component_manager_id': server_version['urn']})
rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
+ creds = [slice_cred]
else:
users = sfa_users_arg(user_records, slice_record)
+ creds = [slice_cred]
+ if delegated_cred:
+ creds.append(delegated_cred)
call_args = [slice_urn, creds, rspec, users]
if self.server_supports_call_id_arg(server):
call_args.append(unique_call_id())
-
+
result = server.CreateSliver(*call_args)
if opts.file is None:
print result