- if expires < time.time():
- raise PLCInvalidArgument, "Expiration date must be in the future"
-
- return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(expires))
-
- def add_person(self, person, commit = True):
- """
- Add person to existing slice.
- """
-
- assert 'slice_id' in self
- assert isinstance(person, PLC.Persons.Person)
- assert 'person_id' in person
-
- slice_id = self['slice_id']
- person_id = person['person_id']
-
- if person_id not in self['person_ids']:
- assert slice_id not in person['slice_ids']
-
- self.api.db.do("INSERT INTO slice_person (person_id, slice_id)" \
- " VALUES(%(person_id)d, %(slice_id)d)",
- locals())
-
- if commit:
- self.api.db.commit()
-
- self['person_ids'].append(person_id)
- person['slice_ids'].append(slice_id)
-
- def remove_person(self, person, commit = True):
- """
- Remove person from existing slice.
- """
-
- assert 'slice_id' in self
- assert isinstance(person, PLC.Persons.Person)
- assert 'person_id' in person
-
- slice_id = self['slice_id']
- person_id = person['person_id']
-
- if person_id in self['person_ids']:
- assert slice_id in person['slice_ids']
-
- self.api.db.do("DELETE FROM slice_person" \
- " WHERE person_id = %(person_id)d" \
- " AND slice_id = %(slice_id)d",
- locals())
-
- if commit:
- self.api.db.commit()
-
- self['person_ids'].remove(person_id)
- person['slice_ids'].remove(slice_id)
-
- def add_node(self, node, is_foreign_node = False, commit = True):
- """
- Add node to existing slice.
- """
-
- assert 'slice_id' in self
- if not is_foreign_node:
- assert isinstance(node, Node)
- else:
- assert isinstance(node, ForeignNode)
- assert 'node_id' in node
-
- slice_id = self['slice_id']
- node_id = node['node_id']
-
- if node_id not in self['node_ids']:
- assert slice_id not in node['slice_ids']
-
- self.api.db.do("INSERT INTO slice_node (node_id, slice_id)" \
- " VALUES(%(node_id)d, %(slice_id)d)",
- locals())
-
- if commit:
- self.api.db.commit()
-
- self['node_ids'].append(node_id)
- node['slice_ids'].append(slice_id)
-
- def remove_node(self, node, is_foreign_node = False, commit = True):
- """
- Remove node from existing slice.
- """
-
- assert 'slice_id' in self
- if not is_foreign_node:
- assert isinstance(node, Node)
- else:
- assert isinstance(node, ForeignNode)
- assert 'node_id' in node
-
- slice_id = self['slice_id']
- node_id = node['node_id']
-
- if node_id in self['node_ids']:
- assert slice_id in node['slice_ids']
-
- self.api.db.do("DELETE FROM slice_node" \
- " WHERE node_id = %(node_id)d" \
- " AND slice_id = %(slice_id)d",
- locals())