from geni.util.geniclient import GeniClient, ServerException
from geni.util.gid import create_uuid
from geni.util.record import GeniRecord
+from geni.util.rspec import Rspec
+from types import StringTypes, ListType
sfi_dir = os.path.expanduser("~/.sfi/")
slicemgr = None
(cmd_opts, cmd_args) = create_cmd_parser(command).parse_args(args[1:])
verbose = options.verbose
if verbose :
- print options.registry, options.sm, options.dir, options.verbose,\
- options.user, options.auth
- print command
+ print "Resgistry %s, sm %s, dir %s, user %s, auth %s" % (options.registry,
+ options.sm,
+ options.dir,
+ options.user,
+ options.auth)
+ print "Command %s" %command
if command in ("resources"):
- print cmd_opts.format
+ print "resources cmd_opts %s" %cmd_opts.format
elif command in ("list","show","remove"):
- print cmd_opts.type
- print cmd_args
+ print "cmd_opts.type %s" %cmd_opts.type
+ print "cmd_args %s" %cmd_args
set_servers(options)
global registry
user_cred = get_user_cred()
list = registry.list(user_cred, args[0])
+ # filter on person, slice, site, node, etc.
+ # THis really should be in the filter_records funct def comment...
list = filter_records(opts.type, list)
display_records(list)
if opts.file:
def slices(opts, args):
global slicemgr
user_cred = get_user_cred()
- results = slicemgr.list_slices(user_cred)
+ results = slicemgr.get_slices(user_cred)
display_list(results)
return
result = slicemgr.get_resources(slice_cred, args[0])
else:
user_cred = get_user_cred()
- result = slicemgr.get_resources(user_cred)
- display_rspec(result)
+ result = slicemgr.get_resources(user_cred)
+ format = opts.format
+ display_rspec(result, format)
if (opts.file is not None):
save_rspec_to_file(opts.file, result)
return
#
#
-def display_rspec(rspec):
- print rspec
- return
+def display_rspec(rspec, format = 'rspec'):
+ if format in ['dns']:
+ spec = Rspec()
+ spec.parseString(rspec)
+ hostnames = []
+ nodespecs = spec.getDictsByTagName('NodeSpec')
+ for nodespec in nodespecs:
+ if nodespec.has_key('name') and nodespec['name']:
+ if isinstance(nodespec['name'], ListType):
+ hostnames.extend(nodespec['name'])
+ elif isinstance(nodespec['name'], StringTypes):
+ hostnames.append(nodespec['name'])
+ result = hostnames
+ elif format in ['ip']:
+ spec = Rspec()
+ spec.parseString(rspec)
+ ips = []
+ ifspecs = spec.getDictsByTagName('IfSpec')
+ for ifspec in ifspecs:
+ if ifspec.has_key('addr') and ifspec['addr']:
+ ips.append(ifspec['addr'])
+ result = ips
+ else:
+ result = rspec
+
+ print result
+ return
def display_list(results):
for result in results:
return
def display_records(recordList, dump = False):
+ ''' Print all fields in the record'''
for record in recordList:
display_record(record, dump)
def display_record(record, dump = False):
if dump:
- record.dump(False)
+ record.dump()
else:
info = record.getdict()
print "%s (%s)" % (info['hrn'], info['type'])