From e07b4c9bbf1f1dbdbf623c85dd47ad5d0422bc6b Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 26 Jun 2014 17:59:30 +0900 Subject: [PATCH] mgmt_driver: base class and noop driver Change-Id: I5253e97b3ca28c5702048b2f16a7c94878265ca7 --- .../unit/services/vm/mgmt_drivers/__init__.py | 0 .../unit/services/vm/mgmt_drivers/noop.py | 57 +++++++ tacker/vm/mgmt_drivers/__init__.py | 0 tacker/vm/mgmt_drivers/abstract_driver.py | 158 ++++++++++++++++++ tacker/vm/mgmt_drivers/constants.py | 33 ++++ 5 files changed, 248 insertions(+) create mode 100644 tacker/tests/unit/services/vm/mgmt_drivers/__init__.py create mode 100644 tacker/tests/unit/services/vm/mgmt_drivers/noop.py create mode 100644 tacker/vm/mgmt_drivers/__init__.py create mode 100644 tacker/vm/mgmt_drivers/abstract_driver.py create mode 100644 tacker/vm/mgmt_drivers/constants.py diff --git a/tacker/tests/unit/services/vm/mgmt_drivers/__init__.py b/tacker/tests/unit/services/vm/mgmt_drivers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tacker/tests/unit/services/vm/mgmt_drivers/noop.py b/tacker/tests/unit/services/vm/mgmt_drivers/noop.py new file mode 100644 index 000000000..b3acefa6f --- /dev/null +++ b/tacker/tests/unit/services/vm/mgmt_drivers/noop.py @@ -0,0 +1,57 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2013, 2014 Intel Corporation. +# Copyright 2013, 2014 Isaku Yamahata +# +# All Rights Reserved. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# @author: Isaku Yamahata, Intel Corporation. + +from tacker.openstack.common import log as logging +from tacker.vm.mgmt_drivers import abstract_driver + + +LOG = logging.getLogger(__name__) + + +class DeviceMgmtNoop(abstract_driver.DeviceMGMTAbstractDriver): + def get_type(self): + return 'noop' + + def get_name(self): + return 'noop' + + def get_description(self): + return 'Tacker DeviceMgmt Noop Driver' + + def mgmt_address(self, plugin, context, device): + LOG.debug(_('mgmt_address %s'), device) + return 'noop-mgmt-address' + + def mgmt_call(self, plugin, context, device, kwargs): + LOG.debug(_('mgmt_device_call %(device)s %(kwargs)s'), + {'device': device, 'kwargs': kwargs}) + + def mgmt_service_address(self, plugin, context, + device, service_instance): + LOG.debug(_('mgmt_service_address %(device)s %(service_instance)s'), + {'device': device, 'service_instance': service_instance}) + return 'noop-mgmt-service-address' + + def mgmt_service_call(self, plugin, context, device, + service_instance, kwargs): + LOG.debug(_('mgmt_service_call %(device)s %(service_instance)s'), + {'device': device, 'service_instance': service_instance}) diff --git a/tacker/vm/mgmt_drivers/__init__.py b/tacker/vm/mgmt_drivers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tacker/vm/mgmt_drivers/abstract_driver.py b/tacker/vm/mgmt_drivers/abstract_driver.py new file mode 100644 index 000000000..3411d0896 --- /dev/null +++ b/tacker/vm/mgmt_drivers/abstract_driver.py @@ -0,0 +1,158 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2013, 2014 Intel Corporation. +# Copyright 2013, 2014 Isaku Yamahata +# +# All Rights Reserved. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# @author: Isaku Yamahata, Intel Corporation. + +import abc + +import six + +from tacker.api import extensions +from tacker.openstack.common import jsonutils +from tacker.vm import constants + + +@six.add_metaclass(abc.ABCMeta) +class DeviceMGMTAbstractDriver(extensions.PluginInterface): + + @abc.abstractmethod + def get_type(self): + """Return one of predefined type of the hosting device drivers.""" + pass + + @abc.abstractmethod + def get_name(self): + """Return a symbolic name for the service VM plugin.""" + pass + + @abc.abstractmethod + def get_description(self): + pass + + def mgmt_create_pre(self, plugin, context, device): + pass + + def mgmt_create_post(self, plugin, context, device): + pass + + def mgmt_update_pre(self, plugin, context, device): + pass + + def mgmt_update_post(self, plugin, context, device): + pass + + def mgmt_delete_pre(self, plugin, context, device): + pass + + def mgmt_delete_post(self, plugin, context, device): + pass + + def mgmt_get_config(self, plugin, context, device): + """ + returns dict of file-like objects which will be passed to hosting + device. + It depends on drivers how to use it. + for nova case, it can be used for meta data, file injection or + config drive + i.e. + metadata case: nova --meta = + file injection case: nova --file : + config drive case: nova --config-drive=true --file \ + : + """ + return {} + + @abc.abstractmethod + def mgmt_address(self, plugin, context, device): + pass + + @abc.abstractmethod + def mgmt_call(self, plugin, context, device, kwargs): + pass + + def mgmt_service_driver(self, plugin, context, device, service_instance): + # use same mgmt driver to communicate with service + return self.get_name() + + def mgmt_service_create_pre(self, plugin, context, device, + service_instance): + pass + + def mgmt_service_create_post(self, plugin, context, device, + service_instance): + pass + + def mgmt_service_update_pre(self, plugin, context, device, + service_instance): + pass + + def mgmt_service_update_post(self, plugin, context, device, + service_instance): + pass + + def mgmt_service_delete_pre(self, plugin, context, device, + service_instance): + pass + + def mgmt_service_delete_post(self, plugin, context, device, + service_instance): + pass + + @abc.abstractmethod + def mgmt_service_address(self, plugin, context, device, service_instance): + pass + + @abc.abstractmethod + def mgmt_service_call(self, plugin, context, device, + service_instance, kwargs): + pass + + +class DeviceMGMTByNetwork(DeviceMGMTAbstractDriver): + def mgmt_address(self, plugin, context, device): + mgmt_entries = [sc_entry for sc_entry in device.service_context + if (sc_entry.role == constants.ROLE_MGMT and + sc_entry.port_id)] + if not mgmt_entries: + return + port = plugin._core_plugin.get_port(context, mgmt_entries[0].port_id) + if not port: + return + mgmt_address = port['fixed_ips'][0] # subnet_id and ip_address + mgmt_address['network_id'] = port['network_id'] + mgmt_address['port_id'] = port['id'] + mgmt_address['mac_address'] = port['mac_address'] + return jsonutils.dumps(mgmt_address) + + def mgmt_service_address(self, plugin, context, device, service_instance): + mgmt_entries = [sc_entry for sc_entry + in service_instance.service_context + if (sc_entry.role == constants.ROLE_MGMT and + sc_entry.port_id)] + if not mgmt_entries: + return + port = plugin._core_plugin.get_port(context, mgmt_entries[0].port_id) + if not port: + return + mgmt_address = port['fixed_ips'][0] # subnet_id and ip_address + mgmt_address['network_id'] = port['network_id'] + mgmt_address['port_id'] = port['id'] + mgmt_address['mac_address'] = port['mac_address'] + return jsonutils.dumps(mgmt_address) diff --git a/tacker/vm/mgmt_drivers/constants.py b/tacker/vm/mgmt_drivers/constants.py new file mode 100644 index 000000000..aa2bdea1f --- /dev/null +++ b/tacker/vm/mgmt_drivers/constants.py @@ -0,0 +1,33 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2013, 2014 Intel Corporation. +# Copyright 2013, 2014 Isaku Yamahata +# +# All Rights Reserved. +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# @author: Isaku Yamahata, Intel Corporation. + +# key +KEY_ACTION = 'action' +KEY_KWARGS = 'kwargs' + +# ACTION type +ACTION_CREATE_DEVICE = 'create_device' +ACTION_UPDATE_DEVICE = 'update_device' +ACTION_DELETE_DEVICE = 'delete_device' +ACTION_CREATE_SERVICE = 'create_service' +ACTION_UPDATE_SERVICE = 'update_service' +ACTION_DELETE_SERVICE = 'delete_service'