os-faults/os_faults/api/container.py
Takashi Kajinami dff77df8fc Adapt to recent dependencies
This covers the following updates to fix CI currently broken.

* Fix compatibility with tox 4
* Update hacking to 6.1.0
* Clean up python 2 support and bump minimum supported version to 3.8
* Remove six because python 2 support is removed
* Update job template to use the recent tested python versions
* Replace items by prefixItems to fix schema error
* Build documentation by sphinx command
* Remove "Change Log" section from documentation
* Split requirements for documentation build
* Ensure tox is installed in functional tests
* Fix devstack job

Change-Id: I3b9c5b20aca55332c721d34fd4c41c5b886f60c5
2024-11-27 19:35:39 +01:00

72 lines
2.1 KiB
Python

# 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 abc
from os_faults.api import base_driver
from os_faults.api.utils import public
class Container(base_driver.BaseDriver, metaclass=abc.ABCMeta):
def __init__(self, container_name, config, node_cls, cloud_management,
hosts=None):
self.container_name = container_name
self.config = config
self.node_cls = node_cls
self.cloud_management = cloud_management
self.hosts = hosts
@abc.abstractmethod
def discover_nodes(self):
"""Discover nodes where this Container is running
:returns: NodesCollection
"""
def get_nodes(self):
"""Get nodes where this Container is running
:returns: NodesCollection
"""
if self.hosts is not None:
nodes = self.cloud_management.get_nodes()
hosts = [h for h in nodes.hosts if h.ip in self.hosts]
return self.node_cls(cloud_management=self.cloud_management,
hosts=hosts)
return self.discover_nodes()
@public
def start(self, nodes=None):
"""Start Container on all nodes or on particular subset
:param nodes: NodesCollection
"""
raise NotImplementedError
@public
def terminate(self, nodes=None):
"""Terminate Container gracefully on all nodes or on particular subset
:param nodes: NodesCollection
"""
raise NotImplementedError
@public
def restart(self, nodes=None):
"""Restart Container on all nodes or on particular subset
:param nodes: NodesCollection
"""
raise NotImplementedError