Example #1
0
        static private void VerifyVmWithStaticCAIsReserved(string vmName, string svcName, string inputDip)
        {
            //Get the DIP of the VM (Get-AzureVM) VirtualNetworkStaticIPContext ipContext
            PersistentVMRoleContext vm = vmPowershellCmdlets.GetAzureVM(vmName, svcName);
            string confirguredVip      = vm.IpAddress;

            if (!string.IsNullOrEmpty(confirguredVip))
            {
                //Verify that the DIP of the VM is matched with an input DIP.
                Console.WriteLine("Verifying that the DIP of the VM {0} is matched with input DIP {1}.", inputDip, confirguredVip);
                Assert.AreEqual(inputDip, confirguredVip, string.Format("Static CA IpAddress {0} is not the same as the Input DIP {1}", confirguredVip, inputDip));
                Console.WriteLine("Verifyied that the DIP of the VM {0} is matched with input DIP {1}.", inputDip, confirguredVip);

                //Verify that the DIP is actually reserved.
                Console.WriteLine("Verifying that the DIP of the VM is actually reserved");
                var ipContext = vmPowershellCmdlets.GetAzureStaticVNetIP(vm.VM);
                Utilities.PrintContext(ipContext);
                Assert.AreEqual(inputDip, ipContext.IPAddress, string.Format("Reserved IPAddress {0}  is not equal to the input DIP {1}", ipContext.IPAddress, inputDip));
                Console.WriteLine("Verifyied that the DIP of the VM is actually reserved");

                //Verify that the IP is not available (Test-AzureStaticVNetIP –VnetName $vnet –IPAddress “10.0.0.5”)
                Console.WriteLine("Verifing that the IP {0} is not available", inputDip);
                VirtualNetworkStaticIPAvailabilityContext availibiltyContext = vmPowershellCmdlets.TestAzureStaticVNetIP(VNetName, inputDip);
                Console.WriteLine("IsAvailable:{0}", availibiltyContext.IsAvailable);
                Console.WriteLine("AvailableAddresses:{0}{1}", Environment.NewLine, availibiltyContext.AvailableAddresses.Aggregate((current, next) => current + Environment.NewLine + next));
                Assert.IsFalse(availibiltyContext.IsAvailable, string.Format("Test-AzureStaticVNetIP should return true as {0} is reserved", inputDip, vm.Name));
                Assert.IsFalse(availibiltyContext.AvailableAddresses.Contains(inputDip), string.Format("{0} is reserved for vm {1} and should not be in available addresses.", inputDip, vmName));
                Console.WriteLine("Verified that the IP {0} is not available", inputDip);
            }
            else
            {
                throw new Exception("Configured IPAddres value is null or empty");
            }
        }
Example #2
0
        internal override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();
            if (CurrentDeploymentNewSM == null)
            {
                return;
            }

            var role = CurrentDeploymentNewSM.Roles.FirstOrDefault(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase));

            if (role == null)
            {
                throw new ApplicationException(string.Format(Resources.NoCorrespondingRoleCanBeFoundInDeployment, Name));
            }
            try
            {
                var vm           = role;
                var roleInstance = CurrentDeploymentNewSM.RoleInstances.First(r => r.RoleName == vm.RoleName);
                var vmContext    = new PersistentVMRoleContext
                {
                    ServiceName           = ServiceName,
                    Name                  = vm.RoleName,
                    DeploymentName        = CurrentDeploymentNewSM.Name,
                    AvailabilitySetName   = vm.AvailabilitySetName,
                    Label                 = vm.Label,
                    InstanceSize          = vm.RoleSize.ToString(),
                    InstanceStatus        = roleInstance.InstanceStatus,
                    IpAddress             = roleInstance.IPAddress,
                    InstanceStateDetails  = roleInstance.InstanceStateDetails,
                    PowerState            = roleInstance.PowerState.ToString(),
                    InstanceErrorCode     = roleInstance.InstanceErrorCode,
                    InstanceName          = roleInstance.InstanceName,
                    InstanceFaultDomain   = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                    InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                    OperationDescription  = CommandRuntime.ToString(),
                    OperationId           = GetDeploymentOperationNewSM.Id,
                    OperationStatus       = GetDeploymentOperationNewSM.Status.ToString(),
                    VM = new PersistentVM
                    {
                        AvailabilitySetName  = vm.AvailabilitySetName,
                        ConfigurationSets    = PersistentVMHelper.MapConfigurationSets(vm.ConfigurationSets),
                        DataVirtualHardDisks = Mapper.Map(vm.DataVirtualHardDisks, new Collection <DataVirtualHardDisk>()),
                        Label             = vm.Label,
                        OSVirtualHardDisk = Mapper.Map(vm.OSVirtualHardDisk, new OSVirtualHardDisk()),
                        RoleName          = vm.RoleName,
                        RoleSize          = vm.RoleSize.ToString(),
                        RoleType          = vm.RoleType,
                        DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint
                    }
                };
                PersistentVMHelper.SaveStateToFile(vmContext.VM, Path);
                WriteObject(vmContext, true);
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, role.RoleName), e);
            }
        }
Example #3
0
        public void AddEndPointACLsonExistingDeployment()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string       newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);
            const string endpointName        = "web";

            imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username,
                                                password, locationName);

            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);

            Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);

            NetworkAclObject aclObj = vmPowershellCmdlets.NewAzureAclConfig();

            vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 100, ACLAction.Deny, "172.0.0.0/8", "notes3");

            var epConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.NoLB, ProtocolInfo.tcp,
                                                           80, 80, endpointName, aclObj);

            vmPowershellCmdlets.AddEndPoint(newAzureQuickVMName, serviceName, new[] { epConfigInfo });

            var returnedVm         = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);
            var returnedAclContext = vmPowershellCmdlets.GetAzureAclConfig(returnedVm.VM, endpointName);

            Assert.IsTrue(Verify.AzureAclConfig(aclObj, returnedAclContext));

            pass = true;
        }
Example #4
0
        public void AzureQuickVMBVT()
        {
            try
            {
                StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
                string windowsVMName = Utilities.GetUniqueShortName(vmNamePrefix);
                string linuxVMName   = Utilities.GetUniqueShortName("PSLinuxVM");

                if (string.IsNullOrEmpty(imageName))
                {
                    imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows" }, false);
                }
                string linuxImageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux" }, false);

                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, windowsVMName, serviceName, imageName, username, password, locationName);

                // Verify
                PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(windowsVMName, serviceName);
                Assert.AreEqual(windowsVMName, vmRoleCtxt.Name, true);

                vmPowershellCmdlets.NewAzureQuickVM(OS.Linux, linuxVMName, serviceName, linuxImageName, "user", password);

                // Verify
                vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(linuxVMName, serviceName);
                Assert.AreEqual(linuxVMName, vmRoleCtxt.Name, true);
                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                pass = false;
            }
        }
Example #5
0
        internal void SetVMSize(string vmName, string serviceName, SetAzureVMSizeConfig vmSizeConfig)
        {
            PersistentVMRoleContext vmRolectx = GetAzureVM(vmName, serviceName);

            vmSizeConfig.Vm = vmRolectx.VM;
            vmRolectx.VM    = SetAzureVMSize(vmSizeConfig);

            UpdateAzureVM(vmName, serviceName, vmRolectx.VM);
        }
Example #6
0
        public void RemoveEndPoint(string vmName, string serviceName, string [] epNames)
        {
            PersistentVMRoleContext vmRoleCtxt = GetAzureVM(vmName, serviceName);

            foreach (string ep in epNames)
            {
                vmRoleCtxt.VM = RemoveAzureEndPoint(ep, vmRoleCtxt).VM;
            }
            UpdateAzureVM(vmName, serviceName, vmRoleCtxt.VM);
        }
        public GetAzureNetworkInterfaceConfigCmdletInfo(string name, PersistentVMRoleContext vm)
        {
            this.cmdletName = Utilities.GetAzureNetworkInterfaceConfig;

            if (!string.IsNullOrEmpty(name))
            {
                this.parameters.Add(new CmdletParam("Name", name));
            }

            this.parameters.Add(new CmdletParam("VM", vm));
        }
Example #8
0
        internal void SetVMDataDisks(string vmName, string serviceName, SetAzureDataDiskConfig[] diskConfig)
        {
            PersistentVMRoleContext vmRolectx = GetAzureVM(vmName, serviceName);

            foreach (SetAzureDataDiskConfig discCfg in diskConfig)
            {
                discCfg.Vm   = vmRolectx.VM;
                vmRolectx.VM = SetAzureDataDisk(discCfg);
            }

            UpdateAzureVM(vmName, serviceName, vmRolectx.VM);
        }
        private IPersistentVM GetAzureVM(String roleName, String serviceName)
        {
            var vm = new PersistentVM {
                RoleName = roleName
            };
            var vmContext = new PersistentVMRoleContext
            {
                DeploymentName = roleName,
                Name           = roleName,
                ServiceName    = serviceName,
                VM             = vm
            };

            return(vmContext);
        }
Example #10
0
        public void ProvisionLinuxVM()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string newAzureQuickVMName = Utilities.GetUniqueShortName("PSLinuxVM");
            string linuxImageName      = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Linux", "testvmimage" }, false);

            vmPowershellCmdlets.NewAzureQuickLinuxVM(OS.Linux, newAzureQuickVMName, serviceName, linuxImageName, "user", password, locationName);

            // Verify
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);

            Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);

            // TODO: Disabling Stop / start / restart tests for now due to timing isues

            /*
             * // Stop & start the VM
             * vmPowershellCmdlets.StopAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * Assert.AreEqual(vmRoleCtxt.PowerState, VMPowerState.Stopped);
             * vmPowershellCmdlets.StartAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * Assert.AreEqual(vmRoleCtxt.PowerState, VMPowerState.Started.ToString());
             *
             * // Restart the VM
             * vmPowershellCmdlets.StopAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * Assert.AreEqual(vmRoleCtxt.PowerState, VMPowerState.Stopped);
             * vmPowershellCmdlets.RestartAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);
             * Assert.AreEqual(vmRoleCtxt.PowerState, VMPowerState.Started.ToString());
             * */

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));

            //TODO: Need to do proper cleanup of the service
            //            vmPowershellCmdlets.RemoveAzureService(newAzureQuickVMSvcName);
            //            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureService(newAzureQuickVMSvcName));

            pass = true;
        }
        public void GetIPForwardingOnVMNicSucceeds()
        {
            // Setup
            var VM = new PersistentVMRoleContext()
            {
                // these are the only 2 properties being used in the cmdlet
                Name           = RoleName,
                DeploymentName = DeploymentName
            };

            cmdlet = new GetAzureIPForwarding
            {
                ServiceName          = ServiceName,
                VM                   = VM,
                NetworkInterfaceName = NetworkInterfaceName,
                CommandRuntime       = mockCommandRuntime,
                Client               = this.client,
            };
            cmdlet.SetParameterSet(GetAzureIPForwarding.IaaSIPForwardingParamSet);

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            computeClientMock.Verify(
                c => c.Deployments.GetBySlotAsync(
                    ServiceName,
                    DeploymentSlot.Production,
                    It.IsAny <CancellationToken>()),
                Times.Never());

            networkingClientMock.Verify(
                c => c.IPForwarding.GetForNetworkInterfaceAsync(
                    cmdlet.ServiceName,
                    DeploymentName,
                    VM.Name,
                    cmdlet.NetworkInterfaceName,
                    It.IsAny <CancellationToken>()),
                Times.Once());

            Assert.Equal(1, mockCommandRuntime.OutputPipeline.Count);
            Assert.Equal("Disabled", mockCommandRuntime.OutputPipeline[0]);
        }
Example #12
0
        public string GetDeploymentName(PersistentVMRoleContext vm, string slot, string serviceName)
        {
            string deploymentName = null;

            if (vm != null)
            {
                deploymentName = vm.DeploymentName;
            }

            if (string.IsNullOrEmpty(slot) && string.IsNullOrEmpty(deploymentName))
            {
                slot = DeploymentSlotType.Production;
            }

            if (string.IsNullOrEmpty(deploymentName))
            {
                deploymentName = this.GetDeploymentBySlot(serviceName, slot);
            }

            return(deploymentName);
        }
Example #13
0
        public void ManagingRDPSSHConnectivity()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Create a new Azure quick VM
            string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");

            if (string.IsNullOrEmpty(imageName))
            {
                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false);
            }
            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
            Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);

            // starting the test.
            PersistentVMRoleContext vmRoleCtxt        = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName); // Get-AzureVM
            InputEndpointContext    inputEndpointCtxt = vmPowershellCmdlets.GetAzureEndPoint(vmRoleCtxt)[0];              // Get-AzureEndpoint

            Console.WriteLine("InputEndpointContext Name: {0}", inputEndpointCtxt.Name);
            Console.WriteLine("InputEndpointContext port: {0}", inputEndpointCtxt.Port);
            Console.WriteLine("InputEndpointContext protocol: {0}", inputEndpointCtxt.Protocol);
            Assert.AreEqual(inputEndpointCtxt.Name, "RemoteDesktop", true);

            string path = ".\\myvmconnection.rdp";

            vmPowershellCmdlets.GetAzureRemoteDesktopFile(newAzureQuickVMName, serviceName, path, false); // Get-AzureRemoteDesktopFile
            Console.WriteLine("RDP file is successfully created at: {0}", path);

            // ToDo: Automate RDP.
            //vmPowershellCmdlets.GetAzureRemoteDesktopFile(newAzureQuickVMName, newAzureQuickVMSvcName, path, true); // Get-AzureRemoteDesktopFile -Launch

            Console.WriteLine("Test passed");

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));

            pass = true;
        }
Example #14
0
        public void NewWindowsAzureQuickVM()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            string newAzureQuickVMName = Utilities.GetUniqueShortName(vmNamePrefix);

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

            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName);

            // Verify
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);

            Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));

            pass = true;
        }
Example #15
0
        [Ignore] // https://github.com/WindowsAzure/azure-sdk-tools/issues/1402
        public void NewWindowsAzureQuickVM()
        {
            powershell.Invoke();

            ServiceManagementCmdletTestHelper vmPowershellCmdlets = new ServiceManagementCmdletTestHelper();

            string imageName    = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false);
            string locationName = vmPowershellCmdlets.GetAzureLocationName(new[] { Resource.Location }, false);

            string newAzureQuickVMName    = Utilities.GetUniqueShortName("PSTestVM");
            string newAzureQuickVMSvcName = Utilities.GetUniqueShortName("PSTestService");

            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, newAzureQuickVMSvcName, imageName, "pstestuser", "p@ssw0rd", locationName);

            // Verify
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);

            Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName);

            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, newAzureQuickVMSvcName));
        }
Example #16
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;
            }
        }
Example #17
0
        public Collection <DataVirtualHardDisk> GetAzureDataDisk(string vmName, string serviceName)
        {
            PersistentVMRoleContext vmRolectx = GetAzureVM(vmName, serviceName);

            return(RunPSCmdletAndReturnAll <DataVirtualHardDisk>(new GetAzureDataDiskCmdletInfo(vmRolectx.VM)));
        }
Example #18
0
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (!string.IsNullOrEmpty(ServiceName) && CurrentDeployment == null)
            {
                return;
            }

            List <PersistentVMRoleContext> roles = new List <PersistentVMRoleContext>();
            RoleList vmRoles = null;

            if (string.IsNullOrEmpty(ServiceName))
            {
                ListAllVMs();
                return;
            }

            if (string.IsNullOrEmpty(Name))
            {
                vmRoles = CurrentDeployment.RoleList;
            }
            else
            {
                vmRoles = new RoleList(CurrentDeployment.RoleList.Where(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)));
            }

            foreach (Role role in vmRoles)
            {
                string lastVM = string.Empty;

                try
                {
                    lastVM = role.RoleName;
                    var vm           = (PersistentVMRole)role;
                    var roleInstance = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName);
                    var vmContext    = new PersistentVMRoleContext
                    {
                        ServiceName           = ServiceName,
                        Name                  = vm.RoleName,
                        DeploymentName        = CurrentDeployment.Name,
                        AvailabilitySetName   = vm.AvailabilitySetName,
                        Label                 = vm.Label,
                        InstanceSize          = vm.RoleSize,
                        InstanceStatus        = roleInstance.InstanceStatus,
                        IpAddress             = roleInstance.IpAddress,
                        InstanceStateDetails  = roleInstance.InstanceStateDetails,
                        PowerState            = roleInstance.PowerState,
                        InstanceErrorCode     = roleInstance.InstanceErrorCode,
                        InstanceName          = roleInstance.InstanceName,
                        InstanceFaultDomain   = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        OperationDescription  = CommandRuntime.ToString(),
                        OperationId           = GetDeploymentOperation.OperationTrackingId,
                        OperationStatus       = GetDeploymentOperation.Status,
                        VM = new PersistentVM
                        {
                            AvailabilitySetName  = vm.AvailabilitySetName,
                            ConfigurationSets    = vm.ConfigurationSets,
                            DataVirtualHardDisks = vm.DataVirtualHardDisks,
                            Label             = vm.Label,
                            OSVirtualHardDisk = vm.OSVirtualHardDisk,
                            RoleName          = vm.RoleName,
                            RoleSize          = vm.RoleSize,
                            RoleType          = vm.RoleType,
                            DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint
                        },
                    };

                    if (CurrentDeployment != null)
                    {
                        vmContext.DNSName = CurrentDeployment.Url.AbsoluteUri;
                    }

                    roles.Add(vmContext);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, lastVM), e);
                }
            }

            if (!string.IsNullOrEmpty(Name) && roles != null && roles.Count > 0)
            {
                SaveRoleState(roles[0].VM);
            }

            WriteObject(roles, true);
        }
Example #19
0
        public IEnumerable <PersistentVMRoleContext> GetVirtualMachineProcess()
        {
            RoleList roleList;

            GetAzureVMCommand.GetAzureVMCommand   variable = null;
            IEnumerable <PersistentVMRoleContext> persistentVMRoleContexts;
            Func <Role, bool> func = null;

            if (string.IsNullOrEmpty(this.ServiceName) || base.CurrentDeployment != null)
            {
                using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        List <PersistentVMRoleContext> persistentVMRoleContexts1 = new List <PersistentVMRoleContext>();
                        if (!string.IsNullOrEmpty(this.ServiceName))
                        {
                            if (!string.IsNullOrEmpty(this.Name))
                            {
                                RoleList roleList1 = base.CurrentDeployment.RoleList;
                                if (func == null)
                                {
                                    func = (Role r) => r.RoleName.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase);
                                }
                                roleList = new RoleList(roleList1.Where <Role>(func));
                            }
                            else
                            {
                                roleList = base.CurrentDeployment.RoleList;
                            }
                            for (int i = 0; i < roleList.Count; i++)
                            {
                                string empty = string.Empty;
                                try
                                {
                                    empty = roleList[i].RoleName;
                                    PersistentVMRole        item = (PersistentVMRole)roleList[i];
                                    PersistentVMRoleContext persistentVMRoleContext = new PersistentVMRoleContext();
                                    if (base.CurrentDeployment != null)
                                    {
                                        persistentVMRoleContext.DNSName = base.CurrentDeployment.Url.AbsoluteUri;
                                    }
                                    persistentVMRoleContext.ServiceName            = this.ServiceName;
                                    persistentVMRoleContext.Name                   = item.RoleName;
                                    persistentVMRoleContext.DeploymentName         = base.CurrentDeployment.Name;
                                    persistentVMRoleContext.VM                     = new PersistentVM();
                                    persistentVMRoleContext.VM.AvailabilitySetName = item.AvailabilitySetName;
                                    persistentVMRoleContext.AvailabilitySetName    = item.AvailabilitySetName;
                                    persistentVMRoleContext.Label                  = item.Label;
                                    persistentVMRoleContext.VM.ConfigurationSets   = item.ConfigurationSets;
                                    persistentVMRoleContext.VM.ConfigurationSets.OfType <NetworkConfigurationSet>().SingleOrDefault <NetworkConfigurationSet>();
                                    persistentVMRoleContext.VM.DataVirtualHardDisks = item.DataVirtualHardDisks;
                                    persistentVMRoleContext.VM.Label             = item.Label;
                                    persistentVMRoleContext.VM.OSVirtualHardDisk = item.OSVirtualHardDisk;
                                    persistentVMRoleContext.VM.RoleName          = item.RoleName;
                                    persistentVMRoleContext.Name                 = item.RoleName;
                                    persistentVMRoleContext.VM.RoleSize          = item.RoleSize;
                                    persistentVMRoleContext.InstanceSize         = item.RoleSize;
                                    persistentVMRoleContext.VM.RoleType          = item.RoleType;
                                    persistentVMRoleContext.InstanceStatus       = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceStatus;
                                    persistentVMRoleContext.IpAddress            = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == this.vm.RoleName).First <RoleInstance>().IpAddress;
                                    persistentVMRoleContext.InstanceStateDetails = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceStateDetails;
                                    persistentVMRoleContext.PowerState           = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().PowerState;
                                    persistentVMRoleContext.InstanceErrorCode    = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceErrorCode;
                                    persistentVMRoleContext.InstanceName         = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceName;
                                    int?instanceFaultDomain = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceFaultDomain;
                                    int value = instanceFaultDomain.Value;
                                    persistentVMRoleContext.InstanceFaultDomain = value.ToString();
                                    int?instanceUpgradeDomain = base.CurrentDeployment.RoleInstanceList.Where <RoleInstance>((RoleInstance r) => r.RoleName == item.RoleName).First <RoleInstance>().InstanceUpgradeDomain;
                                    int num = instanceUpgradeDomain.Value;
                                    persistentVMRoleContext.InstanceUpgradeDomain = num.ToString();
                                    persistentVMRoleContext.set_OperationDescription(base.CommandRuntime.ToString());
                                    persistentVMRoleContext.set_OperationId(base.GetDeploymentOperation.OperationTrackingId);
                                    persistentVMRoleContext.set_OperationStatus(base.GetDeploymentOperation.Status);
                                    persistentVMRoleContexts1.Add(persistentVMRoleContext);
                                }
                                catch (Exception exception)
                                {
                                    base.WriteObject(string.Format("Could not read properties for virtual machine: {0}. It may still be provisioning.", empty));
                                }
                            }
                            if (!string.IsNullOrEmpty(this.Name) && persistentVMRoleContexts1 != null && persistentVMRoleContexts1.Count > 0)
                            {
                                this.SaveRoleState(persistentVMRoleContexts1[0].VM);
                            }
                            persistentVMRoleContexts = persistentVMRoleContexts1;
                            return(persistentVMRoleContexts);
                        }
                        else
                        {
                            this.ListAllVMs();
                            persistentVMRoleContexts = null;
                            return(persistentVMRoleContexts);
                        }
                    }
                    catch (CommunicationException communicationException1)
                    {
                        CommunicationException communicationException = communicationException1;
                        if (communicationException as EndpointNotFoundException == null || base.IsVerbose())
                        {
                            this.WriteErrorDetails(communicationException);
                        }
                        else
                        {
                            persistentVMRoleContexts = null;
                            return(persistentVMRoleContexts);
                        }
                    }
                    persistentVMRoleContexts = null;
                }
                return(persistentVMRoleContexts);
            }
            else
            {
                return(null);
            }
        }
Example #20
0
        public void ExportingImportingVMConfigAsTemplateforRepeatableUsage()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Create a new Azure quick VM
            string newAzureQuickVMName = Utilities.GetUniqueShortName("PSTestVM");

            if (string.IsNullOrEmpty(imageName))
            {
                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false);
            }
            vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, newAzureQuickVMName, serviceName, imageName, username, password, locationName); // New-AzureQuickVM
            Console.WriteLine("VM is created successfully: -Name {0} -ServiceName {1}", newAzureQuickVMName, serviceName);

            // starting the test.
            string path = ".\\mytestvmconfig1.xml";
            PersistentVMRoleContext vmRole = vmPowershellCmdlets.ExportAzureVM(newAzureQuickVMName, serviceName, path); // Export-AzureVM

            Console.WriteLine("Exporting VM is successfully done: path - {0}  Name - {1}", path, vmRole.Name);

            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName); // Remove-AzureVM
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));
            Console.WriteLine("The VM is successfully removed: {0}", newAzureQuickVMName);

            List <PersistentVM> VMs = new List <PersistentVM>();

            foreach (var pervm in vmPowershellCmdlets.ImportAzureVM(path)) // Import-AzureVM
            {
                VMs.Add(pervm);
                Console.WriteLine("The VM, {0}, is imported.", pervm.RoleName);
            }


            for (int i = 0; i < 3; i++)
            {
                try
                {
                    vmPowershellCmdlets.NewAzureVM(serviceName, VMs.ToArray()); // New-AzureVM
                    Console.WriteLine("All VMs are successfully created.");
                    foreach (var vm in VMs)
                    {
                        Console.WriteLine("created VM: {0}", vm.RoleName);
                    }
                    break;
                }
                catch (Exception e)
                {
                    if (e.ToString().ToLowerInvariant().Contains("currently in use") && i != 2)
                    {
                        Console.WriteLine("The removed VM is still using the vhd");
                        Thread.Sleep(120000);
                        continue;
                    }
                    else
                    {
                        Assert.Fail("error during New-AzureVM: {0}", e.ToString());
                    }
                }
            }

            // Verify
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName);

            Assert.AreEqual(newAzureQuickVMName, vmRoleCtxt.Name, true);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureQuickVMName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureQuickVMName, serviceName));

            pass = true;
        }
Example #21
0
 public PersistentVMRoleContext RemoveAzureEndPoint(string epName, PersistentVMRoleContext vmRoleCtxt)
 {
     return(RunPSCmdletAndReturnFirst <PersistentVMRoleContext>(new RemoveAzureEndpointCmdletInfo(epName, vmRoleCtxt)));
 }
Example #22
0
        public void HiMemVMSizeTest()
        {
            string serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
            string vmName      = Utilities.GetUniqueShortName(vmNamePrefix);

            try
            {
                // New-AzureQuickVM test for VM size 'A5'
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, username, password, locationName, InstanceSize.A5.ToString());
                PersistentVMRoleContext result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                RoleSizeContext         returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A5.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("VM size, {0}, is verified for New-AzureQuickVM", InstanceSize.A5);
                vmPowershellCmdlets.RemoveAzureService(serviceName);

                // New-AzureQuickVM test for VM size 'A6'
                vmPowershellCmdlets.NewAzureQuickVM(OS.Windows, vmName, serviceName, imageName, username, password, locationName, InstanceSize.A6.ToString());
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A6.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("VM size, {0}, is verified for New-AzureQuickVM", InstanceSize.A6);
                vmPowershellCmdlets.RemoveAzureService(serviceName);

                // New-AzureVMConfig test for VM size 'A7'
                var          azureVMConfigInfo       = new AzureVMConfigInfo(vmName, InstanceSize.A7.ToString(), imageName);
                var          azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                var          persistentVMConfigInfo  = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
                PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);
                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, locationName);
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A7.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("VM size, {0}, is verified for New-AzureVMConfig", InstanceSize.A7);

                // Set-AzureVMSize test for Hi-MEM VM size (A7 to A6)
                vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.A6.ToString()));
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A6.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("SetVMSize is verified from A7 to A6");

                // Set-AzureVMSize test for Hi-MEM VM size (A6 to A5)
                vmPowershellCmdlets.SetVMSize(vmName, serviceName, new SetAzureVMSizeConfig(InstanceSize.A5.ToString()));
                result       = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);
                returnedSize = vmPowershellCmdlets.GetAzureRoleSize(result.InstanceSize)[0];
                Assert.AreEqual(InstanceSize.A5.ToString(), returnedSize.InstanceSize);
                Console.WriteLine("SetVMSize is verified from A6 to A5");

                pass = true;
            }
            catch (Exception e)
            {
                pass = false;
                Console.WriteLine("Exception occurred: {0}", e.ToString());
                throw;
            }
            finally
            {
                if (!Utilities.CheckRemove(vmPowershellCmdlets.GetAzureService, serviceName))
                {
                    if ((cleanupIfFailed && !pass) || (cleanupIfPassed && pass))
                    {
                        vmPowershellCmdlets.RemoveAzureService(serviceName);
                    }
                }
            }
        }
Example #23
0
        protected override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();
            if (CurrentDeploymentNewSM == null)
            {
                return;
            }

            var role = CurrentDeploymentNewSM.Roles.FirstOrDefault(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase));
            if(role == null)
            {
                throw new ApplicationException(string.Format(Resources.NoCorrespondingRoleCanBeFoundInDeployment, Name));
            }
            try
            {
                var vm = role;
                var roleInstance = CurrentDeploymentNewSM.RoleInstances.First(r => r.RoleName == vm.RoleName);
                var vmContext = new PersistentVMRoleContext
                {
                    ServiceName = ServiceName,
                    Name = vm.RoleName,
                    DeploymentName = CurrentDeploymentNewSM.Name,
                    AvailabilitySetName = vm.AvailabilitySetName,
                    Label = vm.Label,
                    InstanceSize = vm.RoleSize.ToString(),
                    InstanceStatus = roleInstance.InstanceStatus,
                    IpAddress = roleInstance.IPAddress,
                    InstanceStateDetails = roleInstance.InstanceStateDetails,
                    PowerState = roleInstance.PowerState.ToString(),
                    InstanceErrorCode = roleInstance.InstanceErrorCode,
                    InstanceName = roleInstance.InstanceName,
                    InstanceFaultDomain = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                    InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                    OperationDescription = CommandRuntime.ToString(),
                    OperationId = GetDeploymentOperationNewSM.Id,
                    OperationStatus = GetDeploymentOperationNewSM.Status.ToString(),
                    VM = new PersistentVM
                    {
                        AvailabilitySetName = vm.AvailabilitySetName,
                        ConfigurationSets = PersistentVMHelper.MapConfigurationSets(vm.ConfigurationSets),
                        DataVirtualHardDisks = new Collection<DataVirtualHardDisk>(),
                        Label = vm.Label,
                        OSVirtualHardDisk = Mapper.Map(vm.OSVirtualHardDisk, new OSVirtualHardDisk()),
                        RoleName = vm.RoleName,
                        RoleSize = vm.RoleSize.ToString(),
                        RoleType = vm.RoleType,
                        DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint,
                        ProvisionGuestAgent = vm.ProvisionGuestAgent,
                        ResourceExtensionReferences = Mapper.Map<PVM.ResourceExtensionReferenceList>(vm.ResourceExtensionReferences)
                    }
                };

                if (vm.DataVirtualHardDisks != null)
                {
                    vm.DataVirtualHardDisks.ForEach(
                        d => vmContext.VM.DataVirtualHardDisks.Add(Mapper.Map<DataVirtualHardDisk>(d)));
                }
                else
                {
                    vmContext.VM.DataVirtualHardDisks = null;
                }

                PersistentVMHelper.SaveStateToFile(vmContext.VM, Path);
                WriteObject(vmContext, true);
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, role.RoleName), e);
            }
        }
        public Collection<InputEndpointContext> GetAzureEndPoint(PersistentVMRoleContext vmRoleCtxt)
        {
            GetAzureEndpointCmdletInfo getAzureEndpointCmdletInfo = new GetAzureEndpointCmdletInfo(vmRoleCtxt);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureEndpointCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            Collection<InputEndpointContext> epCtxts = new Collection<InputEndpointContext>();

            foreach(PSObject re in result)
            {
                epCtxts.Add((InputEndpointContext)re.BaseObject);
            }
            return epCtxts;
        }
Example #25
0
        protected override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();
            if (!string.IsNullOrEmpty(ServiceName) && CurrentDeploymentNewSM == null)
            {
                return;
            }

            var roles = new List<PersistentVMRoleContext>();
            IList<Management.Compute.Models.Role> vmRoles;

            if (string.IsNullOrEmpty(ServiceName))
            {
                ListAllVMs();
                return;
            }

            if (string.IsNullOrEmpty(Name))
            {
                vmRoles = CurrentDeploymentNewSM.Roles;
            }
            else
            {
                vmRoles = new List<Management.Compute.Models.Role>(CurrentDeploymentNewSM.Roles.Where(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)));
            }

            foreach (var role in vmRoles)
            {
                string lastVM = string.Empty;

                try
                {
                    lastVM = role.RoleName;
                    var vm = role;
                    var roleInstance = CurrentDeploymentNewSM.RoleInstances.First(r => r.RoleName == vm.RoleName);
                    var vmContext = new PersistentVMRoleContext
                    {
                        ServiceName = ServiceName,
                        Name = vm.RoleName,
                        DeploymentName = CurrentDeploymentNewSM.Name,
                        AvailabilitySetName = vm.AvailabilitySetName,
                        Label = vm.Label,
                        InstanceSize = vm.RoleSize.ToString(),
                        InstanceStatus = roleInstance.InstanceStatus,
                        IpAddress = roleInstance.IPAddress,
                        InstanceStateDetails = roleInstance.InstanceStateDetails,
                        PowerState = roleInstance.PowerState.ToString(),
                        InstanceErrorCode = roleInstance.InstanceErrorCode,
                        InstanceName = roleInstance.InstanceName,
                        InstanceFaultDomain = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationId = GetDeploymentOperationNewSM.Id,
                        OperationStatus = GetDeploymentOperationNewSM.Status.ToString(),
                        VM = new PersistentVM
                        {
                            AvailabilitySetName = vm.AvailabilitySetName,
                            ConfigurationSets = PersistentVMHelper.MapConfigurationSets(vm.ConfigurationSets),
                            DataVirtualHardDisks = Mapper.Map(vm.DataVirtualHardDisks, new Collection<DataVirtualHardDisk>()),
                            Label = vm.Label,
                            OSVirtualHardDisk = Mapper.Map(vm.OSVirtualHardDisk, new OSVirtualHardDisk()),
                            RoleName = vm.RoleName,
                            RoleSize = vm.RoleSize.ToString(),
                            RoleType = vm.RoleType,
                            DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint,
                            ProvisionGuestAgent = vm.ProvisionGuestAgent,
                            ResourceExtensionReferences = Mapper.Map<PVM.ResourceExtensionReferenceList>(vm.ResourceExtensionReferences)
                        }
                    };

                    if (CurrentDeploymentNewSM != null)
                    {
                        vmContext.DNSName = CurrentDeploymentNewSM.Uri.AbsoluteUri;
                    }

                    roles.Add(vmContext);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, lastVM), e);
                }
            }

            WriteObject(roles, true);
        }
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (!string.IsNullOrEmpty(ServiceName) && CurrentDeployment == null)
            {
                return;
            }

            List<PersistentVMRoleContext> roles = new List<PersistentVMRoleContext>();
            RoleList vmRoles = null;

            if (string.IsNullOrEmpty(ServiceName))
            {
                ListAllVMs();
                return;
            }

            if (string.IsNullOrEmpty(Name))
            {
                vmRoles = CurrentDeployment.RoleList;
            }
            else
            {
                vmRoles = new RoleList(CurrentDeployment.RoleList.Where(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)));
            }

            foreach (Role role in vmRoles)
            {
                string lastVM = string.Empty;

                try
                {
                    lastVM = role.RoleName;
                    PersistentVMRole vm = (PersistentVMRole)role;
                    PersistentVMRoleContext vmContext = new PersistentVMRoleContext();

                    if (CurrentDeployment != null)
                    {
                        vmContext.DNSName = CurrentDeployment.Url.AbsoluteUri;
                    }

                    vmContext.ServiceName = ServiceName;
                    vmContext.Name = vm.RoleName;
                    vmContext.DeploymentName = CurrentDeployment.Name;
                    vmContext.VM = new PersistentVM();
                    vmContext.VM.AvailabilitySetName = vm.AvailabilitySetName;
                    vmContext.AvailabilitySetName = vm.AvailabilitySetName;
                    vmContext.Label = vm.Label;
                    vmContext.VM.ConfigurationSets = vm.ConfigurationSets;
                    vmContext.VM.DataVirtualHardDisks = vm.DataVirtualHardDisks;
                    vmContext.VM.Label = vm.Label;
                    vmContext.VM.OSVirtualHardDisk = vm.OSVirtualHardDisk;
                    vmContext.VM.RoleName = vm.RoleName;
                    vmContext.Name = vm.RoleName;
                    vmContext.VM.RoleSize = vm.RoleSize;
                    vmContext.InstanceSize = vm.RoleSize;
                    vmContext.VM.RoleType = vm.RoleType;
                    vmContext.InstanceStatus = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).InstanceStatus;
                    vmContext.IpAddress = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).IpAddress;
                    vmContext.InstanceStateDetails = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).InstanceStateDetails;
                    vmContext.PowerState = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).PowerState;
                    vmContext.InstanceErrorCode = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).InstanceErrorCode;
                    vmContext.InstanceName = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).InstanceName;
                    vmContext.InstanceFaultDomain = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture);
                    vmContext.InstanceUpgradeDomain = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName).InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture);
                    vmContext.OperationDescription = CommandRuntime.ToString();
                    vmContext.OperationId = GetDeploymentOperation.OperationTrackingId;
                    vmContext.OperationStatus = GetDeploymentOperation.Status;
                    roles.Add(vmContext);
                }
                catch (Exception)
                {
                    WriteObject(string.Format("Could not read properties for virtual machine: {0}. It may still be provisioning.", lastVM));
                }
            }

            if (!string.IsNullOrEmpty(Name) && roles != null && roles.Count > 0)
            {
                SaveRoleState(roles[0].VM);
            }

            WriteObject(roles, true);
        }
Example #27
0
        public void CaptureImagingExportingImportingVMConfig()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Create a unique VM name
            string newAzureVMName = Utilities.GetUniqueShortName("PSTestVM");

            Console.WriteLine("VM Name: {0}", newAzureVMName);

            // Create a unique Service Name
            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
            Console.WriteLine("Service Name: {0}", serviceName);
            if (string.IsNullOrEmpty(imageName))
            {
                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false);
            }

            // starting the test.
            AzureVMConfigInfo           azureVMConfigInfo       = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small, imageName); // parameters for New-AzureVMConfig (-Name -InstanceSize -ImageName)
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);      // parameters for Add-AzureProvisioningConfig (-Windows -Password)
            PersistentVMConfigInfo      persistentVMConfigInfo  = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
            PersistentVM persistentVM = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);                                    // New-AzureVMConfig & Add-AzureProvisioningConfig

            PersistentVM[] VMs = { persistentVM };
            vmPowershellCmdlets.NewAzureVM(serviceName, VMs); // New-AzureVM
            Console.WriteLine("The VM is successfully created: {0}", persistentVM.RoleName);
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);

            Assert.AreEqual(vmRoleCtxt.Name, persistentVM.RoleName, true);


            vmPowershellCmdlets.StopAzureVM(newAzureVMName, serviceName); // Stop-AzureVM
            for (int i = 0; i < 3; i++)
            {
                vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
                if (vmRoleCtxt.InstanceStatus == "StoppedVM")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("The status of the VM {0} : {1}", persistentVM.RoleName, vmRoleCtxt.InstanceStatus);
                    Thread.Sleep(120000);
                }
            }
            Assert.AreEqual(vmRoleCtxt.InstanceStatus, "StoppedVM", true);

            //TODO
            // RDP

            //TODO:
            // Run sysprep and shutdown

            // Check the status of VM
            //PersistentVMRoleContext vmRoleCtxt2 = vmPowershellCmdlets.GetAzureVM(newAzureVMName, newAzureSvcName); // Get-AzureVM -Name
            //Assert.AreEqual(newAzureVMName, vmRoleCtxt2.Name, true);  //

            // Save-AzureVMImage
            //string newImageName = "newImage";
            //string newImageLabel = "newImageLabel";
            //string postAction = "Delete";

            // Save-AzureVMImage -ServiceName -Name -NewImageName -NewImageLabel -PostCaptureAction
            //vmPowershellCmdlets.SaveAzureVMImage(newAzureSvcName, newAzureVMName, newImageName, newImageLabel, postAction);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(persistentVM.RoleName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName));
        }
Example #28
0
        protected override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();
            if (!string.IsNullOrEmpty(ServiceName) && CurrentDeploymentNewSM == null)
            {
                return;
            }

            var roles = new List <PersistentVMRoleContext>();
            IList <Management.Compute.Models.Role> vmRoles;

            if (string.IsNullOrEmpty(ServiceName))
            {
                ListAllVMs();
                return;
            }

            if (string.IsNullOrEmpty(Name))
            {
                vmRoles = CurrentDeploymentNewSM.Roles;
            }
            else
            {
                vmRoles = new List <Management.Compute.Models.Role>(CurrentDeploymentNewSM.Roles.Where(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)));
            }

            foreach (var role in vmRoles)
            {
                string lastVM = string.Empty;

                try
                {
                    lastVM = role.RoleName;
                    var vm           = role;
                    var roleInstance = CurrentDeploymentNewSM.RoleInstances.First(r => r.RoleName == vm.RoleName);
                    var vmContext    = new PersistentVMRoleContext
                    {
                        ServiceName           = ServiceName,
                        Name                  = vm.RoleName,
                        DeploymentName        = CurrentDeploymentNewSM.Name,
                        AvailabilitySetName   = vm.AvailabilitySetName,
                        Label                 = vm.Label,
                        InstanceSize          = vm.RoleSize.ToString(),
                        InstanceStatus        = roleInstance.InstanceStatus,
                        IpAddress             = roleInstance.IPAddress,
                        InstanceStateDetails  = roleInstance.InstanceStateDetails,
                        PowerState            = roleInstance.PowerState.ToString(),
                        InstanceErrorCode     = roleInstance.InstanceErrorCode,
                        InstanceName          = roleInstance.InstanceName,
                        InstanceFaultDomain   = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        OperationDescription  = CommandRuntime.ToString(),
                        OperationId           = GetDeploymentOperationNewSM.Id,
                        OperationStatus       = GetDeploymentOperationNewSM.Status.ToString(),
                        VM = new PersistentVM
                        {
                            AvailabilitySetName  = vm.AvailabilitySetName,
                            ConfigurationSets    = PersistentVMHelper.MapConfigurationSets(vm.ConfigurationSets),
                            DataVirtualHardDisks = Mapper.Map(vm.DataVirtualHardDisks, new Collection <DataVirtualHardDisk>()),
                            Label             = vm.Label,
                            OSVirtualHardDisk = Mapper.Map(vm.OSVirtualHardDisk, new OSVirtualHardDisk()),
                            RoleName          = vm.RoleName,
                            RoleSize          = vm.RoleSize.ToString(),
                            RoleType          = vm.RoleType,
                            DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint,
                            ProvisionGuestAgent         = vm.ProvisionGuestAgent,
                            ResourceExtensionReferences = Mapper.Map <PVM.ResourceExtensionReferenceList>(vm.ResourceExtensionReferences)
                        }
                    };

                    if (CurrentDeploymentNewSM != null)
                    {
                        vmContext.DNSName = CurrentDeploymentNewSM.Uri.AbsoluteUri;
                    }

                    roles.Add(vmContext);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, lastVM), e);
                }
            }

            WriteObject(roles, true);
        }
Example #29
0
 public GetAzureEndpointCmdletInfo(PersistentVMRoleContext vmRoleCtxt)
 {
     this.cmdletName = Utilities.GetAzureEndpointCmdletName;
     this.cmdletParams.Add(new CmdletParam("VM", vmRoleCtxt));
 }
Example #30
0
 public Collection <InputEndpointContext> GetAzureEndPoint(PersistentVMRoleContext vmRoleCtxt)
 {
     return(RunPSCmdletAndReturnAll <InputEndpointContext>(new GetAzureEndpointCmdletInfo(vmRoleCtxt)));
 }
        public PersistentVMRoleContext RemoveAzureEndPoint(string epName, PersistentVMRoleContext vmRoleCtxt)
        {
            RemoveAzureEndpointCmdletInfo removeAzureEndPointCmdletInfo = new RemoveAzureEndpointCmdletInfo(epName, vmRoleCtxt);
            WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(removeAzureEndPointCmdletInfo);

            Collection<PSObject> result = azurePowershellCmdlet.Run();
            if (result.Count == 1)
            {
                return (PersistentVMRoleContext)result[0].BaseObject;
            }
            return null;
        }
 public GetAzureEndpointCmdletInfo(PersistentVMRoleContext vmRoleCtxt)
 {
     this.cmdletName = Utilities.GetAzureEndpointCmdletName;
     this.cmdletParams.Add(new CmdletParam("VM", vmRoleCtxt));
 }
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (CurrentDeployment == null)
            {
                return;
            }

            var role = CurrentDeployment.RoleList.FirstOrDefault(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase));
            if(role == null)
            {
                throw new ApplicationException(string.Format(Resources.NoCorrespondingRoleCanBeFoundInDeployment, Name));
            }
            try
            {
                var vm = (PersistentVMRole)role;
                var roleInstance = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName);
                var vmContext = new PersistentVMRoleContext
                {
                    ServiceName = ServiceName,
                    Name = vm.RoleName,
                    DeploymentName = CurrentDeployment.Name,
                    AvailabilitySetName = vm.AvailabilitySetName,
                    Label = vm.Label,
                    InstanceSize = vm.RoleSize,
                    InstanceStatus = roleInstance.InstanceStatus,
                    IpAddress = roleInstance.IpAddress,
                    InstanceStateDetails = roleInstance.InstanceStateDetails,
                    PowerState = roleInstance.PowerState,
                    InstanceErrorCode = roleInstance.InstanceErrorCode,
                    InstanceName = roleInstance.InstanceName,
                    InstanceFaultDomain = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                    InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                    OperationDescription = CommandRuntime.ToString(),
                    OperationId = GetDeploymentOperation.OperationTrackingId,
                    OperationStatus = GetDeploymentOperation.Status,
                    VM = new PersistentVM
                    {
                        AvailabilitySetName = vm.AvailabilitySetName,
                        ConfigurationSets = vm.ConfigurationSets,
                        DataVirtualHardDisks = vm.DataVirtualHardDisks,
                        Label = vm.Label,
                        OSVirtualHardDisk = vm.OSVirtualHardDisk,
                        RoleName = vm.RoleName,
                        RoleSize = vm.RoleSize,
                        RoleType = vm.RoleType,
                        DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint
                    }
                };
                PersistentVMHelper.SaveStateToFile(vmContext.VM, Path);
                WriteObject(vmContext, true);
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, role.RoleName), e);
            }
        }
Example #34
0
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();
            if (!string.IsNullOrEmpty(ServiceName) && CurrentDeployment == null)
            {
                return;
            }

            List<PersistentVMRoleContext> roles = new List<PersistentVMRoleContext>();
            RoleList vmRoles = null;

            if (string.IsNullOrEmpty(ServiceName))
            {
                ListAllVMs();
                return;
            }

            if (string.IsNullOrEmpty(Name))
            {
                vmRoles = CurrentDeployment.RoleList;
            }
            else
            {
                vmRoles = new RoleList(CurrentDeployment.RoleList.Where(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)));
            }

            foreach (Role role in vmRoles)
            {
                string lastVM = string.Empty;

                try
                {
                    lastVM = role.RoleName;
                    var vm = (PersistentVMRole)role;
                    var roleInstance = CurrentDeployment.RoleInstanceList.First(r => r.RoleName == vm.RoleName);
                    var vmContext = new PersistentVMRoleContext
                    {
                        ServiceName = ServiceName,
                        Name = vm.RoleName,
                        DeploymentName = CurrentDeployment.Name,
                        AvailabilitySetName = vm.AvailabilitySetName,
                        Label = vm.Label,
                        InstanceSize = vm.RoleSize,
                        InstanceStatus = roleInstance.InstanceStatus,
                        IpAddress = roleInstance.IpAddress,
                        InstanceStateDetails = roleInstance.InstanceStateDetails,
                        PowerState = roleInstance.PowerState,
                        InstanceErrorCode = roleInstance.InstanceErrorCode,
                        InstanceName = roleInstance.InstanceName,
                        InstanceFaultDomain = roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationId = GetDeploymentOperation.OperationTrackingId,
                        OperationStatus = GetDeploymentOperation.Status,
                        VM = new PersistentVM
                        {
                            AvailabilitySetName = vm.AvailabilitySetName,
                            ConfigurationSets = vm.ConfigurationSets,
                            DataVirtualHardDisks = vm.DataVirtualHardDisks,
                            Label = vm.Label,
                            OSVirtualHardDisk = vm.OSVirtualHardDisk,
                            RoleName = vm.RoleName,
                            RoleSize = vm.RoleSize,
                            RoleType = vm.RoleType,
                            DefaultWinRmCertificateThumbprint = vm.DefaultWinRmCertificateThumbprint
                        },
                    };

                    if (CurrentDeployment != null)
                    {
                        vmContext.DNSName = CurrentDeployment.Url.AbsoluteUri;
                    }

                    roles.Add(vmContext);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(string.Format(Resources.VMPropertiesCanNotBeRead, lastVM), e);
                }
            }

            WriteObject(roles, true);
        }
 public RemoveAzureEndpointCmdletInfo(string epName, PersistentVMRoleContext vmRoleCtxt)
 {
     this.cmdletName = Utilities.RemoveAzureEndpointCmdletName;
     this.cmdletParams.Add(new CmdletParam("Name", epName));
     this.cmdletParams.Add(new CmdletParam("VM", vmRoleCtxt));
 }
 public RemoveAzureEndpointCmdletInfo(string epName, PersistentVMRoleContext vmRoleCtxt)
 {
     this.cmdletName = Utilities.RemoveAzureEndpointCmdletName;
     this.cmdletParams.Add(new CmdletParam("Name", epName));
     this.cmdletParams.Add(new CmdletParam("VM", vmRoleCtxt));
 }