def prepare_slice(api, slice_xrn, creds, users): reg_objects = __get_registry_objects(slice_xrn, creds, users) (hrn, type) = urn_to_hrn(slice_xrn) slices = Slices(api) peer = slices.get_peer(hrn) sfa_peer = slices.get_sfa_peer(hrn) slice_record=None if users: slice_record = users[0].get('slice_record', {}) registry = api.registries[api.hrn] credential = api.getCredential() # ensure site record exists site = slices.verify_site(hrn, slice_record, peer, sfa_peer) # ensure slice record exists slice = slices.verify_slice(hrn, slice_record, peer, sfa_peer) # ensure person records exists persons = slices.verify_persons(hrn, slice, users, peer, sfa_peer)
def CreateSliver(api, xrn, creds, xml, users, call_id): """ Verify HRN and initialize the slice record in PLC if necessary. """ if Callids().already_handled(call_id): return "" hrn, type = urn_to_hrn(xrn) peer = None reg_objects = __get_registry_objects(xrn, creds, users) slices = Slices(api) peer = slices.get_peer(hrn) sfa_peer = slices.get_sfa_peer(hrn) registries = Registries(api) registry = registries[api.hrn] credential = api.getCredential() site_id, remote_site_id = slices.verify_site(registry, credential, hrn, peer, sfa_peer, reg_objects) slice = slices.verify_slice(registry, credential, hrn, site_id, remote_site_id, peer, sfa_peer, reg_objects) network = ViniNetwork(api) slice = network.get_slice(api, hrn) current = __get_hostnames(slice.get_nodes()) network.addRSpec(xml, "/var/www/html/schemas/vini.rng") #network.addRSpec(xml, "/root/SVN/sfa/trunk/sfa/managers/vini/vini.rng") request = __get_hostnames(network.nodesWithSlivers()) # remove nodes not in rspec deleted_nodes = list(set(current).difference(request)) # add nodes from rspec added_nodes = list(set(request).difference(current)) api.plshell.AddSliceToNodes(api.plauth, slice.name, added_nodes) api.plshell.DeleteSliceFromNodes(api.plauth, slice.name, deleted_nodes) network.updateSliceTags() # xxx - check this holds enough data for the client to understand what's happened return network.toxml()