ONTAP Rest API Discussions

API to mount existing volume

Taran
9,180 Views

Hi,

I am loking for REST API to mount the existing volume at junction point

1 ACCEPTED SOLUTION

mbeattie
9,070 Views

Hi,

 

You can use the swagger interface on your cluster via "https://<cluster>/docs/api". Here are some examples, start by querying the volume for the state and UUID. EG:

 

Method: Get
URI: https://cluster1.testlab.local/api/storage/volumes?svm.name=vserver1&name=volume1&fields=uuid,state

{
  "records": [
    {
      "uuid": "ac1b73fd-ebbc-11e9-865d-005056804db6",
      "name": "volume1",
      "state": "offline",
      "svm": {
        "name": "vserver1"
      }
    }
  ],
  "num_records": 1
}

Once you have the volume UUID you need to ensure the volume is in an "online" state before it can be mounted (note that in the above example the state is "offline" so you first need to invoke a Patch request to online the volume).

 

Method: Patch
URI: https://cluster1.testlab.local/api/storage/volumes/ac1b73fd-ebbc-11e9-865d-005056804db6

{
  "name": "volume1",
  "state": "online"
}

Using the volumes UUID you can then mount the volume in the vservers namespace. EG

Method: Patch
Uri: https://cluster1.testlab.local/api/storage/volumes/ac1b73fd-ebbc-11e9-865d-005056804db6

{
  "name": "volume1",
  "nas": {
    "path": "/volume1"
  }
}

The REST API will provide JSON ouput that contains the Job UUID number. EG

{
  "job": {
    "uuid": "b1fd3fc1-f47f-11e9-865d-005056804db6",
    "_links": {
      "self": {
        "href": "/api/cluster/jobs/b1fd3fc1-f47f-11e9-865d-005056804db6"
      }
    }
  }
}

You can then query the status of the job:

 

Method: Get
Uri: https://cluster1.testlab.local/api/cluster/jobs/b1fd3fc1-f47f-11e9-865d-005056804db6

{
  "uuid": "b1fd3fc1-f47f-11e9-865d-005056804db6",
  "description": "PATCH /api/storage/volumes/ac1b73fd-ebbc-11e9-865d-005056804db6",
  "state": "success",
  "message": "success",
  "code": 0,
  "start_time": "2019-10-22T14:54:49+11:00",
  "end_time": "2019-10-22T14:54:59+11:00"
}

Hope that helps?

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

7 REPLIES 7

Henrik_Aicher
9,122 Views

Hi Taran,

 

not sure what you want to do but here:

https://library.netapp.com/ecm/ecm_download_file/ECMLP2854934

you can find the Ontap9 RestApi Docu, I assume you use Ontap 9.

 

On page 20ff. is descriped how to use the API,

 

Cheers,

 

Henrik

mbeattie
9,071 Views

Hi,

 

You can use the swagger interface on your cluster via "https://<cluster>/docs/api". Here are some examples, start by querying the volume for the state and UUID. EG:

 

Method: Get
URI: https://cluster1.testlab.local/api/storage/volumes?svm.name=vserver1&name=volume1&fields=uuid,state

{
  "records": [
    {
      "uuid": "ac1b73fd-ebbc-11e9-865d-005056804db6",
      "name": "volume1",
      "state": "offline",
      "svm": {
        "name": "vserver1"
      }
    }
  ],
  "num_records": 1
}

Once you have the volume UUID you need to ensure the volume is in an "online" state before it can be mounted (note that in the above example the state is "offline" so you first need to invoke a Patch request to online the volume).

 

Method: Patch
URI: https://cluster1.testlab.local/api/storage/volumes/ac1b73fd-ebbc-11e9-865d-005056804db6

{
  "name": "volume1",
  "state": "online"
}

Using the volumes UUID you can then mount the volume in the vservers namespace. EG

Method: Patch
Uri: https://cluster1.testlab.local/api/storage/volumes/ac1b73fd-ebbc-11e9-865d-005056804db6

{
  "name": "volume1",
  "nas": {
    "path": "/volume1"
  }
}

The REST API will provide JSON ouput that contains the Job UUID number. EG

{
  "job": {
    "uuid": "b1fd3fc1-f47f-11e9-865d-005056804db6",
    "_links": {
      "self": {
        "href": "/api/cluster/jobs/b1fd3fc1-f47f-11e9-865d-005056804db6"
      }
    }
  }
}

You can then query the status of the job:

 

Method: Get
Uri: https://cluster1.testlab.local/api/cluster/jobs/b1fd3fc1-f47f-11e9-865d-005056804db6

{
  "uuid": "b1fd3fc1-f47f-11e9-865d-005056804db6",
  "description": "PATCH /api/storage/volumes/ac1b73fd-ebbc-11e9-865d-005056804db6",
  "state": "success",
  "message": "success",
  "code": 0,
  "start_time": "2019-10-22T14:54:49+11:00",
  "end_time": "2019-10-22T14:54:59+11:00"
}

Hope that helps?

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Taran
8,951 Views

thanks Matt for the answer. It was of great help

mbeattie
8,922 Views

Hi Taran,

 

No problem, happy to help. If you have ever considered using Ansible for automation orchestration here's a link to explore. This provides an easy method for customers to use NetApp API's without the complexity of programming:

 

https://netapp.io/2018/10/08/getting-started-with-netapp-and-ansible-install-ansible/

 

To provide a simple example based on your use case (mounting an offline volume). EG:

 

cluster1::*> volume show -vserver vserver1 -volume volume1 -fields volume, state, junction-path
vserver  volume  state   junction-path
-------- ------- ------- -------------
vserver1 volume1 offline -

An ansible playbook can be used to define the desired state of the volume and set the tasks to peform (first online the volume and then mount it). EG

 

---
- hosts: localhost
  gather_facts: false
  name: Mount Volume
  vars:
    login: &login
      hostname: cluster1.testlab.local # NetApp Cluster IP
      username: ansible # Ansible Cluster User
      password: N0tMyP@ssw0rd! # Ansible Cluster Password
      https: true
      validate_certs: false
    vserver: vserver1
    volume: volume1
  tasks:
  - name: Online Volume
    na_ontap_volume:
      state: present
      name: "{{ volume }}"
      vserver: "{{ vserver }}"
      is_online: yes
      <<: *login
  - name: Mount Volume
    na_ontap_volume:
      state: present
      name: "{{ volume }}"
      vserver: "{{ vserver }}"
      junction_path: "/{{ volume }}"
      <<: *login

Running the playbook ensures the volume is configured to the desired state you defined. EG

 

[mbeattie@testux01 playbooks]# ansible-playbook mount_volume.yml
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Mount Volume] *********************************************************************************************************************************************************************************

TASK [Online Volume] ********************************************************************************************************************************************************************************
changed: [localhost]

TASK [Mount Volume] *********************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ******************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Comparing the storage configuration after running the playbook shows that the volume is now online and mounted.

 

cluster1::*> volume show -vserver vserver1 -volume volume1 -fields volume, state, junction-path
vserver  volume  state  junction-path
-------- ------- ------ -------------
vserver1 volume1 online /volume1

This is very a simple example however it demonstrates that there are options availble for customers to easily deploy and configure NetApp storage without having to understand how to use the REST API's or develop code. Hope that's useful (or atleast interesting to know about). Please let me know if you have any questions.

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

vajjarap
6,293 Views

Hi, 

Is there a way to get the junction path using uuid of a volume?

It is not showing under nas section : nas.path. though the volume is mounted.




 

 

a613965
5,730 Views

Hello !
I have the same issue : I am looking for getting the junction path through REST API but no way until now ! 😮
I am using ONTAP 9.8

vajjarap
5,727 Views

I have figured out...  we can use "Enter" to unmount the volume.

variable= input("Press Enter to Unmount")
nasjson = {
"path": path,
}
dataobj['nas'] = nasjson
sample_url = "https://{}/api/storage/volumes/{}?return_timeout=15" .format(cluster, vol_uuid)
result = get_res(cluster,sample_url,dataobj,headers_inc)

if result[1] == "success":
print(unmounted)
else:
print("respone",result[0])

Public