DRYD7 - Bootdata API and promenade integration

Add bootdata API for nodes to gather post-boot defintion info
Add owner_data support to the maasdriver Machine model
Add steps to the DeployNode task to setup bootdata and set owner_data
This commit is contained in:
Scott Hussey 2017-06-22 11:54:56 -05:00
parent cc99fccf08
commit ab03692a81
8 changed files with 470 additions and 257 deletions

View File

@ -42,7 +42,10 @@ def start_api(state_manager=None, ingester=None, orchestrator=None):
('/designs/{design_id}', DesignResource(state_manager=state_manager, orchestrator=orchestrator)),
('/designs/{design_id}/parts', DesignsPartsResource(state_manager=state_manager, ingester=ingester)),
('/designs/{design_id}/parts/{kind}', DesignsPartsKindsResource(state_manager=state_manager)),
('/designs/{design_id}/parts/{kind}/{name}', DesignsPartResource(state_manager=state_manager, orchestrator=orchestrator))
('/designs/{design_id}/parts/{kind}/{name}', DesignsPartResource(state_manager=state_manager, orchestrator=orchestrator)),
# API for nodes to discover their bootdata during curtin install
('/bootdata/{hostname}/{data_key}', BootdataResource(state_manager=state_manager))
]
for path, res in v1_0_routes:

View File

@ -0,0 +1,93 @@
# 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.
import falcon
import json
from .base import StatefulResource
class BootdataResource(StatefulResource):
def __init__(self, orchestrator=None, **kwargs):
super(BootdataResource, self).__init__(**kwargs)
self.authorized_roles = ['anyone']
self.orchestrator = orchestrator
def on_get(self, req, resp, hostname, data_key):
if data_key == 'systemd':
resp.body = BootdataResource.systemd_definition
resp.content_type = 'text/plain'
return
elif data_key == 'prominit'
resp.boy = BootdataResource.prominit
resp.content_type = 'text/plain'
return
else:
bootdata = self.state_manager.get_boot_data(hostname)
if bootdata is None:
resp.status = falcon.HTTP_404
return
elif bootdata.get('key', None) == data_key:
resp.content_type = 'text/plain'
host_design_id = bootdata.get('design_id', None)
self.orchestrator.get_effective_site(host_design_id)
host_model = host_design.get_baremetal_node(hostname)
part_list = []
all_parts = self.state_manager.get_promenade_parts('all')
if all_parts is not None:
part_list.extend(all_parts)
host_parts = self.state_manager.get_promenade_parts(hostname)
if host_parts is not None:
part_list.extend(host_parts)
for t in host_model.tags:
tag_parts = self.state_manager.get_promenade_parts(t)
if t is not None:
part_list.extend(tag_parts)
resp.body = yaml.dump_all(part_list, explicit_start=True)
return
else:
resp.status = falcon.HTTP_403
return
systemd_definition = \
"""[Unit]
Description=Promenade Initialization Service
Documentation=http://github.com/att-comdev/drydock
After=network.target local-fs.target
ConditionPathExists=!/var/lib/prom.done
[Service]
Type=simple
Environment=HTTP_PROXY=http://one.proxy.att.com:8080 HTTPS_PROXY=http://one.proxy.att.com:8080 NO_PROXY=127.0.0.1,localhost,135.16.101.87,135.16.101.86,135.16.101.85,135.16.101.84,135.16.101.83,135.16.101.82,135.16.101.81,135.16.101.80,kubernetes
ExecStartPre=echo 4 >/sys/class/net/ens3f0/device/sriov_numvfs
ExecStart=/var/tmp/prom_init.sh /etc/prom_init.yaml
[Install]
WantedBy=multi-user.target
"""
prom_init = \
"""!/bin/bash
echo $HTTP_PROXY
echo $NO_PROXY
cat $1
"""

View File

@ -15,6 +15,7 @@ import time
import logging
import traceback
import sys
import uuid
from oslo_config import cfg
@ -1135,6 +1136,25 @@ class MaasTaskRunner(drivers.DriverTaskRunner):
failed = True
continue
# Need to create bootdata keys for all the nodes being deployed
# TODO this should be in the orchestrator
node = site_design.get_baremetal_node(n)
data_key = uuid.uuid4()
self.state_manager.set_bootdata_key(n, design_id, data_key)
node.owner_data['bootdata_key'] = data_key
self.logger.debug("Configured bootdata for node %s" % (n))
# Set owner data in MaaS
try:
self.logger.info("Setting node %s owner data." % n)
for k,v in node.owner_data.items():
self.logger.debug("Set owner data %s = %s for node %s" % (k, v, n))
machine.set_owner_data(k, v)
except Exception as ex:
self.logger.warning("Error setting node %s owner data: %s" % (n, str(ex)))
failed = True
continue
self.logger.info("Deploying node %s" % (n))
try:

View File

@ -23,7 +23,7 @@ class Machine(model_base.ResourceBase):
resource_url = 'machines/{resource_id}/'
fields = ['resource_id', 'hostname', 'power_type', 'power_state', 'power_parameters', 'interfaces',
'boot_interface', 'memory', 'cpu_count', 'tag_names', 'status_name', 'boot_mac']
'boot_interface', 'memory', 'cpu_count', 'tag_names', 'status_name', 'boot_mac', 'owner_data']
json_fields = ['hostname', 'power_type']
def __init__(self, api_client, **kwargs):
@ -95,6 +95,23 @@ class Machine(model_base.ResourceBase):
detail_config = bson.loads(resp.text)
return detail_config
def set_owner_data(self, key, value):
"""
Add/update/remove node owner data. If the machine is not currently allocated to a user
it cannot have owner data
:param key: Key of the owner data
:param value: Value of the owner data. If None, the key is removed
"""
url = self.interpolate_url()
resp = self.api_client.post(url, op='set_owner_data', files={key: value})
if resp.status_code == 200:
detail_config = bson.loads(resp.text)
return detail_config
def to_dict(self):
"""

View File

@ -26,6 +26,7 @@ import drydock_provisioner.objects.network as network
import drydock_provisioner.objects.hwprofile as hwprofile
import drydock_provisioner.objects.node as node
import drydock_provisioner.objects.hostprofile as hostprofile
import drydock_provisioner.objects.promenade as prom
from drydock_provisioner.statemgmt import DesignState
@ -69,6 +70,7 @@ class Ingester(object):
def ingest_data(self, plugin_name='', design_state=None, design_id=None, context=None, **kwargs):
if design_state is None:
self.logger.error("Ingester:ingest_data called without valid DesignState handler")
raise ValueError("Invalid design_state handler")
@ -104,17 +106,12 @@ class Ingester(object):
design_data.add_hardware_profile(m)
elif type(m) is node.BaremetalNode:
design_data.add_baremetal_node(m)
elif type(m) is prom.PromenadeConfig:
design_state.post_promenade_part(m)
design_state.put_design(design_data)
return design_items
else:
self.logger.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)
"""

View File

@ -79,11 +79,12 @@ class YamlIngester(IngesterPlugin):
for d in parsed_data:
kind = d.get('kind', '')
api = d.get('apiVersion', '')
if api.startswith('drydock/'):
(foo, api_version) = api.split('/')
if kind != '':
if kind == 'Region':
api_version = d.get('apiVersion', '')
if api_version == 'v1.0':
if api_version == 'v1':
model = objects.Site()
metadata = d.get('metadata', {})
@ -115,9 +116,7 @@ class YamlIngester(IngesterPlugin):
else:
raise ValueError('Unknown API version %s of Region kind' %s (api_version))
elif kind == 'NetworkLink':
api_version = d.get('apiVersion', '')
if api_version == "v1.0":
if api_version == "v1":
model = objects.NetworkLink()
metadata = d.get('metadata', {})
@ -151,9 +150,7 @@ class YamlIngester(IngesterPlugin):
else:
raise ValueError('Unknown API version of object')
elif kind == 'Network':
api_version = d.get('apiVersion', '')
if api_version == "v1.0":
if api_version == "v1":
model = objects.Network()
metadata = d.get('metadata', {})
@ -190,9 +187,7 @@ class YamlIngester(IngesterPlugin):
})
models.append(model)
elif kind == 'HardwareProfile':
api_version = d.get('apiVersion', '')
if api_version == 'v1.0':
if api_version == 'v1':
metadata = d.get('metadata', {})
spec = d.get('spec', {})
@ -227,9 +222,7 @@ class YamlIngester(IngesterPlugin):
models.append(model)
elif kind == 'HostProfile' or kind == 'BaremetalNode':
api_version = d.get('apiVersion', '')
if api_version == "v1.0":
if api_version == "v1":
model = None
if kind == 'HostProfile':
@ -370,5 +363,14 @@ class YamlIngester(IngesterPlugin):
"Error processing document in %s, no kind field"
% (f))
continue
elif api.startswith('promenade/'):
(foo, api_version) = api.split('/')
if api_version == 'v1':
metadata = d.get('metadata', {})
target = metadata.get('target', 'all')
name = metadata.get('name', None)
model = objects.PromenadeConfig(target=target, name=name, kind=kind, document=yaml.dump(d))
models.append(model)
return models

View File

@ -0,0 +1,45 @@
# 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.
#
from copy import deepcopy
from oslo_versionedobjects import fields as ovo_fields
import drydock_provisioner.objects as objects
import drydock_provisioner.objects.base as base
import drydock_provisioner.objects.fields as hd_fields
@base.DrydockObjectRegistry.register
class PromenadeConfig(base.DrydockPersistentObject, base.DrydockObject):
VERSION = '1.0'
fields = {
'target': ovo_fields.StringField(),
'name': ovo_fields.StringField(nullable=True),
'kind': ovo_fields.StringField(),
'document': ovo_fields.StringField(),
}
def __init__(self, **kwargs):
super(PromenadeConfig, self).__init__(**kwargs)
return
# HardwareProfile keyed on name
def get_id(self):
return self.get_name()
def get_name(self):
return self.name

View File

@ -29,12 +29,18 @@ class DesignState(object):
self.designs = {}
self.designs_lock = Lock()
self.promenade = {}
self.promenade_lock = Lock()
self.builds = []
self.builds_lock = Lock()
self.tasks = []
self.tasks_lock = Lock()
self.bootdata = {}
self.bootdata_lock = Lock()
return
# TODO Need to lock a design base or change once implementation
@ -207,4 +213,34 @@ class DesignState(object):
else:
raise StateError("Could not acquire lock")
def post_promenade_part(self, part):
my_lock = self.promenade_lock.acquire(blocking=True, timeout=10)
if my_lock:
if self.promenade.get(target, None) is not None:
self.promenade[part.target].append(part.obj_to_primitive())
else:
self.promenade[target] = [part.obj_to_primitive()]
self.promenade_lock.release()
return None
else:
raise StateError("Could not acquire lock")
def get_promenade_parts(self, target):
parts = self.promenade.get(target, None)
if parts is not None:
return [p.obj_to_primitive() for p in parts]
else:
return None
def set_bootdata_key(self, hostname, design_id, data_key):
my_lock = self.bootdata_lock.acquire(blocking=True, timeout=10)
if my_lock:
self.bootdata[hostname] = {'design_id': design_id, 'key': data_key}
self.bootdata_lock.release()
return None
else:
raise StateError("Could not acquire lock")
def get_bootdata_key(self, hostname):
return self.bootdata.get(hostname, None)