示例#1
0
        private void ListAllVMs()
        {
            var servicesList = this.ComputeClient.HostedServices.List();

            foreach (var service in servicesList.HostedServices)
            {
                try
                {
                    var deploymentGetResponse = this.ComputeClient.Deployments.GetBySlot(service.ServiceName, DeploymentSlot.Production);
                    foreach (var role in deploymentGetResponse.Roles)
                    {
                        if (role.RoleType == "PersistentVMRole")
                        {
                            RoleInstance instance  = deploymentGetResponse.RoleInstances.First(r => r.RoleName == role.RoleName);
                            var          vmContext = new PersistentVMRoleListContext
                            {
                                ServiceName = service.ServiceName,
                                Status      = instance.InstanceStatus,
                                Name        = instance.RoleName
                            };

                            WriteObject(vmContext, true);
                        }
                    }
                }
                catch (CloudException e)
                {
                    if (e.Response.StatusCode != HttpStatusCode.NotFound)
                    {
                        throw;
                    }
                }
            }
        }
示例#2
0
        private void ListAllVMs()
        {
            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                HostedServiceList services = this.RetryCall(s => this.Channel.ListHostedServices(s));
                if (services != null)
                {
                    foreach (HostedService service in services)
                    {
                        using (new OperationContextScope(Channel.ToContextChannel()))
                        {
                            try
                            {
                                var deployment = this.RetryCall(s => this.Channel.GetDeploymentBySlot(s, service.ServiceName, DeploymentSlotType.Production));
                                foreach (Role role in deployment.RoleList)
                                {
                                    if (role.RoleType == "PersistentVMRole")
                                    {
                                        RoleInstance instance = deployment.RoleInstanceList.Where(r => r.RoleName == role.RoleName).First();
                                        PersistentVMRoleListContext vmContext = new PersistentVMRoleListContext()
                                        {
                                            ServiceName = service.ServiceName,
                                            Status      = instance.InstanceStatus,
                                            Name        = instance.RoleName
                                        };

                                        WriteObject(vmContext, true);
                                    }
                                }
                            }
                            catch (ServiceManagementClientException exc)
                            {
                                if (exc.HttpStatus != HttpStatusCode.NotFound)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
        }
        private void ListAllVMs()
        {
            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                HostedServiceList services = this.RetryCall(s => this.Channel.ListHostedServices(s));
                if (services != null)
                {
                    foreach (HostedService service in services)
                    {
                        using (new OperationContextScope(Channel.ToContextChannel()))
                        {
                            try
                            {
                                var deployment = this.RetryCall(s => this.Channel.GetDeploymentBySlot(s, service.ServiceName, "Production"));
                                foreach (Role role in deployment.RoleList)
                                {
                                    if (role.RoleType == "PersistentVMRole")
                                    {
                                        RoleInstance instance = deployment.RoleInstanceList.Where(r => r.RoleName == role.RoleName).First();
                                        PersistentVMRoleListContext vmContext = new PersistentVMRoleListContext()
                                        {
                                            ServiceName = service.ServiceName,
                                            Status = instance.InstanceStatus,
                                            Name = instance.RoleName
                                        };

                                        WriteObject(vmContext, true);
                                    }
                                }
                            }
                            catch (ServiceManagementClientException exc)
                            {
                                if(exc.HttpStatus != HttpStatusCode.NotFound)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        public void AzureIaaSBVT()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            DateTime prevTime = DateTime.Now;

            string diskLabel1 = "disk1";
            int    diskSize1  = 30;
            int    lunSlot1   = 0;

            string diskLabel2 = "disk2";
            int    diskSize2  = 50;
            int    lunSlot2   = 2;


            string           ep1Name               = "tcp1";
            int              ep1LocalPort          = 60010;
            int              ep1PublicPort         = 60011;
            string           ep1LBSetName          = "lbset1";
            int              ep1ProbePort          = 60012;
            string           ep1ProbePath          = string.Empty;
            int?             ep1ProbeInterval      = 7;
            int?             ep1ProbeTimeout       = null;
            NetworkAclObject ep1AclObj             = vmPowershellCmdlets.NewAzureAclConfig();
            bool             ep1DirectServerReturn = false;

            string           ep2Name               = "tcp2";
            int              ep2LocalPort          = 60020;
            int              ep2PublicPort         = 60021;
            int              ep2LocalPortChanged   = 60030;
            int              ep2PublicPortChanged  = 60031;
            string           ep2LBSetName          = "lbset2";
            int              ep2ProbePort          = 60022;
            string           ep2ProbePath          = @"/";
            int?             ep2ProbeInterval      = null;
            int?             ep2ProbeTimeout       = 32;
            NetworkAclObject ep2AclObj             = vmPowershellCmdlets.NewAzureAclConfig();
            bool             ep2DirectServerReturn = false;

            string cerFileName         = "testcert.cer";
            string thumbprintAlgorithm = "sha1";

            try
            {
                // Create a certificate
                X509Certificate2 certCreated = Utilities.CreateCertificate(password);
                byte[]           certData2   = certCreated.Export(X509ContentType.Cert);
                File.WriteAllBytes(cerFileName, certData2);

                // Install the .cer file to local machine.
                StoreLocation    certStoreLocation = StoreLocation.CurrentUser;
                StoreName        certStoreName     = StoreName.My;
                X509Certificate2 installedCert     = Utilities.InstallCert(cerFileName, certStoreLocation, certStoreName);

                PSObject certToUpload = vmPowershellCmdlets.RunPSScript(
                    String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), installedCert.Thumbprint))[0];
                string certData = Convert.ToBase64String(((X509Certificate2)certToUpload.BaseObject).RawData);

                string newAzureVMName = Utilities.GetUniqueShortName(vmNamePrefix);
                if (string.IsNullOrEmpty(imageName))
                {
                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
                }

                RecordTimeTaken(ref prevTime);

                //
                // New-AzureService and verify with Get-AzureService
                //
                vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
                Assert.IsTrue(Verify.AzureService(serviceName, serviceName, locationName));
                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureCertificate and verify with Get-AzureCertificate
                //
                vmPowershellCmdlets.AddAzureCertificate(serviceName, certToUpload);
                Assert.IsTrue(Verify.AzureCertificate(serviceName, certCreated.Thumbprint, thumbprintAlgorithm, certData));
                RecordTimeTaken(ref prevTime);

                //
                // Remove-AzureCertificate
                //
                vmPowershellCmdlets.RemoveAzureCertificate(serviceName, certCreated.Thumbprint, thumbprintAlgorithm);
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureCertificate, serviceName, certCreated.Thumbprint, thumbprintAlgorithm));
                RecordTimeTaken(ref prevTime);

                //
                // New-AzureVMConfig
                //
                var          azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small.ToString(), imageName);
                PersistentVM vm = vmPowershellCmdlets.NewAzureVMConfig(azureVMConfigInfo);

                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureCertificate
                //
                vmPowershellCmdlets.AddAzureCertificate(serviceName, certToUpload);

                //
                // New-AzureCertificateSetting
                //
                CertificateSettingList certList = new CertificateSettingList();
                certList.Add(vmPowershellCmdlets.NewAzureCertificateSetting(certStoreName.ToString(), installedCert.Thumbprint));
                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureProvisioningConfig
                //
                AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, certList, username, password);
                azureProvisioningConfig.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureProvisioningConfig(azureProvisioningConfig);
                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureDataDisk (two disks)
                //
                AddAzureDataDiskConfig azureDataDiskConfigInfo1 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize1, diskLabel1, lunSlot1);
                azureDataDiskConfigInfo1.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo1);

                AddAzureDataDiskConfig azureDataDiskConfigInfo2 = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, diskSize2, diskLabel2, lunSlot2);
                azureDataDiskConfigInfo2.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureDataDisk(azureDataDiskConfigInfo2);

                RecordTimeTaken(ref prevTime);

                //
                // Add-AzureEndpoint (two endpoints)
                //
                AzureEndPointConfigInfo azureEndPointConfigInfo1 = new AzureEndPointConfigInfo(
                    AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                    ProtocolInfo.tcp,
                    ep1LocalPort,
                    ep1PublicPort,
                    ep1Name,
                    ep1LBSetName,
                    ep1ProbePort,
                    ProtocolInfo.tcp,
                    ep1ProbePath,
                    ep1ProbeInterval,
                    ep1ProbeTimeout,
                    ep1AclObj,
                    ep1DirectServerReturn,
                    null,
                    null,
                    LoadBalancerDistribution.SourceIP);

                azureEndPointConfigInfo1.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo1);

                AzureEndPointConfigInfo azureEndPointConfigInfo2 = new AzureEndPointConfigInfo(
                    AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                    ProtocolInfo.tcp,
                    ep2LocalPort,
                    ep2PublicPort,
                    ep2Name,
                    ep2LBSetName,
                    ep2ProbePort,
                    ProtocolInfo.http,
                    ep2ProbePath,
                    ep2ProbeInterval,
                    ep2ProbeTimeout,
                    ep2AclObj,
                    ep2DirectServerReturn);

                azureEndPointConfigInfo2.Vm = vm;
                vm = vmPowershellCmdlets.AddAzureEndPoint(azureEndPointConfigInfo2);

                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureAvailabilitySet
                //

                string testAVSetName = "testAVSet1";
                vm = vmPowershellCmdlets.SetAzureAvailabilitySet(testAVSetName, vm);
                RecordTimeTaken(ref prevTime);

                //
                // New-AzureDns
                //

                string dnsName   = "OpenDns1";
                string ipAddress = "208.67.222.222";

                DnsServer dns = vmPowershellCmdlets.NewAzureDns(dnsName, ipAddress);

                RecordTimeTaken(ref prevTime);

                //
                // New-AzureVM
                //
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, null, new[] { dns }, null, null, null, null);
                RecordTimeTaken(ref prevTime);

                //
                // Get-AzureVM without any parameter (List VMs)
                //
                var vmlist = vmPowershellCmdlets.GetAzureVM();
                Console.WriteLine("The number of VMs: {0}", vmlist.Count);
                Assert.AreNotSame(0, vmlist.Count, "No VM exists!!!");
                PersistentVMRoleListContext returnedVMlist =
                    vmlist.First(item => item.ServiceName.Equals(serviceName) && item.Name.Equals(newAzureVMName));
                Assert.IsNotNull(returnedVMlist, "Created VM does not exist!!!");
                Utilities.PrintContext((PersistentVMRoleContext)returnedVMlist);

                //
                // Get-AzureVM
                //
                PersistentVMRoleContext returnedVM = vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName);
                vm = returnedVM.VM;
                RecordTimeTaken(ref prevTime);

                //
                // Verify AzureDataDisk
                //
                Assert.IsTrue(Verify.AzureDataDisk(vm, diskLabel1, diskSize1, lunSlot1, HostCaching.None), "Data disk is not properly added");
                Assert.IsTrue(Verify.AzureDataDisk(vm, diskLabel2, diskSize2, lunSlot2, HostCaching.None), "Data disk is not properly added");
                Console.WriteLine("Data disk added correctly.");

                RecordTimeTaken(ref prevTime);

                //
                // Verify AzureEndpoint
                //
                Assert.IsTrue(Verify.AzureEndpoint(vm, new[] { azureEndPointConfigInfo1, azureEndPointConfigInfo2 }));

                //
                // Verify RDP & PowerShell Endpoints
                //
                var endpoints = vmPowershellCmdlets.GetAzureEndPoint(vm);
                Assert.IsTrue(endpoints.Count(e => e.Name == "PowerShell" && e.LocalPort == 5986 && e.Protocol == "tcp") == 1);
                Assert.IsTrue(endpoints.Count(e => e.Name == "RemoteDesktop" && e.LocalPort == 3389 && e.Protocol == "tcp") == 1);

                //
                // Verify AzureDns
                //
                Assert.IsTrue(Verify.AzureDns(vmPowershellCmdlets.GetAzureDeployment(serviceName).DnsSettings, dns));

                //
                // Verify AzureAvailibilitySet
                //
                Assert.IsTrue(Verify.AzureAvailabilitySet(vm, testAVSetName));

                //
                // Verify AzureOsDisk
                //
                Assert.IsTrue(Verify.AzureOsDisk(vm, "Windows", HostCaching.ReadWrite));

                //
                // Set-AzureDataDisk
                //
                SetAzureDataDiskConfig setAzureDataDiskConfigInfo = new SetAzureDataDiskConfig(HostCaching.ReadOnly, lunSlot1);
                setAzureDataDiskConfigInfo.Vm = vm;
                vm = vmPowershellCmdlets.SetAzureDataDisk(setAzureDataDiskConfigInfo);
                RecordTimeTaken(ref prevTime);

                //
                // Remove-AzureDataDisk
                //
                RemoveAzureDataDiskConfig removeAzureDataDiskConfig = new RemoveAzureDataDiskConfig(lunSlot2, vm);
                vm = vmPowershellCmdlets.RemoveAzureDataDisk(removeAzureDataDiskConfig);
                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureEndpoint
                //
                azureEndPointConfigInfo2 = new AzureEndPointConfigInfo(
                    AzureEndPointConfigInfo.ParameterSet.CustomProbe,
                    ProtocolInfo.tcp,
                    ep2LocalPortChanged,
                    ep2PublicPortChanged,
                    ep2Name,
                    ep2LBSetName,
                    ep2ProbePort,
                    ProtocolInfo.http,
                    ep2ProbePath,
                    ep2ProbeInterval,
                    ep2ProbeTimeout,
                    ep2AclObj,
                    ep2DirectServerReturn);

                azureEndPointConfigInfo2.Vm = vm;
                vm = vmPowershellCmdlets.SetAzureEndPoint(azureEndPointConfigInfo2);
                RecordTimeTaken(ref prevTime);

                //
                // Remove-AzureEndpoint
                //
                vm = vmPowershellCmdlets.RemoveAzureEndPoint(azureEndPointConfigInfo1.EndpointName, vm);
                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureVMSize
                //
                var vmSizeConfig = new SetAzureVMSizeConfig(InstanceSize.Medium.ToString());
                vmSizeConfig.Vm = vm;
                vm = vmPowershellCmdlets.SetAzureVMSize(vmSizeConfig);
                RecordTimeTaken(ref prevTime);

                //
                // Set-AzureOSDisk
                //
                vm = vmPowershellCmdlets.SetAzureOSDisk(HostCaching.ReadOnly, vm);


                //
                // Update-AzureVM
                //
                vmPowershellCmdlets.UpdateAzureVM(newAzureVMName, serviceName, vm);
                RecordTimeTaken(ref prevTime);

                //
                // Get-AzureVM and Verify the VM
                //
                vm = vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName).VM;

                // Verify setting data disk
                Assert.IsTrue(Verify.AzureDataDisk(vm, diskLabel1, diskSize1, lunSlot1, HostCaching.ReadOnly), "Data disk is not properly added");

                // Verify removing a data disk
                Assert.AreEqual(1, vmPowershellCmdlets.GetAzureDataDisk(vm).Count, "DataDisk is not removed.");

                // Verify setting an endpoint
                Assert.IsTrue(Verify.AzureEndpoint(vm, new[] { azureEndPointConfigInfo2 }));

                // Verify removing an endpoint
                Assert.IsFalse(Verify.AzureEndpoint(vm, new[] { azureEndPointConfigInfo1 }));

                // Verify os disk
                Assert.IsTrue(Verify.AzureOsDisk(vm, "Windows", HostCaching.ReadOnly));

                //
                // Remove-AzureVM
                //
                vmPowershellCmdlets.RemoveAzureVM(newAzureVMName, serviceName);

                RecordTimeTaken(ref prevTime);

                Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName));
                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
示例#5
0
        private void ListAllVMs()
        {
            var servicesList = this.ComputeClient.HostedServices.List();
            foreach (var service in servicesList.HostedServices)
            {
                try
                {
                    var deploymentGetResponse = this.ComputeClient.Deployments.GetBySlot(service.ServiceName, DeploymentSlot.Production);
                    foreach (var role in deploymentGetResponse.Roles)
                    {
                        if (role.RoleType == "PersistentVMRole")
                        {
                            RoleInstance instance = deploymentGetResponse.RoleInstances.First(r => r.RoleName == role.RoleName);
                            var vmContext = new PersistentVMRoleListContext
                                            {
                                                ServiceName = service.ServiceName,
                                                Status = instance.InstanceStatus,
                                                Name = instance.RoleName
                                            };

                            WriteObject(vmContext, true);
                        }
                    }
                }
                catch (CloudException e)
                {
                    if (e.Response.StatusCode != HttpStatusCode.NotFound)
                    {
                        throw;
                    }
                }
            }
        }
示例#6
0
        private void ListAllVMs()
        {
            Func <string, HostedServiceList> func = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                GetAzureVMCommand getAzureVMCommand = this;
                if (func == null)
                {
                    func = (string s) => base.Channel.ListHostedServices(s);
                }
                HostedServiceList hostedServiceList = ((CmdletBase <IServiceManagement>)getAzureVMCommand).RetryCall <HostedServiceList>(func);
                if (hostedServiceList != null)
                {
                    List <HostedService> .Enumerator enumerator = hostedServiceList.GetEnumerator();
                    try
                    {
                        Func <string, Deployment> func1 = null;
                        while (enumerator.MoveNext())
                        {
                            HostedService current = enumerator.Current;
                            using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                            {
                                try
                                {
                                    GetAzureVMCommand getAzureVMCommand1 = this;
                                    if (func1 == null)
                                    {
                                        func1 = (string s) => base.Channel.GetDeploymentBySlot(s, current.ServiceName, "Production");
                                    }
                                    Deployment deployment = ((CmdletBase <IServiceManagement>)getAzureVMCommand1).RetryCall <Deployment>(func1);
                                    List <Role> .Enumerator enumerator1 = deployment.RoleList.GetEnumerator();
                                    try
                                    {
                                        Func <RoleInstance, bool> func2 = null;
                                        while (enumerator1.MoveNext())
                                        {
                                            Role role = enumerator1.Current;
                                            if (role.RoleType != "PersistentVMRole")
                                            {
                                                continue;
                                            }
                                            RoleInstanceList roleInstanceList = deployment.RoleInstanceList;
                                            if (func2 == null)
                                            {
                                                func2 = (RoleInstance r) => r.RoleName == role.RoleName;
                                            }
                                            RoleInstance roleInstance = roleInstanceList.Where <RoleInstance>(func2).First <RoleInstance>();
                                            PersistentVMRoleListContext persistentVMRoleListContext = new PersistentVMRoleListContext();
                                            persistentVMRoleListContext.ServiceName = current.ServiceName;
                                            persistentVMRoleListContext.Status      = roleInstance.InstanceStatus;
                                            persistentVMRoleListContext.Name        = roleInstance.RoleName;
                                            PersistentVMRoleListContext persistentVMRoleListContext1 = persistentVMRoleListContext;
                                            base.WriteObject(persistentVMRoleListContext1, true);
                                        }
                                    }
                                    finally
                                    {
                                        enumerator1.Dispose();
                                    }
                                }
                                catch (CommunicationException communicationException1)
                                {
                                    CommunicationException communicationException = communicationException1;
                                    if (communicationException as EndpointNotFoundException == null)
                                    {
                                        throw;
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                }
            }
        }