Schemas and Autogenerated Classes¶
Plugin operations will sometimes need to work with data in these custom formats. For example, the configure
operation will accept snapshot data as an input, and must produce source config data as an output.
To enable this, Python classes are generated from the snapshot schema. The aforementioned inputs and outputs are instances of these autogenerated classes.
Info
Autogenerated Python code will use lower_case_with_underscores
as attribute names as per Python variable naming conventions.
That is, if we were to use mountLocation
as the schema property name, it would be called
mount_location
in the generated Python code.
Info
Note that, wherever they can, these generated Python classes will enforce the constraints made by the schema. For example, if a property is listed as required
in the schema, then every Python object will be required to always have this property. This implies that all required
fields must be given values when the object is constructed. For various examples of this, see the examples below.
RepositoryDefinition¶
Defines properties used to identify a Repository.
RepositoryDefinition Schema¶
The plugin must also decide on a name field and a set of identityFields to display and uniquely identify the repository.
{
"type": "object",
"additionalProperties": false,
"required": ["name", "path"],
"properties": {
"name": { "type": "string" },
"path": { "type": "string" }
},
"identityFields": ["name", "path"],
"nameField": "name"
}
RepositoryDefinition Class¶
Autogenerated based on the RepositoryDefinition Schema.
class RepositoryDefinition:
def __init__(self, name, path):
self._inner_dict = {"name": name, "path": path}
To use the class:
from generated.defintions import RepositoryDefinition
# Since both properties are required, they must be specified when constructing the object
repository = RepositoryDefinition(name="name", path="/some/path")
SourceConfigDefinition¶
Defines properties used to identify a Source Config.
SourceConfigDefinition Schema¶
The plugin must also decide on a name field and a set of identityFields to display and uniquely identify the source config.
{
"type": "object",
"additionalProperties": false,
"required": ["name"],
"properties": {
"name": { "type": "string" },
"path": { "type": "string" }
},
"identityFields": ["name"],
"nameField": "name"
}
SourceConfigDefinition Class¶
Autogenerated based on the SourceConfigDefinition Schema.
class SourceConfigDefinition:
def __init__(self, name, path):
self._inner_dict = {"name": name, "path": path}
To use the class:
from generated.defintions import SourceConfigDefinition
# A source config that only defines the required "name" property.
source_config1 = SourceConfigDefinition(name="sc1")
# A Source config that defines both "name" and "path".
source_config2 = SourceConfigDefinition(name="sc2", path="/some/path")
# Setting the optional "path" property after construction
source_config3 = SourceConfigDefinition(name="sc3")
install_path = find_install_path()
source_config3.path = install_path
LinkedSourceDefinition¶
Defines properties used to identify linked sources.
LinkedSourceDefinition Schema¶
{
"type": "object",
"required": ["name", "port"],
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"port": { "type": "integer" }
}
}
LinkedSourceDefinition Class¶
Autogenerated based on the LinkedSourceDefinition Schema.
class LinkedSourceDefinition:
def __init__(self, name, port):
self._inner_dict = {"name": name, "port": port}
To use the class:
from generated.defintions import LinkedSourceDefinition
source = LinkedSourceDefinition(name="name", port=1000)
# Retrieve the properties from the object and log them
name = source.name
port = source.port
logger.debug("Creating source \"{}\" with port {}".format(name, port))
VirtualSourceDefinition¶
Defines properties used to identify virtual sources.
VirtualSourceDefinition Schema¶
{
"type": "object",
"required": ["name", "port"],
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"port": { "type": "integer" }
}
}
VirtualSourceDefinition Class¶
Autogenerated based on the VirtualSourceDefinition Schema.
class VirtualSourceDefinition:
def __init__(self, name, port):
self._inner_dict = {"name": name, "port": port}
To use the class:
from generated.defintions import VirtualSourceDefinition
source = VirtualSourceDefinition(name="name", port=1000)
SnapshotDefinition¶
Defines properties used to snapshots.
SnapshotDefinition Schema¶
{
"type": "object",
"properties": {
"version": { "type": "string" },
"transation_id": { "type": "integer" }
}
}
SnapshotDefinition Class¶
Autogenerated based on the Snapshot Schema.
class SnapshotDefinition:
def __init__(self, version, transaction_id):
self._inner_dict =
{
"version": version,
"transaction_id": transaction_id
}
To use the class:
from generated.defintions import SnapshotDefinition
# A snapshot with both properties defined at construction time
snapshot1 = SnapshotDefinition(version="1.2.3", transaction_id=1000)
# A snapshot with properties defined after construction
snapshot2 = SnapshotDefinition()
snapshot2.version = "2.0.0"
snapshot2.transaction_id = 1500
# A snapshot that omits the optional "transaction_id" property
snapshot3 = SnapshotDefinition(version="1.0.0")
SnapshotParametersDefinition¶
Defines Snapshot Parameters for the snapshot operation.
SnapshotParametersDefinition Schema¶
{
"type": "object",
"required": ["resync"],
"additionalProperties": false,
"properties": {
"resync": { "type": "boolean" }
}
}
SnapshotParametersDefinition Class¶
Autogenerated based on the Snapshot Parameters Definition Schema.
class SnapshotParametersDefinition:
def __init__(self, resync):
self._inner_dict = { "resync": resync }
To use the class: