1 # Copyright 2012 OpenStack Foundation.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 from oslo_utils import uuidutils
18 from neutron.api import extensions
19 from neutron.api.v2 import base
20 from neutron.common import exceptions
21 from neutron.db import servicetype_db
22 from neutron.extensions import servicetype
23 from neutron import manager
24 from neutron.plugins.common import constants
25 from neutron.services import service_base
28 RESOURCE_NAME = "dummy"
29 COLLECTION_NAME = "%ss" % RESOURCE_NAME
31 # Attribute Map for dummy resource
32 RESOURCE_ATTRIBUTE_MAP = {
34 'id': {'allow_post': False, 'allow_put': False,
35 'validate': {'type:uuid': None},
37 'name': {'allow_post': True, 'allow_put': True,
38 'validate': {'type:string': None},
39 'is_visible': True, 'default': ''},
40 'tenant_id': {'allow_post': True, 'allow_put': False,
41 'required_by_policy': True,
43 'service_type': {'allow_post': True,
45 'validate': {'type:servicetype_ref': None},
63 def get_description(cls):
68 return "2012-11-20T10:00:00-00:00"
71 def get_resources(cls):
72 """Returns Extended Resource for dummy management."""
73 n_mgr = manager.NeutronManager.get_instance()
74 dummy_inst = n_mgr.get_service_plugins()['DUMMY']
75 controller = base.create_resource(
76 COLLECTION_NAME, RESOURCE_NAME, dummy_inst,
77 RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME])
78 return [extensions.ResourceExtension(COLLECTION_NAME,
82 class DummyServicePlugin(service_base.ServicePluginBase):
83 """This is a simple plugin for managing instances of a fictional 'dummy'
84 service. This plugin is provided as a proof-of-concept of how
85 advanced service might leverage the service type extension.
86 Ideally, instances of real advanced services, such as load balancing
87 or VPN will adopt a similar solution.
90 supported_extension_aliases = ['dummy', servicetype.EXT_ALIAS]
91 path_prefix = "/dummy_svc"
92 agent_notifiers = {'dummy': 'dummy_agent_notifier'}
95 self.svctype_mgr = servicetype_db.ServiceTypeManager.get_instance()
98 def get_plugin_type(self):
99 return constants.DUMMY
101 def get_plugin_description(self):
102 return "Neutron Dummy Service Plugin"
104 def get_dummys(self, context, filters, fields):
105 return self.dummys.values()
107 def get_dummy(self, context, id, fields):
109 return self.dummys[id]
111 raise exceptions.NotFound()
113 def create_dummy(self, context, dummy):
115 d['id'] = uuidutils.generate_uuid()
116 self.dummys[d['id']] = d
117 self.svctype_mgr.increase_service_type_refcount(context,
121 def update_dummy(self, context, id, dummy):
124 def delete_dummy(self, context, id):
126 svc_type_id = self.dummys[id]['service_type']
128 self.svctype_mgr.decrease_service_type_refcount(context,
131 raise exceptions.NotFound()