1 from types import StringTypes
3 from PLC.Faults import *
4 from PLC.Parameter import Parameter
5 from PLC.Table import Row, Table
6 from PLC.Attributes import Attribute, Attributes
8 class SliceAttribute(Row):
10 Representation of a row in the slice_attribute table. To use,
11 instantiate with a dict of values.
14 table_name = 'slice_attribute'
15 primary_key = 'slice_attribute_id'
17 'slice_attribute_id': Parameter(int, "Slice attribute identifier"),
18 'slice_id': Parameter(int, "Slice identifier"),
19 'node_id': Parameter(int, "Node identifier, if a sliver attribute"),
20 'attribute_id': Attribute.fields['attribute_id'],
21 'name': Attribute.fields['name'],
22 'description': Attribute.fields['description'],
23 'min_role_id': Attribute.fields['min_role_id'],
24 # XXX Arbitrary max, make configurable
25 'value': Parameter(str, "Slice attribute value", max = 254),
28 def __init__(self, api, fields = {}):
29 Row.__init__(self, fields)
32 def delete(self, commit = True):
34 Delete existing slice attribute.
37 assert 'slice_attribute_id' in self
39 # Clean up miscellaneous join tables
40 for table in 'slice_attribute',:
41 self.api.db.do("DELETE FROM %s" \
42 " WHERE slice_attribute_id = %d" % \
43 (table, self['slice_attribute_id']), self)
48 class SliceAttributes(dict):
50 Representation of row(s) from the slice_attribute table in the
54 def __init__(self, api, slice_attribute_id_list):
57 sql = "SELECT %s FROM view_slice_attributes" % \
58 ", ".join(SliceAttribute.fields)
60 sql += " WHERE slice_attribute_id IN (%s)" % ", ".join(map(str, slice_attribute_id_list))
62 rows = self.api.db.selectall(sql)
65 self[row['slice_attribute_id']] = SliceAttribute(api, row)