public static void Main(String[] vargs) { args = vargs; int index = 0; if (args.Length < 3) { PrintUsageAndExit(); } try { server = new NaServer(args[index++], 1, 15); server.SetAdminUser(args[index++], args[index++]); ListVolumes(); } catch (NaException e) { //Print the error message Console.Error.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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 Main(String[] args) { Args = args; int arglen = Args.Length; // Checking for valid number of parameters if (arglen < 4) { Usage(); } String dfmserver = Args[0]; String dfmuser = Args[1]; String dfmpw = Args[2]; String dfmop = Args[3]; // checking for valid number of parameters for the respective // operations if ((dfmop.Equals("delete") && arglen != 5) || (dfmop.Equals("create") && arglen < 7) || (dfmop.Equals("template-list") && arglen < 4) || (dfmop.Equals("template-delete") && arglen != 5) || (dfmop.Equals("template-create") && arglen < 5)) { Usage(); } // checking if the operation selected is valid if ((!dfmop.Equals("list")) && (!dfmop.Equals("create")) && (!dfmop.Equals("delete")) && (!dfmop.Equals("template-list")) && (!dfmop.Equals("template-create")) && (!dfmop.Equals("template-delete"))) { Usage(); } try { //Initialize connection to server, and //request version 1.0 of the API set // // Creating a server object and setting appropriate attributes server = new NaServer(dfmserver, 1, 0); server.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; server.ServerType = NaServer.SERVER_TYPE.DFM; server.SetAdminUser(dfmuser, dfmpw); // Calling the functions based on the operation selected if (dfmop.Equals("create")) { Create(); } else if (dfmop.Equals("delete")) { Delete(); } else if (dfmop.Equals("template-list")) { TemplateList(); } else if (dfmop.Equals("template-create")) { TemplateCreate(); } else if (dfmop.Equals("template-delete")) { TemplateDelete(); } else { Usage(); } } catch (Exception e) { Console.Error.WriteLine(e.Message); Environment.Exit(1); } }
static void Main(String[] args) { // check for the valid no. of arguments if (args.Length < 4) { Usage(); } String operation = null; server = null; try { // create the server context for DFM Server server = new NaServer(args[0], 1, 0); server.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; server.ServerType = NaServer.SERVER_TYPE.DFM; server.SetAdminUser(args[1], args[2]); Args = args; operation = args[3]; // Check for the given input operation and call //appropriate function. if (operation.Equals("operation-list")) { OperationList(); } else if (operation.Equals("operation-add")) { OperationAdd(); } else if (operation.Equals("operation-delete")) { OperationDelete(); } else if (operation.Equals("role-add")) { RoleAdd(); } else if (operation.Equals("role-delete")) { RoleDelete(); } else if (operation.Equals("role-list")) { RoleList(); } else if (operation.Equals("role-capability-add")) { RoleCapabilityAdd(); } else if (operation.Equals("role-capability-delete")) { RoleCapabilityDelete(); } else if (operation.Equals("admin-role-add")) { AdminRoleAdd(); } else if (operation.Equals("admin-role-delete")) { AdminRoleDelete(); } else if (operation.Equals("admin-role-list")) { RoleAdminList(); } else if (operation.Equals("admin-list")) { AdminList(); } else { Usage(); } } 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 Main(string[] args) { NaElement xi; NaElement xo; NaServer s; if (args.Length < 3) { Console.WriteLine("Usage : vollist <filername> <username> <passwd> [<volume>]"); System.Environment.Exit(1); } String Server = args[0], user = args[1], pwd = args[2]; try { Console.WriteLine("|--------------------------------------------------------|"); Console.WriteLine("| Program to Demo use of Volume APIs to list Volume info |"); Console.WriteLine("|--------------------------------------------------------|"); //Initialize connection to server, and //request version 1.3 of the API set // s = new NaServer(Server, 1, 3); s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; s.SetAdminUser(user, pwd); //Create Vol list Info ONTAPI API xi = new NaElement("volume-list-info"); if (args.Length == 4) { String volume_name = args[3]; xi.AddNewChild("volume", volume_name); } //Invoke Vol list Info ONTAPI API xo = s.InvokeElem(xi); // //Get the list of children from element(Here 'xo') and iterate //through each of the child element to fetch their values // System.Collections.IList volList = xo.GetChildByName("volumes").GetChildren(); System.Collections.IEnumerator volIter = volList.GetEnumerator(); while (volIter.MoveNext()) { NaElement volInfo = (NaElement)volIter.Current; Console.WriteLine("---------------------------------"); Console.Write("Volume Name\t\t: "); Console.WriteLine(volInfo.GetChildContent("name")); Console.Write("Volume State\t\t: "); Console.WriteLine(volInfo.GetChildContent("state")); Console.Write("Disk Count\t\t: "); Console.WriteLine(volInfo.GetChildIntValue("disk-count", -1)); Console.Write("Total Files\t\t: "); Console.WriteLine(volInfo.GetChildIntValue("files-total", -1)); Console.Write("No of files used\t: "); Console.WriteLine(volInfo.GetChildIntValue("files-used", -1)); Console.WriteLine("---------------------------------"); } } catch (Exception e) { Console.Error.WriteLine(e.Message); } }
static void Main(string[] args) { NaElement xi; NaElement xo; NaServer s; String op; if (args.Length < 3) { Console.Out.Write("Usage : optmgmt <filername> " + "<username> <passwd> [operation(get/set)] " + "[<optionName>] [<value>]"); Environment.Exit(1); } try { Console.WriteLine("|------------------------------------------------|"); Console.WriteLine("| Program to Demo use of OPTIONS MANAGEMENT APIs |"); Console.WriteLine("|------------------------------------------------|"); //Initialize connection to server, and //request version 1.3 of the API set // s = new NaServer(args[0], 1, 1); s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; s.SetAdminUser(args[1], args[2]); //Invoke option list Info ONTAPI API if (args.Length > 3) { op = args[3]; // // Get value of a specific option // if (0 == String.Compare(op, "get")) { xi = new NaElement("options-get"); if (args.Length == 5) { xi.AddNewChild("name", args[4]); } else { Console.Error.WriteLine("Improper number of arguments. Correct and re-run."); Environment.Exit(1); } xo = s.InvokeElem(xi); Console.Out.WriteLine("----------------------------"); Console.Out.Write("Option Value:"); Console.Out.WriteLine(xo.GetChildContent("value")); Console.Out.Write("Cluster Constraint:"); Console.Out.WriteLine(xo.GetChildContent("cluster-constraint")); Console.Out.WriteLine("----------------------------"); } // // Set value of a specific option else if (0 == String.Compare(op, "set")) { xi = new NaElement("options-set"); if (args.Length == 6) { xi.AddNewChild("name", args[4]); xi.AddNewChild("value", args[5]); } else { Console.Error.WriteLine("Improper number of arguments. Correct and re-run."); Environment.Exit(1); } xo = s.InvokeElem(xi); Console.Out.WriteLine("----------------------------"); if (xo.GetChildContent("message") != null) { Console.Out.Write("Message: "); Console.Out.WriteLine(xo.GetChildContent("message")); } Console.Out.Write("Cluster Constraint: "); Console.Out.WriteLine(xo.GetChildContent("cluster-constraint")); Console.Out.WriteLine("----------------------------"); } else { Console.Out.WriteLine("Invalid Operation"); Environment.Exit(1); } Environment.Exit(0); } // // List out all the options // else { xi = new NaElement("options-list-info"); xo = s.InvokeElem(xi); // // Get the list of children from element(Here // 'xo') and iterate through each of the child // element to fetch their values // System.Collections.IList optionList = xo.GetChildByName("options").GetChildren(); System.Collections.IEnumerator optionIter = optionList.GetEnumerator(); while (optionIter.MoveNext()) { NaElement optionInfo = (NaElement)optionIter.Current; Console.Out.WriteLine("----------------------------"); Console.Out.Write("Option Name:"); Console.Out.WriteLine(optionInfo.GetChildContent("name")); Console.Out.Write("Option Value:"); Console.Out.WriteLine(optionInfo.GetChildContent("value")); Console.Out.Write("Cluster Constraint:"); Console.Out.WriteLine(optionInfo.GetChildContent("cluster-constraint")); } } } catch (NaConnectionException e) { Console.Error.WriteLine("NaConnException: " + e.Message); Environment.Exit(1); } catch (NaException e) { Console.Error.WriteLine("NAEXCEPTION: " + e.Message); Environment.Exit(1); } catch (System.Exception e) { Console.Error.WriteLine(e.Message); Environment.Exit(1); } }
static void Main(string[] args) { NaElement xi; NaElement xo; NaServer s; String operation; if (args.Length < 4) { PrintUsage(); } try { Console.WriteLine("|-----------------------------------------|"); Console.WriteLine("| Program to Demo use of Performance APIs |"); Console.WriteLine("|-----------------------------------------|"); /* * Initialize connection to server, and * request version 1.3 of the API set */ s = new NaServer(args[0], 1, 3); /* Set connection style(HTTP)*/ s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; s.SetAdminUser(args[1], args[2]); operation = args[3]; /* To invoke perf-object-list-info API * Usage: perf_operation <filer> <user> <password> object-list * */ if (operation.Equals("object-list")) { xi = new NaElement("perf-object-list-info"); xo = s.InvokeElem(xi); System.Collections.IList objList = xo.GetChildByName("objects").GetChildren(); System.Collections.IEnumerator objIter = objList.GetEnumerator(); while (objIter.MoveNext()) { NaElement objInfo = (NaElement)objIter.Current; Console.Out.Write("Object Name = " + objInfo.GetChildContent("name") + "\t"); Console.Out.Write("privilege level = " + objInfo.GetChildContent("privilege-level") + "\n"); } Console.Out.WriteLine("\n"); } /* To invoke perf-object-instance-list-info API * Usage: perf_operation <filer> <user> <password> instance-list <objectname> * */ else if (operation.Equals("instance-list")) { if (args.Length < 5) { Console.Out.WriteLine("Usage:"); Console.Out.WriteLine("perf_operation <filer> <user> <password> <instance-list> <objectname>"); Environment.Exit(1); } xi = new NaElement("perf-object-instance-list-info"); xi.AddNewChild("objectname", args[4]); xo = s.InvokeElem(xi); System.Collections.IList instList = xo.GetChildByName("instances").GetChildren(); System.Collections.IEnumerator instIter = instList.GetEnumerator(); while (instIter.MoveNext()) { NaElement instInfo = (NaElement)instIter.Current; Console.Out.WriteLine("Instance Name = " + instInfo.GetChildContent("name")); } } /* To invoke perf-object-counter-list-info API * Usage: perf_operation <filer> <user> <password> counter-list <objectname> * */ else if (operation.Equals("counter-list")) { if (args.Length < 5) { Console.Out.WriteLine("Usage:"); Console.Out.WriteLine("perf_operation <filer> <user> <password> <counter-list> <objectname>"); Environment.Exit(1); } xi = new NaElement("perf-object-counter-list-info"); xi.AddNewChild("objectname", args[4]); xo = s.InvokeElem(xi); System.Collections.IList counterList = xo.GetChildByName("counters").GetChildren(); System.Collections.IEnumerator counterIter = counterList.GetEnumerator(); while (counterIter.MoveNext()) { NaElement counterInfo = (NaElement)counterIter.Current; Console.Out.Write("Counter Name = " + counterInfo.GetChildContent("name") + "\t\t\t\t"); if (counterInfo.GetChildContent("base-counter") != null) { Console.Out.Write("Base Counter = " + counterInfo.GetChildContent("base-counter") + "\t"); } else { Console.Out.Write("Base Counter = none\t\t\t"); } Console.Out.Write("Privilege Level = " + counterInfo.GetChildContent("privilege-level") + "\t\t"); if (counterInfo.GetChildContent("unit") != null) { Console.Out.Write("Unit = " + counterInfo.GetChildContent("unit") + "\t"); } else { Console.Out.Write("Unit = none\t"); } Console.Out.Write("\n"); } } /* To invoke perf-object-get-instances-iter-* API * Usage: perf_operation <filer> <user> <password> * <get-counter-values> <objectname> <counter1> <counter2> <counter3>...... */ else if (operation.Equals("get-counter-values")) { int totalRecords = 0; int maxRecords = 10; int numRecords = 0; String iterTag = null; if (args.Length < 5) { Console.Out.WriteLine("Usage:"); Console.Out.WriteLine("perf_operation <filer> <user> <password> " + "<get-counter-values> <objectname> [<counter1> <counter2> ...]"); Environment.Exit(1); } xi = new NaElement("perf-object-get-instances-iter-start"); xi.AddNewChild("objectname", args[4]); NaElement counters = new NaElement("counters"); /*Now store rest of the counter names as child * element of counters * * Here it has been hard coded as 5 because * first counter is specified at 6th position from * cmd prompt */ int numCounter = 5; while (numCounter < (args.Length)) { counters.AddNewChild("counter", args[numCounter]); numCounter++; } /* If no counters are specified then all the counters are fetched */ if (numCounter > 5) { xi.AddChildElement(counters); } xo = s.InvokeElem(xi); totalRecords = xo.GetChildIntValue("records", -1); iterTag = xo.GetChildContent("tag"); do { xi = new NaElement("perf-object-get-instances-iter-next"); xi.AddNewChild("tag", iterTag); xi.AddNewChild("maximum", System.Convert.ToString(maxRecords)); xo = s.InvokeElem(xi); numRecords = xo.GetChildIntValue("records", 0); if (numRecords != 0) { System.Collections.IList instList = xo.GetChildByName("instances").GetChildren(); System.Collections.IEnumerator instIter = instList.GetEnumerator(); while (instIter.MoveNext()) { NaElement instData = (NaElement)instIter.Current; Console.Out.WriteLine("Instance = " + instData.GetChildContent("name")); System.Collections.IList counterList = instData.GetChildByName("counters").GetChildren(); System.Collections.IEnumerator counterIter = counterList.GetEnumerator(); while (counterIter.MoveNext()) { NaElement counterData = (NaElement)counterIter.Current; Console.Out.Write("counter name = " + counterData.GetChildContent("name")); Console.Out.Write("\t counter value = " + counterData.GetChildContent("value") + "\n"); } Console.Out.WriteLine("\n"); } } }while (numRecords != 0); xi = new NaElement("perf-object-get-instances-iter-end"); xi.AddNewChild("tag", iterTag); xo = s.InvokeElem(xi); } else { PrintUsage(); } } catch (NaAuthException e) { Console.Error.WriteLine(e.Message + "Bad login/password"); } catch (NaApiFailedException e) { Console.Error.WriteLine("API failed (" + e.Message + ")"); } catch (NaProtocolException e) { Console.Error.WriteLine(e.Message); } catch (System.Exception e) { Console.Error.WriteLine(e.Message); } }
static void Main(string[] args) { NaElement xi; NaElement xo; NaServer s; int index; String options; int dos1 = 0; if (args.Length < 5) { usage(); } index = args[0].IndexOf('-'); if (index == 0 && args[0][index] == '-') { options = args[0].Substring(index + 1); if (options.Equals("s") && args.Length > 5) { dos1 = 1; } else { usage(); } } Console.WriteLine("|------------------------------------|"); Console.WriteLine("| Program to Demo VFILER Tunnel APIs |"); Console.WriteLine("|------------------------------------|"); try { if (dos1 == 1) { //Initialize connection to server, and //request version 1.7 of the API set for vfiler-tunneling // s = new NaServer(args[2], 1, 7); s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; s.SetAdminUser(args[3], args[4]); s.TransportType = NaServer.TRANSPORT_TYPE.HTTPS; s.Port = 443; s.ServerType = NaServer.SERVER_TYPE.FILER; s.SetVfilerTunneling(args[1]); //Invoke any ONTAPI API with arguments //in (key,value) pair //args[0]=option,args[1]=vfiler-name,args[2]=vfiler, //args[3]=user,args[4] = passwd, args[5]=Ontapi API, //args[6] onwards arguments in (key,value) //pair // xi = new NaElement(args[5]); try { if (args.Length > 6) { for (int index1 = 6; index1 < args.Length; index1++) { xi.AddNewChild( args[index1], args[index1 + 1]); index1++; } } } catch (IndexOutOfRangeException e) { Console.Out.WriteLine("Mismatch in arguments passed " + "(in (key,value) Pair) to Ontapi API"); throw new NaApiFailedException(e.Message); } } else { //Initialize connection to server, and //request version 1.7 of the API set for vfiler-tunneling // s = new NaServer(args[1], 1, 7); s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; s.SetAdminUser(args[2], args[3]); s.SetVfilerTunneling(args[0]); //Invoke any ONTAPI API with arguments //in (key,value) pair //args[0]=filer,args[1]=user,args[2]=passwd //args[3]=Ontapi API,args[4] onward arguments // in (key,value) pair // xi = new NaElement(args[4]); try { if (args.Length > 5) { for (int index2 = 5; index2 < args.Length; index2++) { xi.AddNewChild( args[index2], args[index2 + 1]); index2++; } } } catch (IndexOutOfRangeException e) { Console.Error.WriteLine("Mismatch in arguments passed " + "(in (key,value) Pair) to Ontapi API"); throw new NaApiFailedException(e.Message); } } xo = s.InvokeElem(xi); Console.WriteLine(xo.ToPrettyString("")); } catch (NaApiFailedException e) { Console.Error.WriteLine("API Failed Exception : " + e.Message); System.Environment.Exit(1); } catch (Exception e) { Console.Error.WriteLine("Exception: " + e.Message); System.Environment.Exit(1); } }
static void Main(string[] args) { NaElement xi; NaElement xo; NaServer s; String operation; if (args.Length < 4) { PrintUsage(); } try { Console.WriteLine("|-----------------------------------------|"); Console.WriteLine("| Program to demo use of NFS related APIs |"); Console.WriteLine("|-----------------------------------------|\n"); /* * Initialize connection to server, and * request version 1.3 of the API set */ s = new NaServer(args[0], 1, 3); /* Set connection style(HTTP)*/ s.Style = NaServer.AUTH_STYLE.LOGIN_PASSWORD; s.SetAdminUser(args[1], args[2]); operation = args[3]; /* To invoke nfs-enable API * Usage: nfs <filer> <user> <password> enable * */ if (operation.Equals("enable")) { xi = new NaElement("nfs-enable"); xo = s.InvokeElem(xi); Console.Out.WriteLine("enabled successfully!"); } /* To invoke nfs-enable API * Usage: nfs <filer> <user> <password> disable * */ else if (operation.Equals("disable")) { xi = new NaElement("nfs-disable"); xo = s.InvokeElem(xi); Console.Out.WriteLine("disabled successfully!"); } /* To invoke nfs-status API * Usage: nfs <filer> <user> <password> status * */ else if (operation.Equals("status")) { xi = new NaElement("nfs-status"); xo = s.InvokeElem(xi); String enabled = xo.GetChildContent("is-enabled"); if (String.Compare(enabled, "true") == 0) { Console.Out.WriteLine("NFS Server is enabled"); } else { Console.Out.WriteLine("NFS Server is disabled"); } } /* To invoke nfs-exportfs-list-rules API * Usage: nfs <filer> <user> <password> list * */ else if (operation.Equals("list")) { xi = new NaElement("nfs-exportfs-list-rules"); xo = s.InvokeElem(xi); System.Collections.IList retList = xo.GetChildByName("rules").GetChildren(); System.Console.WriteLine(xo.ToPrettyString("")); Environment.Exit(0); System.Collections.IEnumerator retIter = retList.GetEnumerator(); while (retIter.MoveNext()) { NaElement retInfo = (NaElement)retIter.Current; String pathName = retInfo.GetChildContent("pathname"); String rwList = "rw="; String roList = "ro="; String rootList = "root="; if (retInfo.GetChildByName("read-only") != null) { NaElement ruleElem = retInfo.GetChildByName("read-only"); System.Collections.IList hosts = ruleElem.GetChildren(); System.Collections.IEnumerator hostIter = hosts.GetEnumerator(); while (hostIter.MoveNext()) { NaElement hostInfo = (NaElement)hostIter.Current; if (hostInfo.GetChildContent("all-hosts") != null) { String allHost = hostInfo.GetChildContent("all-hosts"); if (String.Compare(allHost, "true") == 0) { roList = roList + "all-hosts"; break; } } else if (hostInfo.GetChildContent("name") != null) { roList = roList + hostInfo.GetChildContent("name") + ":"; } } } if (retInfo.GetChildByName("read-write") != null) { NaElement ruleElem = retInfo.GetChildByName("read-write"); System.Collections.IList hosts = ruleElem.GetChildren(); System.Collections.IEnumerator hostIter = hosts.GetEnumerator(); while (hostIter.MoveNext()) { NaElement hostInfo = (NaElement)hostIter.Current; if (hostInfo.GetChildContent("all-hosts") != null) { String allHost = hostInfo.GetChildContent("all-hosts"); if (String.Compare(allHost, "true") == 0) { rwList = rwList + "all-hosts"; break; } } else if (hostInfo.GetChildContent("name") != null) { rwList = rwList + hostInfo.GetChildContent("name") + ":"; } } } if (retInfo.GetChildByName("root") != null) { NaElement ruleElem = retInfo.GetChildByName("root"); System.Collections.IList hosts = ruleElem.GetChildren(); System.Collections.IEnumerator hostIter = hosts.GetEnumerator(); while (hostIter.MoveNext()) { NaElement hostInfo = (NaElement)hostIter.Current; if (hostInfo.GetChildContent("all-hosts") != null) { String allHost = hostInfo.GetChildContent("all-hosts"); if (String.Compare(allHost, "true") == 0) { rootList = rootList + "all-hosts"; break; } } else if (hostInfo.GetChildContent("name") != null) { rootList = rootList + hostInfo.GetChildContent("name") + ":"; } } } if (String.Compare(roList, "ro=") != 0) { pathName = pathName + ", \t" + roList; } if (String.Compare(rwList, "rw=") != 0) { pathName = pathName + ", \t" + rwList; } if (String.Compare(rootList, "root=") != 0) { pathName = pathName + ", \t" + rootList; } Console.Out.WriteLine(pathName); } } else { PrintUsage(); } } catch (NaAuthException e) { Console.Error.WriteLine("Bad login/password" + e.Message); } catch (NaApiFailedException e) { Console.Error.WriteLine("API failed (" + e.Message + ")"); } catch (NaProtocolException e) { Console.Error.WriteLine(e.StackTrace); } catch (System.Exception e) { Console.Error.WriteLine(e.Message); } }
static void Main(string[] args) { NaServer s; NaElement xi = null; NaElement xo; NaServer.TRANSPORT_TYPE transportType = NaServer.TRANSPORT_TYPE.HTTPS; NaServer.SERVER_TYPE serverType = NaServer.SERVER_TYPE.FILER; NaServer.AUTH_STYLE authStyle = NaServer.AUTH_STYLE.LOGIN_PASSWORD; String vfiler = null; String originatorId = null; String type; int index = 0; int showXML = 0; int inputXML = 0; int port = -1; int timeOut = -1; Boolean status = true; Boolean useRPC = false; Boolean useHostsEquiv = false; Boolean useCBA = false; Boolean verifyServerCert = false; Boolean verifyHostname = false; String certFile = null; String certPasswd = null; NaServer.CERT_STORE_NAME storeName = NaServer.CERT_STORE_NAME.MY; NaServer.CERT_STORE_LOCATION storeLocation = NaServer.CERT_STORE_LOCATION.CURRENT_USER; String certName = null; if (args.Length < 3) { Usage(); } index = 0; try { while (args[index].StartsWith("-")) { switch (args[index][1]) { case 't': type = args[index + 1]; if (type.Equals("dfm")) { serverType = NaServer.SERVER_TYPE.DFM; } else if (type.Equals("ocum")) { serverType = NaServer.SERVER_TYPE.OCUM; transportType = NaServer.TRANSPORT_TYPE.HTTPS; } else if (type.Equals("agent")) { serverType = NaServer.SERVER_TYPE.AGENT; } else if (type.Equals("filer")) { serverType = NaServer.SERVER_TYPE.FILER; } else { Console.WriteLine("\nERROR: Invalid Option for Server type."); Usage(); } index = index + 2; break; case 'v': vfiler = args[index + 1]; index = index + 2; break; case 'r': authStyle = NaServer.AUTH_STYLE.RPC; useRPC = true; index++; break; case 'n': transportType = NaServer.TRANSPORT_TYPE.HTTP; index++; break; case 'p': status = Int32.TryParse(args[index + 1], out port); if (status == false) { Console.WriteLine("\nERROR: Invalid port no."); Usage(); } index = index + 2; break; case 'i': inputXML = 1; index++; break; case 'I': inputXML = 2; index++; break; case 'x': showXML = 1; index++; break; case 'X': showXML = 2; index++; break; case 'h': authStyle = NaServer.AUTH_STYLE.HOSTSEQUIV; useHostsEquiv = true; index++; break; case 'c': status = Int32.TryParse(args[index + 1], out timeOut); if (status == false || timeOut <= 0) { Console.WriteLine("\nERROR: Invalid timeout value."); Usage(); } index = index + 2; break; case 'o': originatorId = args[index + 1]; index = index + 2; break; case 'C': useCBA = true; certFile = args[index + 1]; index = index + 2; break; case 'P': useCBA = true; certPasswd = args[index + 1]; index = index + 2; break; case 'T': String name = args[index + 1]; useCBA = true; switch (name) { case "AuthRoot": storeName = NaServer.CERT_STORE_NAME.AUTH_ROOT; break; case "CertificateAuthority": storeName = NaServer.CERT_STORE_NAME.CERTIFICATE_AUTHORITY; break; case "My": storeName = NaServer.CERT_STORE_NAME.MY; break; case "Root": storeName = NaServer.CERT_STORE_NAME.ROOT; break; case "TrustedPeople": storeName = NaServer.CERT_STORE_NAME.TRUSTED_PEOPLE; break; default: Console.WriteLine("Invalid store name: " + name); Console.WriteLine("Valid store names are: "); Console.WriteLine("My - certificate store for personal certificates"); Console.WriteLine("Root - certificate store for trusted root certificate authorities"); Console.WriteLine("AuthRoot - certificate store for third-party certificate authorities"); Console.WriteLine("CertificateAuthority - certificate store for intermediate certificate authorities"); Console.WriteLine("TrustedPeople - certificate store for directly trusted people and resources\n"); Usage(); break; } index = index + 2; break; case 'L': String location = args[index + 1]; useCBA = true; switch (location) { case "CurrentUser": storeLocation = NaServer.CERT_STORE_LOCATION.CURRENT_USER; break; case "LocalMachine": storeLocation = NaServer.CERT_STORE_LOCATION.LOCAL_MACHINE; break; default: Console.WriteLine("Invalid store location: " + location); Console.WriteLine("Valid store locations are: "); Console.WriteLine("CurrentUser - certificate store used by the current user"); Console.WriteLine("LocalMachine - certificate store assigned to the local machine"); Usage(); break; } index = index + 2; break; case 'N': certName = args[index + 1]; useCBA = true; index = index + 2; break; case 'S': verifyServerCert = true; index++; break; case 'H': verifyHostname = true; index++; break; default: Console.WriteLine("\nERROR: Invalid Option."); Usage(); break; } //switch (args[index][1]) { } //while (args[index].StartsWith("-")){ } catch (System.IndexOutOfRangeException) { Console.WriteLine("\nERROR: Invalid Arguments."); Usage(); } if (authStyle == NaServer.AUTH_STYLE.LOGIN_PASSWORD && args.Length < 4) { Usage(); } if (useHostsEquiv == true && useRPC == true) { Console.WriteLine("\nERROR: Invalid usage of authentication style. " + "Do not use -r option and -h option together.\n"); System.Environment.Exit(1); } if (useRPC == true && timeOut != -1) { Console.WriteLine("\nERROR: Connection timeout value cannot be set for RPC authentication style.\n"); Environment.Exit(1); } if (verifyHostname && !verifyServerCert) { Console.WriteLine("\nERROR: Hostname verification cannot be enabled when server certificate verification is disabled.\n"); Environment.Exit(1); } if (useCBA) { transportType = NaServer.TRANSPORT_TYPE.HTTPS; authStyle = NaServer.AUTH_STYLE.CERTIFICATE; } else if (authStyle == NaServer.AUTH_STYLE.LOGIN_PASSWORD) { if (index == args.Length) { Console.WriteLine("\nERROR: Host not specified."); Usage(); } if ((index + 1) == args.Length) { Console.WriteLine("\nERROR: User not specified."); Usage(); } else if ((index + 2) == args.Length) { Console.WriteLine("\nERROR: Password not specified."); Usage(); } } if (port == -1) { switch (serverType) { default: case NaServer.SERVER_TYPE.FILER: port = (transportType == NaServer.TRANSPORT_TYPE.HTTP ? 80 : 443); break; case NaServer.SERVER_TYPE.DFM: port = (transportType == NaServer.TRANSPORT_TYPE.HTTP ? 8088 : 8488); break; case NaServer.SERVER_TYPE.OCUM: port = 443; break; case NaServer.SERVER_TYPE.AGENT: port = (transportType == NaServer.TRANSPORT_TYPE.HTTP ? 4092 : 4093); break; } } try { //1. Create an instance of NaServer object. //NaServer is used to connect to servers and invoke API's. if (vfiler != null) { // Vfiler tunnelling requires ONTAPI version 7.1 to work s = new NaServer(args[index], 1, 7); } else { s = new NaServer(args[index], 1, 0); } //2. Set the server type s.ServerType = serverType; //3. Set the transport type s.TransportType = transportType; //4. Set the authentication style for subsequent ONTAPI authentications. s.Style = authStyle; //5. Set the login and password used for authenticating when //an ONTAPI API is invoked. if (authStyle == NaServer.AUTH_STYLE.LOGIN_PASSWORD) { s.SetAdminUser(args[++index], args[++index]); } //6. Set the port number s.Port = port; //7. Optional - set the vfiler name for vfiler tunneling if (vfiler != null) { s.SetVfilerTunneling(vfiler); } // Check if originator_id is set if (originatorId != null) { s.OriginatorId = originatorId; } //Set the request timeout. if (timeOut != -1) { s.TimeOut = timeOut; } if (useCBA) { if (certFile == null && certPasswd != null) { Console.WriteLine("\nERROR: Certificate file not specified."); Usage(); } if (certFile != null) { if (certPasswd != null) { s.SetClientCertificate(certFile, certPasswd); } else { s.SetClientCertificate(certFile); } } else { s.SetClientCertificate(storeName, storeLocation, certName); } } s.ServerCertificateVerification = verifyServerCert; if (verifyServerCert) { s.HostnameVerification = verifyHostname; } s.Snoop = 1; /* Invoke any ONTAPI API with arguments * in (key,value) pair * args[0]=filer,args[1]=user,args[2]=passwd * args[3]=Ontapi API,args[4] onward arguments * in (key,value) pair */ try { if (inputXML == 0) { if ((index + 1) == args.Length) { Console.WriteLine("\nERROR: API not specified."); Usage(); } //8. Create an instance of NaElement which contains the ONTAPI API request xi = new NaElement(args[++index]); } //Only use this for debugging else { GetXMLInput(inputXML, ref args, ref index); xi = s.ParseXMLInput(args[++index]); } if (args.Length > index + 1) { for (int index2 = index + 1; index2 < args.Length; index2++) { //9. Optional - add the child elements to the parent xi.AddNewChild(args[index2], args[index2 + 1]); index2++; } } // Only use this for debugging purpose if (showXML > 0) { if (showXML == 1) { Console.WriteLine("INPUT:\n" + xi.ToPrettyString("")); } else { s.DebugStyle = NaServer.DEBUG_STYLE.PRINT_PARSE; } } } catch (System.IndexOutOfRangeException) { throw new NaApiFailedException("Mismatch in arguments passed " + "(in (key,value) Pair) to " + "Ontapi API", -1); } // 10. Invoke a single ONTAPI API to the server. // The response is stored in xo. xo = s.InvokeElem(xi); // Only use this for debugging purpose if (showXML > 0) { if (showXML == 2) { //Simply return because the NaServer will print the raw XML OUTPUT. return; } Console.WriteLine("OUTPUT:"); } //11. Print the ONTAPI API response that is returned by the server Console.WriteLine(xo.ToPrettyString("")); } catch (NaApiFailedException e) { Console.Error.WriteLine(e.Message); } catch (Exception e) { Console.Error.WriteLine(e.Message); } }