- id_list is optional
[plcapi.git] / PLC / SliceAttributes.py
1 from types import StringTypes
2
3 from PLC.Faults import *
4 from PLC.Parameter import Parameter
5 from PLC.Table import Row, Table
6 from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
7
8 class SliceAttribute(Row):
9     """
10     Representation of a row in the slice_attribute table. To use,
11     instantiate with a dict of values.
12     """
13
14     table_name = 'slice_attribute'
15     primary_key = 'slice_attribute_id'
16     fields = {
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_type_id': SliceAttributeType.fields['attribute_type_id'],
21         'name': SliceAttributeType.fields['name'],
22         'description': SliceAttributeType.fields['description'],
23         'min_role_id': SliceAttributeType.fields['min_role_id'],
24         # XXX Arbitrary max, make configurable
25         'value': Parameter(str, "Slice attribute value", max = 254),
26         }
27
28 class SliceAttributes(Table):
29     """
30     Representation of row(s) from the slice_attribute table in the
31     database.
32     """
33
34     def __init__(self, api, slice_attribute_id_list = None):
35         self.api = api
36
37         sql = "SELECT %s FROM view_slice_attributes" % \
38               ", ".join(SliceAttribute.fields)
39
40         if slice_attribute_id_list:
41             sql += " WHERE slice_attribute_id IN (%s)" % ", ".join(map(str, slice_attribute_id_list))
42
43         rows = self.api.db.selectall(sql)
44  
45         for row in rows:
46             self[row['slice_attribute_id']] = SliceAttribute(api, row)