mirror of
https://github.com/ceph/ceph
synced 2025-02-24 11:37:37 +00:00
mgr/orch: HostSpec -> HostPlacementSpec
This object is about describing where to place a service on a host: it includes a host name and either an IP or network and possibly even a name for the service. Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
abc20b6919
commit
778704dd23
@ -30,7 +30,7 @@ from ceph.deployment.drive_selection import selector
|
||||
from mgr_module import MgrModule
|
||||
import mgr_util
|
||||
import orchestrator
|
||||
from orchestrator import OrchestratorError, HostSpec, OrchestratorValidationError
|
||||
from orchestrator import OrchestratorError, HostPlacementSpec, OrchestratorValidationError
|
||||
|
||||
from . import remotes
|
||||
|
||||
@ -2168,7 +2168,7 @@ class BaseScheduler(object):
|
||||
|
||||
* requires a placement_spec
|
||||
|
||||
`place(host_pool)` needs to return a List[HostSpec, ..]
|
||||
`place(host_pool)` needs to return a List[HostPlacementSpec, ..]
|
||||
"""
|
||||
|
||||
def __init__(self, placement_spec):
|
||||
@ -2176,7 +2176,7 @@ class BaseScheduler(object):
|
||||
self.placement_spec = placement_spec
|
||||
|
||||
def place(self, host_pool, count=None):
|
||||
# type: (List, Optional[int]) -> List[HostSpec]
|
||||
# type: (List, Optional[int]) -> List[HostPlacementSpec]
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@ -2190,10 +2190,10 @@ class SimpleScheduler(BaseScheduler):
|
||||
super(SimpleScheduler, self).__init__(placement_spec)
|
||||
|
||||
def place(self, host_pool, count=None):
|
||||
# type: (List, Optional[int]) -> List[HostSpec]
|
||||
# type: (List, Optional[int]) -> List[HostPlacementSpec]
|
||||
if not host_pool:
|
||||
raise Exception('List of host candidates is empty')
|
||||
host_pool = [HostSpec(x, '', '') for x in host_pool]
|
||||
host_pool = [HostPlacementSpec(x, '', '') for x in host_pool]
|
||||
# shuffle for pseudo random selection
|
||||
random.shuffle(host_pool)
|
||||
return host_pool[:count]
|
||||
@ -2241,7 +2241,7 @@ class NodeAssignment(object):
|
||||
# NOTE: This currently queries for all hosts without label restriction
|
||||
if self.spec.placement.label:
|
||||
logger.info("Found labels. Assinging nodes that match the label")
|
||||
candidates = [HostSpec(x[0], '', '') for x in self.get_hosts_func()] # TODO: query for labels
|
||||
candidates = [HostPlacementSpec(x[0], '', '') for x in self.get_hosts_func()] # TODO: query for labels
|
||||
logger.info('Assigning nodes to spec: {}'.format(candidates))
|
||||
self.spec.placement.set_hosts(candidates)
|
||||
|
||||
|
@ -35,7 +35,7 @@ except ImportError:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HostSpec(namedtuple('HostSpec', ['hostname', 'network', 'name'])):
|
||||
class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', 'name'])):
|
||||
def __str__(self):
|
||||
res = ''
|
||||
res += self.hostname
|
||||
@ -46,7 +46,8 @@ class HostSpec(namedtuple('HostSpec', ['hostname', 'network', 'name'])):
|
||||
return res
|
||||
|
||||
|
||||
def parse_host_specs(host, require_network=True):
|
||||
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]'.
|
||||
@ -68,7 +69,7 @@ def parse_host_specs(host, require_network=True):
|
||||
name_re = r'=(.*?)$'
|
||||
|
||||
# assign defaults
|
||||
host_spec = HostSpec('', '', '')
|
||||
host_spec = HostPlacementSpec('', '', '')
|
||||
|
||||
match_host = re.search(host_re, host)
|
||||
if match_host:
|
||||
@ -1045,10 +1046,10 @@ class PlacementSpec(object):
|
||||
# type: (Optional[str], Optional[List], Optional[int]) -> None
|
||||
self.label = label
|
||||
if hosts:
|
||||
if all([isinstance(host, HostSpec) for host in hosts]):
|
||||
self.hosts = hosts # type: List[HostSpec]
|
||||
if all([isinstance(host, HostPlacementSpec) for host in hosts]):
|
||||
self.hosts = hosts # type: List[HostPlacementSpec]
|
||||
else:
|
||||
self.hosts = [parse_host_specs(x, require_network=False) for x in hosts if x]
|
||||
self.hosts = [parse_host_placement_specs(x, require_network=False) for x in hosts if x]
|
||||
else:
|
||||
self.hosts = []
|
||||
|
||||
|
@ -9,7 +9,7 @@ from ceph.deployment import inventory
|
||||
from orchestrator import raise_if_exception, RGWSpec, Completion, ProgressReference
|
||||
from orchestrator import InventoryNode, ServiceDescription
|
||||
from orchestrator import OrchestratorValidationError
|
||||
from orchestrator import parse_host_specs
|
||||
from orchestrator import parse_host_placement_specs
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected, require_network",
|
||||
@ -24,8 +24,8 @@ from orchestrator import parse_host_specs
|
||||
("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', ''), True),
|
||||
("myhost:[v1:10.1.1.10:6789,v2:10.1.1.11:3000]=sname", ('myhost', '[v1:10.1.1.10:6789,v2:10.1.1.11:3000]', 'sname'), True),
|
||||
])
|
||||
def test_parse_host_specs(test_input, expected, require_network):
|
||||
ret = parse_host_specs(test_input, require_network=require_network)
|
||||
def test_parse_host_placement_specs(test_input, expected, require_network):
|
||||
ret = parse_host_placement_specs(test_input, require_network=require_network)
|
||||
assert ret == expected
|
||||
assert str(ret) == test_input
|
||||
|
||||
@ -37,9 +37,9 @@ def test_parse_host_specs(test_input, expected, require_network):
|
||||
# empty string
|
||||
("myhost=1"),
|
||||
])
|
||||
def test_parse_host_specs_raises(test_input):
|
||||
def test_parse_host_placement_specs_raises(test_input):
|
||||
with pytest.raises(ValueError):
|
||||
ret = parse_host_specs(test_input)
|
||||
ret = parse_host_placement_specs(test_input)
|
||||
|
||||
|
||||
def _test_resource(data, resource_class, extra=None):
|
||||
|
Loading…
Reference in New Issue
Block a user