From f2c54722860bce81c293d3c10b32f774cc449a36 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 24 Jan 2020 13:08:02 +0100 Subject: [PATCH] mgr/orchestrator_cli: rename to mgr/orchestrator * Move `mgr/orchestrator.py` to `orchestrator/_interface.py` Signed-off-by: Sebastian Wagner --- qa/tasks/mgr/test_module_selftest.py | 4 +- qa/tasks/mgr/test_orchestrator_cli.py | 2 +- .../README.md | 0 src/pybind/mgr/orchestrator/__init__.py | 16 ++ .../_interface.py} | 130 +++++----- .../module.py | 238 +++++++++--------- src/pybind/mgr/orchestrator_cli/.gitignore | 0 src/pybind/mgr/orchestrator_cli/__init__.py | 3 - src/pybind/mgr/orchestrator_cli/tox.ini | 14 -- src/pybind/mgr/tox.ini | 3 +- 10 files changed, 205 insertions(+), 205 deletions(-) rename src/pybind/mgr/{orchestrator_cli => orchestrator}/README.md (100%) create mode 100644 src/pybind/mgr/orchestrator/__init__.py rename src/pybind/mgr/{orchestrator.py => orchestrator/_interface.py} (95%) rename src/pybind/mgr/{orchestrator_cli => orchestrator}/module.py (82%) delete mode 100644 src/pybind/mgr/orchestrator_cli/.gitignore delete mode 100644 src/pybind/mgr/orchestrator_cli/__init__.py delete mode 100644 src/pybind/mgr/orchestrator_cli/tox.ini diff --git a/qa/tasks/mgr/test_module_selftest.py b/qa/tasks/mgr/test_module_selftest.py index 966a92a6977..969d31a7dc8 100644 --- a/qa/tasks/mgr/test_module_selftest.py +++ b/qa/tasks/mgr/test_module_selftest.py @@ -79,8 +79,8 @@ class TestModuleSelftest(MgrTestCase): def test_crash(self): self._selftest_plugin("crash") - def test_orchestrator_cli(self): - self._selftest_plugin("orchestrator_cli") + def test_orchestrator(self): + self._selftest_plugin("orchestrator") def test_selftest_config_update(self): diff --git a/qa/tasks/mgr/test_orchestrator_cli.py b/qa/tasks/mgr/test_orchestrator_cli.py index 8faa40eb6d9..4c465a78319 100644 --- a/qa/tasks/mgr/test_orchestrator_cli.py +++ b/qa/tasks/mgr/test_orchestrator_cli.py @@ -35,7 +35,7 @@ class TestOrchestratorCli(MgrTestCase): def setUp(self): super(TestOrchestratorCli, self).setUp() - self._load_module("orchestrator_cli") + self._load_module("orchestrator") self._load_module("test_orchestrator") self._orch_cmd("set", "backend", "test_orchestrator") diff --git a/src/pybind/mgr/orchestrator_cli/README.md b/src/pybind/mgr/orchestrator/README.md similarity index 100% rename from src/pybind/mgr/orchestrator_cli/README.md rename to src/pybind/mgr/orchestrator/README.md diff --git a/src/pybind/mgr/orchestrator/__init__.py b/src/pybind/mgr/orchestrator/__init__.py new file mode 100644 index 00000000000..946ddb05867 --- /dev/null +++ b/src/pybind/mgr/orchestrator/__init__.py @@ -0,0 +1,16 @@ +from __future__ import absolute_import + +from .module import OrchestratorCli + +# usage: E.g. `from orchestrator import StatelessServiceSpec` +from ._interface import \ + Completion, TrivialReadCompletion, raise_if_exception, ProgressReference, pretty_print, _Promise, \ + CLICommand, _cli_write_command, _cli_read_command, \ + Orchestrator, OrchestratorClientMixin, \ + OrchestratorValidationError, OrchestratorError, NoOrchestrator, \ + ServiceSpec, NFSServiceSpec, RGWSpec, HostPlacementSpec, \ + ServiceDescription, InventoryFilter, PlacementSpec, HostSpec, \ + DaemonDescription, \ + InventoryNode, DeviceLightLoc, \ + OutdatableData, OutdatablePersistentDict, \ + UpgradeStatusSpec diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator/_interface.py similarity index 95% rename from src/pybind/mgr/orchestrator.py rename to src/pybind/mgr/orchestrator/_interface.py index 18dc0a1da93..576b21dec8e 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -46,71 +46,71 @@ class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', res += '=' + self.name return res + @classmethod + def parse(cls, host, require_network=True): + # type: (str, bool) -> HostPlacementSpec + """ + Split host into host, network, and (optional) daemon name parts. The network + part can be an IP, CIDR, or ceph addrvec like '[v2:1.2.3.4:3300,v1:1.2.3.4:6789]'. + e.g., + "myhost" + "myhost=name" + "myhost:1.2.3.4" + "myhost:1.2.3.4=name" + "myhost:1.2.3.0/24" + "myhost:1.2.3.0/24=name" + "myhost:[v2:1.2.3.4:3000]=name" + "myhost:[v2:1.2.3.4:3000,v1:1.2.3.4:6789]=name" + """ + # Matches from start to : or = or until end of string + host_re = r'^(.*?)(:|=|$)' + # Matches from : to = or until end of string + ip_re = r':(.*?)(=|$)' + # Matches from = to end of string + name_re = r'=(.*?)$' + + # assign defaults + host_spec = cls('', '', '') + + match_host = re.search(host_re, host) + if match_host: + host_spec = host_spec._replace(hostname=match_host.group(1)) + + name_match = re.search(name_re, host) + if name_match: + host_spec = host_spec._replace(name=name_match.group(1)) + + ip_match = re.search(ip_re, host) + if ip_match: + host_spec = host_spec._replace(network=ip_match.group(1)) + + if not require_network: + return host_spec + + from ipaddress import ip_network, ip_address + networks = list() # type: List[str] + network = host_spec.network + # in case we have [v2:1.2.3.4:3000,v1:1.2.3.4:6478] + if ',' in network: + networks = [x for x in network.split(',')] + else: + networks.append(network) + for network in networks: + # only if we have versioned network configs + if network.startswith('v') or network.startswith('[v'): + network = network.split(':')[1] + try: + # if subnets are defined, also verify the validity + if '/' in network: + ip_network(six.text_type(network)) + else: + ip_address(six.text_type(network)) + except ValueError as e: + # logging? + raise e -def parse_host_placement_specs(host, require_network=True): - # type: (str, Optional[bool]) -> HostPlacementSpec - """ - Split host into host, network, and (optional) daemon name parts. The network - part can be an IP, CIDR, or ceph addrvec like '[v2:1.2.3.4:3300,v1:1.2.3.4:6789]'. - e.g., - "myhost" - "myhost=name" - "myhost:1.2.3.4" - "myhost:1.2.3.4=name" - "myhost:1.2.3.0/24" - "myhost:1.2.3.0/24=name" - "myhost:[v2:1.2.3.4:3000]=name" - "myhost:[v2:1.2.3.4:3000,v1:1.2.3.4:6789]=name" - """ - # Matches from start to : or = or until end of string - host_re = r'^(.*?)(:|=|$)' - # Matches from : to = or until end of string - ip_re = r':(.*?)(=|$)' - # Matches from = to end of string - name_re = r'=(.*?)$' - - # assign defaults - host_spec = HostPlacementSpec('', '', '') - - match_host = re.search(host_re, host) - if match_host: - host_spec = host_spec._replace(hostname=match_host.group(1)) - - name_match = re.search(name_re, host) - if name_match: - host_spec = host_spec._replace(name=name_match.group(1)) - - ip_match = re.search(ip_re, host) - if ip_match: - host_spec = host_spec._replace(network=ip_match.group(1)) - - if not require_network: return host_spec - from ipaddress import ip_network, ip_address - networks = list() # type: List[str] - network = host_spec.network - # in case we have [v2:1.2.3.4:3000,v1:1.2.3.4:6478] - if ',' in network: - networks = [x for x in network.split(',')] - else: - networks.append(network) - for network in networks: - # only if we have versioned network configs - if network.startswith('v') or network.startswith('[v'): - network = network.split(':')[1] - try: - # if subnets are defined, also verify the validity - if '/' in network: - ip_network(six.text_type(network)) - else: - ip_address(six.text_type(network)) - except ValueError as e: - # logging? - raise e - - return host_spec - class OrchestratorError(Exception): """ @@ -1593,14 +1593,14 @@ class OrchestratorClientMixin(Orchestrator): :raises RuntimeError: If the remote method failed. :raises OrchestratorError: orchestrator failed to perform - :raises ImportError: no `orchestrator_cli` module or backend not found. + :raises ImportError: no `orchestrator` module or backend not found. """ mgr = self.__get_mgr() try: o = mgr._select_orchestrator() except AttributeError: - o = mgr.remote('orchestrator_cli', '_select_orchestrator') + o = mgr.remote('orchestrator', '_select_orchestrator') if o is None: raise NoOrchestrator() @@ -1619,7 +1619,7 @@ class OrchestratorClientMixin(Orchestrator): :param completions: List of Completions :raises NoOrchestrator: :raises RuntimeError: something went wrong while calling the process method. - :raises ImportError: no `orchestrator_cli` module or backend not found. + :raises ImportError: no `orchestrator` module or backend not found. """ while any(not c.has_result for c in completions): self.process(completions) diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator/module.py similarity index 82% rename from src/pybind/mgr/orchestrator_cli/module.py rename to src/pybind/mgr/orchestrator/module.py index 204a6638b98..277743fb7a0 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -2,7 +2,6 @@ import datetime import errno import json import yaml -from functools import wraps from ceph.deployment.inventory import Device from prettytable import PrettyTable @@ -15,14 +14,17 @@ except ImportError: pass # just for type checking. -from ceph.deployment.drive_group import DriveGroupSpec, DriveGroupValidationError, \ - DeviceSelection, DriveGroupSpecs -from mgr_module import MgrModule, CLICommand, HandleCommandResult +from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection, \ + DriveGroupSpecs +from mgr_module import MgrModule, HandleCommandResult -import orchestrator +from ._interface import OrchestratorClientMixin, DeviceLightLoc, _cli_read_command, \ + raise_if_exception, _cli_write_command, TrivialReadCompletion, OrchestratorError, \ + NoOrchestrator, ServiceSpec, PlacementSpec, OrchestratorValidationError, NFSServiceSpec, \ + RGWSpec, InventoryFilter, InventoryNode, HostPlacementSpec, HostSpec -class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): +class OrchestratorCli(OrchestratorClientMixin, MgrModule): MODULE_OPTIONS = [ { 'name': 'orchestrator', @@ -77,11 +79,11 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): self.set_health_checks(h) def _get_device_locations(self, dev_id): - # type: (str) -> List[orchestrator.DeviceLightLoc] + # type: (str) -> List[DeviceLightLoc] locs = [d['location'] for d in self.get('devices')['devices'] if d['devid'] == dev_id] - return [orchestrator.DeviceLightLoc(**l) for l in sum(locs, [])] + return [DeviceLightLoc(**l) for l in sum(locs, [])] - @orchestrator._cli_read_command( + @_cli_read_command( prefix='device ls-lights', desc='List currently active device indicator lights') def _device_ls(self): @@ -135,7 +137,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): self._refresh_health() raise - @orchestrator._cli_write_command( + @_cli_write_command( prefix='device light', cmd_args='name=enable,type=CephChoices,strings=on|off ' 'name=devid,type=CephString ' @@ -155,30 +157,30 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): def _select_orchestrator(self): return self.get_module_option("orchestrator") - @orchestrator._cli_write_command( + @_cli_write_command( 'orch host add', 'name=host,type=CephString,req=true ' 'name=addr,type=CephString,req=false ' 'name=labels,type=CephString,n=N,req=false', 'Add a host') def _add_host(self, host, addr=None, labels=None): - s = orchestrator.HostSpec(hostname=host, addr=addr, labels=labels) + s = HostSpec(hostname=host, addr=addr, labels=labels) completion = self.add_host(s) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch host rm', "name=host,type=CephString,req=true", 'Remove a host') def _remove_host(self, host): completion = self.remove_host(host) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch host set-addr', 'name=host,type=CephString ' 'name=addr,type=CephString', @@ -186,17 +188,17 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): def _update_set_addr(self, host, addr): completion = self.update_host_addr(host, addr) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_read_command( + @_cli_read_command( 'orch host ls', 'name=format,type=CephChoices,strings=json|plain,req=false', 'List hosts') def _get_hosts(self, format='plain'): completion = self.get_hosts() self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) if format == 'json': hosts = [dict(host=node.name, labels=node.labels) for node in completion.result] @@ -213,7 +215,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): output = table.get_string() return HandleCommandResult(stdout=output) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch host label add', 'name=host,type=CephString ' 'name=label,type=CephString', @@ -221,10 +223,10 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): def _host_label_add(self, host, label): completion = self.add_host_label(host, label) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch host label rm', 'name=host,type=CephString ' 'name=label,type=CephString', @@ -232,10 +234,10 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): def _host_label_rm(self, host, label): completion = self.remove_host_label(host, label) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_read_command( + @_cli_read_command( 'orch device ls', "name=host,type=CephString,n=N,req=false " "name=format,type=CephChoices,strings=json|plain,req=false " @@ -250,12 +252,12 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): date hardware inventory is fine as long as hardware ultimately appears in the output of this command. """ - nf = orchestrator.InventoryFilter(nodes=host) if host else None + nf = InventoryFilter(nodes=host) if host else None completion = self.get_inventory(node_filter=nf, refresh=refresh) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) if format == 'json': data = [n.to_json() for n in completion.result] @@ -271,7 +273,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): table._align['SIZE'] = 'r' table.left_padding_width = 0 table.right_padding_width = 1 - for host_ in completion.result: # type: orchestrator.InventoryNode + for host_ in completion.result: # type: InventoryNode for d in host_.devices.devices: # type: Device table.add_row( ( @@ -287,7 +289,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): out.append(table.get_string()) return HandleCommandResult(stdout='\n'.join(out)) - @orchestrator._cli_read_command( + @_cli_read_command( 'orch ps', "name=host,type=CephString,req=false " "name=daemon_type,type=CephChoices,strings=mon|mgr|osd|mds|iscsi|nfs|rgw|rbd-mirror,req=false " @@ -301,7 +303,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): host=host, refresh=refresh) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) daemons = completion.result def ukn(s): @@ -347,7 +349,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule): return HandleCommandResult(stdout=table.get_string()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch osd create', "name=svc_arg,type=CephString,req=false", 'Create an OSD service. Either --svc_arg=host:drives or -i ') @@ -384,10 +386,10 @@ Usage: completion = self.create_osds(drive_groups) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add mon', "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false " @@ -396,60 +398,60 @@ Usage: def _daemon_add_mon(self, num=None, hosts=[], label=None): if not num and not hosts and not label: # Improve Error message. Point to parse_host_spec examples - raise orchestrator.OrchestratorValidationError("Mons need a placement spec. (num, host, network, name(opt))") - placement = orchestrator.PlacementSpec(label=label, count=num, hosts=hosts) + raise OrchestratorValidationError("Mons need a placement spec. (num, host, network, name(opt))") + placement = PlacementSpec(label=label, count=num, hosts=hosts) placement.validate() - spec = orchestrator.ServiceSpec(placement=placement) + spec = ServiceSpec(placement=placement) completion = self.add_mon(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add mgr', "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false", 'Start rbd-mirror daemon(s)') def _daemon_add_mgr(self, num=None, hosts=None): - spec = orchestrator.ServiceSpec( - placement=orchestrator.PlacementSpec(hosts=hosts, count=num)) + spec = ServiceSpec( + placement=PlacementSpec(hosts=hosts, count=num)) completion = self.add_mgr(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add rbd-mirror', "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false", 'Start rbd-mirror daemon(s)') def _rbd_mirror_add(self, num=None, hosts=None): - spec = orchestrator.ServiceSpec( + spec = ServiceSpec( None, - placement=orchestrator.PlacementSpec(hosts=hosts, count=num)) + placement=PlacementSpec(hosts=hosts, count=num)) completion = self.add_rbd_mirror(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add mds', "name=fs_name,type=CephString " "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false", 'Start MDS daemon(s)') def _mds_add(self, fs_name, num=None, hosts=None): - spec = orchestrator.ServiceSpec( + spec = ServiceSpec( fs_name, - placement=orchestrator.PlacementSpec(hosts=hosts, count=num)) + placement=PlacementSpec(hosts=hosts, count=num)) completion = self.add_mds(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add rgw', 'name=realm_name,type=CephString ' 'name=zone_name,type=CephString ' @@ -464,21 +466,21 @@ Usage: """ if inbuf: try: - rgw_spec = orchestrator.RGWSpec.from_json(json.loads(inbuf)) + rgw_spec = RGWSpec.from_json(json.loads(inbuf)) except ValueError as e: msg = 'Failed to read JSON input: {}'.format(str(e)) + usage return HandleCommandResult(-errno.EINVAL, stderr=msg) - rgw_spec = orchestrator.RGWSpec( + rgw_spec = RGWSpec( rgw_realm=realm_name, rgw_zone=zone_name, - placement=orchestrator.PlacementSpec(hosts=hosts, count=num)) + placement=PlacementSpec(hosts=hosts, count=num)) completion = self.add_rgw(rgw_spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add nfs', "name=svc_arg,type=CephString " "name=pool,type=CephString " @@ -488,19 +490,19 @@ Usage: 'name=label,type=CephString,req=false', 'Start NFS daemon(s)') def _nfs_add(self, svc_arg, pool, namespace=None, num=None, label=None, hosts=[]): - spec = orchestrator.NFSServiceSpec( + spec = NFSServiceSpec( svc_arg, pool=pool, namespace=namespace, - placement=orchestrator.PlacementSpec(label=label, hosts=hosts, count=num), + placement=PlacementSpec(label=label, hosts=hosts, count=num), ) spec.validate_add() completion = self.add_nfs(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon add prometheus', 'name=num,type=CephInt,req=false ' 'name=hosts,type=CephString,n=N,req=false ' @@ -508,14 +510,14 @@ Usage: 'Add prometheus daemon(s)') def _daemon_add_prometheus(self, num=None, label=None, hosts=[]): # type: (Optional[int], Optional[str], List[str]) -> HandleCommandResult - spec = orchestrator.ServiceSpec( - placement=orchestrator.PlacementSpec(label=label, hosts=hosts, count=num), + spec = ServiceSpec( + placement=PlacementSpec(label=label, hosts=hosts, count=num), ) completion = self.add_prometheus(spec) self._orchestrator_wait([completion]) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch', "name=action,type=CephChoices,strings=start|stop|restart|redeploy|reconfig " "name=svc_name,type=CephString", @@ -528,24 +530,24 @@ Usage: service_id = None completion = self.service_action(action, service_type, service_id) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon', "name=action,type=CephChoices,strings=start|stop|restart|redeploy|reconfig " "name=name,type=CephString", 'Start, stop, restart, redeploy, or reconfig a specific daemon') def _daemon_action(self, action, name): if '.' not in name: - raise orchestrator.OrchestratorError('%s is not a valid daemon name' % name) + raise OrchestratorError('%s is not a valid daemon name' % name) (daemon_type, daemon_id) = name.split('.', 1) completion = self.daemon_action(action, daemon_type, daemon_id) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch daemon rm', "name=names,type=CephString,n=N " 'name=force,type=CephBool,req=false', @@ -553,13 +555,13 @@ Usage: def _daemon_rm(self, names, force=False): for name in names: if '.' not in name: - raise orchestrator.OrchestratorError('%s is not a valid daemon name' % name) + raise OrchestratorError('%s is not a valid daemon name' % name) completion = self.remove_daemons(names, force) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch rm', "name=name,type=CephString", 'Remove a service') @@ -570,31 +572,31 @@ Usage: service_type = name; service_name = None if name in ['mon', 'mgr']: - raise orchestrator.OrchestratorError('The mon and mgr services cannot be removed') + raise OrchestratorError('The mon and mgr services cannot be removed') completion = self.remove_service(service_type, service_name) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply mgr', "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false " "name=label,type=CephString,req=false", 'Update the size or placement of managers') def _apply_mgr(self, num=None, hosts=[], label=None): - placement = orchestrator.PlacementSpec( + placement = PlacementSpec( label=label, count=num, hosts=hosts) placement.validate() - spec = orchestrator.ServiceSpec(placement=placement) + spec = ServiceSpec(placement=placement) completion = self.apply_mgr(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply mon', "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false " @@ -603,18 +605,18 @@ Usage: def _apply_mon(self, num=None, hosts=[], label=None): if not num and not hosts and not label: # Improve Error message. Point to parse_host_spec examples - raise orchestrator.OrchestratorValidationError("Mons need a placement spec. (num, host, network, name(opt))") - placement = orchestrator.PlacementSpec(label=label, count=num, hosts=hosts) + raise OrchestratorValidationError("Mons need a placement spec. (num, host, network, name(opt))") + placement = PlacementSpec(label=label, count=num, hosts=hosts) placement.validate() - spec = orchestrator.ServiceSpec(placement=placement) + spec = ServiceSpec(placement=placement) completion = self.apply_mon(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply mds', "name=fs_name,type=CephString " "name=num,type=CephInt,req=false " @@ -622,33 +624,33 @@ Usage: "name=label,type=CephString,req=false", 'Update the number of MDS instances for the given fs_name') def _apply_mds(self, fs_name, num=None, label=None, hosts=[]): - placement = orchestrator.PlacementSpec(label=label, count=num, hosts=hosts) + placement = PlacementSpec(label=label, count=num, hosts=hosts) placement.validate() - spec = orchestrator.ServiceSpec( + spec = ServiceSpec( fs_name, placement=placement) completion = self.apply_mds(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply rbd-mirror', "name=num,type=CephInt,req=false " "name=hosts,type=CephString,n=N,req=false " "name=label,type=CephString,req=false", 'Update the number of rbd-mirror instances') def _apply_rbd_mirror(self, num, label=None, hosts=[]): - spec = orchestrator.ServiceSpec( - placement=orchestrator.PlacementSpec(hosts=hosts, count=num, label=label)) + spec = ServiceSpec( + placement=PlacementSpec(hosts=hosts, count=num, label=label)) completion = self.apply_rbd_mirror(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply rgw', 'name=realm_name,type=CephString ' 'name=zone_name,type=CephString ' @@ -657,16 +659,16 @@ Usage: 'name=label,type=CephString,req=false', 'Update the number of RGW instances for the given zone') def _apply_rgw(self, zone_name, realm_name, num=None, label=None, hosts=[]): - spec = orchestrator.RGWSpec( + spec = RGWSpec( rgw_realm=realm_name, rgw_zone=zone_name, - placement=orchestrator.PlacementSpec(hosts=hosts, label=label, count=num)) + placement=PlacementSpec(hosts=hosts, label=label, count=num)) completion = self.apply_rgw(spec) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply nfs', "name=svc_id,type=CephString " 'name=num,type=CephInt,req=false ' @@ -675,15 +677,15 @@ Usage: 'Scale an NFS service') def _apply_nfs(self, svc_id, num=None, label=None, hosts=[]): # type: (str, Optional[int], Optional[str], List[str]) -> HandleCommandResult - spec = orchestrator.NFSServiceSpec( + spec = NFSServiceSpec( svc_id, - placement=orchestrator.PlacementSpec(label=label, hosts=hosts, count=num), + placement=PlacementSpec(label=label, hosts=hosts, count=num), ) completion = self.apply_nfs(spec) self._orchestrator_wait([completion]) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch apply prometheus', 'name=num,type=CephInt,req=false ' 'name=hosts,type=CephString,n=N,req=false ' @@ -691,14 +693,14 @@ Usage: 'Scale prometheus service') def _apply_prometheus(self, num=None, label=None, hosts=[]): # type: (Optional[int], Optional[str], List[str]) -> HandleCommandResult - spec = orchestrator.ServiceSpec( - placement=orchestrator.PlacementSpec(label=label, hosts=hosts, count=num), + spec = ServiceSpec( + placement=PlacementSpec(label=label, hosts=hosts, count=num), ) completion = self.apply_prometheus(spec) self._orchestrator_wait([completion]) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch set backend', "name=module_name,type=CephString,req=true", 'Select orchestrator module backend') @@ -747,7 +749,7 @@ Usage: return HandleCommandResult(-errno.EINVAL, stderr="Module '{0}' not found".format(module_name)) - @orchestrator._cli_write_command( + @_cli_write_command( 'orch cancel', desc='cancels ongoing operations') def _cancel(self): @@ -757,13 +759,13 @@ Usage: self.cancel_completions() return HandleCommandResult() - @orchestrator._cli_read_command( + @_cli_read_command( 'orch status', desc='Report configured backend and its status') def _status(self): o = self._select_orchestrator() if o is None: - raise orchestrator.NoOrchestrator() + raise NoOrchestrator() avail, why = self.available() if avail is None: @@ -783,22 +785,22 @@ Usage: e1 = self.remote('selftest', 'remote_from_orchestrator_cli_self_test', "ZeroDivisionError") try: - orchestrator.raise_if_exception(e1) + raise_if_exception(e1) assert False except ZeroDivisionError as e: assert e.args == ('hello', 'world') e2 = self.remote('selftest', 'remote_from_orchestrator_cli_self_test', "OrchestratorError") try: - orchestrator.raise_if_exception(e2) + raise_if_exception(e2) assert False - except orchestrator.OrchestratorError as e: + except OrchestratorError as e: assert e.args == ('hello', 'world') - c = orchestrator.TrivialReadCompletion(result=True) + c = TrivialReadCompletion(result=True) assert c.has_result - @orchestrator._cli_write_command( + @_cli_write_command( 'upgrade check', 'name=image,type=CephString,req=false ' 'name=ceph_version,type=CephString,req=false', @@ -806,16 +808,16 @@ Usage: def _upgrade_check(self, image=None, ceph_version=None): completion = self.upgrade_check(image=image, version=ceph_version) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'upgrade status', desc='Check service versions vs available and target containers') def _upgrade_status(self): completion = self.upgrade_status() self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) r = { 'target_image': completion.result.target_image, 'in_progress': completion.result.in_progress, @@ -825,7 +827,7 @@ Usage: out = json.dumps(r, indent=4) return HandleCommandResult(stdout=out) - @orchestrator._cli_write_command( + @_cli_write_command( 'upgrade start', 'name=image,type=CephString,req=false ' 'name=ceph_version,type=CephString,req=false', @@ -833,32 +835,32 @@ Usage: def _upgrade_start(self, image=None, ceph_version=None): completion = self.upgrade_start(image, ceph_version) self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'upgrade pause', desc='Pause an in-progress upgrade') def _upgrade_pause(self): completion = self.upgrade_pause() self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'upgrade resume', desc='Resume paused upgrade') def _upgrade_resume(self): completion = self.upgrade_resume() self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) - @orchestrator._cli_write_command( + @_cli_write_command( 'upgrade stop', desc='Stop an in-progress upgrade') def _upgrade_stop(self): completion = self.upgrade_stop() self._orchestrator_wait([completion]) - orchestrator.raise_if_exception(completion) + raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) diff --git a/src/pybind/mgr/orchestrator_cli/.gitignore b/src/pybind/mgr/orchestrator_cli/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/pybind/mgr/orchestrator_cli/__init__.py b/src/pybind/mgr/orchestrator_cli/__init__.py deleted file mode 100644 index ef27d74a379..00000000000 --- a/src/pybind/mgr/orchestrator_cli/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from __future__ import absolute_import - -from .module import OrchestratorCli diff --git a/src/pybind/mgr/orchestrator_cli/tox.ini b/src/pybind/mgr/orchestrator_cli/tox.ini deleted file mode 100644 index 60a6902c5f2..00000000000 --- a/src/pybind/mgr/orchestrator_cli/tox.ini +++ /dev/null @@ -1,14 +0,0 @@ -[tox] -envlist = py3 -skipsdist = true -toxworkdir = {env:CEPH_BUILD_DIR}/orchestrator_cli -minversion = 2.5 - -[testenv] -deps = -rrequirements.txt -setenv= - UNITTEST = true - py3: PYTHONPATH = {toxinidir}/../../../../build/lib/cython_modules/lib.3 - -commands= - {envbindir}/py.test . diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index d9ea1ef5fd0..d0c2fdf597a 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -16,8 +16,7 @@ commands = mypy --config-file=../../mypy.ini \ cephadm/module.py \ mgr_module.py \ mgr_util.py \ - orchestrator.py \ - orchestrator_cli/module.py \ + orchestrator/__init__.py \ progress/module.py \ rook/module.py \ test_orchestrator/module.py -- 2.39.5