(host_spec: dict)
| 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] |
no test coverage detected