
- Initially this is a naive implementation and not fully utilizing the abilites of OVO - Updated test YAML files to match model - Did not convert Task objects as they will be refactored for Celery in the near future
108 lines
4.2 KiB
Python
108 lines
4.2 KiB
Python
# Copyright 2017 AT&T Intellectual Property. All other 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.
|
|
#
|
|
# ingester - Ingest host topologies to define site design and
|
|
# persist design to helm-drydock's statemgmt service
|
|
|
|
import logging
|
|
import yaml
|
|
import uuid
|
|
|
|
import helm_drydock.objects as objects
|
|
import helm_drydock.objects.site as site
|
|
import helm_drydock.objects.network as network
|
|
import helm_drydock.objects.hwprofile as hwprofile
|
|
import helm_drydock.objects.node as node
|
|
import helm_drydock.objects.hostprofile as hostprofile
|
|
|
|
from helm_drydock.statemgmt import DesignState
|
|
|
|
class Ingester(object):
|
|
|
|
def __init__(self):
|
|
logging.basicConfig(format="%(asctime)-15s [%(levelname)] %(module)s %(process)d %(message)s")
|
|
self.log = logging.Logger("ingester")
|
|
self.registered_plugins = {}
|
|
|
|
def enable_plugins(self, plugins=[]):
|
|
if len(plugins) == 0:
|
|
self.log.error("Cannot have an empty plugin list.")
|
|
|
|
for plugin in plugins:
|
|
try:
|
|
new_plugin = plugin()
|
|
plugin_name = new_plugin.get_name()
|
|
self.registered_plugins[plugin_name] = new_plugin
|
|
except:
|
|
self.log.error("Could not enable plugin %s" % (plugin.__name__))
|
|
|
|
if len(self.registered_plugins) == 0:
|
|
self.log.error("Could not enable at least one plugin")
|
|
raise Exception("Could not enable at least one plugin")
|
|
"""
|
|
enable_plugins
|
|
|
|
params: plugins - A list of class objects denoting the ingester plugins to be enabled
|
|
|
|
Enable plugins that can be used for ingest_data calls. Each plugin should use
|
|
helm_drydock.ingester.plugins.IngesterPlugin as its base class. As long as one
|
|
enabled plugin successfully initializes, the call is considered successful. Otherwise
|
|
it will throw an exception
|
|
"""
|
|
|
|
def ingest_data(self, plugin_name='', design_state=None, **kwargs):
|
|
if design_state is None:
|
|
self.log.error("ingest_data called without valid DesignState handler")
|
|
raise Exception("Invalid design_state handler")
|
|
|
|
design_data = None
|
|
|
|
# If no design_id is specified, instantiate a new one
|
|
if 'design_id' not in kwargs.keys():
|
|
design_id = str(uuid.uuid4())
|
|
design_data = objects.SiteDesign(id=design_id)
|
|
design_state.post_design(design_data)
|
|
else:
|
|
design_id = kwargs.get('design_id')
|
|
design_data = design_state.get_design(design_id)
|
|
|
|
if plugin_name in self.registered_plugins:
|
|
design_items = self.registered_plugins[plugin_name].ingest_data(**kwargs)
|
|
for m in design_items:
|
|
if type(m) is site.Site:
|
|
design_data.set_site(m)
|
|
elif type(m) is network.Network:
|
|
design_data.add_network(m)
|
|
elif type(m) is network.NetworkLink:
|
|
design_data.add_network_link(m)
|
|
elif type(m) is hostprofile.HostProfile:
|
|
design_data.add_host_profile(m)
|
|
elif type(m) is hwprofile.HardwareProfile:
|
|
design_data.add_hardware_profile(m)
|
|
elif type(m) is node.BaremetalNode:
|
|
design_data.add_baremetal_node(m)
|
|
design_state.put_design(design_data)
|
|
else:
|
|
self.log.error("Could not find plugin %s to ingest data." % (plugin_name))
|
|
raise LookupError("Could not find plugin %s" % plugin_name)
|
|
"""
|
|
ingest_data
|
|
|
|
params: plugin_name - Which plugin should be used for ingestion
|
|
params: params - A map of parameters that will be passed to the plugin's ingest_data method
|
|
|
|
Execute a data ingestion using the named plugin (assuming it is enabled)
|
|
"""
|
|
|