+ if not slices:
+ parts = slicename.split("_")
+ login_base = parts[0]
+ slice_record = self.registry.resolve(self.cred, slice_hrn)
+ slice_info = slice_record.as_dict()
+ slice = slice_info['pl_info']
+
+ # if site doesnt exist add it
+ sites = self.shell.GetSites(self.auth, [login_base])
+ if not sites:
+ authority = get_authority(slice_hrn)
+ site_record = self.registry.reolve(self.cred, authority)
+ site_info = site_record.as_dict()
+ site = site_info['pl_info']
+
+ # add the site
+ site.pop('site_id')
+ site_id = self.shell.AddSite(self.auth, site)
+
+ # add the slice
+ self.shell.AddSlice(self.auth, slice_info)
+
+ # add the slice users
+
+ else:
+ slice = slices[0]
+
+
+ # find out where this slice is currently running
+ nodelist = self.shell.GetNodes(self.auth, slice['node_ids'], ['hostname'])
+ hostnames = [node['hostname'] for node in nodelist]
+
+ # get netspec details
+ nodespecs = spec.getDictsByTagName('NodeSpec')
+ nodes = []
+ for nodespec in nodespecs:
+ if isinstance(nodespec['name'], list):
+ nodes.extend(nodespec['name'])
+ elif isinstance(nodespec['name'], StringTypes):
+ nodes.append(nodespec['name'])
+
+ # save slice state locally
+ # we can assume that spec object has been validated so its safer to
+ # save this instead of the unvalidated rspec the user gave us
+ self.slices[slice_hrn] = spec.toxml()
+ self.slices.write()
+
+ # remove nodes not in rspec
+ deleted_nodes = list(set(hostnames).difference(nodes))
+ # add nodes from rspec
+ added_nodes = list(set(nodes).difference(hostnames))
+
+ self.shell.AddSliceToNodes(self.auth, slicename, added_nodes)
+ self.shell.DeleteSliceFromNodes(self.auth, slicename, deleted_nodes)
+
+ # contact registry to get slice users and add them to the slice
+ #slice_record = self.registry.resolve(self.credential, slice_hrn)
+ # persons = slice_record['users']
+ # for perosn in persons:
+ # shell.AddPersonToSlice(person['email'], slice_name)
+ return 1
+
+ def updateSlice(self, slice_hrn, rspec, attributes = []):
+ return self.create_slice(slice_hrn, rspec, attributes)
+
+ def deleteSlice(self, slice_hrn):
+ """
+ Remove this slice from all components it was previouly associated with and
+ free up the resources it was using.
+ """
+ if self.slices.has_key(slice_hrn):
+ self.slices.pop(slice_hrn)
+ self.slices.write()
+
+ slicename = hrn_to_pl_slicename(slice_hrn)
+ slices = self.shell.GetSlices(self.auth, [slicename])
+ if not slices:
+ return 1