def set_timeflow_point(self,
                           container_obj,
                           timestamp_type,
                           timestamp="LATEST",
                           timeflow_name=None):
        """
        This method returns the reference of the timestamp specified.
        container_obj: Delphix object containing the snapshot/timeflow to be
                       provisioned.
        timestamp_type: Type of timestamp - SNAPSHOT or TIME
        timestamp: Name of timestamp/snapshot. Default: Latest
        """

        if timestamp_type.upper() == "SNAPSHOT":
            if timestamp.upper() == "LATEST":
                timeflow_point_parameters = TimeflowPointSemantic()
                timeflow_point_parameters.container = container_obj.reference
                timeflow_point_parameters.location = "LATEST_SNAPSHOT"

            elif timestamp.startswith("@"):
                snapshot_obj = self.find_snapshot(container_obj.reference,
                                                  timestamp,
                                                  snap_name=True)

                if snapshot_obj:
                    timeflow_point_parameters = TimeflowPointLocation()
                    timeflow_point_parameters.timeflow = snapshot_obj.timeflow
                    timeflow_point_parameters.location = (
                        snapshot_obj.latest_change_point.location)

                else:
                    raise DlpxException("ERROR: Was unable to use the "
                                        "specified snapshot {}"
                                        "for database {}".format(
                                            timestamp, container_obj.name))

            elif timestamp:
                snapshot_obj = self.find_snapshot(container_obj.reference,
                                                  timestamp,
                                                  snap_time=True)

                if snapshot_obj:
                    timeflow_point_parameters = TimeflowPointTimestamp()
                    timeflow_point_parameters.timeflow = snapshot_obj.timeflow
                    timeflow_point_parameters.timestamp = (
                        snapshot_obj.latest_change_point.timestamp)

                elif snapshot_obj is None:
                    print_exception("Was unable to find a suitable time"
                                    "  for {} for database {}".format(
                                        (timestamp, container_obj.name)))

        elif timestamp_type.upper() == "TIME":
            if timestamp.upper() == "LATEST":
                timeflow_point_parameters = TimeflowPointSemantic()
                timeflow_point_parameters.location = "LATEST_POINT"

            elif timestamp:
                timeflow_point_parameters = TimeflowPointTimestamp()
                timeflow_point_parameters.type = "TimeflowPointTimestamp"
                timeflow_obj = find_obj_by_name(self.engine, timeflow,
                                                timeflow_name)

                timeflow_point_parameters.timeflow = timeflow_obj.reference
                timeflow_point_parameters.timestamp = timestamp
                return timeflow_point_parameters
        else:
            raise DlpxException("{} is not a valid timestamp_type. Exiting"
                                "\n".format(timestamp_type))

        timeflow_point_parameters.container = container_obj.reference
        return timeflow_point_parameters
Esempio n. 2
0
def set_timeflow_point(engine, server, container_obj):
    """
    This returns the reference of the timestamp specified.
    """

    if arguments["--timestamp_type"].upper() == "SNAPSHOT":
        if arguments["--timestamp"].upper() == "LATEST":
            print_debug("%s: Using the latest Snapshot." % (engine["hostname"]), debug)

            timeflow_point_parameters = TimeflowPointSemantic()
            timeflow_point_parameters.container = container_obj.reference
            timeflow_point_parameters.location = "LATEST_SNAPSHOT"

        elif arguments["--timestamp"].startswith("@"):
            print_debug("%s: Using a named snapshot" % (engine["hostname"]), debug)

            snapshot_obj = find_snapshot_by_database_and_name(
                engine, server, container_obj, arguments["--timestamp"]
            )

            if snapshot_obj != None:
                timeflow_point_parameters = TimeflowPointLocation()
                timeflow_point_parameters.timeflow = snapshot_obj.timeflow
                timeflow_point_parameters.location = (
                    snapshot_obj.latest_change_point.location
                )

            else:
                raise DlpxException(
                    "%s: Was unable to use the specified "
                    "snapshot %s for database %s\n"
                    % (engine["hostname"], arguments["--timestamp"], container_obj.name)
                )

        else:
            print_debug(
                "%s: Using a time-designated snapshot" % (engine["hostname"]), debug
            )

            snapshot_obj = find_snapshot_by_database_and_time(
                engine, server, container_obj, arguments["--timestamp"]
            )
            if snapshot_obj != None:
                timeflow_point_parameters = TimeflowPointTimestamp()
                timeflow_point_parameters.timeflow = snapshot_obj.timeflow
                timeflow_point_parameters.timestamp = (
                    snapshot_obj.latest_change_point.timestamp
                )
            else:
                raise DlpxException(
                    "%s: Was unable to find a suitable time "
                    " for %s for database %s.\n"
                    % (engine["hostname"], arguments["--timestamp"], container_obj.name)
                )

    elif arguments["--timestamp_type"].upper() == "TIME":
        if arguments["--timestamp"].upper() == "LATEST":
            timeflow_point_parameters = TimeflowPointSemantic()
            timeflow_point_parameters.location = "LATEST_POINT"
        else:
            raise DlpxException(
                "%s: Only support a --timestamp value of "
                '"latest" when used with timestamp_type '
                "of time" % s(engine["hostname"])
            )

    else:
        raise DlpxException(
            "%s is not a valied timestamp_type. Exiting\n"
            % (arguments["--timestamp_type"])
        )

    timeflow_point_parameters.container = container_obj.reference
    return timeflow_point_parameters
Esempio n. 3
0
def set_timeflow_point(engine, server, container_obj):
    """
    This returns the reference of the timestamp specified.
    engine:
    server: Delphix Engine object
    container_obj: VDB object
    """

    if arguments["--timestamp_type"].upper() == "SNAPSHOT":
        if arguments["--timestamp"].upper() == "LATEST":
            print_debug(engine["hostname"] + ": Using the latest Snapshot")
            timeflow_point_parameters = TimeflowPointSemantic()
            timeflow_point_parameters.location = "LATEST_SNAPSHOT"

        elif arguments["--timestamp"].startswith("@"):
            print_debug(engine["hostname"] + ": Using a named snapshot")
            snapshot_obj = find_snapshot_by_database_and_name(
                engine, server, container_obj, arguments["--timestamp"])

            if snapshot_obj:
                timeflow_point_parameters = TimeflowPointLocation()
                timeflow_point_parameters.timeflow = snapshot_obj.timeflow
                timeflow_point_parameters.location = (
                    snapshot_obj.latest_change_point.location)

            else:
                raise DlpxException(
                    "ERROR: Was unable to use the specified "
                    "snapshot %s for database %s.\n" %
                    (arguments["--timestamp"], container_obj.name))

        elif arguments["--timestamp"]:
            print_debug(engine["hostname"] +
                        ": Using a time-designated snapshot")
            snapshot_obj = find_snapshot_by_database_and_time(
                engine, server, container_obj, arguments["--timestamp"])

            if snapshot_obj:
                timeflow_point_parameters = TimeflowPointTimestamp()
                timeflow_point_parameters.timeflow = snapshot_obj.timeflow
                timeflow_point_parameters.timestamp = (
                    snapshot_obj.latest_change_point.timestamp)

            else:
                raise DlpxException(
                    "Was unable to find a suitable time"
                    "  for %s for database %s" %
                    (arguments["--timestamp"], container_obj.name))

    elif arguments["--timestamp_type"].upper() == "TIME":

        if arguments["--timestamp"].upper() == "LATEST":
            timeflow_point_parameters = TimeflowPointSemantic()
            timeflow_point_parameters.location = "LATEST_POINT"

        elif arguments["--timestamp"]:
            timeflow_point_parameters = TimeflowPointTimestamp()
            timeflow_point_parameters.type = "TimeflowPointTimestamp"
            timeflow_obj = find_obj_by_name(engine, server, timeflow,
                                            arguments["--timeflow"])

            timeflow_point_parameters.timeflow = timeflow_obj.reference
            timeflow_point_parameters.timestamp = arguments["--timestamp"]
            return timeflow_point_parameters
    else:
        raise DlpxException(arguments["--timestamp_type"] +
                            " is not a valied timestamp_type. Exiting")

    timeflow_point_parameters.container = container_obj.reference
    return timeflow_point_parameters