From 04a7de082bd221eae3c7004f4e0b99dfa4f8be91 Mon Sep 17 00:00:00 2001 From: ahothan Date: Fri, 28 Jul 2017 17:08:46 -0700 Subject: Initial code drop from Cisco Change-Id: Ie2993886dc8e95c5f73ccdb871add8b96ffcc849 Signed-off-by: ahothan --- nfvbench/config_plugin.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 nfvbench/config_plugin.py (limited to 'nfvbench/config_plugin.py') diff --git a/nfvbench/config_plugin.py b/nfvbench/config_plugin.py new file mode 100644 index 0000000..ed6b3c6 --- /dev/null +++ b/nfvbench/config_plugin.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# Copyright 2016 Cisco Systems, Inc. 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. +# + +import abc +import specs + + +class ConfigPluginBase(object): + """Base class for config plugins. Need to implement public interfaces.""" + __metaclass__ = abc.ABCMeta + + class InitializationFailure(Exception): + pass + + def __init__(self, config): + if not config: + raise ConfigPluginBase.InitializationFailure( + 'Initialization parameters need to be assigned.') + + self.config = config + + @abc.abstractmethod + def get_config(self): + """Returns updated default configuration file.""" + + @abc.abstractmethod + def get_openstack_spec(self): + """Returns OpenStack specs for host.""" + + @abc.abstractmethod + def get_run_spec(self, openstack_spec): + """Returns RunSpec for given platform.""" + + @abc.abstractmethod + def validate_config(self, cfg): + """Validate config file.""" + + @abc.abstractmethod + def prepare_results_config(self, cfg): + """This function is called before running configuration is copied. + Example usage is to remove sensitive information like switch credentials. + """ + + @abc.abstractmethod + def get_version(self): + """Returns platform version.""" + + +class ConfigPlugin(ConfigPluginBase): + """No-op config plugin class. Does not change anything.""" + + def __init__(self, config): + ConfigPluginBase.__init__(self, config) + + def get_config(self): + """Public interface for updating config file. Just returns given config.""" + return self.config + + def get_openstack_spec(self): + """Returns OpenStack specs for host.""" + return specs.OpenStackSpec() + + def get_run_spec(self, openstack_spec): + """Returns RunSpec for given platform.""" + return specs.RunSpec(self.config.no_vswitch_access, openstack_spec) + + def validate_config(self, config): + pass + + def prepare_results_config(self, cfg): + return cfg + + def get_version(self): + return {} -- cgit 1.2.3-korg