search
top

Retrieving NFS Export Data on Isilon with RESTful API and PowerShell

Introduction

In an earlier post we covered using RESTful API calls to EMC Isilon to retrieve quota data. In this post we will make the same calls but gather data on NFS exports for screen output as well and optional CSV output.

Prerequisites

To be able to execute RESTful API calls to Isilon you will need to create an account and add the appropriate roles. For GET operations a read-only account is all that you will need. For this post we will create a local group and grant Platform API and NFS read-only roles.

The Code

So now lets get down to the meat of the post and the code we need to execute the RESTful API calls in PowerShell for Isilon.

 

<# 
 .SYNOPSIS 
 This script will Retrieve NFS exports and output path, and clients off Isilon using RestfulAPI.
 
 .DESCRIPTION 
 This script will Retrieve NFS exports and output path, and clients off Isilon using RestfulAPI.
 
 .NOTES 
 File Name : getisilonexports.ps1
 Author : Me
 Version : 1.0 (June 14, 2018 )
 
 .OUTPUTS 
 Screen Output. can be modified to save to csv 
 
 .EXAMPLE 
 C:\PS> .\getisilonexports.ps1 
 
#>

add-type @"
 using System.Net;
 using System.Security.Cryptography.X509Certificates;
 public class TrustAllCertsPolicy : ICertificatePolicy {
 public bool CheckValidationResult(
 ServicePoint srvPoint, X509Certificate certificate,
 WebRequest request, int certificateProblem) {
 return true;
 }
 }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$username = 'root'
$password = 'passw0rd'
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($username + ':' + $password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}

# create Uri
# Change IP address to that of the target Isilon.
$baseurl = 'https://xxx.xx.xxx.xxx:8080' 
$resourceurl = "/platform/1/protocols/nfs/exports/"
$uri = $baseurl + $resourceurl

# get export and print
$ISIObject = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

# Uncomment below and comment out bottom line to export to csv
# $ISIObject.quotas | select-object -Property path,@{Name="Advisory Threshold GB";E={($_.thresholds.advisory/1GB)}},@{Name="Hard Threshold GB";E={($_.thresholds.hard/1GB)}},@{Name="Usage GB";E={"{0:N}" -f ($_.usage.logical/1GB) -as [float]}} | Export-Csv -Path c:\temp\quotas.csv

$ISIObject.quotas | select-object -Property path,@{Name="Advisory Threshold GB";E={($_.thresholds.advisory/1GB)}},@{Name="Hard Threshold GB";E={($_.thresholds.hard/1GB)}},@{Name="Usage GB";E={"{0:N}" -f ($_.usage.logical/1GB) -as [float]}}

 

Let’s take a deeper look into the code example what it is doing. The first part of the script is setting the security to be able to connect to your Isilon array. This code is not original, I found this at code from blogs.msdn.com. Just copy and paste this section and change the username and password. This will work for any other RESTful API in PowerShell using Basic Authentication.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$username = 'root'
$password = 'passw0rd'
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($username + ':' + $password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}

Next section of the code we will setup our URI (Uniform Resource Identifier).  we will identify three variables called $baseurl, $resourceurl and $uri. The $baseurl is the https ip address of the Isilon node you want to run the query against. For the $resourceurl variable we will be using the /platform/1/nfs/exports resource path. You can get a list of all available resource available from EMC RestfulAPI documentation for Isilon. The final $uri is the combining of the two previous variables.

# create Uri
# Change IP address to that of the target Isilon in $baseurl
$baseurl = 'https://xxx.xxx.xxx.xxx:8080' 
$resourceurl = "/platform/1/protocols/nfs/exports/"
$uri = $baseurl + $resourceurl

Next section of the code we are going to create an object and make a Invoke-RestMethod cmdlet and GET action using security for authentication.

$ISIObject = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

Now we are ready to get the output.

# Uncomment below and comment out bottom line to export to csv

# $ISIObject.exports | Select paths,clients | Export-Csv -Path c:\temp\nfsexports.csv

$ISIObject.exports | Select paths,clients

 

The output from the scripts.

restfulnfsisilon

There are more fields available for output. By not adding the select statement we will get the full output available.

all_dirs : 
block_size : 
can_set_time : 
clients : 
commit_asynchronous : 
conflicting_paths : 
description : 
directory_transfer_size : 
encoding : 
id : 
map_all : 
map_full : 
map_lookup_uid : 
map_retry : 
map_root : 
max_file_size : 
paths : 
read_only : 
read_only_clients : 
read_transfer_max_size : 
read_transfer_multiple : 
read_transfer_size : 
read_write_clients : 
readdirplus : True
readdirplus_prefetch : 
return_32bit_file_ids : 
root_clients : 
security_flavors :
setattr_asynchronous : 
snapshot : -
symlinks : True
time_delta : 
unresolved_clients : 
write_datasync_action : 
write_datasync_reply : 
write_filesync_action : 
write_filesync_reply : 
write_transfer_max_size : 
write_transfer_multiple : 
write_transfer_size : 
write_unstable_action : 
write_unstable_reply :

From the available output we can add much more to the output. All you have to do is to add the fields to the select statement.

Download the code from getisilonqutas. File is a txt, just rename to .ps1

Conclusion

So we have explored making a basic Restful API call to Isilon to get specific NFS export information. You can also change the output by exploring the different fields available from the output.

9 Responses to “Retrieving NFS Export Data on Isilon with RESTful API and PowerShell”

  1. Jery says:

    Hi,
    Thanks for the useful info. I am not a storage techie so would like to get your help with something.

    Is there a way to get the logical and physical size of a particular folder?

    For example : /ifs/data/XXxxxx/XXXX/Redirected//username

    Thanks in advance,
    Jery.

    • newlife007 says:

      At the command line you can get the size of a directory by running du -sh /ifs/data/XXxxxx/XXXX/Redirected//username that will give you the total used for the directory in question and all it’s subs. Not sure what you are refferring to with logical and physical since Isilon is a scale out nas and storage from all nodes are shared. If you are using quotas you can use the isi quota quotas view –path=/ifs/data/XXxxxx/XXXX/Redirected//username –type=directory and that will give you something to what you are looking for.

  2. Jery says:

    Hi,
    Thanks for the prompt response.
    du -sh /ifs/data/XXxxxx/XXXX/Redirected/username gave the required output. Is it possible to run this from windows machine using powershell and RESTful api?
    When we used the api to list quotas we got the below info.
    usage : @{inodes=64; logical=10892288; physical=18095104}
    I think this is equivalent to the “Size” and “Size on Disk” when we view the properties in a windows explorer.

    Once again thanks a lot for all your kind help.
    Jery

  3. Jery says:

    Hi,
    Thanks for the prompt response.
    du -sh /ifs/data/XXxxxx/XXXX/Redirected/username gave the required output. Is it possible to run this from windows machine using powershell and RESTful api?
    When we used the api to list quotas we got the below info.
    usage : @{inodes=64; logical=10892288; physical=18095104}
    I think this is equivalent to the “Size” and “Size on Disk” when we view the properties in a windows explorer.

    Once again thanks a lot for all your kind help.
    Jery

    • newlife007 says:

      Jery,
      That may not be possible with Isilon RestAPI but what you could do is map a drive to Isilon on your system and then use PowerShell cmdlets (Get-ChildItem, and wmi calls to do the same as dh -sh command. Give me a bit and I maybe able to get you a script to do so.

      Mark

      • Jery says:

        Hi newlife007,

        Thanks for the response. I did try that but it gives me only the “Size” not the “Size on Disk” which is the actual usage. I think the best way for us would be to turn on quotas and get the info from that. By the way, I was able to leverage the POSH-SSH module for powershell and get the du -Ash and du -sh to get the info. Will post the script if you are interested.

        Thanks again for all the help.
        Jery.

  4. shashidhar says:

    I’m unable to retrive multiple accesszones NFS exports – needed NFS export View command output

    • newlife007 says:

      I wrote this about 4 years ago and have lost access to the Isilon I used to work on. I am looking into the simulator to see if I can recreate and see how to look in access zones. Let me see what I can find. What version of OneFS are you running?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top