version = self.api.manager.GetVersion(self.api, {})
pprinter.pprint(version)
+ def slices(self):
+ """List the running slices at this Aggregate"""
+ print self.api.manager.ListSlices(self.api, [], {})
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
def status(self, xrn):
"""Display the status of a slice or slivers"""
urn = Xrn(xrn, 'slice').get_urn()
- status = self.api.manager.SliverStatus(self.api, [urn], {}, {})
+ status = self.api.manager.SliverStatus(self.api, urn, [], {})
pprinter.pprint(status)
- @args('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>',
- default='GENI', help='version/format of the resulting rspec response')
- def resources(self, rspec_version='GENI'):
- """Display the available resources at an aggregate"""
- options = {'geni_rspec_version': rspec_version}
- resources = self.api.manager.ListResources(self.api, {}, options)
- print resources
-
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
@args('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>',
default='GENI', help='version/format of the resulting rspec response')
- def describe(self, xrn, rspec_version='GENI'):
- """Display the resources allocated by a slice or slivers"""
- urn = Xrn(xrn, 'slice').get_urn()
+ def resources(self, xrn=None, rspec_version='GENI'):
+ """Display the available resources at an aggregate
+or the resources allocated by a slice"""
options = {'geni_rspec_version': rspec_version}
- status = self.api.manager.Describe(self.api, {}, [urn], options)
- print status
-
+ if xrn:
+ options['geni_slice_urn'] = Xrn(xrn, 'slice').get_urn()
+ print options
+ resources = self.api.manager.ListResources(self.api, [], options)
+ print resources
+
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
@args('-r', '--rspec', dest='rspec', metavar='<rspec>', help='rspec file (mandatory)')
@args('-u', '--user', dest='user', metavar='<user>', help='hrn/urn of slice user (mandatory)')
@args('-k', '--key', dest='key', metavar='<key>', help="path to user's public key file (mandatory)")
- def allocate(self, xrn, rspec, user, key):
+ def create(self, xrn, rspec, user, key):
"""Allocate slivers"""
xrn = Xrn(xrn, 'slice')
- urn=xrn.get_urn()
+ slice_urn=xrn.get_urn()
rspec_string = open(rspec).read()
user_xrn = Xrn(user, 'user')
user_urn = user_xrn.get_urn()
user_key_string = open(key).read()
users = [{'urn': user_urn, 'keys': [user_key_string]}]
- options={'geni_users': users}
- status = self.api.manager.Allocate(self.api, urn, {}, rspec_string, options)
- print status
-
- @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
- def provision(self, xrns):
- status = self.api.manager.Provision(self.api, [xrns], {}, {})
- print status
+ options={}
+ self.api.manager.CreateSliver(self, slice_urn, [], rspec_string, users, options)
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
def delete(self, xrn):
"""Delete slivers"""
- result = self.api.manager.DeleteSliver(self.api, [xrn], {}, {})
- print result
-
+ self.api.manager.DeleteSliver(self.api, xrn, [], {})
+
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
- @args('-e', '--expiration', dest='expiration', metavar='<expiration>', help='Expiration date (mandatory)')
- def renew(self, xrn, expiration):
+ def start(self, xrn):
"""Start slivers"""
- result = self.api.manager.start_slice(self.api, xrn, {}, expiration, {})
- print result
+ self.api.manager.start_slice(self.api, xrn, [])
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
- def shutdown(self, xrn):
+ def stop(self, xrn):
"""Stop slivers"""
- result = self.api.manager.Shutdown(self.api, xrn, {}, {})
- print result
+ self.api.manager.stop_slice(self.api, xrn, [])
@args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
- @args('-a', '--action', dest='action', metavar='<action>', help='Action name (mandatory)')
- def operation(self, xrn, action):
+ def reset(self, xrn):
"""Reset sliver"""
- result = self.api.manager.PerformOperationalAction(self.api, [xrn], {}, action, {})
- print result
+ self.api.manager.reset_slice(self.api, xrn)
+
# @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
# @args('-r', '--rspec', dest='rspec', metavar='<rspec>', help='request rspec', default=None)
("remove", "name"),
("resources", ""),
("describe", "slice_hrn"),
- ("create", "slice_hrn rspec"),
("allocate", "slice_hrn rspec"),
("provision", "slice_hrn"),
("action", "slice_hrn action"),
help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
# user specifies remote aggregate/sm/component
- if command in ("resources", "describe", "allocate", "provision", "create", "delete", "allocate", "provision",
+ if command in ("resources", "describe", "allocate", "provision", "delete", "allocate", "provision",
"action", "shutdown", "get_ticket", "renew", "status"):
parser.add_option("-d", "--delegate", dest="delegate", default=None,
action="store_true",
"authority in set of credentials for this call")
# show_credential option
- if command in ("list","resources", "describe", "provision", "allocate", "create","add","update","remove","slices","delete","status","renew"):
+ if command in ("list","resources", "describe", "provision", "allocate", "add","update","remove","slices","delete","status","renew"):
parser.add_option("-C","--credential",dest='show_credential',action='store_true',default=False,
help="show credential(s) used in human-readable form")
# registy filter option
choices=("all", "resources", "leases"), default="resources")
- # 'create' does return the new rspec, makes sense to save that too
- if command in ("resources", "describe", "allocate", "provision", "show", "list", "gid", 'create'):
+ if command in ("resources", "describe", "allocate", "provision", "show", "list", "gid"):
parser.add_option("-o", "--output", dest="file",
help="output XML to file", metavar="FILE", default=None)
return
- def create(self, options, args):
- """
- create or update named slice with given rspec
- """
- server = self.sliceapi()
-
- # xxx do we need to check usage (len(args)) ?
- # slice urn
- slice_hrn = args[0]
- slice_urn = hrn_to_urn(slice_hrn, 'slice')
-
- # credentials
- creds = [self.slice_credential_string(slice_hrn)]
-
- delegated_cred = None
- server_version = self.get_cached_server_version(server)
- if server_version.get('interface') == 'slicemgr':
- # delegate our cred to the slice manager
- # do not delegate cred to slicemgr...not working at the moment
- pass
- #if server_version.get('hrn'):
- # delegated_cred = self.delegate_cred(slice_cred, server_version['hrn'])
- #elif server_version.get('urn'):
- # delegated_cred = self.delegate_cred(slice_cred, urn_to_hrn(server_version['urn']))
-
- if options.show_credential:
- show_credentials(creds)
-
- # rspec
- rspec_file = self.get_rspec_file(args[1])
- 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
-
- 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)
self.logger.log_exc("PlImporter: failed to import person %d %s"%(person['person_id'],person['email']))
# maintain the list of PIs for a given site
+ # for the record, Jordan had proposed the following addition as a welcome hotfix to a previous version:
+ # site_pis = list(set(site_pis))
+ # this was likely due to a bug in the above logic, that had to do with disabled persons
+ # being improperly handled, and where the whole loop on persons
+ # could be performed twice with the same person...
+ # so hopefully we do not need to eliminate duplicates explicitly here anymore
site_record.reg_pis = list(site_pis)
- site_record.reg_pis = site_pis
dbsession.commit()
# import slices
if slice_id != slice_record.pointer:
self.logger.info("updating record (slice) pointer")
slice_record.pointer = slice_id
- dbsession.commit()
+ dbsession.commit()
# xxx update the record ...
- #self.logger.warning ("Slice update not yet implemented")
+ # given that we record the current set of users anyways, there does not seem to be much left to do here
+ # self.logger.warning ("Slice update not yet implemented on slice %s (%s)"%(slice_hrn,slice['name']))
+ #pass
# record current users affiliated with the slice
slice_record.reg_researchers = \
[ self.locate_by_type_pointer ('user',user_id) for user_id in slice['person_ids'] ]
result['aggregate'] = aggregate
return result
except:
- logger.log_exc('Something wrong in _RenewSliver with URL %s'%server.url)
+ logger.log_exc('Something wrong in _Renew with URL %s'%server.url)
return {'aggregate': aggregate, 'exc_info': traceback.format_exc(),
'code': {'geni_code': -1},
'value': False, 'output': ""}
def _Delete(server, xrn, creds, options):
return server.Delete(xrn, creds, options)
- (hrn, type) = urn_to_hrn(xrn)
+ (hrn, type) = urn_to_hrn(xrn[0])
# get the callers hrn
valid_cred = api.auth.checkCredentials(creds, 'deletesliver', hrn)[0]
caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
continue
interface = api.aggregates[aggregate]
server = api.server_proxy(interface, cred)
- threads.run(_DeleteSliver, server, xrn, [cred], options)
+ threads.run(_Delete, server, xrn, [cred], options)
threads.get_results()
return 1
}
- def Describe(self, api, xrns, creds, options):
+ def Describe(self, api, creds, xrns, options):
def _Describe(server, xrn, creds, options):
return server.Describe(xrn, creds, options)
for aggregate in api.aggregates:
interface = api.aggregates[aggregate]
server = api.server_proxy(interface, cred)
- threads.run (_Describe, server, slice_xrn, [cred], options)
+ threads.run (_Describe, server, xrns, [cred], options)
results = [ReturnValue.get_value(result) for result in threads.get_results()]
# get rid of any void result - e.g. when call_id was hit, where by convention we return {}
if not results : return {}
# otherwise let's merge stuff
+ version_manager = VersionManager()
manifest_version = version_manager._get_version('GENI', '3', 'manifest')
result_rspec = RSpec(version=manifest_version)
geni_slivers = []
for result in results:
try:
geni_urn = result['geni_urn']
- result_rspec.version.merge(ReturnValue.get_value(result['result']['geni_rspec']))
- geni_slivers.extend(result['result']['geni_slivers'])
+ result_rspec.version.merge(ReturnValue.get_value(result['geni_rspec']))
+ geni_slivers.extend(result['geni_slivers'])
except:
api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
return {
from sfa.rspecs.rspec import RSpec
from sfa.rspecs.elements.hardware_type import HardwareType
-from sfa.rspecs.elements.node import Node
+from sfa.rspecs.elements.node import NodeElement
from sfa.rspecs.elements.link import Link
from sfa.rspecs.elements.sliver import Sliver
from sfa.rspecs.elements.login import Login
from sfa.rspecs.elements.location import Location
from sfa.rspecs.elements.position_3d import Position3D
from sfa.rspecs.elements.interface import Interface
-from sfa.rspecs.elements.services import Services
from sfa.rspecs.elements.pltag import PLTag
from sfa.rspecs.elements.lease import Lease
from sfa.rspecs.elements.granularity import Granularity
'type': 'plab-vserver',
'tags': []})
rspec_node['sliver_id'] = rspec_sliver['sliver_id']
- rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
- if sliver_allocations[sliver['urn']].component_id:
- rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
+ if sliver['urn'] in sliver_allocations:
+ rspec_node['client_id'] = sliver_allocations[sliver['urn']].client_id
+ if sliver_allocations[sliver['urn']].component_id:
+ rspec_node['component_id'] = sliver_allocations[sliver['urn']].component_id
rspec_node['slivers'] = [rspec_sliver]
# slivers always provide the ssh service
}
return geni_sliver
- def get_leases(self, slice_xrn=None, slice=None, options={}):
+ def get_leases(self, slice=None, options={}):
if slice_xrn and not slice:
return []
site=sites_dict[site_id]
rspec_lease['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], lease['hostname'])
- if slice_xrn:
- slice_urn = slice_xrn
- slice_hrn = urn_to_hrn(slice_urn)
- else:
- slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
- slice_urn = hrn_to_urn(slice_hrn, 'slice')
+ slice_hrn = slicename_to_hrn(self.driver.hrn, lease['name'])
+ slice_urn = hrn_to_urn(slice_hrn, 'slice')
rspec_lease['slice_id'] = slice_urn
rspec_lease['start_time'] = lease['t_from']
rspec_lease['duration'] = (lease['t_until'] - lease['t_from']) / grain
def status (self, urns, options={}):
aggregate = PlAggregate(self)
- desc = aggregate.describe(urns)
+ desc = aggregate.describe(urns, version='GENI 3')
status = {'geni_urn': desc['geni_urn'],
'geni_slivers': desc['geni_slivers']}
return status
requested_time = utcparse(expiration_time)
record = {'expires': int(datetime_to_epoch(requested_time))}
self.shell.UpdateSlice(slice['slice_id'], record)
- description = self.describe(urns, None, options)
+ description = self.describe(urns, 'GENI 3', options)
return description['geni_slivers']
nodes = self.driver.shell.GetNodes(slice['node_ids'], ['node_id', 'hostname', 'interface_ids'])
current_slivers = [node['hostname'] for node in nodes]
- requested_slivers = []
- tags = []
- for node in slivers:
- hostname = None
- if node.get('component_name'):
- hostname = node.get('component_name').strip()
- elif node.get('component_id'):
- hostname = xrn_to_hostname(node.get('component_id').strip())
- if node.get('client_id'):
- tags.append({'slicename': slice['name'],
- 'tagname': 'client_id',
- 'value': node['client_id'],
- 'node': hostname})
- if hostname:
- requested_slivers.append(hostname)
-
# remove nodes not in rspec
deleted_nodes = list(set(current_slivers).difference(slivers.keys()))
code = {
'geni_code': GENICODE.SUCCESS,
'am_type': 'sfa',
+ 'am_code': None,
}
if isinstance(result, SfaFault):
code['geni_code'] = result.faultCode