- registry = api.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)
-
- nodes = api.plshell.GetNodes(api.plauth, slice['node_ids'], ['hostname'])
- current_slivers = [node['hostname'] for node in nodes]
- rspec = parse_rspec(rspec_string)
- requested_slivers = [str(host) for host in rspec.get_nodes_with_slivers()]
- # remove nodes not in rspec
- deleted_nodes = list(set(current_slivers).difference(requested_slivers))
-
- # add nodes from rspec
- added_nodes = list(set(requested_slivers).difference(current_slivers))
-
- # get sliver attributes
- requested_slice_attributes = rspec.get_slice_attributes()
- removed_slice_attributes = []
- existing_slice_attributes = []
- for slice_tag in api.plshell.GetSliceTags(api.plauth, {'slice_id': slice['slice_id']}):
- attribute_found=False
- for requested_attribute in requested_slice_attributes:
- if requested_attribute['name'] == slice_tag['tagname'] and \
- requested_attribute['value'] == slice_tag['value']:
- attribute_found=True
-
- if not attribute_found:
- removed_slice_attributes.append(slice_tag)
- else:
- existing_slice_attributes.append(slice_tag)
-
- try:
- if peer:
- api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice['slice_id'], peer)
-
- api.plshell.AddSliceToNodes(api.plauth, slice['name'], added_nodes)
- api.plshell.DeleteSliceFromNodes(api.plauth, slice['name'], deleted_nodes)
- # remove stale attributes
- for attribute in removed_slice_attributes:
- try:
- api.plshell.DeleteSliceTag(api.plauth, attribute['slice_tag_id'])
- except Exception, e:
- api.logger.warn('Failed to remove sliver attribute. name: %s, value: %s, node_id: %s\nCause:%s'\
- % (name, value, node_id, str(e)))
-
- # add requested_attributes
- for attribute in requested_slice_attributes:
- try:
- name, value, node_id = attribute['name'], attribute['value'], attribute.get('node_id', None)
- api.plshell.AddSliceTag(api.plauth, slice['name'], name, value, node_id)
- except Exception, e:
- api.logger.warn('Failed to add sliver attribute. name: %s, value: %s, node_id: %s\nCause:%s'\
- % (name, value, node_id, str(e)))