def orchestration_save(self, mode="shallow", custom_params=None):
        """Orchestration Save command

        :param mode:
        :param custom_params: json with all required action to configure or remove vlans from certain port
        :return Serialized OrchestrationSavedArtifact to json
        :rtype json
        """

        save_params = {
            'folder_path': '',
            'configuration_type': 'running',
            'return_artifact': True
        }
        params = dict()
        if custom_params:
            params = jsonpickle.decode(custom_params)

        save_params.update(params.get('custom_params', {}))
        save_params['folder_path'] = self.get_path(save_params['folder_path'])
        self._logger.info('Start saving configuration')

        saved_artifact = self.save(**save_params)

        saved_artifact_info = OrchestrationSavedArtifactInfo(
            resource_name=self.resource_config.name,
            created_date=datetime.datetime.now(),
            restore_rules=self.get_restore_rules(),
            saved_artifact=saved_artifact)
        save_response = OrchestrationSaveResult(
            saved_artifacts_info=saved_artifact_info)
        self._validate_artifact_info(saved_artifact_info)

        return serialize_to_json(save_response)
    def prepare_orchestration_save_result(self, saved_file_path):
        artifact_type = saved_file_path.split(":")[0]
        identifier = saved_file_path.replace("{0}:".format(artifact_type), "")
        saved_artifact = OrchestrationSavedArtifact(
            identifier=identifier, artifact_type=artifact_type)
        saved_artifact_info = OrchestrationSavedArtifactInfo(
            resource_name=self._resource_name,
            created_date=datetime.datetime.now(),
            restore_rules=self._get_restore_rules(),
            saved_artifact=saved_artifact,
        )
        save_response = OrchestrationSaveResult(
            saved_artifacts_info=saved_artifact_info)
        self._validate_artifact_info_object(saved_artifact_info)

        return str(jsonpickle.encode(save_response, unpicklable=False))
Beispiel #3
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())
Beispiel #4
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())
Beispiel #5
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())
Beispiel #6
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)