Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / extensions / servicetype.py
1 # Copyright 2013 OpenStack Foundation.
2 # All Rights Reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15
16 from neutron._i18n import _
17 from neutron.api import extensions
18 from neutron.api.v2 import attributes
19 from neutron.api.v2 import base
20 from neutron.db import servicetype_db
21
22
23 RESOURCE_NAME = "service_provider"
24 COLLECTION_NAME = "%ss" % RESOURCE_NAME
25 SERVICE_ATTR = 'service_type'
26 PLUGIN_ATTR = 'plugin'
27 DRIVER_ATTR = 'driver'
28 EXT_ALIAS = 'service-type'
29
30 # Attribute Map for Service Provider Resource
31 # Allow read-only access
32 RESOURCE_ATTRIBUTE_MAP = {
33     COLLECTION_NAME: {
34         'service_type': {'allow_post': False, 'allow_put': False,
35                          'is_visible': True},
36         'name': {'allow_post': False, 'allow_put': False,
37                  'is_visible': True},
38         'default': {'allow_post': False, 'allow_put': False,
39                     'is_visible': True},
40     }
41 }
42
43
44 class Servicetype(extensions.ExtensionDescriptor):
45
46     @classmethod
47     def get_name(cls):
48         return _("Neutron Service Type Management")
49
50     @classmethod
51     def get_alias(cls):
52         return EXT_ALIAS
53
54     @classmethod
55     def get_description(cls):
56         return _("API for retrieving service providers for "
57                  "Neutron advanced services")
58
59     @classmethod
60     def get_updated(cls):
61         return "2013-01-20T00:00:00-00:00"
62
63     @classmethod
64     def get_resources(cls):
65         """Returns Extended Resource for service type management."""
66         my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()]
67         attributes.PLURALS.update(dict(my_plurals))
68         attr_map = RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]
69         collection_name = COLLECTION_NAME.replace('_', '-')
70         controller = base.create_resource(
71             collection_name,
72             RESOURCE_NAME,
73             servicetype_db.ServiceTypeManager.get_instance(),
74             attr_map)
75         return [extensions.ResourceExtension(collection_name,
76                                              controller,
77                                              attr_map=attr_map)]
78
79     def get_extended_resources(self, version):
80         if version == "2.0":
81             return RESOURCE_ATTRIBUTE_MAP
82         else:
83             return {}