X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FSlices.py;h=5e2b2e20ab128125d104a0864170ec89216c0cad;hb=1f888ad5e1553f500926e35a0893519432cd94cd;hp=e62bd639c5cb91de39d2fad02a4c2034c4b43b1b;hpb=e347fc823bbba9d88a3fddf07d5c21024dfd1e55;p=plcapi.git diff --git a/PLC/Slices.py b/PLC/Slices.py index e62bd63..5e2b2e2 100644 --- a/PLC/Slices.py +++ b/PLC/Slices.py @@ -9,7 +9,6 @@ from PLC.Debug import profile from PLC.Table import Row, Table from PLC.SliceInstantiations import SliceInstantiations from PLC.Nodes import Node, Nodes -from PLC.ForeignNodes import ForeignNode, ForeignNodes import PLC.Persons class Slice(Row): @@ -36,7 +35,20 @@ class Slice(Row): 'node_ids': Parameter([int], "List of nodes in this slice", ro = True), 'person_ids': Parameter([int], "List of accounts that can use this slice", ro = True), 'slice_attribute_ids': Parameter([int], "List of slice attributes", ro = True), + 'peer_id': Parameter(int, "Peer at which this slice was created", nullok = True), } + # for Cache + class_key = 'name' + foreign_fields = ['instantiation', 'url', 'description', 'max_nodes', 'expires'] + foreign_xrefs = [ + {'field': 'node_ids' , 'class': 'Node', 'table': 'slice_node' }, + {'field': 'person_ids', 'class': 'Person', 'table': 'slice_person'}, + {'field': 'creator_person_id', 'class': 'Person', 'table': 'unused-on-direct-refs'}, + {'field': 'site_id', 'class': 'Site', 'table': 'unused-on-direct-refs'}, + ] + # forget about this one, it is read-only anyway + # handling it causes Cache to re-sync all over again + # 'created' def validate_name(self, name): # N.B.: Responsibility of the caller to ensure that login_base @@ -55,7 +67,7 @@ class Slice(Row): conflicts = Slices(self.api, [name]) for slice in conflicts: if 'slice_id' not in self or self['slice_id'] != slice['slice_id']: - raise PLCInvalidArgument, "Slice name already in use" + raise PLCInvalidArgument, "Slice name already in use, %s"%name return name @@ -66,13 +78,14 @@ class Slice(Row): return instantiation + # timestamps + def validate_created (self, timestamp): + return self.validate_timestamp (timestamp) + def validate_expires(self, expires): # N.B.: Responsibility of the caller to ensure that expires is # not too far into the future. - 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)) + return self.validate_timestamp (expires,True) def add_person(self, person, commit = True): """ @@ -125,16 +138,13 @@ class Slice(Row): self['person_ids'].remove(person_id) person['slice_ids'].remove(slice_id) - def add_node(self, node, is_foreign_node = False, commit = True): + def add_node(self, node, 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 isinstance(node, Node) assert 'node_id' in node slice_id = self['slice_id'] @@ -179,6 +189,7 @@ class Slice(Row): self['node_ids'].remove(node_id) node['slice_ids'].remove(slice_id) + ########## def sync(self, commit = True): """ Add or update a slice.