
This commit add some changes to deploy show endpoint, the name was changed to just deploy with GET verb and also changes the deploy to be saved as a list of dict to attend the API requirements. Now the api accepts from_release and to_release as optional params, in case it is provided the endpoint will return a dict otherwise will return a list of dict. Test Plan: PASS: Create deploy PASS: Update deploy PASS: Software deploy start PASS: Software deploy show Story: 2010676 Task: 49645 Change-Id: I68d243c05da88c7eecf2d866c7202c3c7be51a2b Signed-off-by: Luis Eduardo Bonatti <LuizEduardo.Bonatti@windriver.com>
114 lines
2.9 KiB
Python
114 lines
2.9 KiB
Python
"""
|
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""
|
|
|
|
import logging
|
|
import threading
|
|
from software.software_entities import DeployHandler
|
|
from software.software_entities import DeployHostHandler
|
|
from software.constants import DEPLOY_STATES
|
|
|
|
LOG = logging.getLogger('main_logger')
|
|
|
|
|
|
def get_instance():
|
|
"""Return a Software API instance."""
|
|
return SoftwareAPI()
|
|
|
|
|
|
class SoftwareAPI:
|
|
_instance = None
|
|
_lock = threading.RLock()
|
|
|
|
def __new__(cls):
|
|
if cls._instance is None:
|
|
cls._instance = super(SoftwareAPI, cls).__new__(cls)
|
|
return cls._instance
|
|
|
|
def __init__(self):
|
|
self.deploy_handler = DeployHandler()
|
|
self.deploy_host_handler = DeployHostHandler()
|
|
|
|
def create_deploy(self, from_release, to_release, reboot_required: bool):
|
|
self.begin_update()
|
|
self.deploy_handler.create(from_release, to_release, reboot_required)
|
|
self.end_update()
|
|
|
|
def get_deploy(self, from_release, to_release):
|
|
self.begin_update()
|
|
try:
|
|
return self.deploy_handler.query(from_release, to_release)
|
|
finally:
|
|
self.end_update()
|
|
|
|
def get_deploy_all(self):
|
|
self.begin_update()
|
|
try:
|
|
return self.deploy_handler.query_all()
|
|
finally:
|
|
self.end_update()
|
|
|
|
def update_deploy(self, state: DEPLOY_STATES):
|
|
self.begin_update()
|
|
try:
|
|
self.deploy_handler.update(state)
|
|
finally:
|
|
self.end_update()
|
|
|
|
def delete_deploy(self):
|
|
self.begin_update()
|
|
try:
|
|
self.deploy_handler.delete()
|
|
finally:
|
|
self.end_update()
|
|
|
|
def create_deploy_host(self, hostname):
|
|
self.begin_update()
|
|
try:
|
|
self.deploy_host_handler.create(hostname)
|
|
finally:
|
|
self.end_update()
|
|
|
|
def get_deploy_host(self):
|
|
self.begin_update()
|
|
try:
|
|
return self.deploy_host_handler.query_all()
|
|
finally:
|
|
self.end_update()
|
|
|
|
def update_deploy_host(self, hostname, state):
|
|
self.begin_update()
|
|
try:
|
|
return self.deploy_host_handler.update(hostname, state)
|
|
finally:
|
|
self.end_update()
|
|
|
|
def delete_deploy_host(self, hostname):
|
|
self.begin_update()
|
|
try:
|
|
self.deploy_host_handler.delete(hostname)
|
|
finally:
|
|
self.end_update()
|
|
|
|
def delete_deploy_host_all(self):
|
|
self.begin_update()
|
|
try:
|
|
self.deploy_host_handler.delete_all()
|
|
finally:
|
|
self.end_update()
|
|
|
|
def begin_update(self):
|
|
tid = threading.get_native_id()
|
|
msg = f"{tid} is to acquire lock."
|
|
LOG.info(msg)
|
|
SoftwareAPI._lock.acquire()
|
|
|
|
def end_update(self):
|
|
SoftwareAPI._lock.release()
|
|
tid = threading.get_native_id()
|
|
msg = f"{tid} released lock."
|
|
LOG.info(msg)
|