Open laszewsk opened 5 years ago
So lets assume we have in the yaml file:
definitions:
VM:
type: object
properties:
provider:
type: string
description: Name of the provider
id:
type: string
description: a unique id for the vm
name:
type: string
description: the name of the vm
image:
type: string
description: the image for the vm
region:
type: string
description: an optional region
size:
type: string
description: The size of the vm
state:
type: string
description: The state of the vm
private_ips:
type: string
description: The private IPs
public_ips:
type: string
description: The public IPS
metadata:
type: string
description: The meta data passed along to the VM
What I like is that we add a new filed such as
x-faker: cloudmesh.faker.unique_ip("[127-255].0.0.[1-255]")
which for example would create an ip address randomly in that range, but be unique
or region:
x-faker: cloudmesh.faker.list["uswest", "useats", .... some more in the list]
This sounds cool. It will be very helpful. We have data generator here
https://github.com/cloudmesh-community/graphql/blob/master/cloudmesh-graphql-server/database.py
We can write standalone prg by taking cue from this file.
I have done basic implementation.
https://github.com/cloudmesh-community/graphql/commit/6bac8335f7dfa6fd2bca523bc4dfef4d9b068767
Cmd to execute script
./yaml_reader.py --yaml-file input.yml --out-file output --json --yaml
Either json
or yaml
option are required. I have checked in sample 'input.yml' file. Here is the output
definitions:
VM:
properties:
id:
description: a unique id for the vm
type: string
image:
description: the image for the vm
type: string
value: CC-Ubuntu14.04
x-faker: cloudmesh_faker.list(['CC-Ubuntu16.04','CC-Ubuntu14.04','CC-Ubuntu18.04','CC-Ubuntu12.04'])
metadata:
description: The meta data passed along to the VM
type: string
name:
description: the name of the vm
type: string
private_ips:
description: The private IPs
type: string
value: 64.0.0.11
x-faker: cloudmesh_faker.unique_ip("[24-96].0.0.[1-128]")
provider:
description: Name of the provider
type: string
public_ips:
description: The public IPS
type: string
value: 229.0.0.246
x-faker: cloudmesh_faker.unique_ip("[127-255].0.0.[1-255]")
region:
description: an optional region
type: string
value: South Central US
x-faker: cloudmesh_faker.list(['West Central US','West US 2','East US 2','East
US','North Central US','South Central US','Central US','West US'])
size:
description: The size of the vm
type: string
state:
description: The state of the vm
type: string
value: Stopping
x-faker: cloudmesh_faker.list(['Starting','Running','Stopping','Stopped','Deallocating','Deallocated'])
type: object
this will come in handy
We are in need of a data faker for general
For REST this is pretty simple:
Let us assume the REST service is defined in yaml via OpenAPI. Under definitions: we find the definition of the resource. What we want is some way of defining lots of them with a reasonable data set that makes somewhat sense.
I was thinking. Maybe we can have a prg that just writes this to a file and than we in : notation attach a python function to it that creates sample data. I remember you have a data generator somewher, where is it, I think we need to generalize this