mgmt driver for openwrt

Change-Id: I0759e1ecb8524300c2007873585baf8122cad9d2
This commit is contained in:
Isaku Yamahata 2015-05-13 21:39:56 -07:00
parent af4cf6c6e5
commit 55ec101acd
5 changed files with 105 additions and 0 deletions

View File

@ -497,6 +497,7 @@ infra_driver = heat
# Specify drivers for mgmt
# exmpale: mgmt_driver = noop
mgmt_driver = noop
mgmt_driver = openwrt
[servicevm_nova]
# parameters for novaclient to talk to nova

View File

@ -56,6 +56,7 @@ tacker.servicevm.mgmt.drivers =
noop = tacker.tests.unit.services.vm.mgmt_drivers.noop:DeviceMgmtNoop
agent_rpc = tacker.vm.mgmt_drivers.rpc.rpc:AgentRpcMGMTDriver
agent_proxy = tacker.vm.mgmt_drivers.rpc.proxy:AgentRpcProxyMGMTDriver
openwrt = tacker.vm.mgmt_drivers.openwrt.openwrt:DeviceMgmtOpenWRT
[build_sphinx]

View File

@ -93,6 +93,10 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
device_template_dict.setdefault('service_types', []).extend(
[{'service_type': service_type}
for service_type in service_types])
for vdu in vnfd_dict.get('vdus', {}).values():
mgmt_driver = vdu.get('mgmt_driver')
if mgmt_driver:
device_template_dict['mgmt_driver'] = mgmt_driver
LOG.debug(_('device_template %s'), device_template)
@log.log

View File

@ -0,0 +1,99 @@
# Copyright 2015 Intel Corporation.
# Copyright 2015 Isaku Yamahata <isaku.yamahata at intel com>
# <isaku.yamahata at gmail com>
# 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 yaml
from oslo_config import cfg
from tacker.agent.linux import utils
from tacker.common import log
from tacker.openstack.common import log as logging
from tacker.vm.mgmt_drivers import abstract_driver
from tacker.vm.mgmt_drivers import constants as mgmt_constants
LOG = logging.getLogger(__name__)
OPTS = [
cfg.StrOpt('user', default='root', help=_('user name to login openwrt')),
cfg.StrOpt('password', default='', help=_('password to login openwrt')),
]
cfg.CONF.register_opts(OPTS, 'openwrt')
class DeviceMgmtOpenWRT(abstract_driver.DeviceMGMTAbstractDriver):
def get_type(self):
return 'openwrt'
def get_name(self):
return 'openwrt'
def get_description(self):
return 'Tacker DeviceMgmt OpenWRT Driver'
def mgmt_url(self, plugin, context, device):
LOG.debug(_('mgmt_url %s'), device)
return device.get('mgmt_url', '')
@log.log
def _config_service(self, mgmt_url, service, config):
user = cfg.CONF.openwrt.user
password = cfg.CONF.openwrt.password
cmd = ["sshpass", "-p", "%s" % password,
"ssh", "-o", "StrictHostKeyChecking=no",
"%s@%s" % (user, mgmt_url),
"uci import %s; /etc/init.d/%s restart" % (service, service)]
utils.execute(cmd, process_input=config)
@log.log
def mgmt_call(self, plugin, context, device, kwargs):
if (kwargs[mgmt_constants.KEY_ACTION] !=
mgmt_constants.ACTION_UPDATE_DEVICE):
return
dev_attrs = device.get('attributes', {})
service_type = dev_attrs.get('service_type')
if not service_type:
return
mgmt_url = device.get('mgmt_url', '')
if not mgmt_url:
return
vdus_config = dev_attrs.get('config', '')
config_yaml = yaml.load(vdus_config)
if not config_yaml:
return
vdus_config_dict = config_yaml.get('vdus', {})
for vdu_dict in vdus_config_dict.values():
config = vdu_dict.get('config', {})
for key, conf_value in config.items():
KNOWN_SERVICES = ('firewall', )
if key not in KNOWN_SERVICES:
continue
self._config_service(mgmt_url, key, conf_value)
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})