Source code for ironic.api.controllers.v1.bios

# Copyright 2018 Red Hat 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.

from ironic_lib import metrics_utils
from pecan import rest

from ironic import api
from ironic.api.controllers.v1 import utils as api_utils
from ironic.api import method
from ironic.common import args
from ironic.common import exception
from ironic import objects

METRICS = metrics_utils.get_metrics_logger(__name__)





[docs]def collection_from_list(node_ident, bios_settings): bios_list = [] for bios_setting in bios_settings: bios_list.append(convert_with_links(bios_setting, node_ident)) return {'bios': bios_list}
[docs]class NodeBiosController(rest.RestController): """REST controller for bios.""" def __init__(self, node_ident=None): super(NodeBiosController, self).__init__() self.node_ident = node_ident
[docs] @METRICS.timer('NodeBiosController.get_all') @method.expose() def get_all(self): """List node bios settings.""" node = api_utils.check_node_policy_and_retrieve( 'baremetal:node:bios:get', self.node_ident) settings = objects.BIOSSettingList.get_by_node_id( api.request.context, node.id) return collection_from_list(self.node_ident, settings)
[docs] @METRICS.timer('NodeBiosController.get_one') @method.expose() @args.validate(setting_name=args.name) def get_one(self, setting_name): """Retrieve information about the given bios setting. :param setting_name: Logical name of the setting to retrieve. """ node = api_utils.check_node_policy_and_retrieve( 'baremetal:node:bios:get', self.node_ident) try: setting = objects.BIOSSetting.get(api.request.context, node.id, setting_name) except exception.BIOSSettingNotFound: raise exception.BIOSSettingNotFound(node=node.uuid, name=setting_name) return {setting_name: convert_with_links(setting, node.uuid)}