Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASMCMS-9225: Move BSS client to new paradigm #401

Open
wants to merge 1 commit into
base: casmcms-9225-05-pcs-client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/bos/common/clients/bss/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# MIT License
#
# (C) Copyright 2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
from .client import BSSClient
40 changes: 40 additions & 0 deletions src/bos/common/clients/bss/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# MIT License
#
# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
from abc import ABC
import logging

from bos.common.clients.endpoints import BaseRawEndpoint
from bos.common.utils import PROTOCOL

LOGGER = logging.getLogger(__name__)

SERVICE_NAME = 'cray-bss'
ENDPOINT = f"{PROTOCOL}://{SERVICE_NAME}/boot/v1"


class BaseBssEndpoint(BaseRawEndpoint, ABC):
"""
This base class provides generic access to the BSS API.
"""
BASE_ENDPOINT = ENDPOINT
76 changes: 76 additions & 0 deletions src/bos/common/clients/bss/boot_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# MIT License
#
# (C) Copyright 2021-2022, 2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
import logging

from .base import BaseBssEndpoint

LOGGER = logging.getLogger(__name__)


class BootParametersEndpoint(BaseBssEndpoint):
ENDPOINT = 'bootparameters'

def set_bss(self, node_set, kernel_params, kernel, initrd) -> str:
'''
Tell the Boot Script Service (BSS) which boot artifacts are associated
with each node.

Currently, this is biased towards 'hosts' (i.e. xnames) rather than
NIDS.

Args:
node_set (set): A list of nodes to assign the boot artifacts to
kernel_params (string): Kernel parameters to assign to the node
kernel (string): The kernel to assign to the node
initrd (string): The initrd to assign to the node
session (requests Session instance): An existing session to use

Returns:
The 'bss-referral-token' value from the header of the response from BSS.

Raises:
KeyError -- 'bss-referral-token' not found in header
requests.exceptions.HTTPError -- An HTTP error encountered while
communicating with the
Hardware State Manager
Exception -- called with empty node_set
'''
if not node_set:
# Cannot simply return if no nodes are specified, as this function
# is intended to return the response object from BSS.
# Accordingly, an Exception is raised.
raise Exception("set_bss called with empty node_set")

LOGGER.info("Params: %s", kernel_params)

# Assignment payload
payload = {
"hosts": list(node_set),
"params": kernel_params,
"kernel": kernel,
"initrd": initrd
}

return self.put(json=payload,
verify=False).headers['bss-referral-token']
33 changes: 33 additions & 0 deletions src/bos/common/clients/bss/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# MIT License
#
# (C) Copyright 2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
from bos.common.clients.api_client import APIClient

from .boot_parameters import BootParametersEndpoint


class BSSClient(APIClient):

@property
def boot_parameters(self) -> BootParametersEndpoint:
return self.get_endpoint(BootParametersEndpoint)
5 changes: 3 additions & 2 deletions src/bos/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import time
from typing import Generator, List, NoReturn, Type

from bos.common.clients.bss import BSSClient
from bos.common.clients.pcs import PCSClient
from bos.common.utils import exc_type_msg
from bos.common.values import Status
Expand Down Expand Up @@ -65,7 +66,7 @@ class ApiClients:

def __init__(self):
#self.bos = BOSClient()
#self.bss = BSSClient()
self.bss = BSSClient()
#self.cfs = CFSClient()
#self.hsm = HSMClient()
#self.ims = IMSClient()
Expand All @@ -77,7 +78,7 @@ def __enter__(self):
Enter context for all API clients
"""
#self._stack.enter_context(self.bos)
#self._stack.enter_context(self.bss)
self._stack.enter_context(self.bss)
#self._stack.enter_context(self.cfs)
#self._stack.enter_context(self.hsm)
#self._stack.enter_context(self.ims)
Expand Down
3 changes: 1 addition & 2 deletions src/bos/operators/power_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from bos.common.utils import exc_type_msg, get_image_id_from_kernel, \
using_sbps_check_kernel_parameters, components_by_id
from bos.common.values import Action, Status
from bos.operators.utils.clients import bss
from bos.operators.utils.clients.ims import tag_image
from bos.operators.utils.clients.cfs import set_cfs
from bos.operators.base import BaseOperator, main
Expand Down Expand Up @@ -152,7 +151,7 @@ def _set_bss(self, boot_artifacts, bos_sessions, retries=5):
for key, nodes in boot_artifacts.items():
kernel, kernel_parameters, initrd = key
try:
resp = bss.set_bss(node_set=nodes,
resp = self.client.bss.boot_parameters.set_bss(node_set=nodes,
kernel_params=kernel_parameters,
kernel=kernel,
initrd=initrd)
Expand Down
90 changes: 0 additions & 90 deletions src/bos/operators/utils/clients/bss.py

This file was deleted.

Loading