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

# Module `netapp_ontap.resources.cli`

Copyright © 2020 NetApp Inc. All rights reserved.

## Overview

This module is the implementation of the CLI resource. This resource is used as an advanced way to send commands to the host system. These commands may or may not have equivalent method of operation in the other resource sets.

## Examples

### Show command

    import json

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import CLI

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        response = CLI().execute("vserver services web show")
        print(json.dumps(response.http_response.json(), indent=4))

Try it out

    {
        "records": [
            {
                "vserver": "mycluster",
                "name": "FW_BMC"
            },
            {
                "vserver": "mycluster",
                "name": "backups"
            },
            {
                "vserver": "mycluster",
                "name": "disco"
            },
            {
                "vserver": "mycluster",
                "name": "docs"
            },
            {
                "vserver": "mycluster",
                "name": "docs-api"
            },
            {
                "vserver": "mycluster",
                "name": "docs-dev-api"
            },
            {
                "vserver": "mycluster",
                "name": "fud"
            },
            {
                "vserver": "mycluster",
                "name": "ontapi"
            },
            {
                "vserver": "mycluster",
                "name": "portal"
            },
            {
                "vserver": "mycluster",
                "name": "rest"
            },
            {
                "vserver": "mycluster",
                "name": "saml"
            },
            {
                "vserver": "mycluster",
                "name": "saml-sp"
            },
            {
                "vserver": "mycluster",
                "name": "security"
            },
            {
                "vserver": "mycluster",
                "name": "spi"
            },
            {
                "vserver": "mycluster",
                "name": "supdiag"
            },
            {
                "vserver": "mycluster",
                "name": "sysmgr"
            },
            {
                "vserver": "vs1",
                "name": "backups"
            },
            {
                "vserver": "vs1",
                "name": "docs-api"
            },
            {
                "vserver": "vs1",
                "name": "docs-dev-api"
            },
            {
                "vserver": "vs1",
                "name": "ontapi"
            },
            {
                "vserver": "vs1",
                "name": "rest"
            },
            {
                "vserver": "vs1",
                "name": "security"
            }
        ],
        "num_records": 23
    }

### Show command with query

    import json

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import CLI

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        response = CLI().execute("vserver services web show", vserver="vs1")
        print(json.dumps(response.http_response.json(), indent=4))

Try it out

    {
        "records": [
            {
                "vserver": "vs1",
                "name": "backups"
            },
            {
                "vserver": "vs1",
                "name": "docs-api"
            },
            {
                "vserver": "vs1",
                "name": "docs-dev-api"
            },
            {
                "vserver": "vs1",
                "name": "ontapi"
            },
            {
                "vserver": "vs1",
                "name": "rest"
            },
            {
                "vserver": "vs1",
                "name": "security"
            }
        ],
        "num_records": 6
    }

### Modify command with query

    import json

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import CLI

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        response = CLI().execute(
            "vserver services web modify", body={"enabled": False}, vserver="vs1",
            name="ontapi",
        )
        print(json.dumps(response.http_response.json(), indent=4))

Try it out

    {
        "num_records": 1
    }

### Create command

    import json

    from netapp_ontap import HostConnection
    from netapp_ontap.resources import CLI

    with HostConnection("<mgmt-ip>", username="admin", password="password", verify=False):
        response = CLI().execute(
            "volume create",
            body={"volume": "vol1", "vserver": "vs1", "aggregate": "aggr1"},
            poll=False,
        )
        print(json.dumps(response.http_response.json(), indent=4))
        print(json.dumps(response.poll().http_response.json(), indent=4))

Try it out

    {
        "job": {
            "uuid": "bce9cad6-afbe-11ea-8a81-005056bbe450",
            "_links": {
                "self": {
                    "href": "/api/cluster/jobs/bce9cad6-afbe-11ea-8a81-005056bbe450"
                }
            }
        },
        "cli_output": "[Job 325] Job is queued: Create vol1."
    }
    {
        "uuid": "bce9cad6-afbe-11ea-8a81-005056bbe450",
        "description": "Create vol1",
        "state": "success",
        "message": "Complete: Successful [0]",
        "code": 0,
        "start_time": "2020-06-16T06:47:13-04:00",
        "end_time": "2020-06-16T06:47:13-04:00",
        "_links": {
            "self": {
                "href": "/api/cluster/jobs/bce9cad6-afbe-11ea-8a81-005056bbe450"
            }
        }
    }

## Classes

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

  To help CLI and ONTAP users transition to the ONTAP REST API, ONTAP 9.6 provides a private REST API endpoint that can be used to access any CLI command. Usage of this API call is recorded and returned in the AutoSupport data collection so that NetApp can identify usablity and functionality improvements in the REST API for future releases. There is no per-API documentation for the REST API access for each CLI command. Unlike the documented REST APIs, the API paths and properties for the CLI passthrough correspond very closely to the CLI. There are several rules that govern all the differences between a CLI command and the REST API mirroring the CLI command.

  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

  ### Methods

  `def execute(self, command, body: dict = None, privilege_level: str = 'admin', poll: bool = True, **kwargs) -> NetAppResponse`

    Execute a command on the CLI and return the result

    ## Args

    `command`
      A string representing the command to execute. This should not include any input or query parameters. Only the base command. E.g.: "volume show", "system node coredump delete", etc.
    `body`
      Any input parameters required to execute the command. These would be passed to the API in the body and used as the required or optional command input.
    `privilege_level`
      If the command needs to be run at a particular privilege level, it can be specified here. The options are "admin" (default), "advanced", "diagnostic".
    `poll`
      If the command starts a job, it will be tracked until it is complete. If this is not desired, set this value to False.
    `kwargs`
      Any parameters needed to filter the objects on which the command will operate.

    ## Returns

    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`