Пример #1
0
def configure(virtual_source, repository, snapshot):
    helpers._record_hook("virtual configure", virtual_source.connection)
    helpers._set_running(virtual_source.connection, virtual_source.guid)

    virtual_source.mongo_install_path = repository.mongo_install_path
    virtual_source.mongo_shell_path = repository.mongo_shell_path

    logger.info("snapshot:{}".format(snapshot))
    logger.info("d_source_type:{}".format(snapshot.d_source_type))
    d_source_type = snapshot.d_source_type
    if d_source_type in [
            "nonshardedsource", "offlinemongodump", "onlinemongodump", "seed",
            "stagingpush", "extendedcluster"
    ]:
        virtual_source.parameters.mongos_port = virtual_source.parameters.start_portpool
    common.setup_dataset(virtual_source, 'Virtual', snapshot, d_source_type)

    logger.debug("End of virtual configure")
    logger.debug(" ")

    discovery_type = "Auto"
    pretty_name = "{}-{}-{}".format(d_source_type,
                                    virtual_source.parameters.mount_path,
                                    virtual_source.parameters.start_portpool)

    return SourceConfigDefinition(discovery_type=discovery_type,
                                  pretty_name=pretty_name)
Пример #2
0
def vdb_enable (virtual_connection,parameters,repository,source_config, snapshot):
    logger = setupLogger._setup_logger(__name__)

    env = {
            "DLPX_TOOLKIT_NAME" : "Oracle on Windows",
            "DLPX_TOOLKIT_WORKFLOW" : "vdb_enable",
            "DLPX_TOOLKIT_PATH" : repository.delphix_tookit_path,
            "ORACLE_HOME" : repository.ora_home,
            "ORACLE_BASE" : repository.ora_base,
            "ORACLE_INST" : parameters.instance_name,
            "ORACLE_USER" : parameters.username,
            "ORACLE_PASSWD" : parameters.password,
            "VDB_MNT_PATH" : parameters.mount_path,
            "ORA_UNQ_NAME" : parameters.dbunique_name,
            "ORA_DB_NAME" : parameters.db_name
           }

    logger.debug("Virtual Parameters: {}".format(parameters))
    logger.debug("Virtual Repository Parameters: {}".format(repository))
    logger.debug("Source Config Parameters: {}".format(source_config))
    logger.debug("Snapshot Parameters: {}".format(snapshot))

    enable_vdb =  executeScript.execute_powershell(virtual_connection,'vdb_enable.ps1',env)
    logger.debug("Enable VDB: {}".format(enable_vdb))

    db_name = parameters.db_name
    db_uniq_name = parameters.dbunique_name
    db_identity_name = parameters.instance_name

    return SourceConfigDefinition(db_name=db_name, db_uniq_name=db_uniq_name,db_identity_name=db_identity_name)
Пример #3
0
    def _internal_direct_post_snapshot(self, request):
        """Post Snapshot Wrapper for direct plugins.

        Executed after creating a snapshot. This plugin
        operation is run after creating a snapshot for a direct source.

        Run post-snapshot operation for a direct source.

        Args:
           request (DirectPostSnapshotRequest): Post Snapshot arguments.

        Returns:
           DirectPostSnapshotResponse: A response containing the return value -
           DirectPostSnapshotResult which has the snapshot metadata on success.
           In case of errors, response object will contain PluginErrorResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotDefinition

        def to_protobuf(snapshot):
            parameters = common_pb2.PluginDefinedObject()
            parameters.json = json.dumps(snapshot.to_dict())
            snapshot_protobuf = common_pb2.Snapshot()
            snapshot_protobuf.parameters.CopyFrom(parameters)
            return snapshot_protobuf

        if not self.post_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_POST_SNAPSHOT)

        direct_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.direct_source.linked_source.parameters.json))
        direct_source = DirectSource(
            guid=request.direct_source.linked_source.guid,
            connection=RemoteConnection.from_proto(
                request.direct_source.connection),
            parameters=direct_source_definition)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        snapshot = self.post_snapshot_impl(direct_source=direct_source,
                                           repository=repository,
                                           source_config=source_config)

        # Validate that this is a SnapshotDefinition object
        if not isinstance(snapshot, SnapshotDefinition):
            raise IncorrectReturnTypeError(Op.LINKED_POST_SNAPSHOT,
                                           type(snapshot), SnapshotDefinition)

        direct_post_snapshot_response = (
            platform_pb2.DirectPostSnapshotResponse())
        direct_post_snapshot_response.return_value.snapshot.CopyFrom(
            to_protobuf(snapshot))

        return direct_post_snapshot_response
Пример #4
0
    def _internal_worker(self, request):
        """Staged Worker Wrapper for staged plugins.

        Executed as part of validated sync. This plugin
        operation is run to sync staging source as part
        of the validated sync operation.

        Run worker operation for a staged source.

        Args:
           request (StagedWorkerRequest): Worker arguments.

        Returns:
           StagedWorkerResponse: A response containing StagedWorkerResult
           if successful or PluginErrorResult in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While linked.worker() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.worker_impl:
            raise OperationNotDefinedError(Op.LINKED_WORKER)

        staged_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.staged_source.linked_source.parameters.json))
        mount = Mount(
            remote_environment=(RemoteEnvironment.from_proto(
                request.staged_source.staged_mount.remote_environment)),
            mount_path=request.staged_source.staged_mount.mount_path,
            shared_path=request.staged_source.staged_mount.shared_path)
        staged_source = StagedSource(
            guid=request.staged_source.linked_source.guid,
            source_connection=RemoteConnection.from_proto(
                request.staged_source.source_connection),
            parameters=staged_source_definition,
            mount=mount,
            staged_connection=RemoteConnection.from_proto(
                request.staged_source.staged_connection))

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        self.worker_impl(staged_source=staged_source,
                         repository=repository,
                         source_config=source_config)

        staged_worker_response = platform_pb2.StagedWorkerResponse()
        staged_worker_response.return_value.CopyFrom(
            platform_pb2.StagedWorkerResult())

        return staged_worker_response
Пример #5
0
    def _internal_status(self, request):
        """Virtual status operation wrapper.

        Executed to get the status of a virtual source - active or inactive.

        Run status operation for a virtual source.

        Args:
          request (VirtualStatusRequest):
          Virtual status operation arguments.

        Returns:
          VirtualStatusResponse: A response containing VirtualStatusResult
          if successful or PluginErrorResult in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import RepositoryDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While virtual.status() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.status_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_STATUS)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]
        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        virtual_status = self.status_impl(repository=repository,
                                          source_config=source_config,
                                          virtual_source=virtual_source)

        # Validate that this is a Status object.
        if not isinstance(virtual_status, Status):
            raise IncorrectReturnTypeError(Op.VIRTUAL_STATUS,
                                           type(virtual_status), Status)

        virtual_status_response = platform_pb2.VirtualStatusResponse()
        virtual_status_response.return_value.status = virtual_status.value
        return virtual_status_response
Пример #6
0
    def _internal_reconfigure(self, request):
        """Reconfigure operation wrapper.

        Executed while attaching a VDB during a virtual source enable job and
        returns a virtual source config.

        Args:
          request (ReconfigureRequest): Reconfigure operation arguments.

        Returns:
          ReconfigureResponse: A response containing the return value of the
          reconfigure operation, as a ReconfigureResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import SnapshotDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import RepositoryDefinition

        if not self.reconfigure_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_RECONFIGURE)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]
        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        snapshot = SnapshotDefinition.from_dict(
            json.loads(request.snapshot.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))

        config = self.reconfigure_impl(snapshot=snapshot,
                                       repository=repository,
                                       source_config=source_config,
                                       virtual_source=virtual_source)

        # Validate that this is a SourceConfigDefinition object.
        if not isinstance(config, SourceConfigDefinition):
            raise IncorrectReturnTypeError(Op.VIRTUAL_RECONFIGURE,
                                           type(config),
                                           SourceConfigDefinition)

        reconfigure_response = platform_pb2.ReconfigureResponse()
        reconfigure_response.return_value.source_config.parameters.json = (
            json.dumps(config.to_dict()))
        return reconfigure_response
Пример #7
0
    def _internal_pre_snapshot(self, request):
        """Virtual pre snapshot operation wrapper.

        Executed before creating a ZFS snapshot. This plugin operation is run
        prior to creating a snapshot for a virtual source.

        Run pre-snapshot operation for a virtual source.

        Args:
          virtual_pre_snapshot_request (VirtualPreSnapshotRequest):
          Virtual pre snapshot operation arguments.

        Returns:
          VirtualPreSnapshotResponse: A response containing
          VirtualPreSnapshotResult if successful or PluginErrorResult in case
          of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import RepositoryDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While virtual.pre_snapshot() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.pre_snapshot_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_PRE_SNAPSHOT)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]
        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        self.pre_snapshot_impl(repository=repository,
                               source_config=source_config,
                               virtual_source=virtual_source)

        virtual_pre_snapshot_response = (
            platform_pb2.VirtualPreSnapshotResponse())
        virtual_pre_snapshot_response.return_value.CopyFrom(
            platform_pb2.VirtualPreSnapshotResult())
        return virtual_pre_snapshot_response
Пример #8
0
def _source_config(virtual_source,
                   repository=None,
                   source_config=None,
                   snapshot=None):
    port = virtual_source.parameters.couchbase_port
    mount_path = virtual_source.parameters.mount_path
    host = virtual_source.connection.environment.host.name
    pretty_name = "Couchbase:" + str(port) + " - " + mount_path
    return SourceConfigDefinition(couchbase_src_host=host,
                                  couchbase_src_port=port,
                                  pretty_name=pretty_name,
                                  db_path=mount_path)
Пример #9
0
    def _internal_unconfigure(self, request):
        """Unconfigure operation wrapper.

        Executed when disabling or deleting an existing virtual source which
        has already been mounted to a target environment. This plugin operation
        is run before unmounting the virtual source from the target
        environment.

        Args:
          request (UnconfigureRequest): Unconfigure operation arguments.

        Returns:
          UnconfigureResponse: A response containing UnconfigureResult
           if successful or PluginErrorResult in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import RepositoryDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While virtual.unconfigure() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.unconfigure_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_UNCONFIGURE)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]

        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        self.unconfigure_impl(repository=repository,
                              source_config=source_config,
                              virtual_source=virtual_source)

        unconfigure_response = platform_pb2.UnconfigureResponse()
        unconfigure_response.return_value.CopyFrom(
            platform_pb2.UnconfigureResult())
        return unconfigure_response
Пример #10
0
def reconfigure(virtual_source, repository, source_config, snapshot):
    logger.debug("virtual.reconfigure > Start")
    start(virtual_source, repository, source_config)
    logger.debug(source_config)
    logger.debug("Snapshot")
    logger.debug(snapshot)
    #srcConfig = configure(virtual_source,snapshot,repository)
    logger.debug("virtual.reconfigure > End")
    virtual_status(virtual_source, repository, source_config)
    return SourceConfigDefinition(db_name="output",
                                  base_dir=virtual_source.parameters.base_dir,
                                  port=virtual_source.parameters.port,
                                  data_dir=virtual_source.mounts[0].mount_path)
Пример #11
0
    def _internal_direct_pre_snapshot(self, request):
        """Pre Snapshot Wrapper for direct plugins.

        Executed before creating a snapshot. This plugin
        operation is run prior to creating a snapshot for a direct source.

        Run pre-snapshot operation for a direct source.

        Args:
           request (DirectPreSnapshotRequest): Pre Snapshot arguments.

        Returns:
           DirectPreSnapshotResponse: A response containing
           DirectPreSnapshotResult if successful or PluginErrorResult in case
           of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While linked.pre_snapshot() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.pre_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_PRE_SNAPSHOT)

        direct_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.direct_source.linked_source.parameters.json))
        direct_source = DirectSource(
            guid=request.direct_source.linked_source.guid,
            connection=RemoteConnection.from_proto(
                request.direct_source.connection),
            parameters=direct_source_definition)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        self.pre_snapshot_impl(direct_source=direct_source,
                               repository=repository,
                               source_config=source_config)

        direct_pre_snapshot_response = platform_pb2.DirectPreSnapshotResponse()
        direct_pre_snapshot_response.return_value.CopyFrom(
            platform_pb2.DirectPreSnapshotResult())

        return direct_pre_snapshot_response
Пример #12
0
    def _internal_start(self, request):
        """Start operation wrapper.

        Executed after attaching a VDB during a virtual source enable job to
        start the database.

        Args:
          request (StartRequest): Start operation arguments.

        Returns:
          StartResponse: A response containing StartResult if successful or
          PluginErrorResult in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import RepositoryDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While virtual.start() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.start_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_START)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]
        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        self.start_impl(repository=repository,
                        source_config=source_config,
                        virtual_source=virtual_source)

        start_response = platform_pb2.StartResponse()
        start_response.return_value.CopyFrom(platform_pb2.StartResult())
        return start_response
Пример #13
0
    def _internal_initialize(self, request):
        """Initialize operation wrapper.

        Executed during VDB creation after mounting onto the target
        environment.

        Run initialize operation for an empty virtual source.

        Args:
          request (InitializeRequest): Initialize operation arguments.

        Returns:
          InitializeResponse: A response containing InitializeResult
          if successful or PluginErrorResult in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import RepositoryDefinition
        from generated.definitions import SourceConfigDefinition

        if not self.initialize_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_INITIALIZE)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]
        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        self.initialize_impl(repository=repository,
                             source_config=source_config,
                             virtual_source=virtual_source)
        initialize_response = platform_pb2.InitializeResponse()
        initialize_response.return_value.CopyFrom(
            platform_pb2.InitializeResult())
        return initialize_response
Пример #14
0
    def _internal_status(self, request):
        """Staged Status Wrapper for staged plugins.

        Executed as part of several operations to get the status
        of a staged source - active or inactive.

        Run status operation for a staged source.

        Args:
           request (StagedStatusRequest): Post Snapshot arguments.

        Returns:
           StagedStatusResponse: A response containing the return value -
           StagedStatusResult which has active or inactive status. In
           case of errors, response object will contain PluginErrorResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition

        #
        # While linked.status() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.status_impl:
            raise OperationNotDefinedError(Op.LINKED_STATUS)

        staged_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.staged_source.linked_source.parameters.json))
        mount = Mount(
            remote_environment=(RemoteEnvironment.from_proto(
                request.staged_source.staged_mount.remote_environment)),
            mount_path=request.staged_source.staged_mount.mount_path,
            shared_path=request.staged_source.staged_mount.shared_path)
        staged_source = StagedSource(
            guid=request.staged_source.linked_source.guid,
            source_connection=RemoteConnection.from_proto(
                request.staged_source.source_connection),
            parameters=staged_source_definition,
            mount=mount,
            staged_connection=RemoteConnection.from_proto(
                request.staged_source.staged_connection))

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        status = self.status_impl(staged_source=staged_source,
                                  repository=repository,
                                  source_config=source_config)

        # Validate that this is a Status object.
        if not isinstance(status, Status):
            raise IncorrectReturnTypeError(Op.LINKED_STATUS, type(status),
                                           Status)

        staged_status_response = platform_pb2.StagedStatusResponse()
        staged_status_response.return_value.status = status.value

        return staged_status_response
Пример #15
0
    def _internal_staged_pre_snapshot(self, request):
        """Pre Snapshot Wrapper for staged plugins.

        Executed before creating a snapshot. This plugin
        operation is run prior to creating a snapshot for a staged source.

        Run pre-snapshot operation for a staged source.

        Args:
            request (StagedPreSnapshotRequest): Pre Snapshot arguments.

        Returns:
            StagedPreSnapshotResponse: A response containing
                StagedPreSnapshotResult if successful or PluginErrorResult
                in case of an error.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotParametersDefinition

        #
        # While linked.pre_snapshot() is not a required operation, this should
        # not be called if it wasn't implemented.
        #
        if not self.pre_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_PRE_SNAPSHOT)

        linked_source = request.staged_source.linked_source
        staged_source_definition = (LinkedSourceDefinition.from_dict(
            json.loads(linked_source.parameters.json)))
        staged_mount = request.staged_source.staged_mount
        mount = Mount(remote_environment=RemoteEnvironment.from_proto(
            staged_mount.remote_environment),
                      mount_path=staged_mount.mount_path,
                      shared_path=staged_mount.shared_path)
        staged_source = StagedSource(
            guid=linked_source.guid,
            source_connection=RemoteConnection.from_proto(
                request.staged_source.source_connection),
            parameters=staged_source_definition,
            mount=mount,
            staged_connection=RemoteConnection.from_proto(
                request.staged_source.staged_connection))

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        snapshot_parameters = SnapshotParametersDefinition.from_dict(
            json.loads(request.snapshot_parameters.parameters.json))

        self.pre_snapshot_impl(staged_source=staged_source,
                               repository=repository,
                               source_config=source_config,
                               snapshot_parameters=snapshot_parameters)

        response = platform_pb2.StagedPreSnapshotResponse()
        response.return_value.CopyFrom(platform_pb2.StagedPreSnapshotResult())

        return response
Пример #16
0
    def _internal_staged_post_snapshot(self, request):
        """Post Snapshot Wrapper for staged plugins.

        Executed after creating a snapshot. This plugin
        operation is run after creating a snapshot for a staged source.

        Run post-snapshot operation for a staged source.

        Args:
           request (StagedPostSnapshotRequest): Post Snapshot arguments.

        Returns:
            StagedPostSnapshotResponse: A response containing the return value
                StagedPostSnapshotResult which has the snapshot metadata on
                success. In case of errors, response object will contain
                PluginErrorResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import RepositoryDefinition
        from generated.definitions import LinkedSourceDefinition
        from generated.definitions import SourceConfigDefinition
        from generated.definitions import SnapshotDefinition
        from generated.definitions import SnapshotParametersDefinition

        def to_protobuf(snapshot):
            parameters = common_pb2.PluginDefinedObject()
            parameters.json = json.dumps(snapshot.to_dict())
            snapshot_protobuf = common_pb2.Snapshot()
            snapshot_protobuf.parameters.CopyFrom(parameters)
            return snapshot_protobuf

        if not self.post_snapshot_impl:
            raise OperationNotDefinedError(Op.LINKED_POST_SNAPSHOT)

        staged_source_definition = LinkedSourceDefinition.from_dict(
            json.loads(request.staged_source.linked_source.parameters.json))
        mount = Mount(
            remote_environment=RemoteEnvironment.from_proto(
                request.staged_source.staged_mount.remote_environment),
            mount_path=request.staged_source.staged_mount.mount_path,
            shared_path=request.staged_source.staged_mount.shared_path)
        staged_source = StagedSource(
            guid=request.staged_source.linked_source.guid,
            source_connection=RemoteConnection.from_proto(
                request.staged_source.source_connection),
            parameters=staged_source_definition,
            mount=mount,
            staged_connection=RemoteConnection.from_proto(
                request.staged_source.staged_connection))

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))
        snap_params = json.loads(request.snapshot_parameters.parameters.json)
        #
        # The snapshot_parameters object should be set to None if the json from
        # the protobuf is None to differentiate no snapshot parameters vs empty
        # snapshot parameters.
        #
        snapshot_parameters = (
            None if snap_params is None else
            SnapshotParametersDefinition.from_dict(snap_params))

        snapshot = self.post_snapshot_impl(
            staged_source=staged_source,
            repository=repository,
            source_config=source_config,
            optional_snapshot_parameters=snapshot_parameters)

        # Validate that this is a SnapshotDefinition object
        if not isinstance(snapshot, SnapshotDefinition):
            raise IncorrectReturnTypeError(Op.LINKED_POST_SNAPSHOT,
                                           type(snapshot), SnapshotDefinition)

        response = platform_pb2.StagedPostSnapshotResponse()
        response.return_value.snapshot.CopyFrom(to_protobuf(snapshot))

        return response
Пример #17
0
def initial_provision(virtual_connection, parameters, snapshot, repository):
    logger = setupLogger._setup_logger(__name__)

    env = {
        "DLPX_TOOLKIT_NAME": "Oracle on Windows",
        "DLPX_TOOLKIT_WORKFLOW": "initial_provision",
        "DLPX_TOOLKIT_PATH": repository.delphix_tookit_path,
        "ORACLE_HOME": repository.ora_home,
        "ORACLE_BASE": repository.ora_base,
        "ORACLE_INST": parameters.instance_name,
        "ORACLE_USER": parameters.username,
        "ORACLE_PASSWD": parameters.password,
        "VDB_MNT_PATH": parameters.mount_path,
        "ORA_UNQ_NAME": parameters.dbunique_name,
        "ORA_DB_NAME": parameters.db_name,
        "ARCHIVE_LOG_MODE": str(parameters.archivelog_mode),
        "CUSTOM_INIT_PARAMS": str(parameters.custom_init_params),
        "CUSTOM_INIT_PARAMS_FILE": parameters.custom_init_params_file,
        "ORA_SRC": snapshot.ora_src,
        "ORA_STG": snapshot.ora_inst,
        "ORA_SRC_TYPE": snapshot.src_type,
        "ORA_VDB_SRC": snapshot.ora_unq
    }

    logger.debug("Virtual Parameters: {}".format(parameters))
    logger.debug("Virtual Repository Parameters: {}".format(repository))
    logger.debug("Snapshot Parameters: {}".format(snapshot))

    crt_svc = executeScript.execute_powershell(virtual_connection,
                                               'crtOraSvc.ps1', env)
    logger.debug("Creating Service: {}".format(crt_svc))

    copy_to_vdbdir = executeScript.execute_powershell(
        virtual_connection, 'vdb_copy_to_vdbdir.ps1', env)
    logger.debug("Copying dSource to VDB Dir: {}".format(copy_to_vdbdir))

    crt_dirs = executeScript.execute_powershell(virtual_connection,
                                                'vdb_crtDirectories.ps1', env)
    logger.debug("Creating Directories: {}".format(crt_dirs))

    vdb_prep_pfile = executeScript.execute_powershell(virtual_connection,
                                                      'vdb_prep_pfile.ps1',
                                                      env)
    logger.debug("VDB Prep pFile: {}".format(vdb_prep_pfile))

    if (snapshot.src_type == 'dSource'):
        vdb_startup_mount = executeScript.execute_powershell(
            virtual_connection, 'vdb_startup_mount.ps1', env)
        logger.debug("VDB StartUp Mount: {}".format(vdb_startup_mount))

        vdb_rename_files = executeScript.execute_powershell(
            virtual_connection, 'vdb_rename_files.ps1', env)
        logger.debug("VDB Rename Files: {}".format(vdb_rename_files))

        vdb_configure = executeScript.execute_powershell(
            virtual_connection, 'vdb_configure.ps1', env)
        logger.debug("VDB Configure: {}".format(vdb_configure))

        vdb_change_dbname_dbid = executeScript.execute_powershell(
            virtual_connection, 'vdb_change_dbname_dbid.ps1', env)
        logger.debug("VDB Change DB ID: {}".format(vdb_change_dbname_dbid))

        vdb_finalize = executeScript.execute_powershell(
            virtual_connection, 'vdb_finalize.ps1', env)
        logger.debug("VDB Finalize: {}".format(vdb_finalize))

    else:  ### snapshot.src_type=='VDB'
        child_vdb_provision = executeScript.execute_powershell(
            virtual_connection, 'vdb_childProvision.ps1', env)
        logger.debug("Child VDB Provision: {}".format(child_vdb_provision))

    if (str(parameters.archivelog_mode) == 'True'):
        vdb_disable_archivelog = executeScript.execute_powershell(
            virtual_connection, 'vdb_disable_archivelog.ps1', env)
        logger.debug(
            "VDB Disable Archive Log: {}".format(vdb_disable_archivelog))

    db_name = parameters.db_name
    db_uniq_name = parameters.dbunique_name
    db_identity_name = parameters.instance_name

    return SourceConfigDefinition(db_name=db_name,
                                  db_uniq_name=db_uniq_name,
                                  db_identity_name=db_identity_name)
Пример #18
0
def configure(virtual_source, snapshot, repository):
    logger.debug("virtual.configure")
    binary_path = virtual_source.connection.environment.host.binary_path
    library_script = pkgutil.get_data('resources', 'library.sh')
    mount_path = virtual_source.mounts[0].mount_path
    vdbConn = build_lua_connect_string(virtual_source.parameters.vdb_user,
                                       "localhost")
    logger.debug("Mount Path:" + mount_path)
    logger.debug("Snapshot Settings:")
    logger.debug(snapshot)
    logger.debug("Snapshot_id" + snapshot.snapshot_id)
    logger.debug("Config Settings: ")
    config_settings_prov = virtual_source.parameters.config_settings_prov
    logger.debug(config_settings_prov)
    config_params = ""
    ###################################################################
    # TODO: Operation fails if there are config settings. Must revisit.
    ###################################################################
    if len(config_settings_prov) > 0:
        for config_setting in config_settings_prov:
            logger.debug("PropertyName")
            logger.debug(config_setting['propertyName'])
            logger.debug("Value")
            logger.debug(config_setting['value'])
            config_params += config_setting['propertyName']
            config_params += "="
            config_params += config_setting['value']
            config_params += "\n"
            logger.debug("config_params:" + config_params)
    logger.debug("config_params:" + config_params)
    ###################################################################

    environment_vars = {
        "DLPX_LIBRARY_SOURCE": library_script,
        "DLPX_DATA_DIRECTORY": mount_path,
        "DLPX_BIN": binary_path,
        "MYSQLD": repository.install_path,
        "MYSQLVER": repository.version,
        "VDBCONN": vdbConn,
        "VDBPASS": virtual_source.parameters.vdb_pass,
        "MYBASEDIR": virtual_source.parameters.base_dir,
        "PORT": virtual_source.parameters.port,
        "SERVERID": virtual_source.parameters.server_id,
        "MYCONFIG": config_params,
        #"STAGED_HOST":snapshot.snap_host,
        "STAGED_PORT": snapshot.snap_port,
        "STAGED_DATADIR": snapshot.snap_data_dir,
        "CONFIG_BASEDIR": snapshot.snap_base_dir,
        "STAGED_ROOT_PASS": snapshot.snap_pass,
        "STAGED_BACKUP": snapshot.snap_backup_path
    }
    configure_script = pkgutil.get_data('resources', 'provision.sh')
    result = libs.run_bash(virtual_source.connection,
                           configure_script,
                           environment_vars,
                           check=False)
    logger.debug(result)
    output = result.stdout.strip()
    std_err = result.stderr.strip()
    exit_code = result.exit_code
    if exit_code == 0:
        logger.debug("Pre-Snapshot/Restore_DB successful " + output)
    else:
        err = utils.process_exit_codes(exit_code, "PROVISION", std_err)
        logger.debug(
            "There was an error while provisioning.Check error.log for details."
        )
        logger.error(err)
        raise err
    return SourceConfigDefinition(db_name=output,
                                  base_dir=virtual_source.parameters.base_dir,
                                  port=virtual_source.parameters.port,
                                  data_dir=mount_path)
Пример #19
0
    def _internal_post_snapshot(self, request):
        """Virtual post snapshot operation wrapper.

        Executed after creating a ZFS snapshot. This plugin operation is run
        after creating a snapshot for a virtual source.

        Run post-snapshot operation for a virtual source.

        Args:
          request (VirtualPostSnapshotRequest): Virtual post snapshot operation
          arguments.

        Returns:
          VirtualPostSnapshotResponse: A response containing the return value
          of the virtual post snapshot operation, as a
          VirtualPostSnapshotResult.
        """
        # Reasoning for method imports are in this file's docstring.
        from generated.definitions import VirtualSourceDefinition
        from generated.definitions import RepositoryDefinition
        from generated.definitions import SnapshotDefinition
        from generated.definitions import SourceConfigDefinition

        def to_protobuf(snapshot):
            parameters = common_pb2.PluginDefinedObject()
            parameters.json = json.dumps(snapshot.to_dict())
            snapshot_protobuf = common_pb2.Snapshot()
            snapshot_protobuf.parameters.CopyFrom(parameters)
            return snapshot_protobuf

        if not self.post_snapshot_impl:
            raise OperationNotDefinedError(Op.VIRTUAL_POST_SNAPSHOT)

        virtual_source_definition = VirtualSourceDefinition.from_dict(
            json.loads(request.virtual_source.parameters.json))
        mounts = [
            VirtualOperations._from_protobuf_single_subset_mount(m)
            for m in request.virtual_source.mounts
        ]
        virtual_source = VirtualSource(guid=request.virtual_source.guid,
                                       connection=RemoteConnection.from_proto(
                                           request.virtual_source.connection),
                                       parameters=virtual_source_definition,
                                       mounts=mounts)

        repository = RepositoryDefinition.from_dict(
            json.loads(request.repository.parameters.json))
        source_config = SourceConfigDefinition.from_dict(
            json.loads(request.source_config.parameters.json))

        snapshot = self.post_snapshot_impl(repository=repository,
                                           source_config=source_config,
                                           virtual_source=virtual_source)

        # Validate that this is a SnapshotDefinition object
        if not isinstance(snapshot, SnapshotDefinition):
            raise IncorrectReturnTypeError(Op.VIRTUAL_POST_SNAPSHOT,
                                           type(snapshot), SnapshotDefinition)

        virtual_post_snapshot_response = (
            platform_pb2.VirtualPostSnapshotResponse())
        virtual_post_snapshot_response.return_value.snapshot.CopyFrom(
            to_protobuf(snapshot))
        return virtual_post_snapshot_response