Exemplo n.º 1
0
        private static async Task Run()
        {
            try
            {
                // Create an rest service http client provider:
                string            restUrl             = "http://*****:*****@"https://192.168.75.195/sdk";
                string vSphereUserName               = "******";
                string vSphereUserPassword           = "******";
                VSphereClientProvider vSpherePovider = new VSphereClientProvider(restUri, restAccessToken);

                // Create vSphere Session
                string vSphereSessionId = await vSpherePovider.GetSessionId(vSphereUrl, vSphereUserName, vSphereUserPassword);


                // Create a virtual machines info client instance:
                VirtualMachineClient vmClient = new VirtualMachineClient(restUri, restAccessToken, vSphereUrl, vSphereSessionId);

                // Read initial virtual machines name:
                Console.WriteLine("Read all the virtual machines...");
                List <string> vms = await vmClient.GetVirtualMachinesAsync();

                WriteVmList(vms);

                // Read initial virtual machines virtual disk info:
                string vm = vms.First();
                Console.WriteLine($"Read the virtual machine {vm} info...");
                var vmInfo = await vmClient.GetVirtualMachineAsync(vm);

                WriteVmInfo(vmInfo);
            }
            catch (AggregateException ex)
            {
                // If it's an aggregate exception, an async error occurred:
                Console.WriteLine(ex.InnerExceptions[0].Message);
                Console.WriteLine("Press the Enter key to Exit...");
                Console.ReadLine();
                return;
            }
            catch (Exception ex)
            {
                // Something else happened:
                Console.WriteLine(ex.Message);
                Console.WriteLine("Press the Enter key to Exit...");
                Console.ReadLine();
                return;
            }
        }