/
loadbalancercustomattributes.py
73 lines (58 loc) · 2.05 KB
/
loadbalancercustomattributes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
try:
from neutron_lib.api import extensions
except ImportError:
from neutron.api import extensions
def _validate_custom_attributes(data, valid_values=None):
if not isinstance(data, list):
msg = _("Invalid data format for custom_attributes: '%s'") % data
return msg
def convert_none_to_empty_list(value):
return [] if value is None else value
try:
from neutron_lib import constants
ATTR_NOT_SPECIFIED = constants.ATTR_NOT_SPECIFIED
except ImportError:
from neutron.api.v2 import attributes
ATTR_NOT_SPECIFIED = attributes.ATTR_NOT_SPECIFIED
try:
from neutron_lib.api import validators
from neutron.api.v2 import attributes as attr
validators.add_validator('type:customattributes',
_validate_custom_attributes)
except ImportError:
from neutron.api.v2 import attributes as attr
attr.validators['type:customattributes'] = _validate_custom_attributes
# Extended_Attribute MAP
EXTENDED_ATTRIBUTES_2_0 = {
'pools': {
'custom_attributes': {'allow_post': True, 'allow_put': True,
'convert_to': convert_none_to_empty_list,
'default': ATTR_NOT_SPECIFIED,
'validate': {'type:customattributes': None},
'is_visible': True},
}
}
class Loadbalancercustomattributes(extensions.ExtensionDescriptor):
@classmethod
def get_name(cls):
return "Loadbalancer as a Service"
@classmethod
def get_alias(cls):
return "extra_lbaas_opts"
@classmethod
def get_description(cls):
return "Custom LBaaS attributes"
@classmethod
def get_namespace(cls):
return "http://docs.openstack.org/TODO"
@classmethod
def get_updated(cls):
return "2015-07-17T15:00:00-00:00"
@classmethod
def get_extended_resources(self, version):
"""Returns Ext Resources"""
if version == "2.0":
return EXTENDED_ATTRIBUTES_2_0
else:
return {}
#end class Loadbalancercustomattributes