netapp_ontap.resource API documentation
Description: Copyright &copy; 2020 NetApp Inc. All rights reserved …

# Module `netapp_ontap.resource`

Copyright © 2020 NetApp Inc. All rights reserved.

This module defines the base Resource class. This class is implemented by each resource object for the system. The methods here allow the client application to perform actions against the host (GET, POST, PATCH, DELETE) via its REST interface.

## Classes

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

  An abstract class which is the base of all resources.

  A resource represents a moment in time snapshot of an object which exists on the connected host. This object can be fetched, updated, and returned to the host in order to perform meaningful work.

  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.

  ### Static methods

  `def from_dict(input_dict: dict, *args, strict: bool = False) -> Resource`

    Construct a resource from a dictionary.

    This is essentially a named constructor that returns a `Resource` object from the values provided. It will verify that all required parent keys are present in the input.

    ## Args

    `input_dict`
      A set of key/value pairs which are set on the returned instance as attributes.
    `*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.
    `strict`
      If set to True, any value in the input dictionary that is not part of the defined schema will cause an exception to be raised. If set to False, any value in the input schema will be accepted and set as a member of the object.

    ## Returns

    A resource object that can be used to interact with the host and contains the data from the input dictionary.

    ## Raises

    `NetAppRestError`: If not all required parent keys are present in the input or extra input is provided and strict is set to True.

  ### Instance variables

  `instance_location`

    Calculate this instance's location based on its key.

    For example:

        snapshot = Snapshot(volume=Volume(uuid='1234'), uuid='5678')
        assert snapshot._keys == ['volume.uuid', 'uuid']
        assert snapshot.volume.uuid == '1234'
        assert snapshot.uuid == '5678'
        assert snapshot.instance_location == '/api/storage/volumes/1234/snapshots/5678'

    ## Returns

    A string representing the full path to this resource. When interacting with the host, this location is used as the URL.

  `path_keys`

    All keys that are not native to the object (foreign keys).

    In terms of URL, this would typically be all of the keys except for the last key. For example, if the path to the object was /api/storage/volumes/55be2443/snapshots/005056bb3fd7, then this value would be ['volume.uuid']

    ## Returns

    A list of strings. Entries in the list are dotted which represent the object they belong to and the attribute on that object.

  ### Methods

  `def get_collection_url(self, connection: HostConnection = None) -> str`

    Return the URL for collection-based actions (GET, PATCH, DELETE).

    ## Args

    `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.

    ## Returns

    A URL to perform the action on in the form of a string.

  `def get_connection(self) -> HostConnection`

    Returns the `HostConnection` for this object.

    If there is a `HostConnection` active as the current context (i.e. using a with statement), then that connection will be returned. Second, if a connection has been associated with this resource (by calling `Resource.set_connection()`), then that connection will be returned. Finally, it will return the connection that is associated with `CONNECTION`.

    ## Returns

    A connection to be used for API calls.

    ## Raises

    `NetAppRestError`: If there is no connection available to use either set on the object or on the library.

  `def poll(self, hydrate: bool = False, timeout: int = None, interval: int = None) -> NetAppResponse`

    Wait for a job which is running for this resource is complete.

    This function may be called when the client knows there was a job started after a previous API call was made for this object. It will go get the state of that job and then block until it is complete. If hydrate is set to True, this function will continue to block until a subsequent GET call on the resource completes and refreshes the attributes of the resource.

    ## Args

    `hydrate`
      If set to True, after the response is received from the call, a GET call will be made to refresh all fields of the object.
    `timeout`
      Seconds to wait before timing out of poll request. If set, the value overrides the timeout set in the active HostConnection. Otherwise, the timeout set in the active HostConnection is used.
    `interval`
      How long to wait between making REST API calls to check the job status. If set, the value overrides the interval set in the active HostConnection. Otherwise, the interval set in the active HostConnection is used.

    ## Returns

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

    ## Raises

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

  `def set_connection(self, connection: HostConnection)`

    Sets a HostConnection object on the resource.

    This connection will be used for all host operation (GET, PATCH, etc.) and overrides any connection that might be set at the library level.

    ## Args

    `connection`
      The `HostConnection` object to use for all future API calls on this object.
  `def to_dict(self, only: tuple = None) -> dict`

    Return a dictionary representing the object (and its sub-objects).

    ## Args

    `only`
      If a subset of fields are desired instead of all fields belonging to this object, `only` may be passed as a tuple of strings.

    ## Returns

    A dictionary representing the state of this object and any child objects it may contain.

    ## Raises

    `NetAppRestError`: If the current values stored in the resource don't match the schema defined for the resource, then an error will be raised. For example, if a field is supposed to be an integer and a non-integer value is set on it.