implemented Interfaces, InterfaceTags, Messages, NetworkMethods, NetworkTypes, NodeGroups
[plcapi.git] / PLC / SliceTags.py
1 from types import StringTypes
2 import time
3 import re
4 import datetime
5
6 from PLC.Faults import *
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Filter import Filter
9 from PLC.Debug import profile
10 from PLC.Timestamp import Timestamp
11 from PLC.Storage.AlchemyObject import AlchemyObj
12
13 class SliceTags(AlchemyObj):
14     """
15     Representation of a row in the slice_tags table. To use, optionally
16     instantiate with a dict of values. Update as you would a
17     dict. Commit to the database with sync().To use, instantiate
18     with a dict of values.
19     """
20
21     tablename = 'slice_tags'
22  
23     fields = {
24         'slice_tag_id': Parameter(int, "Slice Tag identifier", primary_key=True),
25         'slice_id': Parameter(int, "Slice identifier", indexed=True),
26         'name': Parameter(str, "Slice name"),
27         'node_id': Parameter(int, "Node identifier", nullok=True),
28         'nodegroup_id': Parameter(int, "Node Group identifier", nullok=True),
29         'tag_type_id': Parameter(int, "Tag type identifier"),
30         'tagname': Parameter(str, "Tag type name"),
31         'description': Parameter(str, "Tag type description"),
32         'category': Parameter(str, "Tag type category"),
33         'value': Parameter(str, "Slice attribute value"),
34         }
35
36     tags = {}
37
38     def sync(self, commit = True, validate=True):
39         """
40         Add the record
41         """
42         AlchemyObj.sync(self, commit, validate)
43         AlchemyObj.insert(self, dict(self))
44
45     def delete(self, commit = True):
46         """
47         Delete existing slice.
48         """
49         AlchemyObj.delete(self, dict(self))
50
51
52 class SliceTags(list):
53     """
54     Representation of row(s) from the slices table in the
55     database.
56     """
57
58     def __init__(self, api, filter = None, columns = None):
59          
60         # the view that we're selecting upon: start with view_slices
61         if not filter:
62             slice_tags = SliceTags().select()
63         elif isinstance(filter, dict):
64             slices_tags = SliceTags().select(filter=filter)
65         else:
66             raise PLCInvalidArgument, "Wrong slice_tag filter %r"%filter
67
68         for slice_tag in slice_tags:
69             self.append(slice_tag)