any2tosca 0.1.0__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- any2tosca-1.0.0/PKG-INFO +486 -0
- any2tosca-1.0.0/README.md +453 -0
- any2tosca-1.0.0/any2tosca/__init__.py +28 -0
- any2tosca-1.0.0/any2tosca/cli.py +464 -0
- any2tosca-1.0.0/any2tosca/companions.py +144 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca/converter.py +211 -32
- any2tosca-1.0.0/any2tosca/formats.py +160 -0
- any2tosca-1.0.0/any2tosca/kubernetes.py +99 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca/openapi.py +18 -6
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca/redfish.py +2 -7
- any2tosca-1.0.0/any2tosca/rules/kubernetes.yaml +47 -0
- any2tosca-1.0.0/any2tosca/split.py +461 -0
- any2tosca-1.0.0/any2tosca.egg-info/PKG-INFO +486 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca.egg-info/SOURCES.txt +8 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/pyproject.toml +7 -4
- any2tosca-1.0.0/tests/test_companions.py +235 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/tests/test_converter.py +302 -4
- any2tosca-1.0.0/tests/test_kubernetes.py +278 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/tests/test_openapi.py +31 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/tests/test_redfish.py +36 -11
- any2tosca-1.0.0/tests/test_split.py +352 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/tests/test_yang.py +21 -1
- any2tosca-0.1.0/PKG-INFO +0 -419
- any2tosca-0.1.0/README.md +0 -386
- any2tosca-0.1.0/any2tosca/__init__.py +0 -26
- any2tosca-0.1.0/any2tosca/cli.py +0 -371
- any2tosca-0.1.0/any2tosca.egg-info/PKG-INFO +0 -419
- {any2tosca-0.1.0 → any2tosca-1.0.0}/LICENSE +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca/yaml_utils.py +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca/yang.py +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca.egg-info/dependency_links.txt +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca.egg-info/entry_points.txt +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca.egg-info/requires.txt +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/any2tosca.egg-info/top_level.txt +0 -0
- {any2tosca-0.1.0 → any2tosca-1.0.0}/setup.cfg +0 -0
any2tosca-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: any2tosca
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Convert JSON Schema, OpenAPI (including the Kubernetes specification), Redfish and YANG schemas to TOSCA 2.0 node types and data types
|
|
5
|
+
Author-email: "Ubicity Corp." <info@ubicity.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ubicity-corp/any2tosca
|
|
8
|
+
Project-URL: Documentation, https://github.com/ubicity-corp/any2tosca/blob/master/README.md
|
|
9
|
+
Project-URL: Changelog, https://github.com/ubicity-corp/any2tosca/blob/master/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/ubicity-corp/any2tosca/issues
|
|
11
|
+
Keywords: tosca,json-schema,openapi,kubernetes,redfish,yang,converter
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
20
|
+
Classifier: Topic :: System :: Systems Administration
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Requires-Dist: referencing>=0.28.0
|
|
26
|
+
Requires-Dist: pyang>=2.6
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
30
|
+
Requires-Dist: build; extra == "dev"
|
|
31
|
+
Requires-Dist: twine; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# any2tosca
|
|
35
|
+
|
|
36
|
+
any2tosca turns the schemas you already have into
|
|
37
|
+
[TOSCA 2.0](https://docs.oasis-open.org/tosca/TOSCA/) types. API definitions,
|
|
38
|
+
hardware models and network data models already describe the resources a
|
|
39
|
+
system is built from; any2tosca converts them into TOSCA data types and node
|
|
40
|
+
types, so the types a TOSCA profile needs are generated from the source of
|
|
41
|
+
truth rather than written by hand. The generated types can then be checked
|
|
42
|
+
with [tosca-core](https://github.com/ubicity-corp/tosca-core), the open-source
|
|
43
|
+
TOSCA parser and validator.
|
|
44
|
+
|
|
45
|
+
| Command | Input |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `any2tosca` | [JSON Schema](https://json-schema.org/) |
|
|
48
|
+
| `oas2tosca` | [OpenAPI](https://www.openapis.org/) 2.0 / 3.x |
|
|
49
|
+
| `oas2tosca --kubernetes` | the [Kubernetes](https://kubernetes.io/) OpenAPI specification |
|
|
50
|
+
| `redfish2tosca` | [Redfish](https://www.dmtf.org/standards/redfish) JSON Schema |
|
|
51
|
+
| `yang2tosca` | [YANG](https://datatracker.ietf.org/doc/html/rfc7950) modules |
|
|
52
|
+
|
|
53
|
+
## A quick example
|
|
54
|
+
|
|
55
|
+
Given `server.json`:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"title": "Server",
|
|
60
|
+
"type": "object",
|
|
61
|
+
"properties": {
|
|
62
|
+
"name": {"type": "string"},
|
|
63
|
+
"cpus": {"type": "integer", "minimum": 1, "maximum": 64},
|
|
64
|
+
"disk": {"type": "string", "enum": ["ssd", "hdd"]}
|
|
65
|
+
},
|
|
66
|
+
"required": ["name", "cpus"]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`any2tosca server.json` writes `tosca/server.yaml`:
|
|
71
|
+
|
|
72
|
+
```yaml
|
|
73
|
+
tosca_definitions_version: tosca_2_0
|
|
74
|
+
description: >-
|
|
75
|
+
Types generated from JSON Schema by any2tosca
|
|
76
|
+
data_types:
|
|
77
|
+
Server:
|
|
78
|
+
description: >-
|
|
79
|
+
Server
|
|
80
|
+
properties:
|
|
81
|
+
name:
|
|
82
|
+
type: string
|
|
83
|
+
required: true
|
|
84
|
+
cpus:
|
|
85
|
+
type: integer
|
|
86
|
+
required: true
|
|
87
|
+
validation:
|
|
88
|
+
$and:
|
|
89
|
+
- $greater_or_equal:
|
|
90
|
+
- $value
|
|
91
|
+
- 1
|
|
92
|
+
- $less_or_equal:
|
|
93
|
+
- $value
|
|
94
|
+
- 64
|
|
95
|
+
disk:
|
|
96
|
+
type: string
|
|
97
|
+
required: false
|
|
98
|
+
validation:
|
|
99
|
+
$valid_values:
|
|
100
|
+
- $value
|
|
101
|
+
- - ssd
|
|
102
|
+
- hdd
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Installation
|
|
106
|
+
|
|
107
|
+
any2tosca needs Python 3.10 or later:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pip install any2tosca
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Usage
|
|
114
|
+
|
|
115
|
+
Each command takes input files or directories and writes one TOSCA file per
|
|
116
|
+
input file, with the same base name, into the output directory:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
any2tosca my_schema.json # writes tosca/my_schema.yaml
|
|
120
|
+
any2tosca schemas/ -o tosca/ # every schema in a directory
|
|
121
|
+
oas2tosca openapi.yaml -o tosca/
|
|
122
|
+
redfish2tosca ComputerSystem.v1_20_0.json -I /path/to/DMTF/json-schema -o tosca/
|
|
123
|
+
yang2tosca server.yang -o tosca/
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| Option | |
|
|
127
|
+
|---|---|
|
|
128
|
+
| `-o DIR`, `--output DIR` | the output directory (default: `tosca/`) |
|
|
129
|
+
| `-I DIR`, `--include-dir DIR` | another directory to search for referenced schema files; repeatable |
|
|
130
|
+
| `-v`, `--verbose` | list the types as they are converted |
|
|
131
|
+
| `--profile NAME:VERSION` | also package the output as a profile (see [Output as a profile](#output-as-a-profile)) |
|
|
132
|
+
| `--relationship-model links\|value` | how references to node types are converted (see [Relationship models](#relationship-models)); the default is `links` for `redfish2tosca` and `value` for the others |
|
|
133
|
+
| `--extension-metadata KEY` | copy schema key `KEY` (typically a vendor extension, `x-...`) into the `metadata` of the type or property it appears on; repeatable |
|
|
134
|
+
|
|
135
|
+
### Several files
|
|
136
|
+
|
|
137
|
+
A schema that references another file becomes a TOSCA file that imports the
|
|
138
|
+
other one's output, by `url` and with a `namespace`. Referenced files are
|
|
139
|
+
looked for beside the input file first, then in each `-I` directory. TOSCA does
|
|
140
|
+
not allow circular imports, so reference cycles between files are broken
|
|
141
|
+
during conversion ([docs/circular-import-algorithm.md](docs/circular-import-algorithm.md)).
|
|
142
|
+
|
|
143
|
+
### Output as a profile
|
|
144
|
+
|
|
145
|
+
`--profile NAME:VERSION` also writes `profile.yaml`, which declares the profile
|
|
146
|
+
and imports every file the run writes in dependency order, and a `TOSCA.meta`
|
|
147
|
+
that names it as the entry definitions. The output directory is then a
|
|
148
|
+
profile that can be validated and onboarded as a whole. A warning names any
|
|
149
|
+
file the output imports but the run did not write, such as the `Core.yaml` of
|
|
150
|
+
the `links` relationship model; place it beside `profile.yaml`.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
yang2tosca models/ --profile com.example.network:1.0 -o profile/
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
[tosca-core](https://github.com/ubicity-corp/tosca-core) checks the result
|
|
157
|
+
against TOSCA's rules:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pip install tosca-core
|
|
161
|
+
tosca-validate profile/
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Without `--profile`, the generated files declare no profile name and are meant
|
|
165
|
+
to be imported by a profile or service template of your own.
|
|
166
|
+
|
|
167
|
+
### Splitting one input into several files
|
|
168
|
+
|
|
169
|
+
A single large input, such as an OpenAPI document whose schema names follow a
|
|
170
|
+
package convention, can be converted into several TOSCA files that import each
|
|
171
|
+
other. Split rules, in a YAML file, assign each schema to a file by its name:
|
|
172
|
+
|
|
173
|
+
```yaml
|
|
174
|
+
rules:
|
|
175
|
+
- match: '.*List' # first matching rule wins
|
|
176
|
+
skip: true
|
|
177
|
+
- match: 'io\.k8s\.apimachinery\.pkg\.apis\.meta\.v1\.(?P<name>[^.]+)'
|
|
178
|
+
unit: meta # written to meta.yaml
|
|
179
|
+
- match: 'io\.k8s\.api\.(?P<unit>[a-z]+)\.v1\.(?P<name>[^.]+)'
|
|
180
|
+
- match: '.*'
|
|
181
|
+
skip: true
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The `unit` named group or the `unit` key names the output file; the `name`
|
|
185
|
+
named group gives the TOSCA type name (otherwise the full schema name is used).
|
|
186
|
+
A rule may set the file's import `namespace` (default: the unit name) or `skip`
|
|
187
|
+
the schemas it matches. Schemas that match no rule go to the unit named by
|
|
188
|
+
`default_unit`, and are an error without one.
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
oas2tosca api.json --split rules.yaml --profile io.example:1.0 -o profile/
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
| Option | |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `--split RULES` | split the input using the rules in `RULES`; takes exactly one input file |
|
|
197
|
+
| `--merge-cycles` | merge files that would import each other in a cycle, instead of failing |
|
|
198
|
+
| `--allow-skipped-refs` | warn, instead of failing, when a converted type references a skipped schema |
|
|
199
|
+
|
|
200
|
+
Two schemas that get the same type name in one file, and files that import each
|
|
201
|
+
other in a cycle, are errors. See [docs/splitting.md](docs/splitting.md).
|
|
202
|
+
|
|
203
|
+
## What it generates
|
|
204
|
+
|
|
205
|
+
- **Data types** for objects, enumerations and constrained scalars. An object
|
|
206
|
+
type derives from a parent only where the schema names one (a single `$ref`
|
|
207
|
+
in `allOf`, `anyOf` or `oneOf`); a scalar type derives from its TOSCA
|
|
208
|
+
primitive type, and a schema that accepts any JSON value derives from
|
|
209
|
+
`string`.
|
|
210
|
+
- **Node types** for the schemas that describe resources, as each
|
|
211
|
+
[input format](#input-formats) identifies them. Plain JSON Schema produces
|
|
212
|
+
data types only.
|
|
213
|
+
- **Attributes** for node-type properties marked `readOnly: true`: values the
|
|
214
|
+
system sets rather than ones a template supplies. In data types they stay
|
|
215
|
+
properties.
|
|
216
|
+
- **Property names as the schema spells them**, including `-` and `.`. Type
|
|
217
|
+
names have spaces, `-` and `.` replaced by `_`.
|
|
218
|
+
|
|
219
|
+
### Relationship models
|
|
220
|
+
|
|
221
|
+
A schema can refer to a node type's schema in two ways, and
|
|
222
|
+
`--relationship-model` chooses how such references are converted.
|
|
223
|
+
|
|
224
|
+
**`value`** (the default of `any2tosca`, `oas2tosca` and `yang2tosca`): a
|
|
225
|
+
reference embeds a value of the referenced schema. A property whose schema is
|
|
226
|
+
a node type's schema is typed with a companion data type, `<Name>Value`, with
|
|
227
|
+
the same properties as the node type `<Name>`. For an OpenAPI document whose
|
|
228
|
+
`POST /servers` takes a `Server` and whose `GET /servers` lists them, `oas2tosca`
|
|
229
|
+
writes:
|
|
230
|
+
|
|
231
|
+
```yaml
|
|
232
|
+
node_types:
|
|
233
|
+
Server:
|
|
234
|
+
properties:
|
|
235
|
+
name:
|
|
236
|
+
type: string
|
|
237
|
+
required: true
|
|
238
|
+
cpus:
|
|
239
|
+
type: integer
|
|
240
|
+
required: false
|
|
241
|
+
validation:
|
|
242
|
+
$greater_or_equal:
|
|
243
|
+
- $value
|
|
244
|
+
- 1
|
|
245
|
+
attributes:
|
|
246
|
+
state:
|
|
247
|
+
type: string
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**`links`** (the default of `redfish2tosca`): a reference to another resource
|
|
251
|
+
is a relationship. A property whose value is another node type becomes a
|
|
252
|
+
requirement, with a `Contains` or `DependsOn` relationship, and every node type
|
|
253
|
+
gets a `feature` and a `containable` capability that requirements can target.
|
|
254
|
+
The capability types are written to a companion file, `<name>_caps.yaml`, so
|
|
255
|
+
that other files can target a node type without importing it. The same
|
|
256
|
+
document with `--relationship-model links`:
|
|
257
|
+
|
|
258
|
+
```yaml
|
|
259
|
+
imports:
|
|
260
|
+
- url: Core.yaml
|
|
261
|
+
namespace: core
|
|
262
|
+
- url: servers_caps.yaml
|
|
263
|
+
namespace: srvrscps
|
|
264
|
+
node_types:
|
|
265
|
+
Server:
|
|
266
|
+
properties:
|
|
267
|
+
... # as above
|
|
268
|
+
attributes:
|
|
269
|
+
state:
|
|
270
|
+
type: string
|
|
271
|
+
capabilities:
|
|
272
|
+
feature:
|
|
273
|
+
type: srvrscps:ServerFeature
|
|
274
|
+
containable:
|
|
275
|
+
type: srvrscps:ServerContainable
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### The base types: `Core.yaml`
|
|
279
|
+
|
|
280
|
+
Under the `links` model, node types build on four base types that any2tosca
|
|
281
|
+
does not generate: the `Feature` and `Containable` capability types and the
|
|
282
|
+
`Contains` and `DependsOn` relationship types. The output imports them from a
|
|
283
|
+
`Core.yaml` beside it, which you provide:
|
|
284
|
+
|
|
285
|
+
```yaml
|
|
286
|
+
tosca_definitions_version: tosca_2_0
|
|
287
|
+
relationship_types:
|
|
288
|
+
Contains: {}
|
|
289
|
+
DependsOn: {}
|
|
290
|
+
capability_types:
|
|
291
|
+
Containable: {}
|
|
292
|
+
Feature: {}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Importing these types from a named profile instead, with an option to choose
|
|
296
|
+
the profile, is planned.
|
|
297
|
+
|
|
298
|
+
## Input formats
|
|
299
|
+
|
|
300
|
+
### JSON Schema
|
|
301
|
+
|
|
302
|
+
`any2tosca` converts plain JSON Schema:
|
|
303
|
+
|
|
304
|
+
| JSON Schema | TOSCA |
|
|
305
|
+
|---|---|
|
|
306
|
+
| `type: string` | `type: string` |
|
|
307
|
+
| `type: integer` | `type: integer` |
|
|
308
|
+
| `type: number` | `type: float` |
|
|
309
|
+
| `type: boolean` | `type: boolean` |
|
|
310
|
+
| `type: object` | `data_type` with `properties` |
|
|
311
|
+
| `type: array` | `type: list` with `entry_schema` |
|
|
312
|
+
| no `type`, no structure | `data_type` derived from `string` |
|
|
313
|
+
| `properties` | `properties` |
|
|
314
|
+
| `required` | `required: true/false` per property |
|
|
315
|
+
| `default` | `default` |
|
|
316
|
+
| `description` / `title` | `description` (folded block style) |
|
|
317
|
+
| `readOnly: true` (node types) | attribute |
|
|
318
|
+
| `minimum` / `maximum` | `$greater_or_equal` / `$less_or_equal` |
|
|
319
|
+
| `exclusiveMinimum` / `exclusiveMaximum` | `$greater_than` / `$less_than` |
|
|
320
|
+
| `minLength` / `maxLength` | `$greater_or_equal` / `$less_or_equal` on `$length: [$value]` |
|
|
321
|
+
| `pattern` | `$matches` |
|
|
322
|
+
| `enum` | `$valid_values` |
|
|
323
|
+
| `items` | `entry_schema` |
|
|
324
|
+
| `additionalProperties` | `type: map` with `entry_schema` |
|
|
325
|
+
| `$ref` (local) | the referenced type, by name |
|
|
326
|
+
| `$ref` (external file) | `namespace:TypeName` and an `imports` entry |
|
|
327
|
+
| `allOf` with a single `$ref` | `derived_from` |
|
|
328
|
+
| `allOf` with mixed schemas | merged properties |
|
|
329
|
+
| `anyOf` / `oneOf` with a `null` alternative | the non-null member |
|
|
330
|
+
| `anyOf` / `oneOf` with a single `$ref` | `derived_from` |
|
|
331
|
+
| `anyOf` / `oneOf` with several `$ref`s | first `$ref` → `derived_from`, the others' properties merged |
|
|
332
|
+
| `definitions` / `$defs` | top-level `data_types` entries |
|
|
333
|
+
|
|
334
|
+
The [JSON Schema reference](https://json-schema.org/understanding-json-schema/reference)
|
|
335
|
+
describes the keywords themselves.
|
|
336
|
+
|
|
337
|
+
### OpenAPI
|
|
338
|
+
|
|
339
|
+
`oas2tosca` converts the schemas of an OpenAPI 2.0 (`definitions`) or 3.x
|
|
340
|
+
(`components.schemas`) document with the JSON Schema rules above. A schema
|
|
341
|
+
used as the request body of a `POST` to a path that also supports `GET`, a
|
|
342
|
+
resource the API creates and can return, becomes a node type; the rest become
|
|
343
|
+
data types. A schema posted only to a path without `GET` is a request to
|
|
344
|
+
perform an action, and becomes a data type.
|
|
345
|
+
|
|
346
|
+
### Kubernetes
|
|
347
|
+
|
|
348
|
+
`oas2tosca --kubernetes` converts the Kubernetes OpenAPI specification
|
|
349
|
+
(`api/openapi-spec/swagger.json` in the Kubernetes repository) into one TOSCA
|
|
350
|
+
file per GA API group, plus the shared `meta`, `resource`, `runtime` and
|
|
351
|
+
`intstr` packages and the `apiextensions` and `apiregistration` APIs:
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
oas2tosca --kubernetes swagger.json --profile io.kubernetes:1.37 -o io/kubernetes/1.37/
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
- Alpha and beta versions and the `*List` kinds are left out. The packaged
|
|
358
|
+
split rules ([any2tosca/rules/kubernetes.yaml](any2tosca/rules/kubernetes.yaml))
|
|
359
|
+
decide the files; `--split RULES` replaces them. A GA field whose type is an
|
|
360
|
+
alpha or beta type falls back to its JSON type (`map`, `string`, ...), with a
|
|
361
|
+
warning.
|
|
362
|
+
- Resources (schemas posted to a collection) become node types. Their
|
|
363
|
+
`x-kubernetes-group-version-kind` becomes a `metadata` map, with `group: ''`
|
|
364
|
+
for the core group; `apiVersion` and `kind`, which the type determines, are
|
|
365
|
+
not properties; and `status` is an attribute.
|
|
366
|
+
- `x-kubernetes-list-type`, `x-kubernetes-list-map-keys` and
|
|
367
|
+
`x-kubernetes-map-type` become property `metadata`.
|
|
368
|
+
- A resource embedded in another schema (a `StatefulSet`'s
|
|
369
|
+
`volumeClaimTemplates`) is typed with its companion data type,
|
|
370
|
+
`PersistentVolumeClaimValue`.
|
|
371
|
+
|
|
372
|
+
[docs/kubernetes.md](docs/kubernetes.md) describes the conversion in full.
|
|
373
|
+
|
|
374
|
+
### Redfish
|
|
375
|
+
|
|
376
|
+
`redfish2tosca` first normalizes a Redfish schema into plain JSON Schema,
|
|
377
|
+
dropping OData annotations, flattening nullable alternatives and promoting
|
|
378
|
+
`x-longDescription` to `description`, then converts it with the Redfish rules:
|
|
379
|
+
|
|
380
|
+
- The resource a schema file defines becomes a node type.
|
|
381
|
+
- A family of versioned schemas (`Drive.v1_13_0.json`, `Drive.v1_14_0.json`, ...)
|
|
382
|
+
becomes a chain of `derived_from` types: an `anyOf` / `oneOf` of versioned
|
|
383
|
+
`$ref`s derives from the highest version, with the properties of unversioned
|
|
384
|
+
members merged in. All versions share one capability file (`Drive_caps.yaml`).
|
|
385
|
+
- `Links` become `DependsOn` requirements, and `Actions` become an interface
|
|
386
|
+
type.
|
|
387
|
+
|
|
388
|
+
These rules apply under `redfish2tosca` only; `any2tosca` converts the same
|
|
389
|
+
files as plain JSON Schema.
|
|
390
|
+
[docs/redfish-conversion.md](docs/redfish-conversion.md) describes every step.
|
|
391
|
+
|
|
392
|
+
### YANG
|
|
393
|
+
|
|
394
|
+
| YANG | TOSCA |
|
|
395
|
+
|---|---|
|
|
396
|
+
| `typedef` | `data_type` |
|
|
397
|
+
| `container` (top-level) | `node_type` |
|
|
398
|
+
| `list` (top-level) | `node_type` |
|
|
399
|
+
| `container` (nested) | inline `data_type` |
|
|
400
|
+
| `list` (nested) | `list` property with `entry_schema` |
|
|
401
|
+
| `leaf` | scalar property |
|
|
402
|
+
| `leaf-list` | `list` property |
|
|
403
|
+
| `grouping` / `uses` | inlined by pyang before conversion |
|
|
404
|
+
| `enumeration` | `$valid_values` |
|
|
405
|
+
| `range` | `$greater_or_equal` / `$less_or_equal` |
|
|
406
|
+
| `length` | `$greater_or_equal` / `$less_or_equal` on `$length: [$value]` |
|
|
407
|
+
| `pattern` | `$matches` |
|
|
408
|
+
| `mandatory true` | `required: true` |
|
|
409
|
+
| named typedef reference | the typedef's `data_type`, by name |
|
|
410
|
+
| `leafref` | `string` |
|
|
411
|
+
|
|
412
|
+
YANG integer types (`int8`–`int64`, `uint8`–`uint64`) map to TOSCA `integer`;
|
|
413
|
+
`decimal64` maps to `float`; all string-like types map to `string`.
|
|
414
|
+
|
|
415
|
+
## Limitations
|
|
416
|
+
|
|
417
|
+
- **JSON Schema keywords left out of the conversion:** `const`, `format`,
|
|
418
|
+
`multipleOf`, `minItems` / `maxItems`, `uniqueItems`, `patternProperties`,
|
|
419
|
+
`if` / `then` / `else`, `not`, `writeOnly`, and OpenAPI's `discriminator`.
|
|
420
|
+
The values they constrain are converted; the constraints they add are not.
|
|
421
|
+
`readOnly` is converted on node types only.
|
|
422
|
+
- **Unions:** an `anyOf` / `oneOf` of several `$ref`s becomes one type, so the
|
|
423
|
+
choice between the alternatives is lost.
|
|
424
|
+
- **Kubernetes `IntOrString`:** TOSCA has no union type, so `IntOrString`
|
|
425
|
+
fields are strings and do not take an integer value.
|
|
426
|
+
|
|
427
|
+
## Python API
|
|
428
|
+
|
|
429
|
+
Each command is also available from Python. Every input format in
|
|
430
|
+
`any2tosca.formats` (`JSON_SCHEMA`, `OPENAPI`, `KUBERNETES`, `REDFISH`, `YANG`)
|
|
431
|
+
loads and normalizes an input file and carries the conventions its command
|
|
432
|
+
converts with, so the same code converts any of them as the command does:
|
|
433
|
+
|
|
434
|
+
```python
|
|
435
|
+
from pathlib import Path
|
|
436
|
+
from any2tosca import convert_schema, build_tosca_document
|
|
437
|
+
from any2tosca.companions import add_value_companions
|
|
438
|
+
from any2tosca.formats import OPENAPI # or JSON_SCHEMA, REDFISH, YANG
|
|
439
|
+
from any2tosca.yaml_utils import dump_tosca_yaml
|
|
440
|
+
|
|
441
|
+
fmt, path = OPENAPI, Path("servers.yaml")
|
|
442
|
+
normalized = fmt.normalize(fmt.load(path), path)
|
|
443
|
+
root_schema = normalized.root_schema
|
|
444
|
+
if fmt.conventions.relationship_model == "value":
|
|
445
|
+
# References embed values: point those to node-type schemas at <Name>Value types.
|
|
446
|
+
root_schema = add_value_companions(root_schema, normalized.node_type_names)
|
|
447
|
+
result = convert_schema(root_schema, normalized.top_level_name, normalized.node_type_names,
|
|
448
|
+
base_path=path.parent, source_path=path,
|
|
449
|
+
conventions=fmt.conventions)
|
|
450
|
+
print(dump_tosca_yaml(build_tosca_document(
|
|
451
|
+
result.data_types, result.node_types, result.relationship_types or None,
|
|
452
|
+
result.interface_types or None, imports=result.imports or None)))
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
Under the `links` model, `result.capability_types` holds the capability types
|
|
456
|
+
for `result.caps_file`; `any2tosca.converter.build_caps_document` builds that file's document.
|
|
457
|
+
The Kubernetes format also splits its input; `any2tosca.split.split_schema`
|
|
458
|
+
does that, as `oas2tosca --kubernetes` does. The Python API is provisional (see
|
|
459
|
+
[Versioning](#versioning)).
|
|
460
|
+
|
|
461
|
+
## Versioning
|
|
462
|
+
|
|
463
|
+
any2tosca follows [semantic versioning](https://semver.org/) for its commands:
|
|
464
|
+
their options and the form of their output (the files written, how types are
|
|
465
|
+
named and derived, the relationship models) change incompatibly only in a new
|
|
466
|
+
major version. The Python API is provisional: it may change in a minor release.
|
|
467
|
+
|
|
468
|
+
## Development
|
|
469
|
+
|
|
470
|
+
```bash
|
|
471
|
+
git clone https://github.com/ubicity-corp/any2tosca
|
|
472
|
+
cd any2tosca
|
|
473
|
+
pip install -e ".[dev]"
|
|
474
|
+
pytest
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
## Contributing
|
|
478
|
+
|
|
479
|
+
Report a problem or ask a question by opening an issue. Changes come as pull
|
|
480
|
+
requests, with a test that pins what they fix and `pytest` passing. Report a
|
|
481
|
+
security vulnerability privately, through the repository's Security tab,
|
|
482
|
+
rather than in an issue.
|
|
483
|
+
|
|
484
|
+
## License
|
|
485
|
+
|
|
486
|
+
Apache License 2.0; see [LICENSE](LICENSE).
|