//This function will remove a role from an administrator
        static void AdminRoleDelete()
        {
            if (Args.Length < 6)
            {
                Usage();
            }

            String adminNameID = Args[4];
            String rolenameID  = Args[5];

            try
            {
                // create the input rbac-admin-role-remove API request
                NaElement input = new NaElement("rbac-admin-role-remove");
                input.AddNewChild("admin-name-or-id", adminNameID);
                //check for the role name or delete all roles
                input.AddNewChild("role-name-or-id", rolenameID);
                // invoke the API request
                NaElement output = server.InvokeElem(input);
                Console.WriteLine("admin role(s) deleted successfully! ");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #2
0
        static void Delete()
        {
            String dfmSchedule = Args[4];

            try {
                // invoking the api && printing the xml ouput
                NaElement input = new NaElement("dfm-schedule-destroy");
                input.AddNewChild("schedule-name-or-id", dfmSchedule);
                input.AddNewChild("schedule-category", "dfm_schedule");
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nSchedule deletion "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        //This function will add a new role to the RBAC system
        static void RoleAdd()
        {
            if (Args.Length != 6)
            {
                Usage();
            }
            String role        = Args[4];
            String description = Args[5];

            try
            {
                // create the input API request for role-add
                NaElement input = new NaElement("rbac-role-add");
                input.AddNewChild("role-name", role);
                input.AddNewChild("description", description);
                // invoke the api request and get the new role id
                NaElement output = server.InvokeElem(input);
                Console.WriteLine("new role-id: " +
                                  output.GetChildContent("role-id"));
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            Console.WriteLine("role added successfully!");
        }
        // This function will delete an existing operation.
        static void OperationDelete()
        {
            if (Args.Length < 5)
            {
                Usage();
            }
            String name = Args[4];

            try
            {
                // create the input rbac-operation-delete API request
                NaElement input = new NaElement("rbac-operation-delete");
                input.AddNewChild("operation", name);
                // invoke the API request
                NaElement output = server.InvokeElem(input);
                Console.WriteLine("\nOperation deleted successfully!");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #5
0
        static void MemberRemove()
        {
            String poolName   = Args[4];
            String memberName = Args[5];

            try {
                // invoking the api && printing the xml ouput
                NaElement input = new NaElement("resourcepool-remove-member");
                input.AddNewChild("resourcepool-name-or-id", poolName);
                input.AddNewChild("member-name-or-id", memberName);
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nMember deletion "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        // This function will delete an existing role from the RBAC system
        static void RoleDelete()
        {
            if (Args.Length < 5)
            {
                Usage();
            }
            String role = Args[4];

            try
            {
                // create the API request to delete role
                NaElement input = new NaElement("rbac-role-delete");
                input.AddNewChild("role-name-or-id", role);

                // invoke the API
                NaElement output = server.InvokeElem(input);
                Console.WriteLine("\nrole deleted successfully!");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #7
0
        static void MemberAdd()
        {
            NaElement input;
            NaElement output;

            // Getting the dataset name and member name
            String datasetName = Args[4];
            String memberName  = Args[5];

            try {
                // Setting the edit lock for adding member
                input = new NaElement("dataset-edit-begin");
                input.AddNewChild("dataset-name-or-id", Args[4]);
                output = server.InvokeElem(input);

                // extracting the edit lock id
                String lockId = output.GetChildContent("edit-lock-id");

                try {
                    // creating the input for api execution
                    // creating a dataset-add-member element and adding child
                    // elements
                    input = new NaElement("dataset-add-member");
                    input.AddNewChild("edit-lock-id", lockId);
                    NaElement mem   = new NaElement("dataset-member-parameters");
                    NaElement param = new NaElement("dataset-member-parameter");
                    param.AddNewChild("object-name-or-id", memberName);
                    mem.AddChildElement(param);
                    input.AddChildElement(mem);
                    // invoking the api && printing the xml ouput
                    output = server.InvokeElem(input);

                    input = new NaElement("dataset-edit-commit");
                    input.AddNewChild("edit-lock-id", lockId);
                    output = server.InvokeElem(input);
                }
                catch (Exception e) {
                    Console.Error.WriteLine(e.Message);
                    input = new NaElement("dataset-edit-rollback");
                    input.AddNewChild("edit-lock-id", lockId);
                    server.InvokeElem(input);
                    Environment.Exit(1);
                }

                Console.WriteLine("\nMember addition "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #8
0
        static void Main(string[] args)
        {
            NaElement xi;
            NaElement xo;
            NaServer  s;
            String    decPasswd;

            if (args.Length < 4)
            {
                Console.Error.WriteLine("Usage: encrypt_string <filer> <user> <password> <test-password>");
                Environment.Exit(1);
            }

            String server = args[0], user = args[1], pwd = args[2], testPwd = args[3];

            try
            {
                Console.WriteLine("|--------------------------------------------------|");
                Console.WriteLine("| Program to demo use of encrypted child elements  |");
                Console.WriteLine("|--------------------------------------------------|\n");

                //Initialize connection to server, and
                //request version 1.3 of the API set
                //
                s       = new NaServer(server, 1, 1);
                s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD;
                s.SetAdminUser(user, pwd);

                //Create input element
                xi = new NaElement("test-password-set");
                xi.AddNewEncryptedChild("password", testPwd);

                //try to get the decrypted password
                decPasswd = xi.GetChildEncryptContent("password");
                Console.WriteLine("Expected decrypted password from server:" + decPasswd);

                //Invokes ONTAPI API
                xo = s.InvokeElem(xi);

                //Display output in XML format
                Console.WriteLine("\nOUTPUT XML:");
                String output = xo.ToString();
                Console.WriteLine(output);
            }
            catch (NaAuthException e)
            {
                System.Console.Error.WriteLine("Authorization Failed: " + e.Message);
            }
            catch (NaApiFailedException e)
            {
                System.Console.Error.WriteLine("API FAILED: " + e.Message);
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine(e.Message);
            }
        }
Пример #9
0
        static void GetSchedule(String[] args)
        {
            NaServer s;
            string   filer = args[1];
            string   user  = args[2];
            string   pwd   = args[3];
            string   vol   = args[4];

            NaElement xi, xo;

            //
            // get the schedule
            //
            try
            {
                s               = new NaServer(filer, 1, 0);
                s.Style         = NaServer.AUTH_STYLE.LOGIN_PASSWORD;
                s.TransportType = NaServer.TRANSPORT_TYPE.HTTP;
                s.SetAdminUser(user, pwd);

                xi = new NaElement("snapshot-get-schedule");
                if (args.Length == 5)
                {
                    xi.AddNewChild("volume", vol);
                }
                else
                {
                    Console.Error.WriteLine("Invalid number of arguments");
                    Usage(args);
                    System.Environment.Exit(-1);
                }

                xo = s.InvokeElem(xi);
                //
                // print it out
                //
                Console.WriteLine("Snapshot schedule for volume " + vol + " on filer " + filer + ":");
                Console.WriteLine("-----------------------------------------------------------------");
                Console.WriteLine("Snapshots are taken on minutes [" +
                                  xo.GetChildIntValue("which-minutes", 0) + "] of each hour (" +
                                  xo.GetChildContent("minutes") + " kept)");
                Console.WriteLine("Snapshots are taken on hours [" +
                                  xo.GetChildContent("which-hours") + "] of each day (" +
                                  xo.GetChildContent("hours") + " kept)\n");
                Console.WriteLine(xo.GetChildContent("days") + " nightly snapshots are kept\n");
                Console.WriteLine(xo.GetChildContent("weeks") + " weekly snapshots are kept\n");
                Console.WriteLine("\n");
            }
            catch (NaException e)
            {
                Console.WriteLine("ERROR: " + e.Message);
            }
        }
Пример #10
0
        static void MemberAdd()
        {
            String memberResourceTag = null;

            // Getting the resource pool and member name
            String poolName   = Args[4];
            String memberName = Args[5];

            // parsing optional parameters
            int i = 6;

            while (i < Args.Length)
            {
                if (Args[i].Equals("-m"))
                {
                    memberResourceTag = Args[++i]; ++i;
                }
                else
                {
                    Usage();
                }
            }

            try {
                // creating the input for api execution
                // creating a resourcepool-add-member element and adding
                // child elements
                NaElement input = new NaElement("resourcepool-add-member");
                input.AddNewChild("resourcepool-name-or-id", poolName);
                input.AddNewChild("member-name-or-id", memberName);
                if (memberResourceTag != null)
                {
                    input.AddNewChild("resource-tag", memberResourceTag);
                }

                // invoking the api && printing the xml ouput
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nMember addition "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #11
0
        static NaElement getPolicyContent()
        {
            NaElement policyContent = null;

            try
            {
                // creating a dp policy start element
                NaElement input = new NaElement("dp-policy-list-iter-start");
                input.AddNewChild("dp-policy-name-or-id", Args[4]);

                // invoke the api && capturing the records && tag values
                NaElement output = server.InvokeElem(input);

                // Extracting the record && tag values && printing them
                String tag = output.GetChildContent("tag");

                // Extracting records one at a time
                input = new NaElement("dp-policy-list-iter-next");
                input.AddNewChild("maximum", "1");
                input.AddNewChild("tag", tag);
                NaElement record = server.InvokeElem(input);

                // Navigating to the dp-policy-infos child element
                NaElement policyInfos =
                    record.GetChildByName("dp-policy-infos");

                // Navigating to the dp-policy-info child element
                NaElement policyInfo =
                    policyInfos.GetChildByName("dp-policy-info");

                // Navigating to the dp-policy-content child element
                policyContent = policyInfo.GetChildByName("dp-policy-content");

                // invoking the iter-end zapi
                input = new NaElement("dp-policy-list-iter-end");
                input.AddNewChild("tag", tag);

                server.InvokeElem(input);
            }
            catch (NaException e) {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            // Returning the original policy content
            return(policyContent);
        }
Пример #12
0
        static void RenameSnapshot(String[] args)
        {
            try
            {
                NaServer  s;
                string    filer = args[1];
                string    user = args[2];
                string    pwd = args[3];
                string    vol = args[4];
                string    ssnameOld = args[5];
                string    ssnameNew = args[6];
                NaElement xi, xo;

                s               = new NaServer(filer, 1, 0);
                s.Style         = NaServer.AUTH_STYLE.LOGIN_PASSWORD;
                s.TransportType = NaServer.TRANSPORT_TYPE.HTTP;
                s.SetAdminUser(user, pwd);

                xi = new NaElement("snapshot-rename");
                if (args.Length == 7)
                {
                    xi.AddNewChild("volume", vol);
                    xi.AddNewChild("current-name", ssnameOld);
                    xi.AddNewChild("new-name", ssnameNew);
                }
                else
                {
                    Console.Error.WriteLine("Invalid number of arguments");
                    Usage(args);
                    System.Environment.Exit(-1);
                }

                xo = s.InvokeElem(xi);
                //
                // print it out
                //
                Console.WriteLine("Snapshot " + ssnameOld + " renamed to " +
                                  ssnameNew + " for volume " + vol + " on filer " + filer);
            }
            catch (IndexOutOfRangeException e)
            {
                Console.Error.WriteLine("ERROR:" + e.Message);
                Usage(args);
                System.Environment.Exit(-1);
            }
            catch (NaException e)
            {
                Console.Error.WriteLine("ERROR: " + e.Message);
            }
        }
Пример #13
0
        static void ListInfo(String[] args)
        {
            NaServer s;
            string   filer = args[1];
            string   user  = args[2];
            string   pwd   = args[3];
            string   vol   = args[4];

            NaElement xi, xo;

            //
            // get the schedule
            //
            try
            {
                s               = new NaServer(filer, 1, 0);
                s.Style         = NaServer.AUTH_STYLE.LOGIN_PASSWORD;
                s.TransportType = NaServer.TRANSPORT_TYPE.HTTP;
                s.SetAdminUser(user, pwd);

                xi = new NaElement("snapshot-list-info");
                xi.AddNewChild("volume", vol);
                xo = s.InvokeElem(xi);

                System.Collections.IList       snapshots = xo.GetChildByName("snapshots").GetChildren();
                System.Collections.IEnumerator snapiter  = snapshots.GetEnumerator();
                while (snapiter.MoveNext())
                {
                    NaElement snapshot = (NaElement)snapiter.Current;
                    Console.WriteLine("SNAPSHOT:");
                    int      accesstime = snapshot.GetChildIntValue("access-time", 0);
                    DateTime datetime   = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(accesstime);
                    Console.WriteLine("   NAME \t\t= " + snapshot.GetChildContent("name"));
                    Console.WriteLine("   ACCESS TIME (GMT) \t= " + datetime);
                    Console.WriteLine("   BUSY \t\t= " + snapshot.GetChildContent("busy"));
                    Console.WriteLine("   TOTAL (of 1024B) \t= " + snapshot.GetChildContent("total"));
                    Console.WriteLine("   CUMULATIVE TOTAL (of 1024B) = " + snapshot.GetChildContent("cumulative-total"));
                    Console.WriteLine("   DEPENDENCY \t\t= " + snapshot.GetChildContent("dependency"));
                }
            }
            catch (NaAuthException e)
            {
                Console.Error.WriteLine("Authentication Error : " + e.Message);
            }
            catch (NaApiFailedException e)
            {
                Console.Error.WriteLine("API Failed : " + e.Message);
            }
        }
        //This funcion will add a new operation to the RBAC system.
        static void OperationAdd()
        {
            if (Args.Length < 8)
            {
                Usage();
            }
            String name     = Args[4];
            String desc     = Args[5];
            String synopsis = Args[6];
            String type     = Args[7];

            try
            {
                // construct the input rbac-operation-add API request
                NaElement input         = new NaElement("rbac-operation-add");
                NaElement operation     = new NaElement("operation");
                NaElement rbacOperation = new NaElement("rbac-operation");
                rbacOperation.AddNewChild("operation-name", name);
                NaElement operationNameDetails =
                    new NaElement("operation-name-details");
                NaElement rbacOperationNameDetails =
                    new NaElement("rbac-operation-name-details");
                rbacOperationNameDetails.
                AddNewChild("operation-description", desc);
                rbacOperationNameDetails.
                AddNewChild("operation-synopsis", synopsis);
                rbacOperationNameDetails.AddNewChild("resource-type", type);
                input.AddChildElement(operation);
                operation.AddChildElement(rbacOperation);
                rbacOperation.AddChildElement(operationNameDetails);
                operationNameDetails.AddChildElement(rbacOperationNameDetails);

                // invoke the API request
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("Operation added successfully!");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #15
0
        static void Delete()
        {
            String policyName = Args[4];

            try
            {
                NaElement input = new NaElement("dp-policy-edit-begin");
                input.AddNewChild("dp-policy-name-or-id", policyName);
                NaElement output = server.InvokeElem(input);

                String lockId = output.GetChildContent("edit-lock-id");

                // Deleting the policy name
                // creating a dp-policy-destroy element and adding edit-lock
                input = new NaElement("dp-policy-destroy");
                input.AddNewChild("edit-lock-id", lockId);
                output = server.InvokeElem(input);

                try
                {
                    input = new NaElement("dp-policy-edit-commit");
                    input.AddNewChild("edit-lock-id", lockId);
                    output = server.InvokeElem(input);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    input = new NaElement("dp-policy-edit-rollback");
                    input.AddNewChild("edit-lock-id", lockId);
                    server.InvokeElem(input);
                    Environment.Exit(1);
                }

                Console.WriteLine("\nPolicy deletion "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e) {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #16
0
        static void addResourcePool(String rPool)
        {
            NaElement input;
            NaElement output;

            try {
                // Setting the edit lock for adding resource pool
                input = new NaElement("dataset-edit-begin");
                input.AddNewChild("dataset-name-or-id", Args[4]);
                output = server.InvokeElem(input);

                // extracting the edit lock id
                String lockId = output.GetChildContent("edit-lock-id");

                try {
                    // Invoking add resource pool element
                    input = new NaElement("dataset-add-resourcepool");
                    input.AddNewChild("edit-lock-id", lockId);
                    input.AddNewChild("resourcepool-name-or-id", rPool);
                    output = server.InvokeElem(input);

                    input = new NaElement("dataset-edit-commit");
                    input.AddNewChild("edit-lock-id", lockId);
                    output = server.InvokeElem(input);
                }
                catch (Exception e) {
                    Console.Error.WriteLine(e.Message);
                    input = new NaElement("dataset-edit-rollback");
                    input.AddNewChild("edit-lock-id", lockId);
                    server.InvokeElem(input);
                    Environment.Exit(1);
                }

                Console.WriteLine("\nResourcepool add "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            NaServer  s;
            NaElement xi, xo;

            if (args.Length < 3)
            {
                Console.Error.WriteLine("Usage: hello_ontapi  filer user passwd");
                Environment.Exit(1);
            }
            String Server = args[0];
            String User   = args[1];
            String Pwd    = args[2];

            try
            {
                Console.WriteLine("|---------------------------------------------------------------|");
                Console.WriteLine("| Program to Demo a simple API call to query Data ONTAP Version |");
                Console.WriteLine("|---------------------------------------------------------------|\n");
                //Initialize connection to server, and
                //request version 1.3 of the API set
                //
                s       = new NaServer(Server, 1, 0);
                s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD;
                s.SetAdminUser(User, Pwd);

                //Invokes ONTAPI API to get the Data ONTAP
                //version number of a filer
                xi = new NaElement("system-get-version");
                xo = s.InvokeElem(xi);
                //Parse output
                String output = xo.GetChildContent("version");
                //Print output
                Console.Out.WriteLine("Hello! " +
                                      "Data ONTAP version of " + Server + " is \"" + output + "\"");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
            }
            catch (System.Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
        //This function will assign an existing role to an existing
        // administrator.
        static void AdminRoleAdd()
        {
            if (Args.Length < 6)
            {
                Usage();
            }

            String adminnameID  = Args[4];
            String rolenameID   = Args[5];
            String newAdminName = null;
            String newAdminID   = null;

            try
            {
                // create the input rbac-admin-role-add API request
                NaElement input = new NaElement("rbac-admin-role-add");
                input.AddNewChild("admin-name-or-id", adminnameID);
                input.AddNewChild("role-name-or-id", rolenameID);

                // invoke the API request
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("admin role added successfully! ");
                NaElement newAdminNameID =
                    output.GetChildByName("admin-name-or-id").
                    GetChildByName("rbac-admin-name-or-id");
                newAdminName = newAdminNameID.GetChildContent("admin-name");
                newAdminID   = newAdminNameID.GetChildContent("admin-id");
                Console.WriteLine("new admin name                    :" +
                                  newAdminName);
                Console.WriteLine("new admin id                      :" +
                                  newAdminID);
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        protected override void ProcessRecord()
        {
            if (_server == null || _user == null || _passwd == null)
            {
                WriteObject(Usage);
                return;
            }

            try
            {
                NaServer  server = new NaServer(_server, 1, 0);
                NaElement input  = new NaElement("volume-list-info");
                server.SetAdminUser(User, Passwd);
                if (_volume != null)
                {
                    input.AddNewChild("volume", _volume);
                }
                NaElement output = server.InvokeElem(input);

                System.Collections.IList volList = output.
                                                   GetChildByName("volumes").GetChildren();
                System.Collections.IEnumerator volIter = volList.GetEnumerator();
                WriteObject("\n------------------------------------------------------------------------");
                WriteObject("Name \t type \t state \t size-total \t size-used \t size-available");
                WriteObject("------------------------------------------------------------------------");
                String vol = "";
                while (volIter.MoveNext())
                {
                    NaElement volInfo = (NaElement)volIter.Current;
                    vol = volInfo.GetChildContent("name") + "\t" +
                          volInfo.GetChildContent("type") + "\t" +
                          volInfo.GetChildContent("state") + "\t" +
                          volInfo.GetChildContent("size-total") + "\t" +
                          volInfo.GetChildContent("size-used") + "\t" +
                          volInfo.GetChildContent("size-available");
                    WriteObject(vol);
                }
                WriteObject("------------------------------------------------------------------------\n");
            }
            catch (Exception e)
            {
                WriteObject(e.Message);
            }
        }
        static void TemplateDelete()
        {
            String templateName = Args[4];

            try
            {
                // invoking the api && printing the xml ouput
                NaElement input = new NaElement("vfiler-template-delete");
                input.AddNewChild("vfiler-template-name-or-id", templateName);
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nTemplate deletion "
                                  + Result(output.GetAttr("status")));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        static void setup(String vName, String tName)
        {
            try
            {
                // creating the input for api execution
                // creating a vfiler-create element and adding child elements
                NaElement input = new NaElement("vfiler-setup");
                input.AddNewChild("vfiler-name-or-id", vName);
                input.AddNewChild("vfiler-template-name-or-id", tName);
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nvFiler unit setup with template "
                                  + tName + " " + Result(output.GetAttr("status")));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        static void Create()
        {
            String templateName = null;

            // Getting the vfiler name, resource pool name and ip
            String vfilerName = Args[4];
            String poolName   = Args[5];
            String ip         = Args[6];

            if (Args.Length > 7)
            {
                templateName = Args[7];
            }

            try
            {
                // creating the input for api execution
                // creating a vfiler-create element and adding child elements
                NaElement input = new NaElement("vfiler-create");
                input.AddNewChild("ip-address", ip);
                input.AddNewChild("name", vfilerName);
                input.AddNewChild("resource-name-or-id", poolName);
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nvFiler unit creation "
                                  + Result(output.GetAttr("status")));
                Console.WriteLine("\nvFiler unit created on Storage System : "
                                  + output.GetChildContent("filer-name") + "\nRoot Volume : "
                                  + output.GetChildContent("root-volume-name"));

                if (templateName != null)
                {
                    setup(vfilerName, templateName);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        protected override void ProcessRecord()
        {
            if (_server == null || _user == null || _passwd == null)
            {
                WriteObject(Usage);
                return;
            }

            try
            {
                NaServer server = new NaServer(_server, 1, 0);
                server.SetAdminUser(User, Passwd);
                NaElement output  = server.Invoke("system-get-version");
                String    version = output.GetChildContent("version");
                WriteObject("Hello world!  DOT version of " + _server + " is: " + version);
            }
            catch (Exception e)
            {
                WriteObject(e.Message);
            }
        }
        static void Delete()
        {
            String policyName = Args[4];

            try {
                // invoking the api && printing the xml ouput
                NaElement input = new NaElement("provisioning-policy-destroy");
                input.AddNewChild("provisioning-policy-name-or-id", policyName);
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nPolicy deletion "
                                  + Result(output.GetAttr("status")));
            }
            catch (NaException e) {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        // This function will list about an existing operation or
        // all operations in the system.
        static void OperationList()
        {
            String operation = null;
            String name      = null;
            String desc      = null;
            String type      = null;
            String synopsis  = null;

            if (Args.Length == 5)
            {
                operation = Args[4];
            }

            try
            {
                // create the input API request
                NaElement input = new NaElement("rbac-operation-info-list");

                if (operation != null)
                {
                    input.AddNewChild("operation", operation);
                }

                // now invoke the api request and get the operations list
                NaElement output = server.InvokeElem(input);

                System.Collections.IList oprList =
                    output.GetChildByName("operation-list").GetChildren();
                System.Collections.IEnumerator oprIter =
                    oprList.GetEnumerator();

                // iterate through each operation
                Console.WriteLine(
                    "\n----------------------------------------------------");
                while (oprIter.MoveNext())
                {
                    NaElement opr = (NaElement)oprIter.Current;
                    name = opr.GetChildContent("operation-name");
                    Console.WriteLine("\nName             :" + name);
                    System.Collections.IList nameDetailList =
                        opr.GetChildByName("operation-name-details").GetChildren();
                    System.Collections.IEnumerator detailIter =
                        nameDetailList.GetEnumerator();
                    while (detailIter.MoveNext())
                    {
                        NaElement detail = (NaElement)detailIter.Current;
                        desc     = detail.GetChildContent("operation-description");
                        type     = detail.GetChildContent("resource-type");
                        synopsis = detail.GetChildContent("operation-synopsis");
                        Console.WriteLine("Description      : " + desc);
                        Console.WriteLine("Synopsis         : " + synopsis);
                        Console.WriteLine("Resource type    : " + type);
                    }
                }
                Console.WriteLine(
                    "----------------------------------------------------");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        static void TemplateList()
        {
            String templateName = null;

            try
            {
                // creating a template lsit start element
                NaElement input =
                    new NaElement("vfiler-template-list-info-iter-start");
                if (Args.Length > 4)
                {
                    templateName = Args[4];
                    input.
                    AddNewChild("vfiler-template-name-or-id", templateName);
                }

                // invoke the api && capturing the records && tag values
                NaElement output = server.InvokeElem(input);

                // Extracting the record && tag values && printing them
                String records = output.GetChildContent("records");

                if (records.Equals("0"))
                {
                    Console.WriteLine("\nNo templates to display");
                }

                String tag = output.GetChildContent("tag");


                // Extracting records one at a time
                input = new NaElement("vfiler-template-list-info-iter-next");
                input.AddNewChild("maximum", records);
                input.AddNewChild("tag", tag);
                NaElement record = server.InvokeElem(input);

                // Navigating to the vfiler templates child element
                NaElement stat = record.GetChildByName("vfiler-templates");

                // Navigating to the vfiler-info child element
                System.Collections.IList infoList = null;

                if (stat != null)
                {
                    infoList = stat.GetChildren();
                }
                if (infoList == null)
                {
                    return;
                }


                System.Collections.IEnumerator infoIter =
                    infoList.GetEnumerator();

                // Iterating through each record
                while (infoIter.MoveNext())
                {
                    String    value;
                    NaElement info = (NaElement)infoIter.Current;

                    Console.WriteLine(
                        "--------------------------------------------------------");
                    // extracting the template name and printing it
                    value = info.GetChildContent("vfiler-template-name");
                    Console.WriteLine("Template Name : " + value);

                    value = info.GetChildContent("vfiler-template-id");
                    Console.WriteLine("Template Id : " + value);

                    value = info.GetChildContent("vfiler-template-description");
                    Console.Write("Template Description : ");
                    if (value != null)
                    {
                        Console.Write(value);
                    }

                    Console.WriteLine("\n----------------------------------"
                                      + "--------------");

                    // printing detials if only one template is selected
                    if (templateName != null)
                    {
                        value = info.GetChildContent("cifs-auth-type");
                        Console.WriteLine("\nCIFS Authhentication     : "
                                          + value);

                        value = info.GetChildContent("cifs-domain");
                        Console.Write("CIFS Domain              : ");
                        if (value != null)
                        {
                            Console.Write(value);
                        }

                        value = info.GetChildContent("cifs-security-style");
                        Console.WriteLine("\nCIFS Security Style      : "
                                          + value);

                        value = info.GetChildContent("dns-domain");
                        Console.Write("DNS Domain               : ");
                        if (value != null)
                        {
                            Console.Write(value);
                        }

                        value = info.GetChildContent("nis-domain");
                        Console.Write("\nNIS Domain               : ");
                        if (value != null)
                        {
                            Console.WriteLine(value);
                        }
                    }
                }

                // invoking the iter-end zapi
                input = new NaElement("vfiler-template-list-info-iter-end");
                input.AddNewChild("tag", tag);
                server.InvokeElem(input);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        static void TemplateCreate()
        {
            String cifsAuth     = null;
            String cifsDomain   = null;
            String cifsSecurity = null;

            // Getting the template name
            String templateName = Args[4];

            // parsing optional parameters
            int i = 5;

            while (i < Args.Length)
            {
                if (Args[i].Equals("-a"))
                {
                    cifsAuth = Args[++i]; ++i;
                }
                else if (Args[i].Equals("-d"))
                {
                    cifsDomain = Args[++i]; ++i;
                }
                else if (Args[i].Equals("-s"))
                {
                    cifsSecurity = Args[++i]; ++i;
                }
                else
                {
                    Usage();
                }
            }

            try
            {
                // creating the input for api execution
                // creating a vfiler-template-create element and adding
                // child elements
                NaElement input    = new NaElement("vfiler-template-create");
                NaElement temp     = new NaElement("vfiler-template");
                NaElement template = new NaElement("vfiler-template-info");
                template.AddNewChild("vfiler-template-name", templateName);
                if (cifsAuth != null)
                {
                    template.AddNewChild("cifs-auth-type", cifsAuth);
                }
                if (cifsDomain != null)
                {
                    template.AddNewChild("cifs-domain", cifsDomain);
                }
                if (cifsSecurity != null)
                {
                    template.AddNewChild("cifs-security-style", cifsSecurity);
                }
                temp.AddChildElement(template);
                input.AddChildElement(temp);

                // invoking the api && printing the xml ouput
                NaElement output = server.InvokeElem(input);

                Console.WriteLine("\nvFiler template creation "
                                  + Result(output.GetAttr("status")));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        //This function will add a capability to a role.
        static void RoleCapabilityAdd()
        {
            if (Args.Length < 8)
            {
                Usage();
            }

            String rolenameID   = Args[4];
            String operation    = Args[5];
            String resourceType = Args[6];
            String resourceName = Args[7];

            // check for the proper resource type
            if (!resourceType.Equals("dataset") &&
                !resourceType.Equals("filer"))
            {
                Console.Error.WriteLine("Invalid resource type");
                System.Environment.Exit(2);
            }

            try
            {
                // create the input rbac-role-capability-add API request
                NaElement input = new NaElement("rbac-role-capability-add");
                input.AddNewChild("operation", operation);
                input.AddNewChild("role-name-or-id", rolenameID);

                NaElement resource   = new NaElement("resource");
                NaElement resourceID = new NaElement("resource-identifier");
                input.AddChildElement(resource);
                resource.AddChildElement(resourceID);
                // check for the resource type and frame the request
                if (resourceType.Equals("dataset"))
                {
                    NaElement dataset         = new NaElement("dataset");
                    NaElement datasetResource =
                        new NaElement("dataset-resource");
                    datasetResource.AddNewChild("dataset-name", resourceName);
                    dataset.AddChildElement(datasetResource);
                    resourceID.AddChildElement(dataset);
                }
                else if (resourceType.Equals("filer"))
                {
                    NaElement filer         = new NaElement("filer");
                    NaElement filerResource = new NaElement("filer-resource");
                    filerResource.AddNewChild("filer-name", resourceName);
                    filer.AddChildElement(filerResource);
                    resourceID.AddChildElement(filer);
                }

                // invoke the API
                NaElement output = server.InvokeElem(input);
                Console.WriteLine("capability added successfully! ");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }
        public static void ListVservers()
        {
            NaElement xi, xo;
            String    rootVol, rootVolAggr, secStyle, state;
            String    tag = "";

            while (tag != null)
            {
                xi = new NaElement("vserver-get-iter");
                if (args.Length > 3)
                {
                    if (args.Length < 5 || !args[3].Equals("-v"))
                    {
                        PrintUsageAndExit();
                    }
                    server.Vserver = args[4];
                }
                if (!tag.Equals(""))
                {
                    xi.AddNewChild("tag", tag);
                }
                xo = server.InvokeElem(xi);
                if (xo.GetChildIntValue("num-records", 0) == 0)
                {
                    Console.WriteLine("No vserver(s) information available\n");
                    return;
                }
                tag = xo.GetChildContent("next-tag");
                List <NaElement> vserverList = xo.GetChildByName("attributes-list").GetChildren();
                Console.WriteLine("----------------------------------------------------");
                foreach (NaElement vserverInfo in vserverList)
                {
                    Console.WriteLine("Name                    : " + vserverInfo.GetChildContent("vserver-name"));
                    Console.WriteLine("Type                    : " + vserverInfo.GetChildContent("vserver-type"));
                    rootVolAggr = vserverInfo.GetChildContent("root-volume-aggregate");
                    rootVol     = vserverInfo.GetChildContent("root-volume");
                    secStyle    = vserverInfo.GetChildContent("root-volume-security-style");
                    state       = vserverInfo.GetChildContent("state");
                    Console.WriteLine("Root volume aggregate   : " + (rootVolAggr != null ? rootVolAggr : ""));
                    Console.WriteLine("Root volume             : " + (rootVol != null ? rootVol : ""));
                    Console.WriteLine("Root volume sec style   : " + (secStyle != null ? secStyle : ""));
                    Console.WriteLine("UUID                    : " + vserverInfo.GetChildContent("uuid"));
                    Console.WriteLine("State                   : " + (state != null ? state : ""));
                    NaElement allowedProtocols = null;
                    Console.Write("Allowed protocols       : ");
                    if ((allowedProtocols = vserverInfo.GetChildByName("allowed-protocols")) != null)
                    {
                        List <NaElement> allowedProtocolsList = allowedProtocols.GetChildren();
                        foreach (NaElement protocol in allowedProtocolsList)
                        {
                            Console.Write(protocol.GetContent() + " ");
                        }
                    }
                    Console.Write("\nName server switch      : ");
                    NaElement nameServerSwitch = null;
                    if ((nameServerSwitch = vserverInfo.GetChildByName("name-server-switch")) != null)
                    {
                        List <NaElement> nsSwitchList = nameServerSwitch.GetChildren();
                        foreach (NaElement nsSwitch in  nsSwitchList)
                        {
                            Console.Write(nsSwitch.GetContent() + " ");
                        }
                    }
                    Console.WriteLine("\n----------------------------------------------------");
                }
            }
        }
        //This function will list the operations, capabilities
        // and inherited roles that one or more roles have.
        static void RoleList()
        {
            String role          = null;
            String roleID        = null;
            String roleName      = null;
            String description   = null;
            String inhRoleID     = null;
            String inhRoleName   = null;
            String operationName = null;
            String operationDesc = null;
            String operationSyn  = null;
            String resourceType  = null;

            if (Args.Length == 5)
            {
                role = Args[4];
            }

            try
            {
                // create the input rbac-role-info-list API request
                NaElement input = new NaElement("rbac-role-info-list");

                if (role != null)
                {
                    input.AddNewChild("role-name-or-id", role);
                }

                // invoke the API and capture the role attributes
                NaElement output = server.InvokeElem(input);

                // get the list of role attributes which is contained under
                // role-attributes element
                System.Collections.IList attrList =
                    output.GetChildByName("role-attributes").GetChildren();
                System.Collections.IEnumerator attrIter =
                    attrList.GetEnumerator();

                //iterate through each role attribute
                while (attrIter.MoveNext())
                {
                    NaElement attribute = (NaElement)attrIter.Current;
                    Console.WriteLine(
                        "----------------------------------------------------");
                    NaElement rolenameID =
                        attribute.GetChildByName("role-name-and-id").
                        GetChildByName("rbac-role-resource");
                    roleID      = rolenameID.GetChildContent("rbac-role-id");
                    roleName    = rolenameID.GetChildContent("rbac-role-name");
                    description = attribute.GetChildContent("description");
                    Console.WriteLine("role name                         : " +
                                      roleName);
                    Console.WriteLine("role id                           : " +
                                      roleID);
                    Console.WriteLine("role description                  : " +
                                      description + "\n");

                    // iterate through the inherited roles
                    System.Collections.IList inheritedList =
                        attribute.GetChildByName("inherited-roles").GetChildren();
                    System.Collections.IEnumerator inheritedIter =
                        inheritedList.GetEnumerator();

                    while (inheritedIter.MoveNext())
                    {
                        NaElement inheritedRole =
                            (NaElement)inheritedIter.Current;
                        Console.WriteLine("inherited role details:\n");
                        inhRoleID =
                            inheritedRole.GetChildContent("rbac-role-id");
                        inhRoleName =
                            inheritedRole.GetChildContent("rbac-role-name");
                        Console.WriteLine
                            ("inherited role name                : " + inhRoleName);
                        Console.WriteLine
                            ("inherited role id                  : " + inhRoleID);
                    }

                    Console.WriteLine("operation details:\n");
                    System.Collections.IList capList =
                        attribute.GetChildByName("capabilities").GetChildren();

                    System.Collections.IEnumerator capIter =
                        capList.GetEnumerator();
                    // iterate through the role capabilities
                    while (capIter.MoveNext())
                    {
                        NaElement capability = (NaElement)capIter.Current;
                        NaElement operation  = capability.
                                               GetChildByName("operation").
                                               GetChildByName("rbac-operation");
                        operationName = operation.
                                        GetChildContent("operation-name");
                        NaElement operationNameDetails =
                            operation.GetChildByName("operation-name-details").
                            GetChildByName("rbac-operation-name-details");
                        operationDesc = operationNameDetails.
                                        GetChildContent("operation-description");
                        operationSyn = operationNameDetails.
                                       GetChildContent("operation-synopsis");
                        resourceType = operationNameDetails.
                                       GetChildContent("resource-type");

                        Console.WriteLine("operation name                    :"
                                          + operationName);
                        Console.WriteLine("operation description             :"
                                          + operationDesc);
                        Console.WriteLine("operation synopsis                :"
                                          + operationSyn);
                        Console.WriteLine("resource type                     :"
                                          + resourceType + "\n");
                    }
                }
                Console.WriteLine(
                    "----------------------------------------------------");
            }
            catch (NaException e)
            {
                //Print the error message
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Environment.Exit(1);
            }
        }