The NetApp Manageability SDK, usually shortened to NMSDK, contains the libraries used by many applications to connect and execute actions against NetApp systems. It has libraries for, among others, Java, .NET, Perl, Python, Ruby, and compiled C/C++ binaries for various *nix flavors as well, which means that regardless of your platform, you can write applications and scripts against the NetApp API.

Docker, and containers in general, are great for providing application packaging and the ability to easily distribute an application to any Linux server with a compatible kernel. In order to facilitate this, I have created Dockerfiles for the three scripting languages: Perl, Python, and Ruby. To create the Docker images you will need to download the NMSDK zip file and place it into the same directory as the Dockerfile. Then simply build the image as normal.

For the first Dockerfile (Python) I’ll provide an example of how to build the container image and how to use it. This principle remains the same for the others (Perl and Ruby), so simply duplicate for those.

Python

The Dockerfile:

# The NetApp Manageability SDK (NMSDK) Python modules - containerized
# Copyright 2016 NetApp, Inc.
#
# To create this container you'll need the NMSDK zip file from http://nt-ap.com/1lyiLtM
# Download the file, put it in the same directory as the Dockerfile, then do a standard
# build: docker build -t you/nmsdk-python .
#
FROM python:latest

MAINTAINER Andrew Sullivan asulliva@netapp.com

ADD netapp-manageability-sdk-5.4P1.zip /nmsdk/nmsdk.zip
RUN apt-get update && \
    apt-get install -y unzip && apt-get clean -y && \
    unzip -j /nmsdk/nmsdk.zip "netapp*/lib/python/NetApp/*.py" -d /nmsdk && \
    rm -f /nmsdk/nmsdk.zip

ENV PYTHONPATH "/nmsdk"

Creating the Docker image is straight forward:

[andrew@host1 ~]# docker build -t your_registry:5000/nmsdk-python:5.4 .
Sending build context to Docker daemon 163.3 MB
Step 0 : FROM python:latest
Trying to pull repository docker.io/library/python ... latest: Pulling from library/python
6d1ae97ee388: Pull complete
.
.
.
bde90ee986a2: Pull complete
Digest: sha256:32f4fc4ac4f63fc5219ae57992a2e80d30dd05165c30111f61200527f726a291
Status: Downloaded newer image for docker.io/python:latest

 ---> bde90ee986a2
Step 1 : MAINTAINER Andrew Sullivan asulliva@netapp.com
 ---> Running in 6e2f1c0a6cf5
 ---> f892b1885d1e
Removing intermediate container 6e2f1c0a6cf5
Step 2 : ADD netapp-manageability-sdk-5.4P1.zip /nmsdk/nmsdk.zip
 ---> 941af99e7c83
Removing intermediate container a669f0ae5a07
Step 3 : RUN apt-get update && apt-get install -y unzip && apt-get ...
 ---> Running in b4079f7947f3
.
.
.
Setting up unzip (6.0-16+deb8u2) ...
Archive:  /nmsdk/nmsdk.zip
  inflating: /nmsdk/DfmErrno.py
  inflating: /nmsdk/NaElement.py
  inflating: /nmsdk/NaErrno.py
  inflating: /nmsdk/NaServer.py
 ---> 1b5cbb7bb6ed
Removing intermediate container b4079f7947f3
Step 4 : ENV PYTHONPATH "/nmsdk"
 ---> Running in d5fef81d090a
 ---> 674812059eb8
Removing intermediate container d5fef81d090a
Successfully built 674812059eb8

And now we can add the tagged image to the private Registry:

docker push your_registry:5000/nmsdk-python:5.4

Once the image is available, we can create additional images using it as a base. First, we need a Python script to execute using the NMSDK. This example Python script, available below, will need to be placed into the same directory as the Dockerfile before building.

#!/usr/local/bin/python
#
# A sample script using the Python NMSDK
#
# Copyright 2016 NetApp, Inc.
#
from NaServer import *

hostname = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]

ntap = NaServer(hostname, 1, 1)
ntap.set_server_type("Filer")
ntap.set_transport_type("HTTP")
ntap.set_admin_user(username, password)

result = ntap.invoke("system-get-version")

if (result.results_errno() != 0):
   print("An error occurred: \n" + str(result.results_reason()))

else :
   print("ONTAP Version: " + result.child_get_string("version") + "\n")
# An example of using the nmsdk-python container.
# Copyright 2016 NetApp, Inc.
#
# After building the nmsdk-python container, build the ONTAPI test
# in the same way: docker build -t your_registry:5000/testontapi-python .
#
# To see it in action, execute the container:
#   docker run --rm your_registry/testontapi-python your.netapp admin Pa$$w0rd
#
FROM your_registry:5000/nmsdk-python:5.4

ADD testontapi.py /opt/netapp/testontapi.py

ENTRYPOINT ["python", "/opt/netapp/testontapi.py"]
CMD [""]

Once we have the script and Dockerfile, simply build the container. One interesting thing to note, by setting the ENTRYPOINT value to the path of the script, and the CMD value to empty, we can execute the container just like a CLI script:

This is only an example of how to use the NMSDK without having the respective language or libraries installed directly to the system. You could also use this to create a microservice or a server based application if desired.

Other Languages

Perl

# The NetApp Manageability SDK (NMSDK) Perl modules - containerized
# Copyright 2016 NetApp, Inc.
#
# To create this container you'll need the NMSDK zip file from http://nt-ap.com/1lyiLtM
# Download the file, put it in the same directory as the Dockerfile, then do a standard
# build: docker build -t you/nmsdk-perl .
#
FROM perl:latest

MAINTAINER Andrew Sullivan asulliva@netapp.com

ADD netapp-manageability-sdk-5.4P1.zip /nmsdk/nmsdk.zip
RUN cpanm LWP::UserAgent XML::Parser Net::SSLeay Socket Switch && \
    apt-get update && \
    apt-get install -y unzip && apt-get clean -y && \
    unzip -j /nmsdk/nmsdk.zip "netapp*/lib/perl/NetApp/*.pm" -d /nmsdk && \
    rm -f /nmsdk/nmsdk.zip

ENV PERLLIB "/usr/share/perl5:/nmsdk"

Ruby

# The NetApp Manageability SDK (NMSDK) Ruby modules - containerized
# Copyright 2016 NetApp, Inc.
#
# To create this container you'll need the NMSDK zip file from http://nt-ap.com/1lyiLtM
# Download the file, put it in the same directory as the Dockerfile, then do a standard
# build: docker build -t you/nmsdk-rb .
#
FROM ruby:latest

MAINTAINER Andrew Sullivan asulliva@netapp.com

ADD netapp-manageability-sdk-5.4P1.zip /nmsdk/nmsdk.zip
RUN apt-get update && \
    apt-get install -y unzip && apt-get clean -y && \
    unzip -j /nmsdk/nmsdk.zip "netapp*/lib/ruby/NetApp/*.rb" -d /nmsdk && \
    rm -f /nmsdk/nmsdk.zip

ENV RUBYLIB "/nmsdk"

If you have any questions or suggestions, please don’t hesitate to reach out to me using the comments below or via Slack.

Andrew Sullivan on GithubAndrew Sullivan on Twitter
Andrew Sullivan
Technical Marketing Engineer at NetApp
Andrew has worked in the information technology industry for over 10 years, with a rich history of database development, DevOps experience, and virtualization. He is currently focused on storage and virtualization automation, and driving simplicity into everyday workflows.