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

Method to_host_pattern

src/python-common/ceph/deployment/service_spec.py:252–278  ·  view source on GitHub ↗
(cls, arg: HostPatternType)

Source from the content-addressed store, hash-verified

250
251 @classmethod
252 def to_host_pattern(cls, arg: HostPatternType) -> "HostPattern":
253 if arg is None:
254 return cls()
255 elif isinstance(arg, str):
256 return cls(arg)
257 elif isinstance(arg, cls):
258 return arg
259 elif isinstance(arg, dict):
260 if 'pattern' not in arg:
261 raise SpecValidationError("Got dict for host pattern "
262 f"with no pattern field: {arg}")
263 pattern = arg['pattern']
264 if not pattern:
265 raise SpecValidationError("Got dict for host pattern"
266 f"with empty pattern: {arg}")
267 assert isinstance(pattern, str)
268 if 'pattern_type' in arg:
269 pattern_type = arg['pattern_type']
270 if not pattern_type or pattern_type == 'fnmatch':
271 return cls(pattern, pattern_type=PatternType.fnmatch)
272 elif pattern_type == 'regex':
273 return cls(pattern, pattern_type=PatternType.regex)
274 else:
275 raise SpecValidationError("Got dict for host pattern "
276 f"with unknown pattern type: {arg}")
277 return cls(pattern)
278 raise SpecValidationError(f"Cannot convert {type(arg)} object to HostPattern")
279
280 def __eq__(self, other: Any) -> bool:
281 try:

Callers 3

__eq__Method · 0.95
from_jsonMethod · 0.95
__init__Method · 0.80

Calls 2

SpecValidationErrorClass · 0.90
typeEnum · 0.50

Tested by

no test coverage detected