From: Shubha Jain Date: Thu, 8 Jan 2026 08:53:19 +0000 (+0530) Subject: python-common/service_spec: simplify hostname normalization in HostPlacementSpec X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e5824e94430fdb84436aac02a17011380bcebcf5;p=ceph.git python-common/service_spec: simplify hostname normalization in HostPlacementSpec Signed-off-by: Shubha Jain --- diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index 1922c614d251..4b092449bbea 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -112,11 +112,6 @@ class HostPlacementSpec(NamedTuple): network: str name: str - @classmethod - def normalized(cls, hostname: str, network: str = '', name: str = '') -> 'HostPlacementSpec': - """Create a HostPlacementSpec with normalized hostname.""" - return cls(normalize_hostname(hostname), network, name) - def __str__(self) -> str: res = '' res += self.hostname @@ -131,10 +126,9 @@ class HostPlacementSpec(NamedTuple): def from_json(cls, data: Union[dict, str]) -> 'HostPlacementSpec': if isinstance(data, str): return cls.parse(data) - # Use normalized() for consistent lowercasing if isinstance(data, dict): - return cls.normalized( - data.get('hostname', ''), + return cls( + normalize_hostname(data.get('hostname', '')), data.get('network', ''), data.get('name', '') ) @@ -370,16 +364,18 @@ class PlacementSpec(object): def set_hosts(self, hosts: Union[List[str], List[HostPlacementSpec]]) -> None: # To backpopulate the .hosts attribute when using labels or count # in the orchestrator backend. - if all(isinstance(host, HostPlacementSpec) for host in hosts): - # Type narrowing: all items are HostPlacementSpec - placement_hosts = cast(List[HostPlacementSpec], hosts) + if all(isinstance(h, HostPlacementSpec) for h in hosts): + # All items are HostPlacementSpec → normalize directly self.hosts = [ - HostPlacementSpec.normalized(h.hostname, h.network, h.name) - for h in placement_hosts + HostPlacementSpec(normalize_hostname(h.hostname), h.network, h.name) # type: ignore[union-attr] + for h in hosts ] else: - self.hosts = [HostPlacementSpec.parse(x, require_network=False) # type: ignore - for x in hosts if x] + # Otherwise, parse from strings + self.hosts = [ + HostPlacementSpec.parse(h, require_network=False) # type: ignore + for h in hosts if h + ] # deprecated def filter_matching_hosts(self, _get_hosts_func: Callable) -> List[str]: