]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/services/orchestrator.py
1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
5 from typing
import List
, Optional
7 from orchestrator
import InventoryFilter
, DeviceLightLoc
, Completion
8 from orchestrator
import ServiceDescription
, DaemonDescription
9 from orchestrator
import OrchestratorClientMixin
, raise_if_exception
, OrchestratorError
10 from orchestrator
import HostSpec
12 from ..tools
import wraps
14 logger
= logging
.getLogger('orchestrator')
17 # pylint: disable=abstract-method
18 class OrchestratorAPI(OrchestratorClientMixin
):
20 super(OrchestratorAPI
, self
).__init
__()
21 self
.set_mgr(mgr
) # type: ignore
25 status
, desc
= super(OrchestratorAPI
, self
).available()
26 logger
.info("is orchestrator available: %s, %s", status
, desc
)
27 return dict(available
=status
, description
=desc
)
28 except (RuntimeError, OrchestratorError
, ImportError):
31 description
='Orchestrator is unavailable for unknown reason')
33 def orchestrator_wait(self
, completions
):
34 return self
._orchestrator
_wait
(completions
)
37 def wait_api_result(method
):
39 def inner(self
, *args
, **kwargs
):
40 completion
= method(self
, *args
, **kwargs
)
41 self
.api
.orchestrator_wait([completion
])
42 raise_if_exception(completion
)
43 return completion
.result
47 class ResourceManager(object):
48 def __init__(self
, api
):
52 class HostManger(ResourceManager
):
54 def list(self
) -> List
[HostSpec
]:
55 return self
.api
.get_hosts()
57 def get(self
, hostname
: str) -> Optional
[HostSpec
]:
58 hosts
= [host
for host
in self
.list() if host
.hostname
== hostname
]
59 return hosts
[0] if hosts
else None
62 def add(self
, hostname
: str):
63 return self
.api
.add_host(HostSpec(hostname
))
66 def remove(self
, hostname
: str):
67 return self
.api
.remove_host(hostname
)
70 def add_label(self
, host
: str, label
: str) -> Completion
:
71 return self
.api
.add_host_label(host
, label
)
74 def remove_label(self
, host
: str, label
: str) -> Completion
:
75 return self
.api
.remove_host_label(host
, label
)
78 class InventoryManager(ResourceManager
):
80 def list(self
, hosts
=None, refresh
=False):
81 host_filter
= InventoryFilter(hosts
=hosts
) if hosts
else None
82 return self
.api
.get_inventory(host_filter
=host_filter
, refresh
=refresh
)
85 class ServiceManager(ResourceManager
):
87 def list(self
, service_name
: Optional
[str] = None) -> List
[ServiceDescription
]:
88 return self
.api
.describe_service(None, service_name
)
91 def get(self
, service_name
: str) -> ServiceDescription
:
92 return self
.api
.describe_service(None, service_name
)
95 def list_daemons(self
,
96 service_name
: Optional
[str] = None,
97 hostname
: Optional
[str] = None) -> List
[DaemonDescription
]:
98 return self
.api
.list_daemons(service_name
, host
=hostname
)
100 def reload(self
, service_type
, service_ids
):
101 if not isinstance(service_ids
, list):
102 service_ids
= [service_ids
]
105 self
.api
.service_action('reload', service_type
, service_name
,
107 for service_name
, service_id
in service_ids
109 self
.api
.orchestrator_wait(completion_list
)
110 for c
in completion_list
:
111 raise_if_exception(c
)
114 class OsdManager(ResourceManager
):
116 def create(self
, drive_group_specs
):
117 return self
.api
.apply_drivegroups(drive_group_specs
)
120 def remove(self
, osd_ids
, replace
=False, force
=False):
121 return self
.api
.remove_osds(osd_ids
, replace
, force
)
124 def removing_status(self
):
125 return self
.api
.remove_osds_status()
128 class OrchClient(object):
134 if cls
._instance
is None:
135 cls
._instance
= cls()
139 self
.api
= OrchestratorAPI()
141 self
.hosts
= HostManger(self
.api
)
142 self
.inventory
= InventoryManager(self
.api
)
143 self
.services
= ServiceManager(self
.api
)
144 self
.osds
= OsdManager(self
.api
)
147 return self
.status()['available']
150 return self
.api
.status()
153 def blink_device_light(self
, hostname
, device
, ident_fault
, on
):
154 # type: (str, str, str, bool) -> Completion
155 return self
.api
.blink_device_light(
156 ident_fault
, on
, [DeviceLightLoc(hostname
, device
, device
)])