Exemplo n.º 1
0
def remove_drive(session, drive_id, return_type=None, **kwargs):
    """
    Removes a drive from the VPSA.  Only drives that aren't participating in a
    RAID group may be removed.

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

    :type drive_id: str
    :param drive_id: The drive 'name' value as returned by get_all_drives.
        For example: 'volume-00002a73'.  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_volume_id(drive_id)

    path = '/api/drives/{0}/remove.json'.format(drive_id)

    return session.post_api(path=path, return_type=return_type, **kwargs)
Exemplo n.º 2
0
def get_drive(session, drive_id, return_type=None, **kwargs):
    """
    Retrieves details for a single drive.

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

    :type drive_id: str
    :param drive_id: The drive 'name' value as returned by get_all_drives.
        For example: 'volume-00002a73'.  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_volume_id(drive_id)

    path = '/api/drives/{0}.json'.format(drive_id)

    return session.get_api(path=path, return_type=return_type, **kwargs)
Exemplo n.º 3
0
def rename_drive(session, drive_id, display_name, return_type=None, **kwargs):
    """
    Sets the "display_name" drive parameter to a new value.

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

    :type drive_id: str
    :param drive_id: The drive 'name' value as returned by get_all_drives.
        For example: 'volume-00002a73'.  Required.

    :type display_name: str
    :param display_name: The new "display_name" to set.  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_volume_id(drive_id)
    display_name = verify_field(display_name, "display_name")

    body_values = {'newname': display_name}

    path = '/api/drives/{0}/rename.json'.format(drive_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
Exemplo n.º 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)
Exemplo n.º 5
0
def replace_drive(session,
                  drive_id,
                  to_drive_id,
                  force='NO',
                  return_type=None,
                  **kwargs):
    """
    Replaces a drive, identified by drive_id parameter, with a new unallocated
    drive, identified by to_drive_id parameter, in a RAID group.  The
    replacement drive must not be currently allocated to a RAID group.

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

    :type drive_id: str
    :param drive_id: The drive to be replaced.  This is the drive 'name' value
        as returned by get_all_drives.  For example: 'volume-00002a73'.
        Required.

    :type to_drive_id: str
    :param to_drive_id: The replacement drive.  This is the drive 'name' value
        as returned by get_all_drives.  For example: 'volume-00002a76'.
        Required.

    :type force: str
    :param force: If set to 'YES', ignore non-critical warnings and force the
        VPSA to accept the request.  If 'NO', return message on warning and
        abort.  Set to 'NO' 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.
    """
    verify_volume_id(drive_id)
    verify_volume_id(to_drive_id)
    force = verify_boolean(force, "force")

    body_values = {'toname': to_drive_id, 'force': force}

    path = '/api/drives/{0}/replace.json'.format(drive_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
Exemplo n.º 6
0
def get_drive_performance(session,
                          drive_id,
                          interval=1,
                          return_type=None,
                          **kwargs):
    """
    Retrieves metering statistics for the drive for the specified interval.
    Default interval is one second.

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

    :type drive_id: str
    :param drive_id: The drive 'name' value as returned by get_all_drives.
        For example: 'volume-00002a73'.  Required.

    :type interval: int
    :param interval: The interval to collect statistics for, in seconds.

    :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_volume_id(drive_id)
    interval = verify_interval(interval)

    path = '/api/drives/{0}/performance.json'.format(drive_id)

    parameters = {'interval': interval}

    return session.get_api(path=path,
                           parameters=parameters,
                           return_type=return_type,
                           **kwargs)
Exemplo n.º 7
0
def shred_drive(session, drive_id, force='NO', return_type=None, **kwargs):
    """
    Initializes drive shredding for an individual drive.  Drive must not be
    participating in a RAID group.  CAUTION: This procedure will permanently
    destroy data and is irreversible.

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

    :type drive_id: str
    :param drive_id: The drive 'name' value as returned by get_all_drives.
        For example: 'volume-00002a73'.  Required.

    :type force: str
    :param force: If set to 'YES', ignore non-critical warnings and force the
        VPSA to accept the request.  If 'NO', return message on warning and
        abort.  Set to 'NO' 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.
    """
    verify_volume_id(drive_id)
    force = verify_boolean(force, "force")

    body_values = {'force': force}

    path = '/api/drives/{0}/shred.json'.format(drive_id)

    return session.post_api(path=path,
                            body=body_values,
                            return_type=return_type,
                            **kwargs)
Exemplo n.º 8
0
def create_zcs_image(session,
                     display_name,
                     path,
                     volume_id=None,
                     return_type=None,
                     **kwargs):
    """
    Creates a new Zadara Container Services (ZCS) image.  Running container
    instances are created from these images.

    :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 ZCS image.  For
        example: 'ubuntu', 'SSH', etc.  May not contain a single quote
        (') character.  Required.

    :type path: str
    :param path: When importing from Docker Hub, this is the name of the
        Docker image; for example: 'ubuntu' or 'zadara/ssh'.  When importing
        from a volume (requires the volume_id parameter), the full path on the
        volume to the Docker image tar file; for example:
        'images/testimage.tar'.  Required.

    :type volume_id: str
    :param volume_id: The volume 'name' value as returned by get_all_volumes.
        For example: 'volume-00000001'.  When specified, the ZCS image will be
        imported from this volume.  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")
    path = verify_field(path, "ZCS image path")

    body_values = {'name': display_name, 'path': path}

    # We'll inflect the required "mode" parameter by detecting if volume_id
    # is defined.
    if volume_id is not None:
        verify_volume_id(volume_id)
        body_values['mode'] = 'volume'

    else:
        body_values['mode'] = 'docker'

    path = '/api/images.json'

    try:
        res = session.post_api(path=path,
                               body=body_values,
                               return_type=return_type,
                               **kwargs)
    except RuntimeError as exc:
        err = str(exc)
        # The API server returned an error: "The request has been submitted".
        if err.startswith(ERROR_MSG):
            res = {'response': {"status": 0}}
        else:
            raise

    return res
Exemplo n.º 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)
Exemplo n.º 10
0
def attach_servers_to_volume(session, servers, volume_id, access_type=None,
                             readonly='NO', force='NO', return_type=None,
                             **kwargs):
    """
    Attaches one or more servers to a volume.

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

    :type servers: str
    :param servers: A comma separated string of servers with no spaces
        around the commas.  The value must match server's 'name'
        attribute.  For example: 'srv-00000001,srv-00000002'.  Required.

    :type volume_id: str
    :param volume_id: The volume 'name' value as returned by get_all_volumes.
        For example: 'volume-00000001'.  Required.

    :type access_type: str
    :param access_type: When to an NAS share volume, if set to 'NFS', only NFS
        access will be allowed from this server.  If set to 'SMB', only
        SMB/CIFS will be allowed from this server.  If set to None, both NFS
        and SMB/CIFS will be allowed from this server.  Note that when using
        None, the ip address for the server must be defined in CIDR format,
        even if it's a single host ending in /32.  Not relevant for iSCSI
        volumes.  Optional.

    :type readonly: str
    :param readonly: If set to 'YES', the share will only be readable by this
        server.  If set to 'NO', this server will be able to read and write to
        the share.  Optional.

    :type force: str
    :param force: If set to 'YES', ignore non-critical warnings and force the
        VPSA to accept the request.  If 'NO', return message on warning and
        abort.  Set to 'NO' 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.
    """
    verify_server_id(servers)
    verify_volume_id(volume_id)
    verify_access_type(access_type)

    body_values = {'volume_name': volume_id}

    if access_type is not None:
        verify_access_type(access_type)

        # This allows an extra option through the command line utility
        access_type = None if access_type == 'BOTH' else access_type
        body_values['access_type'] = access_type

    readonly = verify_boolean(readonly, "readonly")
    body_values['readonly'] = readonly

    force = verify_boolean(force, "force")
    body_values['force'] = force

    path = '/api/servers/{0}/volumes.json'.format(servers)

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