Initialize 'ServiceSpec' object data from a json structure There are two valid styles for service specs: the "old" style: .. code:: yaml service_type: nfs service_id: foo pool: mypool namespace: myns and th
(cls: Type[ServiceSpecT], json_spec: Dict)
| 1093 | @classmethod |
| 1094 | @handle_type_error |
| 1095 | def from_json(cls: Type[ServiceSpecT], json_spec: Dict) -> ServiceSpecT: |
| 1096 | """ |
| 1097 | Initialize 'ServiceSpec' object data from a json structure |
| 1098 | |
| 1099 | There are two valid styles for service specs: |
| 1100 | |
| 1101 | the "old" style: |
| 1102 | |
| 1103 | .. code:: yaml |
| 1104 | |
| 1105 | service_type: nfs |
| 1106 | service_id: foo |
| 1107 | pool: mypool |
| 1108 | namespace: myns |
| 1109 | |
| 1110 | and the "new" style: |
| 1111 | |
| 1112 | .. code:: yaml |
| 1113 | |
| 1114 | service_type: nfs |
| 1115 | service_id: foo |
| 1116 | config: |
| 1117 | some_option: the_value |
| 1118 | networks: [10.10.0.0/16] |
| 1119 | spec: |
| 1120 | pool: mypool |
| 1121 | namespace: myns |
| 1122 | |
| 1123 | In https://tracker.ceph.com/issues/45321 we decided that we'd like to |
| 1124 | prefer the new style as it is more readable and provides a better |
| 1125 | understanding of what fields are special for a give service type. |
| 1126 | |
| 1127 | Note, we'll need to stay compatible with both versions for the |
| 1128 | the next two major releases (octopus, pacific). |
| 1129 | |
| 1130 | :param json_spec: A valid dict with ServiceSpec |
| 1131 | |
| 1132 | :meta private: |
| 1133 | """ |
| 1134 | if not isinstance(json_spec, dict): |
| 1135 | raise SpecValidationError( |
| 1136 | f'Service Spec is not an (JSON or YAML) object. got "{str(json_spec)}"') |
| 1137 | |
| 1138 | json_spec = cls.normalize_json(json_spec) |
| 1139 | |
| 1140 | c = json_spec.copy() |
| 1141 | |
| 1142 | # kludge to make `from_json` compatible to `Orchestrator.describe_service` |
| 1143 | # Open question: Remove `service_id` form to_json? |
| 1144 | if c.get('service_name', ''): |
| 1145 | service_type_id = c['service_name'].split('.', 1) |
| 1146 | |
| 1147 | if not c.get('service_type', ''): |
| 1148 | c['service_type'] = service_type_id[0] |
| 1149 | if not c.get('service_id', '') and len(service_type_id) > 1: |
| 1150 | c['service_id'] = service_type_id[1] |
| 1151 | del c['service_name'] |
| 1152 |
nothing calls this directly
no test coverage detected