Пример #1
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);
            }
        }
        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);
            }
        }