# Module `netapp_ontap.resources.client_lock`

Copyright © 2023 NetApp Inc. All rights reserved.

This file has been automatically generated based on the ONTAP REST API documentation.

## Overview

A lock is a synchronization mechanism for enforcing limits on concurrent access to files where many clients can be accessing the same file at the same time. Locks can be viewed or broken according to a wide range of query fields that are presented in the lock information definition.
It is recommended that you provide as many fields as possible to optimize query processing.

## Examples

### Retrieving locks with all fields for all SVMs

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import ClientLock

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        print(list(ClientLock.get_collection(return_timeout=15, fields="*")))

Try it out

    [
        ClientLock(
            {
                "share_lock": {"soft": False, "mode": "read_write_deny_write_delete"},
                "protocol": "cifs",
                "client_address": "10.74.7.22",
                "node": {
                    "name": "bshalini-vsim3",
                    "uuid": "1f29b875-9ae3-11eb-8597-0050568ec154",
                },
                "interface": {
                    "ip": {"address": "10.140.115.95"},
                    "name": "vs1.data",
                    "uuid": "6bf26e25-9ae4-11eb-8597-0050568ec154",
                },
                "svm": {"name": "vs1", "uuid": "5b4b6847-9ae4-11eb-8597-0050568ec154"},
                "type": "share_level",
                "volume": {
                    "name": "test_vol1",
                    "uuid": "429dcc79-9af2-11eb-b313-0050568ec154",
                },
                "smb": {
                    "open_type": "durable",
                    "connect_state": "connected",
                    "open_group_id": "71756e2325a7eb11843f005056a4731c101068450bcdffff1c2c000000000000",
                },
                "owner_id": "feff-0206000000020000000204000000000000000000000000ffff0a4a07161053010001000000030000006c00000000000000",
                "state": "granted",
                "uuid": "bf03d8b4-e145-498a-902d-b9fe5d546d18",
                "path": "/test_vol1/Demo406.TXT",
                "constituent": False,
            }
        ),
        ClientLock(
            {
                "protocol": "cifs",
                "client_address": "10.74.7.22",
                "node": {
                    "name": "bshalini-vsim3",
                    "uuid": "1f29b875-9ae3-11eb-8597-0050568ec154",
                },
                "interface": {
                    "ip": {"address": "10.140.115.95"},
                    "name": "vs1.data",
                    "uuid": "6bf26e25-9ae4-11eb-8597-0050568ec154",
                },
                "svm": {"name": "vs1", "uuid": "5b4b6847-9ae4-11eb-8597-0050568ec154"},
                "oplock_level": "batch",
                "type": "op_lock",
                "volume": {
                    "name": "test_vol1",
                    "uuid": "429dcc79-9af2-11eb-b313-0050568ec154",
                },
                "smb": {
                    "connect_state": "connected",
                    "open_group_id": "71756e2325a7eb11843f005056a4731c101068450bcdffff1c2c000000000000",
                },
                "owner_id": "feff-0206000000020000000204000000000000000000000000ffff0a4a07161053010001000000030000006c00000000000000",
                "state": "granted",
                "uuid": "0c33d18d-dcbc-492a-81b3-4c5740c46172",
                "path": "/test_vol1/Demo406.TXT",
                "constituent": False,
            }
        ),
    ]

### Retrieving locks of a specific volume

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import ClientLock

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        print(
            list(
                ClientLock.get_collection(
                    return_timeout=15,
                    fields="*",
                    **{"volume.uuid": "429dcc79-9af2-11eb-b313-0050568ec154"}
                )
            )
        )

Try it out

    [
        ClientLock(
            {
                "interface": {
                    "name": "vs1.data",
                    "uuid": "6bf26e25-9ae4-11eb-8597-0050568ec154",
                },
                "svm": {"name": "vs1", "uuid": "5b4b6847-9ae4-11eb-8597-0050568ec154"},
                "volume": {
                    "name": "test_vol1",
                    "uuid": "429dcc79-9af2-11eb-b313-0050568ec154",
                },
                "uuid": "be1cdf00-37f1-4477-b6d0-bba8c4fa8c67",
                "path": "/test_vol1/Demo408.TXT",
            }
        ),
        ClientLock(
            {
                "interface": {
                    "name": "vs1.data",
                    "uuid": "6bf26e25-9ae4-11eb-8597-0050568ec154",
                },
                "svm": {"name": "vs1", "uuid": "5b4b6847-9ae4-11eb-8597-0050568ec154"},
                "volume": {
                    "name": "test_vol1",
                    "uuid": "429dcc79-9af2-11eb-b313-0050568ec154",
                },
                "uuid": "393cc06e-8b37-4f49-b09a-74d1eef79368",
                "path": "/test_vol1/Demo408.TXT",
            }
        ),
    ]

### Retrieving the lock for a specific UUID

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import ClientLock

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = ClientLock(uuid="be1cdf00-37f1-4477-b6d0-bba8c4fa8c67")
        resource.get()
        print(resource)

Try it out

    ClientLock(
        {
            "share_lock": {"soft": False, "mode": "read_write_deny_write_delete"},
            "protocol": "cifs",
            "client_address": "10.74.7.22",
            "node": {
                "name": "bshalini-vsim3",
                "uuid": "1f29b875-9ae3-11eb-8597-0050568ec154",
            },
            "interface": {
                "ip": {"address": "10.140.115.95"},
                "name": "vs1.data",
                "uuid": "6bf26e25-9ae4-11eb-8597-0050568ec154",
            },
            "svm": {"name": "vs1", "uuid": "5b4b6847-9ae4-11eb-8597-0050568ec154"},
            "type": "share_level",
            "volume": {"name": "test_vol1", "uuid": "429dcc79-9af2-11eb-b313-0050568ec154"},
            "smb": {
                "open_type": "durable",
                "connect_state": "connected",
                "open_group_id": "71756e2325a7eb11843f005056a4731c101068450bcdffff1c2c000000000000",
            },
            "owner_id": "feff-0206000000020000000204000000000000000000000000ffff0a4a07161053010001000000030000006c00000000000000",
            "state": "granted",
            "uuid": "be1cdf00-37f1-4477-b6d0-bba8c4fa8c67",
            "path": "/test_vol1/Demo406.TXT",
            "constituent": False,
        }
    )

### Deleting the lock for a specific UUID

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import ClientLock

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = ClientLock(uuid="be1cdf00-37f1-4477-b6d0-bba8c4fa8c67")
        resource.delete()

### Deleting all locks for a specific protocol

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import ClientLock

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = ClientLock()
        resource.delete(protocol="cifs")

## Classes

`class ClientLock (*args, **kwargs)`

  This object represents locks on a volume.

  Initialize the instance of the resource.

  Any keyword arguments are set on the instance as properties. For example, if the class was named 'MyResource', then this statement would be true:

      MyResource(name='foo').name == 'foo'

  ## Args

  `*args`
    Each positional argument represents a parent key as used in the URL of the object. That is, each value will be used to fill in a segment of the URL which refers to some parent object. The order of these arguments must match the order they are specified in the URL, from left to right.
  `**kwargs`
    each entry will have its key set as an attribute name on the instance and its value will be the value of that attribute.

  ### Ancestors

  - Resource

  ### Static methods

  `def count_collection (*args, connection: HostConnection = None, **kwargs) -> int`

    Returns a count of all ClientLock resources that match the provided query

    This calls GET on the object to determine the number of records. It is more efficient than calling get_collection() because it will not construct any objects. Query parameters can be passed in as kwargs to determine a count of objects that match some filtered criteria.

    ## Args

    `*args`
      Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to get the count of bars for a particular foo, the foo.name value should be passed.
    `connection`
      The `HostConnection` object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
    `**kwargs`
      Any key/value pairs passed will be sent as query parameters to the host. These query parameters can affect the count. A return_records query param will be ignored.

    ## Returns

    On success, returns an integer count of the objects of this type. On failure, returns -1.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400, or if there is no connection available to use either passed in or on the library.

  `def delete_collection (*args, records: Iterable[_ForwardRef('ClientLock')] = None, body: Union[Resource, dict] = None, poll: bool = True, poll_interval: Optional[int] = None, poll_timeout: Optional[int] = None, connection: HostConnection = None, **kwargs) -> NetAppResponse`

    Deletes locks of given parameter.

    ### Related ONTAP commands

    - `vserver locks break`

    ### Learn more

    - `DOC /protocols/locks`

    Delete all objects in a collection which match the given query.

    All records on the host which match the query will be deleted.

    ## Args

    `*args`
      Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to delete the collection of bars for a particular foo, the foo.name value should be passed.
    `records`
      Can be provided in place of a query. If so, this list of objects will be deleted from the host.
    `body`
      The body of the delete request. This could be a Resource instance or a dictionary object.
    `poll`
      If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
    `poll_interval`
      If the operation returns a job, this specifies how often to query the job for updates.
    `poll_timeout`
      If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
    `connection`
      The `HostConnection` object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
    `**kwargs`
      Any key/value pairs passed will be sent as query parameters to the host. Only resources matching this query will be deleted.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  `def find (*args, connection: HostConnection = None, **kwargs) -> Resource`

    Retrieves locks details.

    ### Related ONTAP commands

    - `vserver locks show`

    ### Learn more

    - `DOC /protocols/locks`

    Find an instance of an object on the host given a query.

    The host will be queried with the provided key/value pairs to find a matching resource. If 0 are found, None will be returned. If more than 1 is found, an error will be raised or returned. If there is exactly 1 matching record, then it will be returned.

    ## Args

    `*args`
      Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to find a bar for a particular foo, the foo.name value should be passed.
    `connection`
      The `HostConnection` object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
    `**kwargs`
      Any key/value pairs passed will be sent as query parameters to the host.

    ## Returns

    A `Resource` object containing the details of the object or None if no matches were found.

    ## Raises

    `NetAppRestError`: If the API call returned more than 1 matching resource.

  `def get_collection (*args, connection: HostConnection = None, max_records: int = None, **kwargs) -> Iterable[Resource]`

    Retrieves locks details.

    ### Related ONTAP commands

    - `vserver locks show`

    ### Learn more

    - `DOC /protocols/locks`

    Fetch a list of all objects of this type from the host.

    This is a lazy fetch, making API calls only as necessary when the result of this call is iterated over. For instance, if max_records is set to 5, then iterating over the collection causes an API call to be sent to the server once for every 5 records. If the client stops iterating before getting to the 6th record, then no additional API calls are made.

    ## Args

    `*args`
      Each entry represents a parent key which is used to build the path to the child object. If the URL definition were /api/foos/{foo.name}/bars, then to get the collection of bars for a particular foo, the foo.name value should be passed.
    `connection`
      The `HostConnection` object to use for this API call. If unset, tries to use the connection which is set globally for the library or from the current context.
    `max_records`
      The maximum number of records to return per call
    `**kwargs`
      Any key/value pairs passed will be sent as query parameters to the host.

    ## Returns

    A list of `Resource` objects

    ## Raises

    `NetAppRestError`: If there is no connection available to use either passed in or on the library. This would be not be raised when get_collection() is called, but rather when the result is iterated.

  ### Methods

  `def delete (self, body: Union[Resource, dict] = None, poll: bool = True, poll_interval: Optional[int] = None, poll_timeout: Optional[int] = None, **kwargs) -> NetAppResponse`

    Deletes locks of given parameter.

    ### Related ONTAP commands

    - `vserver locks break`

    ### Learn more

    - `DOC /protocols/locks`

    Send a deletion request to the host for this object.

    ## Args

    `body`
      The body of the delete request. This could be a Resource instance or a dictionary object.
    `poll`
      If set to True, the call will not return until the asynchronous job on the host has completed. Has no effect if the host did not return a job response.
    `poll_interval`
      If the operation returns a job, this specifies how often to query the job for updates.
    `poll_timeout`
      If the operation returns a job, this specifies how long to continue monitoring the job's status for completion.
    `**kwargs`
      Any key/value pairs passed will be sent as query parameters to the host.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  `def get (self, **kwargs) -> NetAppResponse`

    Retrieves the lock for a specific UUID.

    ### Related ONTAP commands

    - `vserver locks show`

    ### Learn more

    - `DOC /protocols/locks`

    Fetch the details of the object from the host.

    Requires the keys to be set (if any). After returning, new or changed properties from the host will be set on the instance.

    ## Returns

    A `NetAppResponse` object containing the details of the HTTP response.

    ## Raises

    `NetAppRestError`: If the API call returned a status code >= 400

  ### Inherited members

  - `Resource`:
    - `from_dict`
    - `get_collection_url`
    - `get_connection`
    - `instance_location`
    - `path_keys`
    - `poll`
    - `set_connection`
    - `to_dict`
`class ClientLockSchema (*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)`

  The fields of the ClientLock object

  ### Ancestors

  - netapp_ontap.resource.ResourceSchema
  - marshmallow.schema.Schema
  - marshmallow.base.SchemaABC

  ### Class variables

  `byte_lock: ByteLock GET POST PATCH`

    The byte_lock field of the client_lock.

  `client_address: str GET POST PATCH`

    IP address of the client holding the lock.

    Example: 0.0.0.0

  `constituent: bool GET`

    Indicate if volume is contituent or not.

  `delegation: str GET`

    Type of delegation.

    Valid choices:

    - read
    - write
  `interface: IpInterface GET POST PATCH`

    The interface field of the client_lock.

  `node: Node GET POST PATCH`

    The node field of the client_lock.

  `oplock_level: str GET`

    The oplock level determines which operations the client may cache locally.

    Valid choices:

    - exclusive
    - level2
    - batch
    - null
    - read_batch
  `owner_id: str GET`

    Owner ID.

  `path: str GET POST PATCH`

    Object path

  `protocol: str GET POST PATCH`

    Type of lock protocol.

    Valid choices:

    - cifs
    - fcache
    - nfsv4
    - http
    - nlm
    - nfsv4.1
    - crposix
  `share_lock: ShareLock GET POST PATCH`

    The share_lock field of the client_lock.

  `smb: Smb GET POST PATCH`

    The smb field of the client_lock.

  `state: str GET`

    State of lock.

    Valid choices:

    - granted
    - revoking
    - adjusted
    - denied
    - subsumed
    - gone
    - unused
    - waiting
    - timeout
  `svm: Svm GET POST PATCH`

    The svm field of the client_lock.

  `type: str GET`

    Type of lock.

    Valid choices:

    - byte_range
    - share_level
    - op_lock
    - delegation
  `uuid: str GET POST PATCH`

    Lock UUID

    Example: ceeac1b4-8646-4c76-a054-1c96e87594aa

  `volume: Volume GET POST PATCH`

    The volume field of the client_lock.