afbfc10a5b
Remove non-applicable license notice from open source python files and update WR Copyright notice year. Closes-Bug: 1954317 Signed-off-by: BoYuan Chang <boyuan.chang@windriver.com> Change-Id: I519f7ea60a54e105e1e49afa5d888bdf40d69f86
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
# Copyright 2016 Ericsson AB
|
|
# Copyright (c) 2020-2021 Wind River Systems, Inc.
|
|
# 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 barbicanclient import client
|
|
|
|
from oslo_log import log
|
|
|
|
from dccommon import consts as dccommon_consts
|
|
from dccommon.drivers import base
|
|
from dccommon import exceptions
|
|
|
|
|
|
LOG = log.getLogger(__name__)
|
|
API_VERSION = 'v1'
|
|
|
|
|
|
class BarbicanClient(base.DriverBase):
|
|
"""Barbican driver.
|
|
|
|
The session needs to be associated with synchronized 'services' project
|
|
in order for the client to get the host bmc password.
|
|
"""
|
|
|
|
def __init__(
|
|
self, region, session, endpoint_type=dccommon_consts.KS_ENDPOINT_DEFAULT):
|
|
|
|
try:
|
|
self.barbican_client = client.Client(
|
|
API_VERSION,
|
|
session=session,
|
|
region_name=region,
|
|
interface=endpoint_type)
|
|
|
|
self.region_name = region
|
|
except exceptions.ServiceUnavailable:
|
|
raise
|
|
|
|
def get_host_bmc_password(self, host_uuid):
|
|
"""Get the Board Management Controller password corresponding to the host
|
|
|
|
:param host_uuid The host uuid
|
|
"""
|
|
|
|
secrets = self.barbican_client.secrets.list()
|
|
for secret in secrets:
|
|
if secret.name == host_uuid:
|
|
secret_ref = secret.secret_ref
|
|
break
|
|
else:
|
|
return
|
|
|
|
secret = self.barbican_client.secrets.get(secret_ref)
|
|
|
|
bmc_password = secret.payload
|
|
|
|
return bmc_password
|