Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / trunk / PLC / Methods / AddSliceAttributeType.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
5 from PLC.Auth import Auth
6
7 can_update = lambda (field, value): field in \
8              ['name', 'description', 'min_role_id']
9
10 class AddSliceAttributeType(Method):
11     """
12     Adds a new type of slice attribute. Any fields specified in
13     attribute_type_fields are used, otherwise defaults are used.
14
15     Returns the new attribute_type_id (> 0) if successful, faults
16     otherwise.
17     """
18
19     roles = ['admin']
20
21     attribute_type_fields = dict(filter(can_update, SliceAttributeType.fields.items()))
22
23     accepts = [
24         Auth(),
25         attribute_type_fields
26         ]
27
28     returns = Parameter(int, 'New attribute_id (> 0) if successful')
29
30
31     def call(self, auth, attribute_type_fields):
32         attribute_type_fields = dict(filter(can_update, attribute_type_fields.items()))
33         attribute_type = SliceAttributeType(self.api, attribute_type_fields)
34         attribute_type.sync()
35
36         self.event_objects = {'AttributeType': [attribute_type['attribute_type_id']]}
37
38         return attribute_type['attribute_type_id']