- ########## for foreign slices update, from ForeignSlices
- def purge_slice_node (self,commit=True):
- sql = "DELETE FROM slice_node WHERE slice_id=%d"%self['slice_id']
- self.api.db.do(sql)
- if commit:
- self.api.db.commit()
-
- def add_slice_nodes (self, node_ids, commit=True):
- slice_id = self['slice_id']
- ### xxx needs to be optimized
- ### tried to figure a way to use a single sql statement
- ### like: insert into table (x,y) values (1,2),(3,4);
- ### but apparently this is not supported under postgresql
- for node_id in node_ids:
- sql="INSERT INTO slice_node VALUES (%d,%d)"%(slice_id,node_id)
- self.api.db.do(sql)
- if commit:
- self.api.db.commit()
-
- def update_slice_nodes (self, node_ids):
- # xxx to be optimized
- # we could compute the (set) difference between
- # current and updated set of node_ids
- # and invoke the DB only based on that
- #
- # for now : clean all entries for this slice
- self.purge_slice_node()
- # and re-install new list
- self.add_slice_nodes (node_ids)
-