From eaa64b9732e393d62fc228d74efb1d7892b5be1d Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Thu, 4 Jun 2020 14:13:14 +0200 Subject: [PATCH] python-common: move HostSpec to python-common Signed-off-by: Sebastian Wagner --- src/pybind/mgr/orchestrator/_interface.py | 57 +---------------- src/python-common/ceph/deployment/hostspec.py | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 56 deletions(-) create mode 100644 src/python-common/ceph/deployment/hostspec.py diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index db520c0f25da2..85f6fa6735ed3 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -21,6 +21,7 @@ from ceph.deployment import inventory from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec, RGWSpec, \ ServiceSpecValidationError, IscsiServiceSpec from ceph.deployment.drive_group import DriveGroupSpec +from ceph.deployment.hostspec import HostSpec from mgr_module import MgrModule, CLICommand, HandleCommandResult @@ -1162,62 +1163,6 @@ class Orchestrator(object): raise NotImplementedError() -class HostSpec(object): - """ - Information about hosts. Like e.g. ``kubectl get nodes`` - """ - def __init__(self, - hostname, # type: str - addr=None, # type: Optional[str] - labels=None, # type: Optional[List[str]] - status=None, # type: Optional[str] - ): - self.service_type = 'host' - - #: the bare hostname on the host. Not the FQDN. - self.hostname = hostname # type: str - - #: DNS name or IP address to reach it - self.addr = addr or hostname # type: str - - #: label(s), if any - self.labels = labels or [] # type: List[str] - - #: human readable status - self.status = status or '' # type: str - - def to_json(self): - return { - 'hostname': self.hostname, - 'addr': self.addr, - 'labels': self.labels, - 'status': self.status, - } - - @classmethod - def from_json(cls, host_spec): - _cls = cls(host_spec['hostname'], - host_spec['addr'] if 'addr' in host_spec else None, - host_spec['labels'] if 'labels' in host_spec else None) - return _cls - - def __repr__(self): - args = [self.hostname] # type: List[Any] - if self.addr is not None: - args.append(self.addr) - if self.labels: - args.append(self.labels) - if self.status: - args.append(self.status) - - return "({})".format(', '.join(map(repr, args))) - - def __eq__(self, other): - # Let's omit `status` for the moment, as it is still the very same host. - return self.hostname == other.hostname and \ - self.addr == other.addr and \ - self.labels == other.labels - GenericSpec = Union[ServiceSpec, HostSpec] def json_to_generic_spec(spec): diff --git a/src/python-common/ceph/deployment/hostspec.py b/src/python-common/ceph/deployment/hostspec.py new file mode 100644 index 0000000000000..a93d8916ffce8 --- /dev/null +++ b/src/python-common/ceph/deployment/hostspec.py @@ -0,0 +1,61 @@ +try: + from typing import Optional, List, Any +except ImportError: + pass # just for type checking + + +class HostSpec(object): + """ + Information about hosts. Like e.g. ``kubectl get nodes`` + """ + def __init__(self, + hostname, # type: str + addr=None, # type: Optional[str] + labels=None, # type: Optional[List[str]] + status=None, # type: Optional[str] + ): + self.service_type = 'host' + + #: the bare hostname on the host. Not the FQDN. + self.hostname = hostname # type: str + + #: DNS name or IP address to reach it + self.addr = addr or hostname # type: str + + #: label(s), if any + self.labels = labels or [] # type: List[str] + + #: human readable status + self.status = status or '' # type: str + + def to_json(self): + return { + 'hostname': self.hostname, + 'addr': self.addr, + 'labels': self.labels, + 'status': self.status, + } + + @classmethod + def from_json(cls, host_spec): + _cls = cls(host_spec['hostname'], + host_spec['addr'] if 'addr' in host_spec else None, + host_spec['labels'] if 'labels' in host_spec else None) + return _cls + + def __repr__(self): + args = [self.hostname] # type: List[Any] + if self.addr is not None: + args.append(self.addr) + if self.labels: + args.append(self.labels) + if self.status: + args.append(self.status) + + return "HostSpec({})".format(', '.join(map(repr, args))) + + def __eq__(self, other): + # Let's omit `status` for the moment, as it is still the very same host. + return self.hostname == other.hostname and \ + self.addr == other.addr and \ + self.labels == other.labels -- 2.39.5