3 Replies Latest reply: Jul 8, 2013 10:53 AM by zulanch RSS

Using PowerShell Cmdlets

scottfoley
Currently Being Moderated

I have begun using the NetApp API and am wondering if I am missing documentation or using a lesser preferred programming language.  I initially wanted to use c# to call the API and got a test program working, but it seems that NetApp wants things to go through PowerShell.  The only sample source code is for PowerShell Cmdlets.  There is none in the current documentation for using c# directly. 

   

I got the Cmdlet Get_VolumeListInfo from the sample in netapp-manageability-sdk-5.1-dotnet-bindings working.  The documentation in netapp-manageability-sdk-ontap-api-documentation/ontapi_1.20/7-Mode references volume-list-info and the sample uses VolumeListInfo volinput = new VolumeListInfo();. Is there better documentation for Cmdlets and c#?

 

In adding to the Cmdlet I can’t seem to get snapshot-list-info working.     

  SnapshotListInfo snapinput = new SnapshotListInfo(); 

  SnapshotListInfoResult snapoutput = snapinput.Invoke(Server);  

  SnapshotInfo[] snapshots = snapoutput.Snapshots;

 

The Cmdlet throws an error saying that “Either argument volume or (target-name, target-type) pair should be specified”  The documentation refers to using the volume as input, but I am not sure where to supply the volume name.  There are no samples.  Perhaps there is a slight learning curve, so my real question is if many others are using Cmdlets in c# to access the NetApp API?  I get very few results searching for things like SnapshotListInfoResult and NetApp c# api.  Is there a preferred language that most people are using?  I want the ability to do more things than I believe calling PowerShell directly can do.   

 

Thanks,

Scott

  • Re: Using PowerShell Cmdlets
    skiser@tep.com
    Currently Being Moderated

    Scott,

     

    I can't speak for c#, but the PowerShell Cmdlets for NetApp are pretty full featured.  You can do just about anything through the PowerShell Cmdlets that you can do through OnCommand System Manager or SSH/console.  PowerShell is also pretty easy to learn.  I have never been a programmer, but I started using PowerShell a couple of years ago and have created some pretty elaborate scripts with it (for both NetApp and VMware).  Two examples are using the PowerShell Cmdlets to create both source and destination volumes, with a mirror between both (https://communities.netapp.com/docs/DOC-23751) and restoring a VM from an NFS datastore using SnapRestore (https://communities.netapp.com/docs/DOC-23783).

     

    Help files in Powershell are also built in.  If you are not sure of how a particular Cmdlet works, you can just use Get-Help <Cmdlet name>.  You can also use Get-Help <Cmdlet name> -examples to see some usage examples.

     

    A sample script to get snapshot info would be:

     

    Connect-NaController <FilerName> #connect to Filer

    $vols = Get-NaVol #get a list of volumes to pass to the Get-NaSnapshot Cmdlet

    ForEach ($vol in $vols) {

      $snaps = Get-NaSnapshot $vol #get the list of Snapshots for each volume

      $snaps #display the Snapshot list on the screen

    }

     

    Hope that helps.

    -Steve

    • Re: Using PowerShell Cmdlets
      scottfoley
      Currently Being Moderated

      You are using  Cmdlets that NetApp has provided.  I am trying to write my own Cmdlets.  Perhaps I need to look more at what NetApp has written.  My real goal is to have programs run from scheduled tasks (or called from a web page) to get information from multiple NetApps and store it in a database or display it in a web page.  Right now I just remotely run a cli command on the NetApp and parse the output.  Having an API for the NetApp is much easier, but it seems too limiting in some areas.       

      • Re: Using PowerShell Cmdlets
        zulanch
        Currently Being Moderated

        Hi Scott,

         

        You might find it easier to use the more popular ManageOntap.dll .NET library included with the  SDK rather than the .NET bindings. There is sample code for C# in netapp-manageability-sdk-5.1\src\sample\Data_ONTAP\DotNet\CSharp. The "snapman" sample project has an example of calling the snapshot-list-info API.

         

        If you want to stick with the .NET bindings, you can specify a volume like this:

         

        SnapshotListInfo snapinput = new SnapshotListInfo();
        snapinput.Volume = "vol0";
        

         

        The "properties" section under the API class name in the help documentation has the full list of parameters for API classes.

         

        Thanks,

         

        Ben

More Like This

  • Retrieving data ...