def _get_restore_rules(self):
        """Populate required restore rules.

        :return OrchestrationRestoreRules: response
        """
        self._logger.info("Creating Restore Rules")
        return OrchestrationRestoreRules(True)
Esempio n. 2
0
    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())
Esempio n. 3
0
    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=get_schema())
Esempio n. 4
0
    def test_works_with_standard_json_serializer(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)

        result = json.dumps(orchestration_save_result,
                            cls=SimpleJSONEncoder,
                            indent=True)

        validate(json.loads(result), schema=self.get_schema())
Esempio n. 5
0
    def orchestration_save(self,
                           context,
                           cancellation_context,
                           mode,
                           custom_params=None):
        """
        Saves the Shell state and returns a description of the saved artifacts and information
        This command is intended for API use only by sandbox orchestration scripts to implement
        a save and restore workflow
        :param ResourceCommandContext context: the context object containing resource and reservation info
        :param CancellationContext cancellation_context: Object to signal a request for cancellation. Must be enabled in drivermetadata.xml as well
        :param str mode: Snapshot save mode, can be one of two values 'shallow' (default) or 'deep'
        :param str custom_params: Set of custom parameters for the save operation
        :return: SavedResults serialized as JSON
        :rtype: OrchestrationSaveResult
        """

        # See below an example implementation, here we use jsonpickle for serialization,
        # to use this sample, you'll need to add jsonpickle to your requirements.txt file
        # The JSON schema is defined at: https://github.com/QualiSystems/sandbox_orchestration_standard/blob/master/save%20%26%20restore/saved_artifact_info.schema.json
        # You can find more information and examples examples in the spec document at https://github.com/QualiSystems/sandbox_orchestration_standard/blob/master/save%20%26%20restore/save%20%26%20restore%20standard.md
        '''
        # By convention, all dates should be UTC
        created_date = datetime.datetime.utcnow()

        # This can be any unique identifier which can later be used to retrieve the artifact
        # such as filepath etc.

        # By convention, all dates should be UTC
        created_date = datetime.datetime.utcnow()

        # This can be any unique identifier which can later be used to retrieve the artifact
        # such as filepath etc.
        identifier = created_date.strftime('%y_%m_%d %H_%M_%S_%f')

        orchestration_saved_artifact = OrchestrationSavedArtifact('REPLACE_WITH_ARTIFACT_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)

        return OrchestrationSaveResult(saved_artifacts_info)
        '''
        self._log(
            context,
            'GigamonDriver orchestration_save called: %s\r\n' % custom_params)

        p = json.loads(custom_params)
        if 'folder_path' not in p:
            raise Exception(
                'Input JSON should be {"folder_path": "tftp://host/path"}')

        identifier_url = self.save(context=context,
                                   cancellation_context=cancellation_context,
                                   configuration_type=p.get(
                                       'configuration_type', 'running'),
                                   folder_path=p['folder_path'],
                                   vrf_management_name='no-vrf')
        created_date = datetime.datetime.utcnow()
        orchestration_saved_artifact = OrchestrationSavedArtifact(
            'tftp', identifier_url)
        saved_artifacts_info = OrchestrationSavedArtifactInfo(
            resource_name="some_resource",
            created_date=created_date,
            restore_rules=OrchestrationRestoreRules(
                requires_same_resource=True),
            saved_artifact=orchestration_saved_artifact)

        self._log(context, 'GigamonDriver orchestration_save returning\r\n')

        return OrchestrationSaveResult(saved_artifacts_info)