コード例 #1
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);
            this.localAccountsPolicy = VapiAuthHelper.StubFactory.CreateStub <Policy>(SessionStubConfiguration);


            policyParamInfo = new PolicyTypes.Info();
            policyParamInfo.SetMaxDays(maxDays);
            policyParamInfo.SetMinDays(minDays);
            policyParamInfo.SetWarnDays(warnDays);
            Console.WriteLine(
                "Setting values now as per passed parameters maxDays: " + maxDays
                + ", minDays: " + minDays + ", warnDays: " + warnDays);
            localAccountsPolicy.Set(policyParamInfo);
            Console.WriteLine(
                "Values which are set are displayed below after get call:");

            Console.WriteLine("Maximum number of days between password change:"
                              + localAccountsPolicy.Get().GetMaxDays());
            Console.WriteLine("Minimum number of days between password change:"
                              + localAccountsPolicy.Get().GetMinDays());
            Console.WriteLine("Number of days of warning before password expires:"
                              + localAccountsPolicy.Get().GetWarnDays());
            Console.ReadKey();
        }
コード例 #2
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.sataService = VapiAuthHelper.StubFactory.CreateStub <Sata>(
                SessionStubConfiguration);

            Console.WriteLine("\n\n#### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId +
                              ") for SATA adapter configuration sample");

            Console.WriteLine("\n\n#### Example: List of all SATA adapters "
                              + "on the VM");
            List <SataTypes.Summary> sataSummaries =
                this.sataService.List(this.vmId);

            sataSummaries.ForEach(i => Console.WriteLine(i));

            Console.WriteLine("\n\n#### Display information about each "
                              + "adapter");
            foreach (SataTypes.Summary sataSummary in sataSummaries)
            {
                SataTypes.Info info = this.sataService.Get(this.vmId,
                                                           sataSummary.GetAdapter());
                Console.WriteLine(info);
            }

            Console.WriteLine("\n\n#### Example: Create SATA adapter with "
                              + "defaults.");
            SataTypes.CreateSpec sataCreateSpec = new SataTypes.CreateSpec();
            string sataId = this.sataService.Create(this.vmId, sataCreateSpec);

            Console.WriteLine(sataCreateSpec);
            SataTypes.Info sataInfo = this.sataService.Get(this.vmId, sataId);
            Console.WriteLine("SATA Adapter ID=" + sataId);
            Console.WriteLine(sataInfo);
            this.createdSataAdapters.Add(sataId);

            Console.WriteLine("\n\n#### Create SATA adapter with specific "
                              + "bus");
            sataCreateSpec = new SataTypes.CreateSpec();
            sataCreateSpec.SetBus(2L);
            sataId = this.sataService.Create(this.vmId, sataCreateSpec);
            Console.WriteLine(sataCreateSpec);
            sataInfo = this.sataService.Get(this.vmId, sataId);
            Console.WriteLine("SATA Adapter ID=" + sataId);
            Console.WriteLine(sataInfo);
            this.createdSataAdapters.Add(sataId);

            // List all SATA adapters for a VM
            Console.WriteLine("\n\n#### List all SATA adapters on the VM");
            sataSummaries = this.sataService.List(this.vmId);
            sataSummaries.ForEach(i => Console.WriteLine(i));
        }
コード例 #3
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            // Get a placement spec
            VMTypes.PlacementSpec vmPlacementSpec =
                PlacementHelper.GetPlacementSpecForCluster(
                    VapiAuthHelper.StubFactory,
                    SessionStubConfiguration,
                    DatacenterName,
                    ClusterName,
                    VmFolderName,
                    DatastoreName);

            // Get a standard network backing
            string standardNetworkBacking =
                NetworkHelper.GetStandardNetworkBacking(
                    VapiAuthHelper.StubFactory, SessionStubConfiguration,
                    DatacenterName, StandardPortgroupName);

            // Get a distributed network backing
            string distributedNetworkBacking =
                NetworkHelper.GetDistributedNetworkBacking(
                    VapiAuthHelper.StubFactory, SessionStubConfiguration,
                    DatacenterName, DistributedPortgroupName);

            // Create the VM
            CreateVm(vmPlacementSpec, standardNetworkBacking,
                     distributedNetworkBacking);
        }
コード例 #4
0
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "external Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the lookup service on the "
                              + "Platform Services Controller node.");
            LookupServiceHelper lookupServiceHelper = new LookupServiceHelper(
                LookupServiceUrl);

            Console.WriteLine("\nStep 2: Discover the Single Sign-On service "
                              + "URL from lookup service.");
            String ssoUrl = lookupServiceHelper.FindSsoUrl();

            Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and"
                              + " retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 4. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI "
                              + "services.");
            Console.WriteLine("\nListing all tags on the vCenter Server ...");
            Tag taggingService =
                vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig);
            List <string> tagList = taggingService.List();

            if (!tagList.Any())
            {
                Console.WriteLine("\nNo tags found !");
            }
            else
            {
                Console.WriteLine("\nTag Name\tTag Description");
                foreach (string tagId in tagList)
                {
                    Console.WriteLine(
                        taggingService.Get(tagId).GetName()
                        + "\t" + taggingService.Get(tagId).GetDescription());
                }
            }
            vapiAuthHelper.Logout();
        }
コード例 #5
0
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "embedded Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            /*
             * Since the platform services controller is embedded, the sso
             * server is the same as the vcenter server.
             */
            String ssoUrl = "https://" + Server + SSO_PATH;

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL "
                              + "and retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 2. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI "
                              + "services.");
            Console.WriteLine("\nListing all tags on the vCenter Server ...");
            Tag taggingService =
                vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig);
            List <string> tagList = taggingService.List();

            if (!tagList.Any())
            {
                Console.WriteLine("\nNo tags found !");
            }
            else
            {
                Console.WriteLine("\nTag Name\tTag Description");
                foreach (string tagId in tagList)
                {
                    Console.WriteLine(
                        taggingService.Get(tagId).GetName()
                        + "\t" + taggingService.Get(tagId).GetDescription());
                }
            }
            vapiAuthHelper.Logout();
        }
コード例 #6
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.bootService = VapiAuthHelper.StubFactory.CreateStub <Boot>(
                SessionStubConfiguration);

            Console.WriteLine("\n\n#### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId +
                              ") for boot configuration sample");

            // Print the current boot configuration
            Console.WriteLine("\n\n#### Print the original Boot Info");
            BootTypes.Info bootInfo = this.bootService.Get(this.vmId);
            Console.WriteLine(bootInfo);

            // Save the current boot info to revert settings after cleanup
            this.originalBootInfo = bootInfo;

            Console.WriteLine("\n\n#### Example: Update firmware to EFI for " +
                              "boot configuration");
            BootTypes.UpdateSpec bootUpdateSpec = new BootTypes.UpdateSpec();
            bootUpdateSpec.SetType(BootTypes.Type.EFI);
            this.bootService.Update(this.vmId, bootUpdateSpec);
            bootInfo = this.bootService.Get(this.vmId);

            Console.WriteLine("\n\n#### Example: Update boot firmware to tell "
                              + "it to enter setup mode on next boot.");
            bootUpdateSpec = new BootTypes.UpdateSpec();
            bootUpdateSpec.SetEnterSetupMode(true);
            this.bootService.Update(this.vmId, bootUpdateSpec);
            Console.WriteLine(bootUpdateSpec);
            bootInfo = this.bootService.Get(this.vmId);
            Console.WriteLine(bootInfo);

            Console.WriteLine("\n\n#### Example: Update firmware to introduce "
                              + "a delay in boot process and automatically reboot after a "
                              + "failure to boot, retry delay = 30000 ms");
            bootUpdateSpec = new BootTypes.UpdateSpec();
            bootUpdateSpec.SetDelay(10000L);
            bootUpdateSpec.SetRetry(true);
            bootUpdateSpec.SetRetryDelay(30000L);
            this.bootService.Update(this.vmId, bootUpdateSpec);
            bootInfo = this.bootService.Get(this.vmId);
            Console.WriteLine(bootInfo);
        }
コード例 #7
0
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "external Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the lookup service on the "
                              + "Platform Services Controller node.");
            LookupServiceHelper lookupServiceHelper = new LookupServiceHelper(
                LookupServiceUrl);

            Console.WriteLine("\nStep 2: Discover the Single Sign-On service "
                              + "URL from lookup service.");
            String ssoUrl = lookupServiceHelper.FindSsoUrl();

            Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and"
                              + " retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 4. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI "
                              + "services.");
            Datacenter datacenterService =
                vapiAuthHelper.StubFactory.CreateStub <Datacenter>(
                    sessionStubConfig);
            List <DatacenterTypes.Summary> dcList =
                datacenterService.List(new DatacenterTypes.FilterSpec());

            Console.WriteLine("\nList of datacenters on the vcenter server:");
            foreach (DatacenterTypes.Summary dcSummary in dcList)
            {
                Console.WriteLine(dcSummary);
            }
            vapiAuthHelper.Logout();
        }
コード例 #8
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.memoryService =
                VapiAuthHelper.StubFactory.CreateStub <Memory>(
                    SessionStubConfiguration);

            Console.WriteLine("\n\n#### Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId +
                              " ) for memory configuration sample.");

            // Get the current memory info
            Console.WriteLine("\n\n#### Print original memory info.");
            MemoryTypes.Info memoryInfo = memoryService.Get(this.vmId);
            Console.WriteLine(memoryInfo);

            /*
             * Save the current memory info to verify that we have cleaned up
             * properly.
             */
            this.originalMemoryInfo = memoryInfo;

            Console.WriteLine("\n\n#### Example: Update memory size field of "
                              + "memory configuration.");
            MemoryTypes.UpdateSpec memoryUpdateSpec =
                new MemoryTypes.UpdateSpec();
            memoryUpdateSpec.SetSizeMiB(8 * 1024L);
            memoryService.Update(this.vmId, memoryUpdateSpec);
            Console.WriteLine(memoryUpdateSpec);
            memoryInfo = memoryService.Get(this.vmId);
            Console.WriteLine(memoryInfo);

            Console.WriteLine("\n\n#### Example: Update hot add enabled field "
                              + "of memory configuration.");
            memoryUpdateSpec = new MemoryTypes.UpdateSpec();
            memoryUpdateSpec.SetHotAddEnabled(true);
            memoryService.Update(this.vmId, memoryUpdateSpec);
            Console.WriteLine(memoryUpdateSpec);
            memoryInfo = memoryService.Get(this.vmId);
            Console.WriteLine(memoryInfo);
        }
コード例 #9
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            // Get a placement spec
            VMTypes.PlacementSpec vmPlacementSpec =
                PlacementHelper.GetPlacementSpecForCluster(
                    VapiAuthHelper.StubFactory, SessionStubConfiguration,
                    DatacenterName, ClusterName, VmFolderName, DatastoreName);

            // Create the default VM
            CreateVm(vmPlacementSpec);
        }
コード例 #10
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.cpuService = VapiAuthHelper.StubFactory.CreateStub <Cpu>(
                SessionStubConfiguration);

            Console.WriteLine("\n\n### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId
                              + " ) for CPU configuration sample.");

            Console.WriteLine("\n\n### Example: Print original cpu info");
            CpuTypes.Info cpuInfo = cpuService.Get(this.vmId);
            Console.WriteLine(cpuInfo);

            /*
             * Save the current cpu info to verify that we have cleaned up
             * properly
             */
            this.originalCpuInfo = cpuInfo;

            Console.WriteLine("\n\n### Example: Update count field of CPU " +
                              "configuration");
            CpuTypes.UpdateSpec cpuUpdateSpec = new CpuTypes.UpdateSpec();
            cpuUpdateSpec.SetCount(2L);
            cpuService.Update(this.vmId, cpuUpdateSpec);
            Console.WriteLine(cpuUpdateSpec);
            cpuInfo = cpuService.Get(this.vmId);
            Console.WriteLine(cpuInfo);

            Console.WriteLine("\n\n### Example: Update cpu fields, number of "
                              + "cores per socket=2, enable hot add");
            cpuUpdateSpec = new CpuTypes.UpdateSpec();
            cpuUpdateSpec.SetCoresPerSocket(2L);
            cpuUpdateSpec.SetHotAddEnabled(true);
            cpuService.Update(this.vmId, cpuUpdateSpec);
            Console.WriteLine(cpuUpdateSpec);
            cpuInfo = this.cpuService.Get(this.vmId);
            Console.WriteLine(cpuInfo);
        }
コード例 #11
0
        public override void Run()
        {
            System.Net.ServicePointManager.SecurityProtocol |=
                System.Net.SecurityProtocolType.Tls12;

            Console.WriteLine("\n\n#### Example: Login to vCenter server with "
                              + "embedded Platform Services Controller");

            VapiAuthenticationHelper vapiAuthHelper =
                new VapiAuthenticationHelper();

            /*
             * Since the platform services controller is embedded, the sso
             * server is the same as the vcenter server.
             */
            String ssoUrl = "https://" + Server + SSO_PATH;

            SetupSslTrustForServer();

            Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL "
                              + "and retrieve the SAML bearer token.");
            SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl,
                                                                     UserName, Password);

            Console.WriteLine("\nStep 2. Login to vAPI services using the "
                              + "SAML bearer token.");
            StubConfiguration sessionStubConfig =
                vapiAuthHelper.LoginBySamlBearerToken(Server,
                                                      samlBearerToken);

            Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI "
                              + "services.");
            Datacenter datacenterService =
                vapiAuthHelper.StubFactory.CreateStub <Datacenter>(
                    sessionStubConfig);
            List <DatacenterTypes.Summary> dcList =
                datacenterService.List(new DatacenterTypes.FilterSpec());

            Console.WriteLine("\nList of datacenters on the vcenter server:");
            foreach (DatacenterTypes.Summary dcSummary in dcList)
            {
                Console.WriteLine(dcSummary);
            }
            vapiAuthHelper.Logout();
        }
コード例 #12
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.vmService =
                VapiAuthHelper.StubFactory.CreateStub <VM>(
                    SessionStubConfiguration);
            List <VMTypes.Summary> vmList =
                this.vmService.List(new VMTypes.FilterSpec());

            Console.WriteLine("---------------------------------------------");
            Console.WriteLine("List of VMs");
            foreach (VMTypes.Summary vmsummary in vmList)
            {
                Console.WriteLine(vmsummary);
            }
            Console.WriteLine("---------------------------------------------");
        }
コード例 #13
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.scsiService = VapiAuthHelper.StubFactory.CreateStub <Scsi>(
                SessionStubConfiguration);

            Console.WriteLine("\n\n#### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId +
                              ") for SCSI adapter configuration sample");

            Console.WriteLine("\n\n#### Example: List of all SCSI adapters "
                              + "on the VM");
            List <ScsiTypes.Summary> scsiSummaries =
                this.scsiService.List(this.vmId);

            scsiSummaries.ForEach(i => Console.WriteLine(i));

            Console.WriteLine("\n\n#### Display information about each "
                              + "adapter");
            foreach (ScsiTypes.Summary scsiSummary in scsiSummaries)
            {
                ScsiTypes.Info info = this.scsiService.Get(this.vmId,
                                                           scsiSummary.GetAdapter());
                Console.WriteLine(info);
            }

            Console.WriteLine("\n\n#### Example: Create SCSI adapter with "
                              + "defaults.");
            ScsiTypes.CreateSpec scsiCreateSpec = new ScsiTypes.CreateSpec();
            string scsiId = this.scsiService.Create(this.vmId, scsiCreateSpec);

            Console.WriteLine(scsiCreateSpec);
            ScsiTypes.Info scsiInfo = this.scsiService.Get(this.vmId, scsiId);
            Console.WriteLine("SCSI Adapter ID=" + scsiId);
            Console.WriteLine(scsiInfo);
            this.createdScsiAdapters.Add(scsiId);

            Console.WriteLine("\n\n#### Create SCSI adapter with specific "
                              + "bus and sharing=true");
            scsiCreateSpec = new ScsiTypes.CreateSpec();
            scsiCreateSpec.SetBus(2L);
            scsiCreateSpec.SetSharing(ScsiTypes.Sharing.VIRTUAL);
            scsiId = this.scsiService.Create(this.vmId, scsiCreateSpec);
            Console.WriteLine(scsiCreateSpec);
            scsiInfo = this.scsiService.Get(this.vmId, scsiId);
            Console.WriteLine("SCSI Adapter ID=" + scsiId);
            Console.WriteLine(scsiInfo);
            this.createdScsiAdapters.Add(scsiId);

            Console.WriteLine("\n\n#### Update SCSI adapter by setting "
                              + "sharing=false");
            ScsiTypes.UpdateSpec scsiUpdateSpec = new ScsiTypes.UpdateSpec();
            scsiUpdateSpec.SetSharing(ScsiTypes.Sharing.NONE);
            this.scsiService.Update(this.vmId, scsiId, scsiUpdateSpec);
            Console.WriteLine(scsiUpdateSpec);
            scsiInfo = this.scsiService.Get(this.vmId, scsiId);
            Console.WriteLine("SCSI Adapter ID=" + scsiId);
            Console.WriteLine(scsiInfo);

            // List all SCSI adapters for a VM
            Console.WriteLine("\n\n#### List all SCSI adapters on the VM");
            scsiSummaries = this.scsiService.List(this.vmId);
            scsiSummaries.ForEach(i => Console.WriteLine(i));
        }
コード例 #14
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(

                    Server, UserName, Password);
            this.cdromService =
                VapiAuthHelper.StubFactory.CreateStub <Cdrom>(
                    SessionStubConfiguration);
            this.powerService =
                VapiAuthHelper.StubFactory.CreateStub <Power>(
                    SessionStubConfiguration);
            this.sataService =
                VapiAuthHelper.StubFactory.CreateStub <Sata>(
                    SessionStubConfiguration);

            Console.WriteLine("\n\n#### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId="
                              + this.vmId + " ) for the CD-ROM configuration sample.");

            Console.WriteLine("\n\n#### Setup: Create SATA controller");
            SataTypes.CreateSpec sataCreateSpec = new SataTypes.CreateSpec();
            this.sataId = sataService.Create(this.vmId, sataCreateSpec);
            Console.WriteLine(sataCreateSpec);

            Console.WriteLine("\n\n### Example: List all CD-ROMs");
            ListAllCdroms();

            Console.WriteLine("\n\n### Example: Create CD-ROM with ISO_FILE"
                              + " backing");
            CreateCdrom(CdromTypes.BackingType.ISO_FILE);

            Console.WriteLine("\n\n### Example: Create CD-ROM with "
                              + "CLIENT_DEVICE backing");
            CreateCdrom(CdromTypes.BackingType.CLIENT_DEVICE);

            Console.WriteLine("\n\n### Example: Create SATA CD-ROM with"
                              + " CLIENT_DEVICE backing");
            CreateCdromForAdapterType(CdromTypes.HostBusAdapterType.SATA,
                                      CdromTypes.BackingType.CLIENT_DEVICE);

            Console.WriteLine("\n\n### Example: Create SATA CD-ROM on specific"
                              + " bus with CLIENT_DEVICE backing");
            CreateSataCdromAtSpecificLocation(
                CdromTypes.BackingType.CLIENT_DEVICE, 0L, null);

            Console.WriteLine("\n\n### Example: Create SATA CD-ROM on specific"
                              + " bus and unit number with CLIENT_DEVICE "
                              + "backing");
            CreateSataCdromAtSpecificLocation(
                CdromTypes.BackingType.CLIENT_DEVICE, 0L, 10L);

            Console.WriteLine("\n\n### Example: Create IDE CD-ROM with"
                              + " CLIENT_DEVICE backing");
            CreateCdromForAdapterType(CdromTypes.HostBusAdapterType.IDE,
                                      CdromTypes.BackingType.CLIENT_DEVICE);

            Console.WriteLine("\n\n### Example: Create IDE CD-ROM as a slave"
                              + " device with HOST_DEVICE backing");
            CreateIdeCdromAsSpecificDevice(
                CdromTypes.BackingType.HOST_DEVICE, false);
        }
コード例 #15
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.diskService = VapiAuthHelper.StubFactory.CreateStub <Disk>(
                SessionStubConfiguration);
            this.ethernetService =
                VapiAuthHelper.StubFactory.CreateStub <Ethernet>(
                    SessionStubConfiguration);
            this.bootDeviceService =
                VapiAuthHelper.StubFactory.CreateStub <Device>(
                    SessionStubConfiguration);

            Console.WriteLine("\n\n#### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("\nUsing VM: " + VmName + " (vmId="
                              + this.vmId + " ) for boot device configuration sample");

            Console.WriteLine("\nValidate whether the VM has the required "
                              + "minimum number of devices");
            VM vmService = VapiAuthHelper.StubFactory.CreateStub <VM>(
                SessionStubConfiguration);

            VMTypes.Info vmInfo = vmService.Get(this.vmId);
            if (vmInfo.GetCdroms().Count < 1 || vmInfo.GetFloppies().Count < 1 ||
                vmInfo.GetDisks().Count < 1 || vmInfo.GetNics().Count < 1)
            {
                throw new Exception("\n Selected VM does not have the required "
                                    + "minimum number of devices: i.e. 1 Ethernet adapter, "
                                    + "1 CD-ROM, 1 Floppy drive, 3 disks");
            }

            Console.WriteLine("\n\n#### Example: Print the current boot device"
                              + " configuration");
            List <DeviceTypes.Entry> bootDeviceEntries =
                this.bootDeviceService.Get(this.vmId);

            bootDeviceEntries.ForEach(i => Console.WriteLine(i));

            // Save the current boot info to revert it during cleanup
            this.orginalBootDeviceEntries = bootDeviceEntries;

            Console.WriteLine("\n\n#### Example: Set boot order to be Floppy, "
                              + "Disk1, Disk2, Disk3, Ethernet NIC, CD-ROM");

            // Get the device identifiers for disks
            List <DiskTypes.Summary> diskSummaries =
                this.diskService.List(this.vmId);

            Console.WriteLine("\nList of disks attached to the VM: \n");
            diskSummaries.ForEach(i => Console.WriteLine(i));
            List <String> diskIds = new List <String>();

            foreach (DiskTypes.Summary diskSummary in diskSummaries)
            {
                diskIds.Add(diskSummary.GetDisk());
            }

            // Get device identifiers for Ethernet NICs
            List <EthernetTypes.Summary> ethernetSummaries =
                this.ethernetService.List(this.vmId);

            Console.WriteLine("\nList of Ethernet NICs attached to the VM:\n");
            ethernetSummaries.ForEach(i => Console.WriteLine(i));
            List <String> ethernetIds = new List <String>();

            foreach (EthernetTypes.Summary ethernetSummary in ethernetSummaries)
            {
                ethernetIds.Add(ethernetSummary.GetNic());
            }

            List <DeviceTypes.Entry> devices = new List <DeviceTypes.Entry>(4);

            devices.Add(new DeviceTypes.Entry());
            devices[0].SetType(DeviceTypes.Type.FLOPPY);

            devices.Add(new DeviceTypes.Entry());
            devices[1].SetDisks(diskIds);
            devices[1].SetType(DeviceTypes.Type.DISK);

            devices.Add(new DeviceTypes.Entry());
            devices[2].SetNic(ethernetIds[0]);
            devices[2].SetType(DeviceTypes.Type.ETHERNET);

            devices.Add(new DeviceTypes.Entry());
            devices[3].SetType(DeviceTypes.Type.CDROM);

            this.bootDeviceService.Set(this.vmId, devices);
            bootDeviceEntries = this.bootDeviceService.Get(this.vmId);
            Console.WriteLine("\nNew boot device configuration");
            bootDeviceEntries.ForEach(i => Console.WriteLine(i));
        }
コード例 #16
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            // Get the cluster
            this.clusterId = new DynamicID();
            this.clusterId.SetType("ClusterComputeResource");
            this.clusterId.SetId(ClusterHelper.GetCluster(
                                     VapiAuthHelper.StubFactory, SessionStubConfiguration,
                                     DatacenterName, ClusterName));

            this.tagName = RandomIdGenerator.GetRandomString("Tag-");
            var tagDesc = "Sample tag";

            this.categoryName = RandomIdGenerator.GetRandomString("Cat-");
            var categoryDesc = "Sample category";

            // create services
            this.tagService = VapiAuthHelper.StubFactory.CreateStub <Tag>(
                SessionStubConfiguration);
            this.categoryService =
                VapiAuthHelper.StubFactory.CreateStub <Category>(
                    SessionStubConfiguration);
            this.tagAssociation =
                VapiAuthHelper.StubFactory.CreateStub <TagAssociation>(
                    SessionStubConfiguration);

            // create a category
            this.categoryId = CreateCategory(categoryService, categoryName,
                                             categoryDesc, CategoryModel.Cardinality.MULTIPLE);
            Console.WriteLine("Created category '{0}'", categoryName);

            // create a tag
            this.tagId = CreateTag(
                this.tagService, this.tagName, tagDesc, this.categoryId);
            Console.WriteLine("Created tag '{0}'", this.tagName);

            // update the category
            var newCategoryDesc = "Tag category updated at " + DateTime.Now;

            UpdateCategoryDesc(this.categoryService, this.categoryId,
                               newCategoryDesc);
            Console.WriteLine("Updated category description to '{0}'",
                              newCategoryDesc);

            // update the tag
            var newTagDesc = "Tag updated at " + DateTime.Now;

            UpdateTagDesc(tagService, tagId, newTagDesc);
            Console.WriteLine("Updated tag description to '{0}'", newTagDesc);

            // tag the Cluster with the newely created tag
            this.tagAssociation.Attach(this.tagId, this.clusterId);
            if (this.tagAssociation.ListAttachedTags(
                    this.clusterId).Contains(this.tagId))
            {
                Console.WriteLine("Cluster '{0}' tagged with '{1}'",
                                  ClusterName, tagName);
                this.tagAttached = true;
            }
            else
            {
                throw new Exception(string.Format(
                                        "Could not tag Cluster '{0}' with '{1}'",
                                        ClusterName, tagName));
            }
        }
コード例 #17
0
        public override void Run()
        {
            // Login
            VapiAuthHelper           = new VapiAuthenticationHelper();
            SessionStubConfiguration =
                VapiAuthHelper.LoginByUsernameAndPassword(
                    Server, UserName, Password);

            this.powerService = VapiAuthHelper.StubFactory.CreateStub <Power>(
                SessionStubConfiguration);
            this.ethernetService =
                VapiAuthHelper.StubFactory.CreateStub <Ethernet>(
                    SessionStubConfiguration);

            Console.WriteLine("\n\n#### Setup: Get the virtual machine id");
            this.vmId = VmHelper.GetVm(VapiAuthHelper.StubFactory,
                                       SessionStubConfiguration, VmName);
            Console.WriteLine("Using VM: " + VmName + " (vmId=" + this.vmId +
                              ") for ethernet adapter configuration sample");

            // List all ethernet adapters of the virtual machine
            List <EthernetTypes.Summary> nicSummaries =
                this.ethernetService.List(this.vmId);

            nicSummaries.ForEach(i => Console.WriteLine(i));

            Console.WriteLine("\n\n#### Print info for each Ethernet NIC on "
                              + "the vm.");
            foreach (EthernetTypes.Summary nicSummary in nicSummaries)
            {
                EthernetTypes.Info info =
                    this.ethernetService.Get(this.vmId, nicSummary.GetNic());
                Console.WriteLine(info);
            }

            Console.WriteLine("\n\n#### Example: Create ethernet NIC using "
                              + "standard portgroup and default settings");
            string stdNetworkId = NetworkHelper.GetStandardNetworkBacking(
                VapiAuthHelper.StubFactory, SessionStubConfiguration,
                Datacenter, StandardPortGroup);

            EthernetTypes.CreateSpec nicCreateSpec =
                new EthernetTypes.CreateSpec();
            EthernetTypes.BackingSpec nicBackingSpec =
                new EthernetTypes.BackingSpec();
            nicBackingSpec.SetNetwork(stdNetworkId);
            nicBackingSpec.SetType(
                EthernetTypes.BackingType.STANDARD_PORTGROUP);
            nicCreateSpec.SetBacking(nicBackingSpec);
            string nicId =
                this.ethernetService.Create(this.vmId, nicCreateSpec);

            this.createdNics.Add(nicId);
            Console.WriteLine(nicCreateSpec);
            EthernetTypes.Info nicInfo =
                this.ethernetService.Get(this.vmId, nicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + nicId);
            Console.WriteLine(nicInfo);

            Console.WriteLine("\n\n#### Example: Create Ethernet NIC using"
                              + " standard portgroup and specifying start_connected=true,"
                              + " allow_guest_control=true, mac_type, mac_address,"
                              + " wake_on_lan=enabled.");
            nicBackingSpec = new EthernetTypes.BackingSpec();
            nicBackingSpec.SetNetwork(stdNetworkId);
            nicBackingSpec.SetType(
                EthernetTypes.BackingType.STANDARD_PORTGROUP);
            nicCreateSpec = new EthernetTypes.CreateSpec();
            nicCreateSpec.SetAllowGuestControl(true);
            nicCreateSpec.SetMacType(EthernetTypes.MacAddressType.MANUAL);
            nicCreateSpec.SetMacAddress("01:23:45:67:89:10");
            nicCreateSpec.SetBacking(nicBackingSpec);
            nicId = this.ethernetService.Create(this.vmId, nicCreateSpec);
            this.createdNics.Add(nicId);
            Console.WriteLine(nicCreateSpec);
            nicInfo = this.ethernetService.Get(this.vmId, nicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + nicId);
            Console.WriteLine(nicInfo);

            Console.WriteLine("\n\n#### Example: Create Ethernet NIC using"
                              + " distributed portgroup and specifying start_connected=true,"
                              + " allow_guest_control=true, mac_type, mac_address,"
                              + " wake_on_lan=enabled.");
            nicBackingSpec = new EthernetTypes.BackingSpec();
            nicBackingSpec.SetNetwork(stdNetworkId);
            nicBackingSpec.SetType(
                EthernetTypes.BackingType.STANDARD_PORTGROUP);
            nicCreateSpec = new EthernetTypes.CreateSpec();
            nicCreateSpec.SetAllowGuestControl(true);
            nicCreateSpec.SetMacType(EthernetTypes.MacAddressType.MANUAL);
            nicCreateSpec.SetMacAddress("24:68:10:12:14:16");
            nicCreateSpec.SetBacking(nicBackingSpec);
            nicId = this.ethernetService.Create(this.vmId, nicCreateSpec);
            this.createdNics.Add(nicId);
            Console.WriteLine(nicCreateSpec);
            nicInfo = this.ethernetService.Get(this.vmId, nicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + nicId);
            Console.WriteLine(nicInfo);

            String lastNicId = nicId;

            Console.WriteLine(
                "\n\n#### Example: Update Ethernet NIC with different"
                + " backing.");
            nicBackingSpec = new EthernetTypes.BackingSpec();
            nicBackingSpec.SetType(
                EthernetTypes.BackingType.STANDARD_PORTGROUP);
            nicBackingSpec.SetNetwork(stdNetworkId);
            EthernetTypes.UpdateSpec nicUpdateSpec =
                new EthernetTypes.UpdateSpec();
            nicUpdateSpec.SetBacking(nicBackingSpec);
            this.ethernetService.Update(this.vmId, lastNicId, nicUpdateSpec);
            Console.WriteLine(nicUpdateSpec);
            nicInfo = this.ethernetService.Get(this.vmId, lastNicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + lastNicId);
            Console.WriteLine(nicInfo);

            Console.WriteLine("\n\n#### Example: Update the Ethernet NIC,"
                              + " wake_on_lan = false, mac_type=GENERATED,"
                              + " startConnected = false, allowGuestControl = false.");
            nicUpdateSpec = new EthernetTypes.UpdateSpec();
            nicUpdateSpec.SetAllowGuestControl(false);
            nicUpdateSpec.SetStartConnected(false);
            nicUpdateSpec.SetWakeOnLanEnabled(false);
            this.ethernetService.Update(this.vmId, lastNicId, nicUpdateSpec);
            Console.WriteLine(nicUpdateSpec);
            nicInfo = this.ethernetService.Get(this.vmId, lastNicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + lastNicId);
            Console.WriteLine(nicInfo);

            Console.WriteLine("\n\n#### Powering on VM to run "
                              + "connect/disconnect example.");
            this.powerService.Start(this.vmId);
            nicInfo = this.ethernetService.Get(this.vmId, lastNicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + lastNicId);
            Console.WriteLine(nicInfo);

            Console.WriteLine("\n\n#### Example: Connect Ethernet NIC after"
                              + " powering on VM.");
            this.ethernetService.Connect(this.vmId, lastNicId);
            nicInfo = this.ethernetService.Get(this.vmId, lastNicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + lastNicId);
            Console.WriteLine(nicInfo);

            Console.WriteLine("\n\n#### Example: Disconnect Ethernet NIC after"
                              + " powering on VM.");
            this.ethernetService.Disconnect(this.vmId, lastNicId);
            nicInfo = this.ethernetService.Get(this.vmId, lastNicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + lastNicId);
            Console.WriteLine(nicInfo);

            // Power off the VM
            Console.WriteLine("\n\n#### Powering off the VM after"
                              + " connect/disconnect example.");
            this.powerService.Stop(this.vmId);
            nicInfo = this.ethernetService.Get(this.vmId, lastNicId);
            Console.WriteLine("VM ID=" + this.vmId);
            Console.WriteLine("Ethernet NIC ID=" + lastNicId);
            Console.WriteLine(nicInfo);
        }