+ rspec = open(rspec_file).read()
+
+ # users
+ # 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>]
+ # }]
+ users = []
+ # xxx Thierry 2012 sept. 21
+ # contrary to what I was first thinking, calling Resolve with details=False does not yet work properly here
+ # I am turning details=True on again on a - hopefully - temporary basis, just to get this whole thing to work again
+ slice_records = self.registry().Resolve(slice_urn, [self.my_credential_string])
+ # slice_records = self.registry().Resolve(slice_urn, [self.my_credential_string], {'details':True})
+ if slice_records and 'reg-researchers' in slice_records[0] and slice_records[0]['reg-researchers']:
+ slice_record = slice_records[0]
+ user_hrns = slice_record['reg-researchers']
+ user_urns = [hrn_to_urn(hrn, 'user') for hrn in user_hrns]
+ user_records = self.registry().Resolve(user_urns, [self.my_credential_string])
+
+ 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')
+ else:
+ users = sfa_users_arg(user_records, slice_record)
+
+ # do not append users, keys, or slice tags. Anything
+ # not contained in this request will be removed from the slice
+
+ # CreateSliver has supported the options argument for a while now so it should
+ # be safe to assume this server support it
+ api_options = {}
+ api_options ['append'] = False
+ api_options ['call_id'] = unique_call_id()
+ result = server.CreateSliver(slice_urn, creds, rspec, users, *self.ois(server, api_options))
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ if options.file is not None:
+ save_rspec_to_file (value, options.file)
+ if (self.options.raw is None) and (options.file is None):
+ print value
+
+ return value
+
+ def delete(self, options, args):
+ """
+ delete named slice (DeleteSliver)
+ """
+ server = self.sliceapi()
+
+ # slice urn
+ slice_hrn = args[0]
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+
+ # creds
+ slice_cred = self.slice_credential_string(slice_hrn)
+ creds = [slice_cred]
+
+ # options and call_id when supported
+ api_options = {}
+ api_options ['call_id'] = unique_call_id()
+ if options.show_credential:
+ show_credentials(creds)
+ result = server.DeleteSliver(slice_urn, creds, *self.ois(server, api_options ) )
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+ return value
+
+ def status(self, options, args):
+ """
+ retrieve slice status (SliverStatus)
+ """
+ server = self.sliceapi()
+
+ # slice urn
+ slice_hrn = args[0]
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+
+ # creds
+ slice_cred = self.slice_credential_string(slice_hrn)
+ creds = [slice_cred]
+
+ # options and call_id when supported
+ api_options = {}
+ api_options['call_id']=unique_call_id()
+ if options.show_credential:
+ show_credentials(creds)
+ result = server.SliverStatus(slice_urn, creds, *self.ois(server,api_options))
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+
+ def start(self, options, args):
+ """
+ start named slice (Start)
+ """
+ server = self.sliceapi()
+
+ # the slice urn
+ slice_hrn = args[0]
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+
+ # cred
+ slice_cred = self.slice_credential_string(args[0])
+ creds = [slice_cred]
+ # xxx Thierry - does this not need an api_options as well ?
+ result = server.Start(slice_urn, creds)
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+ return value
+
+ def stop(self, options, args):
+ """
+ stop named slice (Stop)
+ """
+ server = self.sliceapi()
+ # slice urn
+ slice_hrn = args[0]
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+ # cred
+ slice_cred = self.slice_credential_string(args[0])
+ creds = [slice_cred]
+ result = server.Stop(slice_urn, creds)
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+ return value
+
+ # reset named slice
+ def reset(self, options, args):
+ """
+ reset named slice (reset_slice)
+ """
+ server = self.sliceapi()
+ # slice urn
+ slice_hrn = args[0]
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+ # cred
+ slice_cred = self.slice_credential_string(args[0])
+ creds = [slice_cred]
+ result = server.reset_slice(creds, slice_urn)
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+ return value
+
+ def renew(self, options, args):
+ """
+ renew slice (RenewSliver)
+ """
+ server = self.sliceapi()
+ if len(args) != 2:
+ self.print_help()
+ sys.exit(1)
+ [ slice_hrn, input_time ] = args
+ # slice urn
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+ # time: don't try to be smart on the time format, server-side will
+ # creds
+ slice_cred = self.slice_credential_string(args[0])
+ creds = [slice_cred]
+ # options and call_id when supported
+ api_options = {}
+ api_options['call_id']=unique_call_id()
+ if options.show_credential:
+ show_credentials(creds)
+ result = server.RenewSliver(slice_urn, creds, input_time, *self.ois(server,api_options))
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+ return value
+
+
+ def shutdown(self, options, args):
+ """
+ shutdown named slice (Shutdown)
+ """
+ server = self.sliceapi()
+ # slice urn
+ slice_hrn = args[0]
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
+ # creds
+ slice_cred = self.slice_credential_string(slice_hrn)
+ creds = [slice_cred]
+ result = server.Shutdown(slice_urn, creds)
+ value = ReturnValue.get_value(result)
+ if self.options.raw:
+ save_raw_to_file(result, self.options.raw, self.options.rawformat, self.options.rawbanner)
+ else:
+ print value
+ return value
+
+
+ def get_ticket(self, options, args):
+ """
+ get a ticket for the specified slice
+ """
+ server = self.sliceapi()
+ # slice urn