<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NFS status using python API in Python Discussions</title>
    <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/122313#M6</link>
    <description>&lt;P&gt;seems that i was doing something wrongly in the first place.&lt;/P&gt;&lt;P&gt;So far it seems to work. Maybe a problem between keyboard and chair.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Aug 2016 13:04:41 GMT</pubDate>
    <dc:creator>python_API_and_NFS_status</dc:creator>
    <dc:date>2016-08-15T13:04:41Z</dc:date>
    <item>
      <title>NFS status using python API</title>
      <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/117960#M1</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just started with experimenting with python API for netapp, however, when i used the example nfs.py (from API documentation), the results are quite unexpected. Mainly i mean the example for getting the nfs status from the netapp.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just took the example script and run it, however i get "NFS status: disabled" instead of enabled. When i try the same powershell script (also provided from API docu), the result is expected "NFS: enabled"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have anybody seen this behavior? Is it a bug in API? or i'm missing something else?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried it with python3 (3.4.3) and python2 (2.7.10). both is getting the same output "nfs disabled" even if the NFS is enabled.&lt;/P&gt;&lt;P&gt;(unfortunately it's not on linux machine, but run under cygwin)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/python3

#=======================================================================#
#                                                                       #
# $ID$                                                                  #
#                                                                       #
# nfs.py                                                                #
#                                                                       #
# Sample code for the following APIs:                                   #
#               nfs-enable, nfs-disable                                 #
#               nfs-status, nfs-exportfs-list-rules,                    #
#                                                                       #
#                                                                       #
#                                                                       #
# Copyright 2011 Network Appliance, Inc. All rights                     #
# reserved. Specifications subject to change without notice.            #
#                                                                       #
# This SDK sample code is provided AS IS, with no support or            #
# warranties of any kind, including but not limited to                  #
# warranties of merchantability or fitness of any kind,                 #
# expressed or implied.  This code is subject to the license            #
# agreement that accompanies the SDK.                                   #
#=======================================================================#


import re
import sys
sys.path.append("./NetApp")
from NaServer import *

def print_usage():
    print ("Usage:\n")
    print ("nfs.py &amp;lt;filer&amp;gt; &amp;lt;user&amp;gt; &amp;lt;password&amp;gt; &amp;lt;command&amp;gt;\n")
    print ("&amp;lt;filer&amp;gt; -- Filer name\n")
    print ("&amp;lt;user&amp;gt; -- User name\n")
    print ("&amp;lt;password&amp;gt; -- Password\n")
    print ("&amp;lt;command&amp;gt; -- enable, disable, status, list\n")
    sys.exit(2)


def do_nfs():
    s = NaServer(filer, 1, 3)
    out = s.set_transport_type('HTTPS')

    if(out and (out.results_errno() != 0)) :
        r = out.results_reason()
        print("Connection to filer failed" + r + "\n")
        sys.exit(2)

    out = s.set_style('LOGIN')

    if( out and (out.results_errno() != 0)):

        r = out.results_reason()
        print("Connection to filer failed" + r + "\n")
        sys.exit(2)

    out = s.set_admin_user(user, pw)

    if(cmd == "enable"):
        out = s.invoke("nfs-enable")

        if(out.results_status() == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)

        else:
            print("Operation successful\n")

    elif (cmd == "disable"):
        out = s.invoke("nfs=disable")
gv[4]&lt;BR /&gt;do_nfs()&lt;BR /&gt;&lt;BR /&gt;$ ./nfs.py hostname "user" "password" status&lt;BR /&gt;NFS Server is disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:gv[4]&lt;BR /&gt;do_nfs()&lt;BR /&gt;&lt;BR /&gt;$ ./nfs.py hostname "user" "password" status&lt;BR /&gt;NFS Server is disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:&lt;BR /&gt;&lt;BR /&gt;
        if(out.results_status == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)

        else:
            print("Operation successful\n")

    elif (cmd == "status"):
        out = s.invoke("nfs-status")

        if(out.results_status == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)

        enabled = out.child_get_string("is-enabled")

        if(enabled == "true"):
            print("NFS Server is enabled\n")

        else:
            print("NFS Server is disabled\n")

    elif ( cmd == "list") :
        out = s.invoke( "nfs-exportfs-list-rules" )
        export_info = out.child_get("rules")

        if(export_info):
            result = export_info.children_get()

        else :
            sys.exit(2)

        for export in result:
            path_name = export.child_get_string("pathname")
            rw_list = "rw="
            ro_list = "ro="
            root_list = "root="
            if(export.child_get("read-only")):
                ro_results = export.child_get("read-only")
                ro_hosts = ro_results.children_get()
                for ro in ro_hosts:

                    if(ro.child_get_string("all-hosts")):
                        all_hosts = ro.child_get_string("all-hosts")

                        if(all_hosts == "true") :
                            ro_list = ro_list + "all-hosts"
                            break

                    elif(ro.child_get_string("name")) :
                        host_name = ro.child_get_string("name")
                        ro_list = ro_list + host_name + ":"

            if(export.child_get("read-write")):
                rw_results = export.child_get("read-write")
                rw_hosts = rw_results.children_get()
                for rw in rw_hosts:

                    if(rw.child_get_string("all-hosts")):
                        all_hosts = rw.child_get_string("all-hosts")

                        if(all_hosts == "true") :
                            rw_list = rw_list + "all-hosts"
                            break

                    elif(rw.child_get_string("name")):
                        host_name = rw.child_get_string("name")
                        rw_list = rw_list + host_name + ":"

            if(export.child_get("root")):
                root_results = export.child_get("root")
                root_hosts = root_results.children_get()

                for root in root_hosts:

                    if(root.child_get_string("all-hosts")):
                        all_hosts = root.child_get_string("all-hosts")
gv[4]&lt;BR /&gt;do_nfs()&lt;BR /&gt;&lt;BR /&gt;$ ./nfs.py hostname "user" "password" status&lt;BR /&gt;NFS Server is disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:gv[4]&lt;BR /&gt;do_nfs()&lt;BR /&gt;&lt;BR /&gt;$ ./nfs.py hostname "user" "password" status&lt;BR /&gt;NFS Server is disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:gv[4]&lt;BR /&gt;do_nfs()&lt;BR /&gt;&lt;BR /&gt;$ ./nfs.py hostname "user" "password" status&lt;BR /&gt;NFS Server is disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
                        if(all_hosts == "true"):
                            root_list = root_list + "all-hosts"
                            break

                    elif(root.child_get_string("name")):
                        host_name = root.child_get_string("name")
                        root_list = root_list + host_name + ":"

            path_name = path_name + "  "

            if(ro_list != "ro="):
                path_name = path_name + ro_list

            if(rw_list != "rw=") :
                path_name = path_name + "," + rw_list

            if(root_list != "root="):
                path_name = path_name + "," + root_list

            print(path_name + "\n")

    else :
        print ("Invalid operation\n")
        print_usage()

args = len(sys.argv) - 1

if(args &amp;lt; 4):
    print_usage()

filer = sys.argv[1]
user = sys.argv[2]
pw = sys.argv[3]
cmd = sys.argv[4]&lt;BR /&gt;do_nfs()&lt;BR /&gt;&lt;BR /&gt;$ ./nfs.py hostname "user" "password" status&lt;BR /&gt;NFS Server is disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:&lt;BR /&gt;gv[4]
do_nfs()&lt;/PRE&gt;&lt;PRE&gt;$ ./nfs.py hostname "user" "password" status
NFS Server is disabled&lt;BR /&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here is the same test, but using nfs.ps1 from API:&lt;/P&gt;&lt;PRE&gt;PS C:\Users\CZZ02012\Documents&amp;gt; .\nfs.ps1 hostname "user" "password" status
NFS Server is enabled&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Jun 2025 21:33:25 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/117960#M1</guid>
      <dc:creator>python_API_and_NFS_status</dc:creator>
      <dc:date>2025-06-04T21:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: NFS status using python API</title>
      <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/119611#M2</link>
      <description>&lt;P&gt;Can you fix the formatting of your message, I think it's all over the place, it would help understanding!&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:38:42 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/119611#M2</guid>
      <dc:creator>yannb</dc:creator>
      <dc:date>2016-05-25T15:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: NFS status using python API</title>
      <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/121877#M3</link>
      <description>&lt;P&gt;Not sure if you are still chasing help with this, but start with the typo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;out = s.invoke("nfs=disable")&lt;/PRE&gt;&lt;P&gt;should be&lt;/P&gt;&lt;PRE&gt;out = s.invoke("nfs-disable")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a type on the NetApp example&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Jul 2016 11:41:13 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/121877#M3</guid>
      <dc:creator>cams</dc:creator>
      <dc:date>2016-07-31T11:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: NFS status using python API</title>
      <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/121951#M4</link>
      <description>&lt;P&gt;Are you executing this against a 7-mode or clustered Data ONTAP system? &amp;nbsp;With cDOT the results may be unpredictable since the NFS server belongs to the SVM and there can be more than one SVM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a python snippet which will print the NFS server and protocol status for each SVM which has the NFS protocol. &amp;nbsp;Note that if NFS has not been "enabled"&amp;nbsp;for the SVM, regardless of the status of the service, it won't show up in this listing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;print("{:20s} {:12s} {:6s} {:6s} {:6s} {:6s}".format(
    "SVM",
    "NFS Enabled",
    "v2",
    "v3",
    "v4.0",
    "v4.1"))

result = server.invoke('nfs-service-get-iter')

if result.results_status() == "failed":
    reason = result.results_reason()
    print( reason + "\n" )
    sys.exit(2)

if result.child_get_int('num-records') == 0:
    print( "No SVMs returned" )
    sys.exit(0)

for service in result.child_get('attributes-list').children_get():
    svm_name = service.child_get_string('vserver')
    svm_nfs2_status = service.child_get_string('is-nfsv2-enabled');
    svm_nfs3_status = service.child_get_string('is-nfsv3-enabled');
    svm_nfs40_status = service.child_get_string('is-nfsv40-enabled');
    svm_nfs41_status = service.child_get_string('is-nfsv41-enabled');
    
    server.set_vserver(svm_name)
    query = server.invoke('nfs-status')
    svm_nfs_enabled = query.child_get_string('is-enabled')
    
    print("{:20s} {:12s} {:6s} {:6s} {:6s} {:6s}".format(
        svm_name,
        svm_nfs_enabled,
        svm_nfs2_status,
        svm_nfs3_status,
        svm_nfs40_status,
        svm_nfs41_status))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, if you're executing against the SVM directly you wouldn't use the "nfs-service-get-iter" API against the cluster mangement interface, rather you would use the "nfs-service-get" API against the SVM management interface. &amp;nbsp;Just a subtle difference between them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;print("{:20s} {:12s} {:6s} {:6s} {:6s} {:6s}".format(
    "SVM",
    "NFS Enabled",
    "v2",
    "v3",
    "v4.0",
    "v4.1"))

result = server.invoke('nfs-service-get')

if result.results_status() == "failed":
    reason = result.results_reason()
    print( reason + "\n" )
    sys.exit(2)

for service in result.child_get('attributes').children_get():
    svm_name = service.child_get_string('vserver')
    svm_nfs2_status = service.child_get_string('is-nfsv2-enabled');
    svm_nfs3_status = service.child_get_string('is-nfsv3-enabled');
    svm_nfs40_status = service.child_get_string('is-nfsv40-enabled');
    svm_nfs41_status = service.child_get_string('is-nfsv41-enabled');
    
    query = server.invoke('nfs-status')
    svm_nfs_enabled = query.child_get_string('is-enabled')
    
    print("{:20s} {:12s} {:6s} {:6s} {:6s} {:6s}".format(
        svm_name,
        svm_nfs_enabled,
        svm_nfs2_status,
        svm_nfs3_status,
        svm_nfs40_status,
        svm_nfs41_status))&lt;/PRE&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 17:52:56 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/121951#M4</guid>
      <dc:creator>asulliva</dc:creator>
      <dc:date>2016-08-02T17:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: NFS status using python API</title>
      <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/122312#M5</link>
      <description>&lt;P&gt;Hello, testing it agains 7-mode only. We dont have cDot yet.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 13:01:47 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/122312#M5</guid>
      <dc:creator>python_API_and_NFS_status</dc:creator>
      <dc:date>2016-08-15T13:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: NFS status using python API</title>
      <link>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/122313#M6</link>
      <description>&lt;P&gt;seems that i was doing something wrongly in the first place.&lt;/P&gt;&lt;P&gt;So far it seems to work. Maybe a problem between keyboard and chair.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 13:04:41 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/NFS-status-using-python-API/m-p/122313#M6</guid>
      <dc:creator>python_API_and_NFS_status</dc:creator>
      <dc:date>2016-08-15T13:04:41Z</dc:date>
    </item>
  </channel>
</rss>

