예제 #1
0
def get_snapshot_policy(session, policy_id, return_type=None, **kwargs):
    """
    Retrieves details for a single snapshot policy.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_policy_id(policy_id)

    path = '/api/snapshot_policies/{0}.json'.format(policy_id)

    return session.get_api(path=path, return_type=return_type, **kwargs)
예제 #2
0
def delete_snapshot_policy(session, policy_id, return_type=None, **kwargs):
    """
    Deletes a snapshot policy.  The policy must not be in use by any local
    volumes, remote mirror jobs, or remote object storage backup jobs.  This
    action is irreversible.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_policy_id(policy_id)

    path = '/api/snapshot_policies/{0}.json'.format(policy_id)

    return session.delete_api(path=path, return_type=return_type, **kwargs)
예제 #3
0
def rename_snapshot_policy(session, policy_id, display_name,
                           return_type=None, **kwargs):
    """
    Sets the "display_name" snapshot policy parameter to a new value.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type display_name: str
    :param display_name: A text label to assign to the snapshot policy.  For
        example: 'Daily Snapshots at 3 AM'.  May not contain a single quote
        (') character.  Required.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_policy_id(policy_id)
    display_name = verify_field(display_name, "display_name")

    body_values = {'new_name': display_name}

    path = '/api/snapshot_policies/{0}/rename.json'.format(policy_id)

    return session.post_api(path=path, body=body_values,
                            return_type=return_type, **kwargs)
예제 #4
0
def detach_snapshot_policy(session,
                           policy_id,
                           mirror_id,
                           snap_rule_id,
                           delete_snapshots="YES",
                           return_type=None,
                           **kwargs):
    """
    Detach a Snapshot Policy from a Volume

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type mirror_id: str
    :param mirror_id: The mirror job 'job_name' value as returned by
        get_all_mirrors.  For example: 'srcjvpsa-00000001'.  Required.

    :type snap_rule_id: str
    :param snap_rule_id: A snap rule ID.
    (found in /consistency_groups/{volume_cg_id}/snapshot_policies API).
    For example: 'snaprule-00000001'.  Required.

    :type delete_snapshots: str
    :param delete_snapshots: "YES" iff delete snapshots after detach.
    "NO" otherwise

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_policy_id(policy_id)
    verify_volume_id(mirror_id)
    verify_snaprule_id(snap_rule_id)

    path = "/api/mirror_jobs/{0}/detach_snapshot_policy.json".format(mirror_id)
    body_values = {
        "id": mirror_id,
        "snaprule": snap_rule_id,
        "delete_snapshots": delete_snapshots
    }

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
예제 #5
0
def remove_mirror_snapshot_policy(session,
                                  mirror_id,
                                  policy_id,
                                  delete_snapshots,
                                  return_type=None,
                                  **kwargs):
    """
    Removes a snapshot policy from an existing mirror job.  A mirror job must
    always have at least one snapshot policy attached.  This should only be
    initiated from the source VPSA.  e.g. the mirror job ID should start with
    "srcjvpsa-".

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type mirror_id: str
    :param mirror_id: The mirror job 'job_name' value as returned by
        get_all_mirrors.  For example: 'srcjvpsa-00000001'.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type delete_snapshots: str
    :param delete_snapshots: If set to 'YES', all snapshots created by the
        specified policy will be deleted.  If 'NO', they won't.  Required.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_mirror_id(mirror_id)
    verify_policy_id(policy_id)
    delete_snapshots = verify_boolean(delete_snapshots, "delete_snapshots")

    body_values = {
        'policyname': policy_id,
        'delete_snapshots': delete_snapshots
    }

    path = '/api/mirror_jobs/{0}/detach_snapshot_policy.json'.format(mirror_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
예제 #6
0
def replace_ros_backup_job_snapshot_policy(session,
                                           ros_backup_job_id,
                                           policy_id,
                                           return_type=None,
                                           **kwargs):
    """
    Replaces the existing snapshot policy used for a remote object storage
    backup job with the specified policy.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type ros_backup_job_id: str
    :param ros_backup_job_id: The remote object storage backup job 'name'
        value as returned by get_all_ros_backup_jobs.  For example:
        'bkpjobs-00000001'.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  This
        policy will determine the frequency and retention of backups for this
        job.  Required.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_ros_backup_job_id(ros_backup_job_id)
    verify_policy_id(policy_id)

    body_values = {'policyname': policy_id}

    path = '/api/object_storage_backup_jobs/{0}/replace_snapshot_policy.json' \
        .format(ros_backup_job_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
예제 #7
0
def add_mirror_snapshot_policy(session,
                               mirror_id,
                               policy_id,
                               return_type=None,
                               **kwargs):
    """
    Adds an additional snapshot policy to an existing mirror job.  This should
    only be initiated from the source VPSA.  e.g. the mirror job ID should
    start with "srcjvpsa-".

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type mirror_id: str
    :param mirror_id: The mirror job 'job_name' value as returned by
        get_all_mirrors.  For example: 'srcjvpsa-00000001'.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_mirror_id(mirror_id)
    verify_policy_id(policy_id)

    body_values = {'policyname': policy_id}

    path = '/api/mirror_jobs/{0}/attach_snapshot_policy.json'.format(mirror_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
예제 #8
0
def update_snapshot_policy(session, policy_id, create_policy=None,
                           local_delete_policy=None,
                           remote_delete_policy=None, display_name=None,
                           allow_empty=None, return_type=None, **kwargs):
    """
    Change various settings related to a snapshot policy.  These changes will
    be propagated to any local volume, remote mirror job, or remote object
    storage backup job that uses this policy.  Parameters set to 'None' will
    not have their existing values changed.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type create_policy: str
    :param create_policy: See documentation for create_snapshot_policy.
        Optional.

    :type local_delete_policy: int
    :param local_delete_policy: See documentation for create_snapshot_policy.
        Optional.

    :type remote_delete_policy: int
    :param remote_delete_policy: See documentation for create_snapshot_policy.
        Optional.

    :type display_name: str
    :param display_name: A text label to assign to the new snapshot policy.

    :type allow_empty: str
    :param allow_empty: See documentation for create_snapshot_policy.
        Optional.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_policy_id(policy_id)

    body_values = {}

    if create_policy is not None:
        verify_policy_creation(create_policy)
        body_values['create_policy'] = create_policy

    if local_delete_policy is not None:
        if local_delete_policy < 0:
            raise ValueError('The local_delete_policy parameter must not be '
                             'negative ("{0}" was passed).'
                             .format(local_delete_policy))

        body_values['delete_policy'] = 'N' + str(local_delete_policy)

    if remote_delete_policy is not None:
        if remote_delete_policy < 0:
            raise ValueError('The remote_delete_policy parameter must not be '
                             'negative ("{0}" was passed).'
                             .format(remote_delete_policy))

        body_values['destination_policy'] = 'N' + str(remote_delete_policy)

    if allow_empty is not None:
        body_values['empty'] = verify_boolean(allow_empty, 'allow_empty')

    if display_name is not None:
        body_values['display_name'] = display_name

    if not body_values:
        raise ValueError('At least one of the following must be set: '
                         '"display_name", "create_policy", '
                         '"local_delete_policy", "remote_delete_policy", '
                         '"display_name", "allow_empty"')

    path = '/api/snapshot_policies/{0}.json'.format(policy_id)

    return session.put_api(path=path, body=body_values,
                           return_type=return_type, **kwargs)
예제 #9
0
def create_ros_backup_job(session,
                          display_name,
                          ros_destination_id,
                          sse,
                          volume_id,
                          policy_id,
                          compression='YES',
                          return_type=None,
                          **kwargs):
    """
    Creates a new remote object storage backup job.  Backups are based on
    snapshots taken by the specified snapshot policy.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type display_name: str
    :param display_name: A text label to assign to the remote object storage
        backup job.  For example: 'Daily S3 Backup'.  May not contain a single
        quote (') character.  Required.

    :type sse: str
    :param sse: The remote object storage destination SSE:
     'NO', 'AES256', 'KMS', 'KMSKEYID  Required.

    :type ros_destination_id: str
    :param ros_destination_id: The remote object storage destination 'name'
        value as returned by get_all_ros_destinations.  For example:
        'obsdst-00000001'.  Required.

    :type volume_id: str
    :param volume_id: The volume 'name' value as returned by get_all_volumes
        for the volume to be backed up.  For example: 'volume-00000001'.
        Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  This
        policy will determine the frequency and retention of backups for this
        job.  Required.

    :type compression: str
    :param compression: If set to 'YES', backup data will be compressed in
        flight.  If 'NO', backup data will not be compressed.  Set to 'YES' by
        default.  Optional.

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    display_name = verify_field(display_name, "display_name")
    verify_ros_destination_id(ros_destination_id)
    verify_volume_id(volume_id)
    verify_policy_id(policy_id)

    body_values = {
        'name': display_name,
        'destination': ros_destination_id,
        'volume': volume_id,
        'policy': policy_id,
        'sse': sse,
        'compression': verify_boolean(compression, "compression")
    }

    path = '/api/object_storage_backup_jobs.json'

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
예제 #10
0
def resume_broken_mirror(session,
                         rvpsa_id,
                         display_name,
                         policy_id,
                         local_snapshot_id,
                         remote_snapshot_id,
                         wan_optimization='YES',
                         compress=None,
                         dedupe=None,
                         force='NO',
                         return_type=None,
                         **kwargs):
    """
    Resumes a previously broken mirror job between VPSAs.  Use in conjunction
    with get_suggested_mirrors to find candidates for resume.

    :type session: zadarapy.session.Session
    :param session: A valid zadarapy.session.Session object.  Required.

    :type rvpsa_id: str
    :param rvpsa_id: The remote VPSA 'name' value as returned by
        get_all_remote_vpsas.  For example: 'rvpsa-00000001'.  Required.

    :type display_name: str
    :param display_name: A text label to assign to the mirror job.  For
        example: 'Daily Mirror to West Region'.  May not contain a single
        quote (') character.  Required.

    :type policy_id: str
    :param policy_id: The snapshot policy 'name' value as returned by
        get_all_snapshot_policies.  For example: 'policy-00000001'.  Required.

    :type local_snapshot_id: str
    :param local_snapshot_id: The local snapshot to be used to resume the
        broken mirror.  This corresponds to the "src_snap_name" value returned
        by get_suggested_mirrors.  For example: 'snap-00000001'.  Required.

    :type remote_snapshot_id: str
    :param remote_snapshot_id: The remote snapshot to be used to resume the
        broken mirror.  This corresponds to the "dst_snap_name" value returned
        by get_suggested_mirrors.  For example: 'snap-00000001'.  Required.

    :type wan_optimization: str
    :param wan_optimization: If set to 'YES', the mirror will attempt to
        reduce the amount of data needing to be synchronized to the remote
        side at the expense of more load on the source VPSA.  If set to 'NO',
        more data will be sent by the mirror with less load on the source
        VPSA.  Set to 'YES' by default.  Required.

    :type compress: str
    :param compress: "YES" for compress. "NO" for not


    :type dedupe: str
    :param dedupe: "YES" for dedupe. "NO" for not


    :type force: str
    :param force: "YES" for force command. "NO" for not

    :type return_type: str
    :param return_type: If this is set to the string 'json', this function
        will return a JSON string.  Otherwise, it will return a Python
        dictionary.  Optional (will return a Python dictionary by default).

    :rtype: dict, str
    :returns: A dictionary or JSON data set as a string depending on
        return_type parameter.
    """
    verify_remote_vpsa_id(rvpsa_id)
    display_name = verify_field(display_name, "display_name")
    verify_policy_id(policy_id)
    verify_snapshot_id(local_snapshot_id)
    verify_snapshot_id(remote_snapshot_id)
    wan_optimization = verify_boolean(wan_optimization, "wan_optimization")

    body_values = {
        "displayname": display_name,
        "policy": policy_id,
        "snapname": local_snapshot_id,
        "remote_snapname": remote_snapshot_id,
        "wanoptimization": wan_optimization,
        "force": force
    }

    if compress is not None:
        compress = verify_boolean(compress, "compress")
        body_values["compress"] = compress
    if dedupe is not None:
        dedupe = verify_boolean(dedupe, "dedupe")
        body_values["dedupe"] = dedupe

    path = '/api/remote_vpsas/{0}/resume_mirror_job.json'.format(rvpsa_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)