#How do I get the number of luns in every volume in netapp ontap?

1 messages · Page 1 of 1 (latest)

fervent gate
#

I am trying to find how to get the number of luns in each volume. This is my draft but I cannot get it to work, could someone let me know why it is being skipped?

  • name: Get all LUNs from clusters
    na_ontap_rest_info:
    gather_subset:
    - "storage/luns"
    fields:
    - "svm"
    use_python_keys: true
    register: ontap_volumes2
  • name: Print volume details
    debug:
    msg:
    - "LUNS: {{ item.name }}"
    loop:
    "{{ ontap_volumes2.ontap_info.storage_luns.records }}"
    loop_control:
    label: "{{ item.name }}"
    register: number_luns
  • name: Count LUNs
    set_fact:
    counter: "{{ counter | default(0) | int + 1 }}"
    loop:
    "{{ ontap_volumes.ontap_info.storage_volumes.records }}"
    loop_control:
    label: "{{ item.name }}"
    when: item.name in number_luns
fast summit
#

You don't have to count with a loop. Just get the size of the records list.

set_fact: "{{ ontap_volumes.ontap_info.storage_volumes.records |length }}"

fervent gate
#

‘ - name: Get all non-root volumes from clusters
na_ontap_rest_info:
gather_subset:
- "storage/volumes"
fields:
- "svm"
- "clone"
- "space"
parameters:
is_svm_root: false
use_python_keys: true
register: ontap_volumes

  • name: Number of LUN
    set_fact: "{{ ontap_volumes.ontap_info.storage_volumes.records |length }}"
    register: num_lun’
#

Are there any other things in the gather_subset and fields I should be including?

#

Sorry for the bad formatting I can’t seem to get the code block right on mobile

topaz ginkgo
#

the exampe you have show storage/volumes which is going to return volumes and not lun

prisma nebula
#

storage/luns then num_records

fast summit
#

I totally forgot that num_records exists 😅

Updated example using the correct variables provided in the question
set_fact: "{{ ontap_volumes2.ontap_info.storage_luns.num_records }}"

fervent gate
#

Hello thank you for your responses but it seems that it shows the total number of luns in the cluster but not for the specific volume looped item

fervent gate
fast summit
#

Yes that is possible. LUN information does contain the volume name, so you can do something like this:

` - name: get luns
na_ontap_rest_info:
gather_subset: storage/luns
use_python_keys: true
fields:
- location
register: luns

  • debug:
    msg: "{{ luns.ontap_info.storage_luns.records | selectattr('location.volume.name','equalto','your-volume-name') |length }}"`
topaz ginkgo
#

If you only need the info for a single volume you could simpliy the above with

` - name: get luns
na_ontap_rest_info:
gather_subset: storage/luns
use_python_keys: true
fields:
- location
parameters:
location.volume.name: <volume name>
register: luns

  • debug:
    msg: "{{ luns.ontap_info.storage_luns.num_records }}"`
fervent gate
#

Thank you for your help, but what I am trying to do it try to do is, I want to create a new lun so I want to find the volume that can hold it. I want to find the number of luns for every volume and see if the volume has not reached 4 luns for example, if it did not then place the new lun in that volume if not I will create a new volume. So that’s why I am trying to find the number of luns in all volumes.

fast summit
#

Now it makes sense why you tried to loop in the first place. Coming back to that idea you can use my provided example to loop through all volumes, select the luns in that volume and write the count result to a new variable.

` - name: get volumes
netapp.ontap.na_ontap_rest_info:
gather_subset: storage/volumes
use_python_keys: true
hal_linking: false
register: volumes

  • name: get luns
    netapp.ontap.na_ontap_rest_info:
    gather_subset: storage/luns
    use_python_keys: true
    hal_linking: false
    fields:
    - location
    register: luns

  • ansible.builtin.set_fact:
    count_lun: "{{ count_lun |default({}) |combine({ item.name: (luns.ontap_info.storage_luns.records | selectattr('location.volume.name','equalto',item.name) |length) }) }}"
    loop: "{{ volumes.ontap_info.storage_volumes.records }}"`

This will return a list with all your volumes and the number of LUNs of each volume.
"count_lun": { "foo": 2, "foo2": 1, "rootvol": 0, "test001": 0 }

fervent gate
#

yes thanks a lot that did ! it helped a lot, much appreciated

fervent gate
#

I am trying to do the same to find the list of Volumes inside an SVM. I tried applying the same logic but it did not work. Is it possible to point me to what did I do wrong?

` - name: Get all non-root volumes from cluster
include_tasks: tasks/get_cluster_info_rest.yaml
vars:
gather_subset:
- storage/volumes
fields: ['*']
parameters:
is_svm_root: false

- name: Set SVM Variable
  ansible.builtin.set_fact:
      svm: "SVM_{{ cluster_id }}_{{ db_type }}_{{ infra_type }}_{{ oracle_cluster_id }}"

- name: output
  debug:
    msg: "{{ item }}"
  loop: "{{ ontap_rest_info['storage/volumes']['records']}}"
  
- name: Get all volumes from SVM
  ansible.builtin.set_fact:
    vol_list: "{{ item | selectattr('svm.name','equalto',svm) }}"
  loop: "{{ ontap_rest_info['storage/volumes']['records']}}"
  no_log: false

- name: output
  debug:
    msg: "{{ vol_list }}"`
#

I get
TASK [Get all volumes from SVM] *************************************************************************************************************************************************************************************************************************************************************************** [WARNING]: TASK: Get all volumes from SVM: The loop variable 'item' is already in use. You should set the loop_varvalue in theloop_control option for the task to something else to avoid variable collisions and unexpected behavior. fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'svm'. 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'svm'\n\nThe error appears to be in '/home/user/role/tasks/create_vol.yaml': line 22, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Get all volumes from SVM\n ^ here\n"}

topaz ginkgo
half hedge
#

Here is my playbook that counts LIFs per node in a cluster. It should count LUNs per volume in a cluster with trivial changes

half hedge