-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from QualiSystems/dev
merging to master - new classes for save and restore
- Loading branch information
Showing
8 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from pkgutil import extend_path | ||
__path__ = extend_path(__path__, __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from datetime import datetime | ||
|
||
|
||
class OrchestrationSavedArtifact(object): | ||
def __init__(self, artifact_type, identifier): | ||
""" | ||
Represents a saved artifact according to the save and restore standard. | ||
This is a base class which can be extended with additional attributes required to later | ||
restore the artifact such as location or credentials. | ||
:param str artifact_type: Describes the type of saved artifact (e.g. vCenter_image, tftp_file, network_location) | ||
:param str identifier: A unique identifier for the saved artifact (e.g the image url, a file full path) | ||
""" | ||
self.artifact_type = artifact_type | ||
self.identifier = identifier | ||
|
||
|
||
class OrchestrationSaveResult(object): | ||
def __init__(self, saved_artifacts_info): | ||
""" | ||
Container class for the orhcestration_save result | ||
:param OrchestrationSavedArtifactInfo saved_artifacts_info: An object describing the artifacts saved by this operation | ||
""" | ||
self.saved_artifacts_info = saved_artifacts_info | ||
|
||
|
||
class OrchestrationRestoreRules(object): | ||
def __init__(self, requires_same_resource, additional_rules={}): | ||
""" | ||
Container class for the orhcestration_save result | ||
:param OrchestrationSavedArtifactInfo saved_artifacts_info: An object describing the artifacts saved by this operation | ||
""" | ||
self.requires_same_resource = requires_same_resource | ||
for rule in additional_rules: | ||
setattr(self, rule, additional_rules[rule]) | ||
|
||
|
||
class OrchestrationSavedArtifactInfo(object): | ||
def __init__(self, resource_name, created_date, restore_rules, saved_artifact): | ||
""" | ||
This object describes the saved artifacts from a specific save operation. | ||
This information is stored and may later be sent to the Shell as a part of a restore | ||
operation. | ||
:param str resource_name: The name of the resource on which the save operation was performed | ||
:param datetime created_date: The time in which this save operation occurred | ||
:param OrchestrationRestoreRules restore_rules: A list of rules governing constraints on restoring the saved artifact | ||
:param OrchestrationSavedArtifact saved_artifact: The description of the saved artifact itself, the saved artifact can be of different types | ||
""" | ||
self.resource_name = resource_name | ||
self.created_date = created_date | ||
self.restore_rules = restore_rules | ||
self.saved_artifact = saved_artifact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from unittest import TestCase | ||
import jsonpickle | ||
from jsonschema import validate | ||
import datetime | ||
|
||
from cloudshell.shell.core.interfaces.save_restore import OrchestrationSavedArtifact, \ | ||
OrchestrationSavedArtifactInfo, OrchestrationSaveResult, OrchestrationRestoreRules | ||
|
||
|
||
class TestSaveAndRestore(TestCase): | ||
|
||
def get_schema(self): | ||
return { | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"definitions": { | ||
"artifact": { | ||
"type": "object", | ||
"properties": { | ||
"artifact_type": { | ||
"type": "string" | ||
}, | ||
"identifier": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"artifact_type", | ||
"identifier" | ||
] | ||
} | ||
}, | ||
"properties": { | ||
"saved_artifacts_info": { | ||
"type": "object", | ||
"properties": { | ||
"resource_name": { | ||
"type": "string" | ||
}, | ||
"created_date": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"restore_rules": { | ||
"type": "object", | ||
"properties": { | ||
"requires_same_resource": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"requires_same_resource" | ||
] | ||
}, | ||
"saved_artifact": { | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/artifact" | ||
}, | ||
{ | ||
"properties": {} | ||
} | ||
], | ||
"additionalProperties": True | ||
} | ||
}, | ||
"required": [ | ||
"resource_name", | ||
"created_date", | ||
"restore_rules", | ||
"saved_artifact" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"saved_artifacts_info" | ||
] | ||
} | ||
|
||
def test_serializes_to_schema(self): | ||
created_date = datetime.datetime.now() | ||
identifier = created_date.strftime('%y_%m_%d %H_%M_%S_%f') | ||
|
||
orchestration_saved_artifact = OrchestrationSavedArtifact('test_type', identifier) | ||
|
||
saved_artifacts_info = OrchestrationSavedArtifactInfo( | ||
resource_name="some_resource", | ||
created_date=created_date, | ||
restore_rules=OrchestrationRestoreRules(requires_same_resource=True), | ||
saved_artifact=orchestration_saved_artifact) | ||
|
||
orchestration_save_result = OrchestrationSaveResult(saved_artifacts_info) | ||
json_string = jsonpickle.encode(orchestration_save_result, unpicklable=False) | ||
validate(jsonpickle.loads(json_string), schema=self.get_schema()) | ||
|
||
def test_can_serialize_custom_rules(self): | ||
created_date = datetime.datetime.now() | ||
identifier = created_date.strftime('%y_%m_%d %H_%M_%S_%f') | ||
|
||
orchestration_saved_artifact = OrchestrationSavedArtifact('test_type', identifier) | ||
|
||
saved_artifacts_info = OrchestrationSavedArtifactInfo( | ||
resource_name="some_resource", | ||
created_date=created_date, | ||
restore_rules=OrchestrationRestoreRules(requires_same_resource=True, additional_rules={'some_rule': 'True'}), | ||
saved_artifact=orchestration_saved_artifact) | ||
|
||
orchestration_save_result = OrchestrationSaveResult(saved_artifacts_info) | ||
json_string = jsonpickle.encode(orchestration_save_result, unpicklable=False) | ||
validate(jsonpickle.loads(json_string), schema=self.get_schema()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ mock | |
teamcity-messages | ||
jsonpickle | ||
nose-exclude | ||
inject | ||
inject | ||
cloudshell-automation-api | ||
jsonschema |