# Module `netapp_ontap.resources.ip_service_policy`

Copyright © 2020 NetApp Inc. All rights reserved.

## Overview

Service policies are named groupings that define what services are supported by an IP interface. The network IP service-policies GET API retrieves and displays relevant information pertaining to the service policies configured in the cluster. The API retrieves the list of all service policies configured in the cluster or a specific service policy.

## Examples

### Retrieving all service policies in the cluster

The following output shows the collection of all service policies configured in a 2-node cluster. By default (without 'field=*' parameter), only the UUID and name fields are shown for each entry.

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import IpServicePolicy

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        print(list(IpServicePolicy.get_collection()))

Try it out

    [
        IpServicePolicy(
            {
                "_links": {
                    "self": {
                        "href": "/api/network/ip/service-policies/e4e2f193-c1a3-11e8-bb9d-005056bb88c8"
                    }
                },
                "uuid": "e4e2f193-c1a3-11e8-bb9d-005056bb88c8",
                "name": "net-intercluster",
            }
        ),
        IpServicePolicy(
            {
                "_links": {
                    "self": {
                        "href": "/api/network/ip/service-policies/e4e3f6da-c1a3-11e8-bb9d-005056bb88c8"
                    }
                },
                "uuid": "e4e3f6da-c1a3-11e8-bb9d-005056bb88c8",
                "name": "net-route-announce",
            }
        ),
        IpServicePolicy(
            {
                "_links": {
                    "self": {
                        "href": "/api/network/ip/service-policies/e5111111-c1a3-11e8-bb9d-005056bb88c8"
                    }
                },
                "uuid": "e5111111-c1a3-11e8-bb9d-005056bb88c8",
                "name": "vserver-route-announce",
            }
        ),
        IpServicePolicy(
            {
                "_links": {
                    "self": {
                        "href": "/api/network/ip/service-policies/e6111111-c1a3-11e8-bb9d-005056bb88c8"
                    }
                },
                "uuid": "e6111111-c1a3-11e8-bb9d-005056bb88c8",
                "name": "data-route-announce",
            }
        ),
    ]

### Retrieving a specific service policy (scope=svm)

The following output displays the response when a specific "svm" scoped service policy is requested. Among other parameters, the response contains the svm parameters associated with the service policy. The system returns an error when there is no service policy with the requested UUID.

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import IpServicePolicy

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = IpServicePolicy(uuid="dad323ff-4ce0-11e9-9372-005056bb91a8")
        resource.get(fields="*")
        print(resource)

Try it out

    IpServicePolicy(
        {
            "_links": {
                "self": {
                    "href": "/api/network/ip/service-policies/dad323ff-4ce0-11e9-9372-005056bb91a8"
                }
            },
            "uuid": "dad323ff-4ce0-11e9-9372-005056bb91a8",
            "services": ["data_core", "data_nfs", "data_cifs", "data_flexcache"],
            "scope": "svm",
            "svm": {
                "_links": {
                    "self": {"href": "/api/svm/svms/d9060680-4ce0-11e9-9372-005056bb91a8"}
                },
                "uuid": "d9060680-4ce0-11e9-9372-005056bb91a8",
                "name": "vs0",
            },
            "name": "default-data-files",
            "ipspace": {
                "name": "Default",
                "_links": {
                    "self": {
                        "href": "/api/network/ipspaces/45ec2dee-4ce0-11e9-9372-005056bb91a8"
                    }
                },
                "uuid": "45ec2dee-4ce0-11e9-9372-005056bb91a8",
            },
        }
    )

### Retrieving a specific service policy (scope=svm) when requesting commonly used fields

The following output displays the response when commonly used fields are requested for a specific "svm" scoped service policy. Among other parameters, the response contains the svm parameters associated with the service policy. The system returns an error when there is no service policy with the requested UUID.

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import IpServicePolicy

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = IpServicePolicy(uuid="e0889ce6-1e6a-11e9-89d6-005056bbdc04")
        resource.get(fields="name,scope,svm.name,ipspace.name")
        print(resource)

Try it out

    IpServicePolicy(
        {
            "_links": {
                "self": {
                    "href": "/api/network/ip/service-policies/e0889ce6-1e6a-11e9-89d6-005056bbdc04"
                }
            },
            "uuid": "e0889ce6-1e6a-11e9-89d6-005056bbdc04",
            "scope": "svm",
            "svm": {"name": "vs0"},
            "name": "test_policy",
            "ipspace": {"name": "Default"},
        }
    )

### Retrieving a specific service policy (scope=cluster)

The following output displays the response when a specific cluster-scoped service policy is requested. The SVM object is not included for cluster-scoped service policies. A service policy with a scope of "cluster" is associated with an IPspace. The system returns an error when there is no service policy with the requested UUID.

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import IpServicePolicy

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = IpServicePolicy(uuid="4c6b72b9-0f6c-11e9-875d-005056bb21b8")
        resource.get(fields="*")
        print(resource)

Try it out

    IpServicePolicy(
        {
            "_links": {
                "self": {
                    "href": "/api/network/ip/service-policies/4c6b72b9-0f6c-11e9-875d-005056bb21b8"
                }
            },
            "uuid": "4c6b72b9-0f6c-11e9-875d-005056bb21b8",
            "services": ["intercluster_core"],
            "scope": "cluster",
            "name": "net-intercluster",
            "ipspace": {
                "name": "Default",
                "_links": {
                    "self": {
                        "href": "/api/network/ipspaces/4051f13e-0f6c-11e9-875d-005056bb21b8"
                    }
                },
                "uuid": "4051f13e-0f6c-11e9-875d-005056bb21b8",
            },
        }
    )

### Retrieving a specific service policy (scope=cluster) when requesting commonly used fields

The following output displays the response when commonly used fields are requested for a specific "cluster" scoped service policy. The SVM object is not included for cluster-scoped service policies. A service policy with a scope of "cluster" is associated with an IPspace. The system returns an error when there is no service policy with the requested UUID.

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import IpServicePolicy

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        resource = IpServicePolicy(uuid="4c6b72b9-0f6c-11e9-875d-005056bb21b8")
        resource.get(fields="name,scope,ipspace.name")
        print(resource)

Try it out

    IpServicePolicy(
        {
            "_links": {
                "self": {
                    "href": "/api/network/ip/service-policies/4c6b72b9-0f6c-11e9-875d-005056bb21b8"
                }
            },
            "uuid": "4c6b72b9-0f6c-11e9-875d-005056bb21b8",
            "services": ["intercluster_core"],
            "scope": "cluster",
            "name": "net-intercluster",
            "ipspace": {"name": "Default"},
        }
    )

## Classes

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

  Allows interaction with IpServicePolicy objects on the host

  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`

    Retrieves a collection of service policies.

    ### Related ONTAP commands

    - `network interface service-policy show`

    ### Learn more

    - `DOC /network/ip/service-policies`

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

    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 find(*args, connection: HostConnection = None, **kwargs) -> Resource`

    Retrieves a collection of service policies.

    ### Related ONTAP commands

    - `network interface service-policy show`

    ### Learn more

    - `DOC /network/ip/service-policies`

    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) -> typing.Iterable`

    Retrieves a collection of service policies.

    ### Related ONTAP commands

    - `network interface service-policy show`

    ### Learn more

    - `DOC /network/ip/service-policies`

    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 get(self, **kwargs) -> NetAppResponse`

    Retrieves a specific service policy.

    ### Related ONTAP commands

    - `network interface service-policy show`

    ### Learn more

    - `DOC /network/ip/service-policies`

    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

  `def ip_service_policy_show(name: cliche.arg_types.choices.Choices.define.._Choices = None, scope: cliche.arg_types.choices.Choices.define.._Choices = None, services: cliche.arg_types.choices.Choices.define.._Choices = None, uuid: cliche.arg_types.choices.Choices.define.._Choices = None, fields: typing.List = None) -> netapp_ontap.resource_table.ResourceTable`

    Fetch a list of IpServicePolicy resources

    ## Args

    `name`
    `scope`
    `services`

    uuid:

  ### Inherited members

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

  The fields of the IpServicePolicy object

  ### Ancestors

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

  ### Class variables

  `ipspace GET POST PATCH`

    The ipspace field of the ip_service_policy.

  `links GET`

    The links field of the ip_service_policy.

  `name GET POST PATCH`

    The name field of the ip_service_policy.

    Example: default-intercluster

  `scope GET POST PATCH`

    The scope field of the ip_service_policy.

  `services GET POST PATCH`

    The services field of the ip_service_policy.

  `svm GET POST PATCH`

    The svm field of the ip_service_policy.

  `uuid GET POST PATCH`

    The uuid field of the ip_service_policy.

    Example: 1cd8a442-86d1-11e0-ae1c-123478563412