MCPcopy Create free account
hub / github.com/ceph/ceph / normalize_json

Method normalize_json

src/python-common/ceph/deployment/hostspec.py:113–139  ·  view source on GitHub ↗
(host_spec: dict)

Source from the content-addressed store, hash-verified

111
112 @staticmethod
113 def normalize_json(host_spec: dict) -> dict:
114 if 'hostname' in host_spec:
115 host_spec['hostname'] = normalize_hostname(host_spec['hostname'])
116 labels = host_spec.get('labels')
117 if labels is not None:
118 if isinstance(labels, str):
119 host_spec['labels'] = [labels]
120 elif (
121 not isinstance(labels, list)
122 or any(not isinstance(v, str) for v in labels)
123 ):
124 raise SpecValidationError(
125 f'Labels ({labels}) must be a string or list of strings'
126 )
127
128 loc = host_spec.get('location')
129 if loc is not None:
130 if (
131 not isinstance(loc, dict)
132 or any(not isinstance(k, str) for k in loc.keys())
133 or any(not isinstance(v, str) for v in loc.values())
134 ):
135 raise SpecValidationError(
136 f'Location ({loc}) must be a dictionary of strings to strings'
137 )
138
139 return host_spec
140
141 def __repr__(self) -> str:
142 args = [self.hostname] # type: List[Any]

Callers 1

from_jsonMethod · 0.45

Calls 6

normalize_hostnameFunction · 0.85
anyClass · 0.85
SpecValidationErrorClass · 0.85
getMethod · 0.45
keysMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected