public SetAzureAvailabilitySetCmdletInfo(string availabilitySetName, PersistentVM vm) { cmdletName = Utilities.SetAzureAvailabilitySetCmdletName; cmdletParams.Add(new CmdletParam("AvailabilitySetName", availabilitySetName)); this.cmdletParams.Add(new CmdletParam("VM", vm)); }
public SetAzureSubnetCmdletInfo(PersistentVM vm, string[] subnetNames) { this.cmdletName = Utilities.SetAzureSubnetCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vm)); this.cmdletParams.Add(new CmdletParam("SubnetNames", subnetNames)); }
public UpdateAzureVMCmdletInfo(string vmName, string serviceName, PersistentVM persistentVM) { cmdletName = Utilities.UpdateAzureVMCmdletName; this.cmdletParams.Add(new CmdletParam("Name", vmName)); this.cmdletParams.Add(new CmdletParam("ServiceName", serviceName)); this.cmdletParams.Add(new CmdletParam("VM", persistentVM)); }
public NewAzureVMCmdletInfo(string serviceName, PersistentVM[] vMs, string vnetName, DnsServer[] dnsSettings, string serviceLabel, string serviceDescription, string deploymentLabel, string deploymentName, string location, string affinityGroup, string rsvIPName,InternalLoadBalancerConfig internalLoadBalancerConfig, bool waitForBoot) { this.cmdletName = Utilities.NewAzureVMCmdletName; this.cmdletParams.Add(new CmdletParam("ServiceName", serviceName)); this.cmdletParams.Add(new CmdletParam("VMs", vMs)); if (!string.IsNullOrEmpty(vnetName)) { this.cmdletParams.Add(new CmdletParam("VNetName", vnetName)); } if (dnsSettings != null) { this.cmdletParams.Add(new CmdletParam("DnsSettings", dnsSettings)); } if (!string.IsNullOrEmpty(affinityGroup)) { this.cmdletParams.Add(new CmdletParam("AffinityGroup", affinityGroup)); } if (!string.IsNullOrEmpty(serviceLabel)) { this.cmdletParams.Add(new CmdletParam("ServiceLabel", serviceLabel)); } if (!string.IsNullOrEmpty(serviceDescription)) { this.cmdletParams.Add(new CmdletParam("ServiceDescription", serviceDescription)); } if (!string.IsNullOrEmpty(deploymentLabel)) { this.cmdletParams.Add(new CmdletParam("DeploymentLabel", deploymentLabel)); } if (!string.IsNullOrEmpty(deploymentName)) { this.cmdletParams.Add(new CmdletParam("DeploymentName", deploymentName)); } if (!string.IsNullOrEmpty(location)) { this.cmdletParams.Add(new CmdletParam("Location", location)); } if (!string.IsNullOrEmpty(rsvIPName)) { this.cmdletParams.Add(new CmdletParam("ReservedIPName", rsvIPName)); } if (waitForBoot) { this.cmdletParams.Add(new CmdletParam("WaitForBoot", waitForBoot)); } if (internalLoadBalancerConfig != null) { this.cmdletParams.Add(new CmdletParam("InternalLoadBalancerConfig", internalLoadBalancerConfig)); } }
public void NewAzureVMWithWindowsAndCustomData() { try { var customDataFile = @".\CustomData.bin"; var customDataContent = File.ReadAllText(customDataFile); // Add-AzureProvisioningConfig with X509Certificate var azureVMConfigInfo = new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), imageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(username, password, customDataFile); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName, true); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); // Get-AzureVM var vmContext = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName); // Get-AzureCertificate var winRmCert = vmPowershellCmdlets.GetAzureCertificate(_serviceName, vmContext.VM.DefaultWinRmCertificateThumbprint, "sha1").First(); // Install the WinRM cert to the local machine's root location. InstallCertificate(winRmCert, StoreLocation.LocalMachine, StoreName.Root); var connUri = vmPowershellCmdlets.GetAzureWinRMUri(_serviceName, _vmName); var cred = new PSCredential(username, Utilities.convertToSecureString(password)); Utilities.RetryActionUntilSuccess(() => { // Invoke Command var scriptBlock = ScriptBlock.Create(@"Get-Content -Path 'C:\AzureData\CustomData.bin'"); var invokeInfo = new InvokeCommandCmdletInfo(connUri, cred, scriptBlock); var invokeCmd = new PowershellCmdlet(invokeInfo); var results = invokeCmd.Run(false); Assert.IsTrue(customDataContent == results.First().BaseObject as string); }, "Access is denied", 10, 30); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
/// <summary> /// /// </summary> /// <param name="vm"></param> /// <param name="epInfos"></param> /// <returns></returns> internal static bool AzureEndpoint(PersistentVM vm, AzureEndPointConfigInfo[] epInfos) { try { var serverEndpoints = vmPowershellCmdlets.GetAzureEndPoint(vm); // List the endpoints found for debugging. Console.WriteLine("***** Checking for Endpoints **************************************************"); Console.WriteLine("***** Listing Returned Endpoints"); foreach (InputEndpointContext ep in serverEndpoints) { Console.WriteLine("Endpoint - Name:{0} Protocol:{1} Port:{2} LocalPort:{3} Vip:{4}", ep.Name, ep.Protocol, ep.Port, ep.LocalPort, ep.Vip); if (!string.IsNullOrEmpty(ep.LBSetName)) { Console.WriteLine("\t- LBSetName:{0}", ep.LBSetName); Console.WriteLine("\t- Probe - Port:{0} Protocol:{1} Interval:{2} Timeout:{3}", ep.ProbePort, ep.ProbeProtocol, ep.ProbeIntervalInSeconds, ep.ProbeTimeoutInSeconds); } } Console.WriteLine("*******************************************************************************"); // Check if the specified endpoints were found. foreach (AzureEndPointConfigInfo epInfo in epInfos) { bool found = false; foreach (InputEndpointContext ep in serverEndpoints) { if (epInfo.CheckInputEndpointContext(ep)) { found = true; Console.WriteLine("Endpoint found: {0}", epInfo.EndpointName); break; } } Assert.IsTrue(found, string.Format("Error: Endpoint '{0}' was not found!", epInfo.EndpointName)); } return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); return(false); } }
public void CreateReservedIPThenWindowsVM() { try { string reservedIpName = Utilities.GetUniqueShortName("ResrvdIP"); string reservedIpLabel = Utilities.GetUniqueShortName(" ResrvdIPLbl", 5); string dnsName = Utilities.GetUniqueShortName("Dns"); string vmName = Utilities.GetUniqueShortName(vmNamePrefix); string deploymentName = Utilities.GetUniqueShortName("Depl"); var input = new ReservedIPContext() { //Address = string.Empty, DeploymentName = string.Empty, Label = reservedIpLabel, InUse = false, Location = locationName, ReservedIPName = reservedIpName, State = "Created" }; // Reserve a new IP Utilities.ExecuteAndLog(() => vmPowershellCmdlets.NewAzureReservedIP(reservedIpName, locationName, reservedIpLabel), "Reserve a new IP"); //Get the reserved ip and verify the reserved Ip properties. VerifyReservedIpNotInUse(input); // Create a new VM with the reserved ip. DnsServer dns = null; Utilities.ExecuteAndLog(() => { dns = vmPowershellCmdlets.NewAzureDns(dnsName, DNS_IP); }, "Create a new Azure DNS"); Utilities.ExecuteAndLog(() => { PersistentVM vm = CreateVMObjectWithDataDiskSubnetAndAvailibilitySet(vmName, OS.Windows); vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, vnet, new[] { dns }, location: locationName, reservedIPName: reservedIpName); }, "Create a new windows azure vm with reserved ip."); VerifyReservedIpInUse(serviceName, input); Utilities.ExecuteAndLog(() => vmPowershellCmdlets.RemoveAzureVM(vmName, serviceName, true), "Remove Azure VM and verify that a warning is given."); VerifyReservedIpNotInUse(input); Utilities.ExecuteAndLog(() => vmPowershellCmdlets.RemoveAzureReservedIP(reservedIpName, true), "Release the reserved ip"); VerifyReservedIpRemoved(reservedIpName); pass = true; } catch (Exception ex) { pass = false; Console.WriteLine(ex.ToString()); throw; } }
public void NewAzureVMWithLocation() { string _altLocation = GetAlternateLocation(locationName); try { // New-AzureService vmPowershellCmdlets.NewAzureService(_serviceName, locationName); var azureVMConfigInfo = new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), imageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM try { vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, _altLocation); Assert.Fail("Should fail, but succeeded!"); } catch (Exception ex) { if (ex is AssertFailedException) { throw; } else { Console.WriteLine("Failure is expected. Continue the tests..."); } } vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, locationName); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); var vmReturned = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName); Utilities.PrintContext(vmReturned); Assert.AreEqual(_serviceName, vmReturned.ServiceName); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
private SetAzureVMCustomScriptExtensionCmdletInfo(PersistentVM vm, string referenceName, string version, bool forceUpdate) { cmdletName = Utilities.SetAzureVMCustomScriptExtensionCmdletName; cmdletParams.Add(new CmdletParam("VM", vm)); if (!string.IsNullOrEmpty(version)) { cmdletParams.Add(new CmdletParam("Version", version)); } if (!string.IsNullOrEmpty(referenceName)) { cmdletParams.Add(new CmdletParam("ReferenceName", referenceName)); } if (forceUpdate) { cmdletParams.Add(new CmdletParam("ForceUpdate")); } }
public void NewAzureLinuxVMWithoutPasswordAndNoSSHEnpoint() { try { _serviceName = Utilities.GetUniqueShortName(serviceNamePrefix); //Create service vmPowershellCmdlets.NewAzureService(_serviceName, locationName); //Add installed certificate to the service PSObject certToUpload = vmPowershellCmdlets.RunPSScript( String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), _installedCert.Thumbprint))[0]; vmPowershellCmdlets.AddAzureCertificate(_serviceName, certToUpload); string newAzureLinuxVMName = Utilities.GetUniqueShortName("PSLinuxVM"); var key = vmPowershellCmdlets.NewAzureSSHKey(NewAzureSshKeyType.PublicKey, _installedCert.Thumbprint, keyPath); var sshKeysList = new Model.LinuxProvisioningConfigurationSet.SSHPublicKeyList(); sshKeysList.Add(key); // Add-AzureProvisioningConfig without password and NoSSHEndpoint var azureVMConfigInfo = new AzureVMConfigInfo(newAzureLinuxVMName, InstanceSize.Small.ToString(), _linuxImageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(username, noSshEndpoint: true, sSHPublicKeyList: sshKeysList); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); Collection <InputEndpointContext> endpoints = vmPowershellCmdlets.GetAzureEndPoint(vmPowershellCmdlets.GetAzureVM(newAzureLinuxVMName, _serviceName)); Console.WriteLine("The number of endpoints: {0}", endpoints.Count); foreach (var ep in endpoints) { Utilities.PrintContext(ep); } Assert.AreEqual(0, endpoints.Count); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
protected Collection <InputEndpoint> GetInputEndpoints() { PersistentVM instance = base.VM.GetInstance(); NetworkConfigurationSet networkConfigurationSet = instance.ConfigurationSets.OfType <NetworkConfigurationSet>().SingleOrDefault <NetworkConfigurationSet>(); if (networkConfigurationSet == null) { networkConfigurationSet = new NetworkConfigurationSet(); instance.ConfigurationSets.Add(networkConfigurationSet); } if (networkConfigurationSet.InputEndpoints == null) { networkConfigurationSet.InputEndpoints = new Collection <InputEndpoint>(); } Collection <InputEndpoint> inputEndpoints = networkConfigurationSet.InputEndpoints; return(inputEndpoints); }
private Management.Compute.Models.Role CreatePersistentVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { persistentVM.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } foreach (var datadisk in persistentVM.DataVirtualHardDisks.Where(d => d.MediaLink == null && string.IsNullOrEmpty(d.DiskName))) { datadisk.MediaLink = mediaLinkFactory.Create(); } var result = new Management.Compute.Models.Role { AvailabilitySetName = persistentVM.AvailabilitySetName, OSVirtualHardDisk = Mapper.Map(persistentVM.OSVirtualHardDisk, new Management.Compute.Models.OSVirtualHardDisk()), RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label, ProvisionGuestAgent = persistentVM.ProvisionGuestAgent, ResourceExtensionReferences = persistentVM.ProvisionGuestAgent != null && persistentVM.ProvisionGuestAgent.Value ? Mapper.Map <List <ResourceExtensionReference> >(persistentVM.ResourceExtensionReferences) : null }; if (persistentVM.DataVirtualHardDisks != null) { persistentVM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map(c, new Microsoft.WindowsAzure.Management.Compute.Models.DataVirtualHardDisk()); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; result.DataVirtualHardDisks.Add(dataDisk); }); } if (persistentVM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(persistentVM.ConfigurationSets).ForEach(c => result.ConfigurationSets.Add(c)); } return(result); }
public void TestAssociateReservedIPToStageSlotIaaSFails() { try { string reservedIpName = Utilities.GetUniqueShortName("ResrvdIP"); string reservedIpLabel = Utilities.GetUniqueShortName(" ResrvdIPLbl", 5); string dnsName = Utilities.GetUniqueShortName("Dns"); string vmName = Utilities.GetUniqueShortName(vmNamePrefix); var input = new ReservedIPContext() { DeploymentName = string.Empty, Label = reservedIpLabel, InUse = false, Location = locationName, ReservedIPName = reservedIpName, State = "Created" }; // Reserve a new IP Utilities.ExecuteAndLog(() => vmPowershellCmdlets.NewAzureReservedIP(reservedIpName, locationName, reservedIpLabel), "Reserve a new IP"); //Get the reserved ip and verify the reserved Ip properties. VerifyReservedIpNotInUse(input); // Create a new VM with the reserved ip. DnsServer dns = null; Utilities.ExecuteAndLog(() => { dns = vmPowershellCmdlets.NewAzureDns(dnsName, DNS_IP); }, "Create a new Azure DNS"); Utilities.ExecuteAndLog(() => { PersistentVM vm = CreateVMObjectWithDataDiskSubnetAndAvailibilitySet(vmName, OS.Windows); vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, vnet, new[] { dns }, location: locationName); }, "Create a new windows azure vm without reserved ip."); Utilities.ExecuteAndLog(() => { vmPowershellCmdlets.SetAzureReservedIPAssociation(reservedIpName, serviceName, DeploymentSlotType.Staging); }, "Create a new Azure Reserved IP Association"); } catch (Exception ex) { pass = true; Console.WriteLine(ex.ToString()); return; } throw new Exception("Test Did not fail as expected when association was tried on stage slot in IaaS"); }
public void AddEndPointACLsWithNewDeployment() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix); string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix); if (string.IsNullOrEmpty(imageName)) { imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false); } vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName); NetworkAclObject aclObj = vmPowershellCmdlets.NewAzureAclConfig(); vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 100, ACLAction.Permit, "172.0.0.0/8", "notes1"); vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 200, ACLAction.Deny, "10.0.0.0/8", "notes2"); AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall, imageName); AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.ExtraSmall, imageName); AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); AddAzureDataDiskConfig azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0); AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.DefaultProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", aclObj, true); PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo); PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo); PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1); PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2); PersistentVM[] VMs = { persistentVM1, persistentVM2 }; vmPowershellCmdlets.NewAzureVM(serviceName, VMs); // Cleanup vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName); vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName); Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName)); Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName)); pass = true; }
public void AzureOSDiskTest() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); try { PersistentVM vm = vmPowershellCmdlets.GetAzureVM(defaultVm, defaultService).VM; Assert.IsTrue(Verify.AzureOsDisk(vm, "Windows", HostCaching.ReadWrite)); PersistentVM vm2 = vmPowershellCmdlets.SetAzureOSDisk(HostCaching.ReadOnly, vm); Assert.IsTrue(Verify.AzureOsDisk(vm2, "Windows", HostCaching.ReadOnly)); pass = true; } catch (Exception e) { pass = false; Assert.Fail("Exception occurred: {0}", e.ToString()); } }
/// <summary> /// /// </summary> /// <param name="vm"></param> /// <param name="availabilitySetName"></param> /// <returns></returns> internal static bool AzureAvailabilitySet(PersistentVM vm, string availabilitySetName) { try { Assert.IsTrue(vm.AvailabilitySetName.Equals(availabilitySetName, StringComparison.InvariantCultureIgnoreCase)); return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); if (e is AssertFailedException) { return(false); } else { throw; } } }
public static void SaveStateToFile(PersistentVM role, string filePath) { if (role == null) { throw new ArgumentNullException("role", Resources.MissingPersistentVMRole); } XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes ignoreAttrib = new XmlAttributes(); ignoreAttrib.XmlIgnore = true; overrides.Add(typeof(DataVirtualHardDisk), "MediaLink", ignoreAttrib); overrides.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", ignoreAttrib); overrides.Add(typeof(OSVirtualHardDisk), "MediaLink", ignoreAttrib); var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PersistentVM), overrides, new Type[] { typeof(NetworkConfigurationSet) }, null, null); using (TextWriter writer = new StreamWriter(filePath)) { serializer.Serialize(writer, role); } }
protected override void ProcessRecord() { try { base.ProcessRecord(); PersistentVM instance = base.VM.GetInstance(); if (instance.OSVirtualHardDisk == null) { base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException("An OSDisk has not been defined for this VM. Use New-OSDisk to assign a new OS disk."), string.Empty, ErrorCategory.InvalidData, null)); } OSVirtualHardDisk oSVirtualHardDisk = instance.OSVirtualHardDisk; oSVirtualHardDisk.HostCaching = this.HostCaching; base.WriteObject(base.VM, true); } catch (Exception exception1) { Exception exception = exception1; base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null)); } }
private PersistentVMRole CreatePersistentVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { if (!string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName) && !NetworkConfigurationSetBuilder.HasNetworkConfigurationSet(persistentVM.ConfigurationSets)) { var networkConfigurationSetBuilder = new NetworkConfigurationSetBuilder(persistentVM.ConfigurationSets); Disk disk = this.Channel.GetDisk(CurrentSubscription.SubscriptionId, persistentVM.OSVirtualHardDisk.DiskName); if (disk.OS == OS.Windows && !persistentVM.NoRDPEndpoint) { networkConfigurationSetBuilder.AddRdpEndpoint(); } else if (disk.OS == OS.Linux && !persistentVM.NoSSHEndpoint) { networkConfigurationSetBuilder.AddSshEndpoint(); } } var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { persistentVM.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } foreach (DataVirtualHardDisk datadisk in persistentVM.DataVirtualHardDisks.Where(d => d.MediaLink == null && string.IsNullOrEmpty(d.DiskName))) { datadisk.MediaLink = mediaLinkFactory.Create(); } return(new PersistentVMRole { AvailabilitySetName = persistentVM.AvailabilitySetName, ConfigurationSets = persistentVM.ConfigurationSets, DataVirtualHardDisks = persistentVM.DataVirtualHardDisks, OSVirtualHardDisk = persistentVM.OSVirtualHardDisk, RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label }); }
public NewAzureVMCmdletInfo(string serviceName, PersistentVM[] vMs, string vnetName, DnsServer[] dnsSettings, string serviceLabel, string serviceDescription, string deploymentLabel, string deploymentDescription, string location, string affinityGroup) { this.cmdletName = Utilities.NewAzureVMCmdletName; this.cmdletParams.Add(new CmdletParam("ServiceName", serviceName)); this.cmdletParams.Add(new CmdletParam("VMs", vMs)); if (vnetName != null) { this.cmdletParams.Add(new CmdletParam("VNetName", vnetName)); } if (dnsSettings != null) { this.cmdletParams.Add(new CmdletParam("DnsSettings", dnsSettings)); } if (affinityGroup != null) { this.cmdletParams.Add(new CmdletParam("AffinityGroup", affinityGroup)); } if (serviceLabel != null) { this.cmdletParams.Add(new CmdletParam("ServiceLabel", serviceLabel)); } if (serviceDescription != null) { this.cmdletParams.Add(new CmdletParam("ServiceDescription", serviceDescription)); } if (deploymentLabel != null) { this.cmdletParams.Add(new CmdletParam("DeploymentLabel", deploymentLabel)); } if (deploymentDescription != null) { this.cmdletParams.Add(new CmdletParam("DeploymentDescription", deploymentDescription)); } if (location != null) { this.cmdletParams.Add(new CmdletParam("Location", location)); } }
public static void SaveStateToFile(PersistentVM role, string filePath) { if (role == null) { throw new ArgumentNullException("role", Resources.MissingPersistentVMRole); } XmlAttributeOverrides overrides = new XmlAttributeOverrides(); XmlAttributes ignoreAttrib = new XmlAttributes(); ignoreAttrib.XmlIgnore = true; overrides.Add(typeof(DataVirtualHardDisk), "MediaLink", ignoreAttrib); overrides.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", ignoreAttrib); overrides.Add(typeof(OSVirtualHardDisk), "MediaLink", ignoreAttrib); var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PersistentVM), overrides, new Type[] { typeof(NetworkConfigurationSet) }, null, null); using (TextWriter writer = new StreamWriter(filePath)) { serializer.Serialize(writer, role); } }
public void NewAzureVMWithWinRMCertificateTest() { try { // Add-AzureProvisioningConfig with X509Certificate var azureVMConfigInfo = new AzureVMConfigInfo(_vmName, InstanceSize.Small.ToString(), imageName); var azureProvisioningConfig = new AzureProvisioningConfigInfo(username, password, _installedCert); var persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null); PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVM vmPowershellCmdlets.NewAzureVM(_serviceName, new[] { vm }, null); Console.WriteLine("New Azure service with name:{0} created successfully.", _serviceName); var result = vmPowershellCmdlets.GetAzureVM(_vmName, _serviceName); Assert.AreEqual(_installedCert.Thumbprint, result.VM.WinRMCertificate.Thumbprint); pass = true; } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public void StopDeallocateVMWithStaticCATest() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); string vnet1 = VirtualNets[0]; string vmName = Utilities.GetUniqueShortName(vmNamePrefix); try { //Test a static CA //Test-AzureStaticVNetIP-VNetName $vnet -IPAddress “10.0.0.5” const string ipaddress = "10.0.0.5"; CheckAvailabilityofIpAddress(vnet1, ipaddress); //Create an IaaS VM with a static CA. PersistentVM vm = CreatIaasVMObject(vmName, ipaddress, StaticCASubnet0); vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm }, vnet1, new DnsServer[1] { DnsServers[0] }, serviceName, "service for DeployVMWithStaticCATest", string.Empty, string.Empty, null, AffinityGroup, null); Console.WriteLine("New Azure service with name:{0} created successfully.", serviceName); //Verfications VerifyVmWithStaticCAIsReserved(vmName, serviceName, ipaddress); //StopDeallocate the VM var vmRoleContext = vmPowershellCmdlets.GetAzureVM(vmName, serviceName); vmPowershellCmdlets.StopAzureVM(vmRoleContext.VM, serviceName, false, true); CheckAvailabilityOfIpAddressAndAssertFalse(vnet1, ipaddress); pass = true; } catch (Exception) { pass = false; throw; } }
public void AdvancedProvisioning() { StartTest(MethodBase.GetCurrentMethod().Name, testStartTime); string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix); string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix); if (string.IsNullOrEmpty(imageName)) { imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false); } vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName); AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall, imageName); AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.ExtraSmall, imageName); AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); AddAzureDataDiskConfig azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0); AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/", null, null); PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo); PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo); PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1); PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2); PersistentVM[] VMs = { persistentVM1, persistentVM2 }; vmPowershellCmdlets.NewAzureVM(serviceName, VMs); // Cleanup vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName); vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName); Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName)); Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName)); pass = true; }
protected Collection <InputEndpointContext> GetInputEndpoints() { PersistentVM instance = base.VM.GetInstance(); NetworkConfigurationSet networkConfigurationSet = instance.ConfigurationSets.OfType <NetworkConfigurationSet>().SingleOrDefault <NetworkConfigurationSet>(); if (networkConfigurationSet == null) { networkConfigurationSet = new NetworkConfigurationSet(); instance.ConfigurationSets.Add(networkConfigurationSet); } if (networkConfigurationSet.InputEndpoints == null) { networkConfigurationSet.InputEndpoints = new Collection <InputEndpoint>(); } Collection <InputEndpoint> inputEndpoints = networkConfigurationSet.InputEndpoints; Collection <InputEndpointContext> inputEndpointContexts = new Collection <InputEndpointContext>(); foreach (InputEndpoint inputEndpoint in inputEndpoints) { InputEndpointContext inputEndpointContext = new InputEndpointContext(); inputEndpointContext.LBSetName = inputEndpoint.LoadBalancedEndpointSetName; inputEndpointContext.LocalPort = inputEndpoint.LocalPort; inputEndpointContext.Name = inputEndpoint.Name; inputEndpointContext.Port = inputEndpoint.Port; inputEndpointContext.Protocol = inputEndpoint.Protocol; inputEndpointContext.Vip = inputEndpoint.Vip; if (inputEndpoint.LoadBalancerProbe != null && !string.IsNullOrEmpty(inputEndpointContext.LBSetName)) { inputEndpointContext.ProbePath = inputEndpoint.LoadBalancerProbe.Path; inputEndpointContext.ProbePort = inputEndpoint.LoadBalancerProbe.Port; inputEndpointContext.ProbeProtocol = inputEndpoint.LoadBalancerProbe.Protocol; } inputEndpointContexts.Add(inputEndpointContext); } return(inputEndpointContexts); }
protected void ValidateParameters() { PersistentVM vm = (PersistentVM)this.VM; if (string.Compare(ParameterSetName, "Linux", StringComparison.OrdinalIgnoreCase) == 0 && ValidationHelpers.IsLinuxPasswordValid(Password) == false) { throw new ArgumentException("Password does not meet complexity requirements."); } if ((string.Compare(ParameterSetName, "Windows", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ParameterSetName, "WindowsDomain", StringComparison.OrdinalIgnoreCase) == 0) && ValidationHelpers.IsWindowsPasswordValid(Password) == false) { throw new ArgumentException("Password does not meet complexity requirements."); } if (string.Compare(ParameterSetName, "Linux", StringComparison.OrdinalIgnoreCase) == 0 && ValidationHelpers.IsLinuxHostNameValid(vm.RoleName) == false) { throw new ArgumentException("Hostname is invalid."); } if ((string.Compare(ParameterSetName, "Windows", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ParameterSetName, "WindowsDomain", StringComparison.OrdinalIgnoreCase) == 0) && ValidationHelpers.IsWindowsComputerNameValid(vm.RoleName) == false) { throw new ArgumentException("Computer Name is invalid."); } }
public static void SaveStateToFile(PersistentVM role, string filePath) { if (role != null) { XmlAttributeOverrides xmlAttributeOverride = new XmlAttributeOverrides(); XmlAttributes xmlAttribute = new XmlAttributes(); xmlAttribute.XmlIgnore = true; xmlAttributeOverride.Add(typeof(DataVirtualHardDisk), "MediaLink", xmlAttribute); xmlAttributeOverride.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", xmlAttribute); xmlAttributeOverride.Add(typeof(OSVirtualHardDisk), "MediaLink", xmlAttribute); Type[] typeArray = new Type[1]; typeArray[0] = typeof(NetworkConfigurationSet); XmlSerializer xmlSerializer = new XmlSerializer(typeof(PersistentVM), xmlAttributeOverride, typeArray, null, null); using (TextWriter streamWriter = new StreamWriter(filePath)) { xmlSerializer.Serialize(streamWriter, role); } return; } else { throw new ArgumentNullException("role", "Role cannot be null"); } }
protected void ValidateParameters() { PersistentVM vm = (PersistentVM)this.VM; if (string.Compare(ParameterSetName, "Linux", StringComparison.OrdinalIgnoreCase) == 0 && ValidationHelpers.IsLinuxPasswordValid(Password) == false) { throw new ArgumentException(Resources.PasswordNotComplexEnough); } if ((string.Compare(ParameterSetName, "Windows", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ParameterSetName, "WindowsDomain", StringComparison.OrdinalIgnoreCase) == 0) && ValidationHelpers.IsWindowsPasswordValid(Password) == false) { throw new ArgumentException(Resources.PasswordNotComplexEnough); } if (string.Compare(ParameterSetName, "Linux", StringComparison.OrdinalIgnoreCase) == 0 && ValidationHelpers.IsLinuxHostNameValid(vm.RoleName) == false) { throw new ArgumentException(Resources.InvalidHostName); } if ((string.Compare(ParameterSetName, "Windows", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(ParameterSetName, "WindowsDomain", StringComparison.OrdinalIgnoreCase) == 0) && ValidationHelpers.IsWindowsComputerNameValid(vm.RoleName) == false) { throw new ArgumentException(Resources.InvalidComputerName); } }
/// <summary> /// /// </summary> /// <param name="vm"></param> /// <param name="expOS"></param> /// <param name="expHC"></param> /// <returns></returns> internal static bool AzureOsDisk(PersistentVM vm, string expOS, HostCaching expHC) { try { OSVirtualHardDisk osdisk = vmPowershellCmdlets.GetAzureOSDisk(vm); Console.WriteLine("OS Disk: Name - {0}, Label - {1}, HostCaching - {2}, OS - {3}", osdisk.DiskName, osdisk.DiskLabel, osdisk.HostCaching, osdisk.OS); Assert.IsTrue(osdisk.Equals(vm.OSVirtualHardDisk), "OS disk returned is not the same!"); Assert.AreEqual(expOS, osdisk.OS); Assert.AreEqual(expHC.ToString(), osdisk.HostCaching); return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); if (e is AssertFailedException) { return(false); } else { throw; } } }
private void ValidateWindowsParameterSetParameters(PersistentVM vm) { if (WindowsParameterSetName.Equals(ParameterSetName, StringComparison.OrdinalIgnoreCase) || WindowsDomainParameterSetName.Equals(ParameterSetName, StringComparison.OrdinalIgnoreCase)) { if (ValidationHelpers.IsWindowsPasswordValid(Password) == false) { throw new ArgumentException(Resources.PasswordNotComplexEnough); } if (ValidationHelpers.IsWindowsComputerNameValid(vm.RoleName) == false) { throw new ArgumentException(Resources.InvalidComputerName); } } }
private void ValidateLinuxParameterSetParameters(PersistentVM vm) { if (LinuxParameterSetName.Equals(ParameterSetName, StringComparison.OrdinalIgnoreCase)) { if (!this.NoSSHPassword && ValidationHelpers.IsLinuxPasswordValid(Password) == false) { throw new ArgumentException(Resources.PasswordNotComplexEnough); } if (ValidationHelpers.IsLinuxHostNameValid(vm.RoleName) == false) { throw new ArgumentException(Resources.InvalidHostName); } } }
internal Collection<ManagementOperationContext> NewAzureVM(string serviceName, PersistentVM[] vms, string vnetName, DnsServer[] dnsSettings, string affinityGroup, string serviceLabel, string serviceDescription, string deploymentLabel, string deploymentDescription, string location) { NewAzureVMCmdletInfo newAzureVMCmdletInfo = new NewAzureVMCmdletInfo(serviceName, vms, vnetName, dnsSettings, affinityGroup, serviceLabel, serviceDescription, deploymentLabel, deploymentDescription, location); WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(newAzureVMCmdletInfo); Collection<ManagementOperationContext> newAzureVMs = new Collection<ManagementOperationContext>(); foreach (PSObject result in azurePowershellCmdlet.Run()) { newAzureVMs.Add((ManagementOperationContext)result.BaseObject); } return newAzureVMs; }
public SubnetNamesCollection GetAzureSubnet(PersistentVM vm) { GetAzureSubnetCmdletInfo getAzureSubnetCmdlet = new GetAzureSubnetCmdletInfo(vm); WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureSubnetCmdlet); Collection <PSObject> result = azurePowershellCmdlet.Run(); SubnetNamesCollection subnets = new SubnetNamesCollection(); foreach (PSObject re in result) { subnets.Add((string)re.BaseObject); } return subnets; }
protected override void ProcessRecord() { base.ProcessRecord(); ValidateParameters(); var role = new PersistentVM { AvailabilitySetName = AvailabilitySetName, ConfigurationSets = new Collection<ConfigurationSet>(), DataVirtualHardDisks = new Collection<DataVirtualHardDisk>(), RoleName = Name, RoleSize = InstanceSize, RoleType = RoleType, Label = Label, ProvisionGuestAgent = true }; role.OSVirtualHardDisk = new OSVirtualHardDisk() { DiskName = DiskName, SourceImageName = ImageName, MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation), HostCaching = HostCaching, DiskLabel = string.IsNullOrEmpty(DiskLabel) ? null : DiskLabel }; WriteObject(role, true); }
private ManagementOperationContext UpdateAzureVM(string vmName, string serviceName, PersistentVM persistentVM) { UpdateAzureVMCmdletInfo updateAzureVMCmdletInfo = new UpdateAzureVMCmdletInfo(vmName, serviceName, persistentVM); WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(updateAzureVMCmdletInfo); Collection<PSObject> result = azurePowershellCmdlet.Run(); if (result.Count == 1) { return (ManagementOperationContext)result[0].BaseObject; } return null; }
private Management.Compute.Models.Role CreatePersistentVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { if (!string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName) && !NetworkConfigurationSetBuilder.HasNetworkConfigurationSet(persistentVM.ConfigurationSets)) { // var networkConfigurationSetBuilder = new NetworkConfigurationSetBuilder(persistentVM.ConfigurationSets); // // Disk disk = this.Channel.GetDisk(CurrentSubscription.SubscriptionId, persistentVM.OSVirtualHardDisk.DiskName); // if (disk.OS == OS.Windows && !persistentVM.NoRDPEndpoint) // { // networkConfigurationSetBuilder.AddRdpEndpoint(); // } // else if (disk.OS == OS.Linux && !persistentVM.NoSSHEndpoint) // { // networkConfigurationSetBuilder.AddSshEndpoint(); // } } var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { persistentVM.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } foreach (var datadisk in persistentVM.DataVirtualHardDisks.Where(d => d.MediaLink == null && string.IsNullOrEmpty(d.DiskName))) { datadisk.MediaLink = mediaLinkFactory.Create(); } var result = new Management.Compute.Models.Role { AvailabilitySetName = persistentVM.AvailabilitySetName, OSVirtualHardDisk = Mapper.Map(persistentVM.OSVirtualHardDisk, new Management.Compute.Models.OSVirtualHardDisk()), RoleName = persistentVM.RoleName, RoleSize = string.IsNullOrEmpty(persistentVM.RoleSize) ? null : (VirtualMachineRoleSize?)Enum.Parse(typeof(VirtualMachineRoleSize), persistentVM.RoleSize, true), RoleType = persistentVM.RoleType, Label = persistentVM.Label }; if (persistentVM.DataVirtualHardDisks != null) { persistentVM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map(c, new Microsoft.WindowsAzure.Management.Compute.Models.DataVirtualHardDisk()); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; result.DataVirtualHardDisks.Add(dataDisk); }); } if (persistentVM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(persistentVM.ConfigurationSets).ForEach(c => result.ConfigurationSets.Add(c)); } return result; }
protected virtual void SaveRoleState(PersistentVM role) { }
public RemoveAzureDataDiskConfig(int lun, PersistentVM vm) { this.Vm = vm; this.lun = lun; }
protected override void SaveRoleState(PersistentVM role) { PersistentVMHelper.SaveStateToFile(role, Path); }
public RemoveAzureEndpointCmdletInfo(string epName, PersistentVM vm) { this.cmdletName = Utilities.RemoveAzureEndpointCmdletName; this.cmdletParams.Add(new CmdletParam("Name", epName)); this.cmdletParams.Add(new CmdletParam("VM", vm)); }
public PersistentVM SetAzureOSDisk(HostCaching hc, PersistentVM vm) { SetAzureOSDiskCmdletInfo setAzureOSDiskCmdletInfo = new SetAzureOSDiskCmdletInfo(hc, vm); WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(setAzureOSDiskCmdletInfo); Collection<PSObject> result = azurePowershellCmdlet.Run(); if (result.Count == 1) { return (PersistentVM)result[0].BaseObject; } return null; }
public PersistentVM SetAzureSubnet(PersistentVM vm, string [] subnetNames) { SetAzureSubnetCmdletInfo setAzureSubnetCmdlet = new SetAzureSubnetCmdletInfo(vm, subnetNames); WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(setAzureSubnetCmdlet); Collection<PSObject> result = azurePowershellCmdlet.Run(); if (result.Count == 1) { return (PersistentVM)result[0].BaseObject; } return null; }
public RemoveAzureAvailabilitySetCmdletInfo(PersistentVM vm) { base.cmdletName = Utilities.RemoveAzureAvailabilitySetCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vm)); }
public SetAzureOSDiskCmdletInfo(HostCaching hs, PersistentVM vm) { cmdletName = Utilities.SetAzureOSDiskCmdletName; this.cmdletParams.Add(new CmdletParam("HostCaching", hs.ToString())); this.cmdletParams.Add(new CmdletParam("VM", vm)); }
private Management.Compute.Models.Role CreatePersistentVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { persistentVM.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } foreach (var datadisk in persistentVM.DataVirtualHardDisks.Where(d => d.MediaLink == null && string.IsNullOrEmpty(d.DiskName))) { datadisk.MediaLink = mediaLinkFactory.Create(); } var result = new Management.Compute.Models.Role { AvailabilitySetName = persistentVM.AvailabilitySetName, OSVirtualHardDisk = Mapper.Map(persistentVM.OSVirtualHardDisk, new Management.Compute.Models.OSVirtualHardDisk()), RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label, ProvisionGuestAgent = persistentVM.ProvisionGuestAgent, ResourceExtensionReferences = persistentVM.ProvisionGuestAgent != null && persistentVM.ProvisionGuestAgent.Value ? Mapper.Map<List<ResourceExtensionReference>>(persistentVM.ResourceExtensionReferences) : null }; if (persistentVM.DataVirtualHardDisks != null) { persistentVM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map(c, new Microsoft.WindowsAzure.Management.Compute.Models.DataVirtualHardDisk()); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; result.DataVirtualHardDisks.Add(dataDisk); }); } if (persistentVM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(persistentVM.ConfigurationSets).ForEach(c => result.ConfigurationSets.Add(c)); } return result; }
public GetAzureDataDiskCmdletInfo(PersistentVM vM) { this.cmdletName = Utilities.GetAzureDataDiskCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vM)); }
private PersistentVMRole CreatePersistenVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { DateTime dateTimeCreated = DateTime.Now; string diskPartName = persistentVM.RoleName; if (persistentVM.OSVirtualHardDisk.DiskLabel != null) { diskPartName += "-" + persistentVM.OSVirtualHardDisk.DiskLabel; } string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", this.ServiceName, diskPartName, dateTimeCreated.Year, dateTimeCreated.Month, dateTimeCreated.Day, dateTimeCreated.Millisecond); string blobEndpoint = currentStorage.BlobEndpoint.AbsoluteUri; if (blobEndpoint.EndsWith("/") == false) { blobEndpoint += "/"; } persistentVM.OSVirtualHardDisk.MediaLink = new Uri(blobEndpoint + "vhds/" + vhdname); } foreach (DataVirtualHardDisk datadisk in persistentVM.DataVirtualHardDisks) { if (datadisk.MediaLink == null && string.IsNullOrEmpty(datadisk.DiskName)) { if (currentStorage == null) { throw new ArgumentException(Resources.CurrentStorageAccountIsNotSet); } DateTime dateTimeCreated = DateTime.Now; string diskPartName = persistentVM.RoleName; if (datadisk.DiskLabel != null) { diskPartName += "-" + datadisk.DiskLabel; } string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", this.ServiceName, diskPartName, dateTimeCreated.Year, dateTimeCreated.Month, dateTimeCreated.Day, dateTimeCreated.Millisecond); string blobEndpoint = currentStorage.BlobEndpoint.AbsoluteUri; if (blobEndpoint.EndsWith("/") == false) { blobEndpoint += "/"; } datadisk.MediaLink = new Uri(blobEndpoint + "vhds/" + vhdname); } if (persistentVM.DataVirtualHardDisks.Count() > 1) { // To avoid duplicate disk names System.Threading.Thread.Sleep(1); } } return(new PersistentVMRole { AvailabilitySetName = persistentVM.AvailabilitySetName, ConfigurationSets = persistentVM.ConfigurationSets, DataVirtualHardDisks = persistentVM.DataVirtualHardDisks, OSVirtualHardDisk = persistentVM.OSVirtualHardDisk, RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label }); }
private PersistentVMRole CreatePersistenVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { persistentVM.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } foreach (DataVirtualHardDisk datadisk in persistentVM.DataVirtualHardDisks.Where(d => d.MediaLink == null && string.IsNullOrEmpty(d.DiskName))) { datadisk.MediaLink = mediaLinkFactory.Create(); } return new PersistentVMRole { AvailabilitySetName = persistentVM.AvailabilitySetName, ConfigurationSets = persistentVM.ConfigurationSets, DataVirtualHardDisks = persistentVM.DataVirtualHardDisks, OSVirtualHardDisk = persistentVM.OSVirtualHardDisk, RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label }; }
public RemoveAzureAvailabilitySetCmdletInfo(PersistentVM vm) { base.cmdletName = Utilities.RemoveAzureAvailabilitySetCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vm)); }
public GetAzureOSDiskCmdletInfo(PersistentVM vm) { cmdletName = Utilities.GetAzureOSDiskCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vm)); }
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)); }
private PersistentVMRole CreatePersistenVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { DateTime dateTimeCreated = DateTime.Now; string diskPartName = persistentVM.RoleName; if (persistentVM.OSVirtualHardDisk.DiskLabel != null) { diskPartName += "-" + persistentVM.OSVirtualHardDisk.DiskLabel; } string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", this.ServiceName, diskPartName, dateTimeCreated.Year, dateTimeCreated.Month, dateTimeCreated.Day, dateTimeCreated.Millisecond); string blobEndpoint = currentStorage.BlobEndpoint.AbsoluteUri; if (blobEndpoint.EndsWith("/") == false) { blobEndpoint += "/"; } persistentVM.OSVirtualHardDisk.MediaLink = new Uri(blobEndpoint + "vhds/" + vhdname); } foreach (DataVirtualHardDisk datadisk in persistentVM.DataVirtualHardDisks) { if (datadisk.MediaLink == null && string.IsNullOrEmpty(datadisk.DiskName)) { if (currentStorage == null) { throw new ArgumentException( "CurrentStorageAccount is not set or not accessible. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it."); } DateTime dateTimeCreated = DateTime.Now; string diskPartName = persistentVM.RoleName; if (datadisk.DiskLabel != null) { diskPartName += "-" + datadisk.DiskLabel; } string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", this.ServiceName, diskPartName, dateTimeCreated.Year, dateTimeCreated.Month, dateTimeCreated.Day, dateTimeCreated.Millisecond); string blobEndpoint = currentStorage.BlobEndpoint.AbsoluteUri; if (blobEndpoint.EndsWith("/") == false) { blobEndpoint += "/"; } datadisk.MediaLink = new Uri(blobEndpoint + "vhds/" + vhdname); } if (persistentVM.DataVirtualHardDisks.Count() > 1) { // To avoid duplicate disk names System.Threading.Thread.Sleep(1); } } return new PersistentVMRole { AvailabilitySetName = persistentVM.AvailabilitySetName, ConfigurationSets = persistentVM.ConfigurationSets, DataVirtualHardDisks = persistentVM.DataVirtualHardDisks, OSVirtualHardDisk = persistentVM.OSVirtualHardDisk, RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label }; }
private PersistentVMRole CreatePersistentVMRole(PersistentVM persistentVM, CloudStorageAccount currentStorage) { if (!string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName) && !NetworkConfigurationSetBuilder.HasNetworkConfigurationSet(persistentVM.ConfigurationSets)) { var networkConfigurationSetBuilder = new NetworkConfigurationSetBuilder(persistentVM.ConfigurationSets); Disk disk = this.Channel.GetDisk(CurrentSubscription.SubscriptionId, persistentVM.OSVirtualHardDisk.DiskName); if (disk.OS == OS.Windows && !persistentVM.NoRDPEndpoint) { networkConfigurationSetBuilder.AddRdpEndpoint(); } else if (disk.OS == OS.Linux && !persistentVM.NoSSHEndpoint) { networkConfigurationSetBuilder.AddSshEndpoint(); } } var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (persistentVM.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(persistentVM.OSVirtualHardDisk.DiskName)) { persistentVM.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } foreach (DataVirtualHardDisk datadisk in persistentVM.DataVirtualHardDisks.Where(d => d.MediaLink == null && string.IsNullOrEmpty(d.DiskName))) { datadisk.MediaLink = mediaLinkFactory.Create(); } return new PersistentVMRole { AvailabilitySetName = persistentVM.AvailabilitySetName, ConfigurationSets = persistentVM.ConfigurationSets, DataVirtualHardDisks = persistentVM.DataVirtualHardDisks, OSVirtualHardDisk = persistentVM.OSVirtualHardDisk, RoleName = persistentVM.RoleName, RoleSize = persistentVM.RoleSize, RoleType = persistentVM.RoleType, Label = persistentVM.Label }; }
public OSVirtualHardDisk GetAzureOSDisk(PersistentVM vm) { GetAzureOSDiskCmdletInfo getAzureOSDiskCmdletInfo = new GetAzureOSDiskCmdletInfo(vm); WindowsAzurePowershellCmdlet azurePowershellCmdlet = new WindowsAzurePowershellCmdlet(getAzureOSDiskCmdletInfo); Collection<PSObject> result = azurePowershellCmdlet.Run(); if (result.Count == 1) { return (OSVirtualHardDisk)result[0].BaseObject; } return null; }
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); } } } }
internal void ExecuteCommand() { ValidateParameters(); if (string.IsNullOrEmpty(Label)) { Label = Name; } Label = ServiceManagementHelper.EncodeToBase64String(Label); var role = new PersistentVM { AvailabilitySetName = AvailabilitySetName, ConfigurationSets = new Collection<ConfigurationSet>(), DataVirtualHardDisks = new Collection<DataVirtualHardDisk>(), RoleName = Name, RoleSize = InstanceSize, RoleType = RoleType, Label = Label }; role.OSVirtualHardDisk = new OSVirtualHardDisk() { DiskName = DiskName, SourceImageName = ImageName, MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation), HostCaching = HostCaching, DiskLabel = string.IsNullOrEmpty(DiskLabel) ? null : DiskLabel }; WriteObject(role, true); }
public RemoveAzureEndpointCmdletInfo(string epName, PersistentVM vm) { this.cmdletName = Utilities.RemoveAzureEndpointCmdletName; this.cmdletParams.Add(new CmdletParam("Name", epName)); this.cmdletParams.Add(new CmdletParam("VM", vm)); }
internal Collection<ManagementOperationContext> NewAzureVM(string serviceName, PersistentVM[] VMs) { return NewAzureVM(serviceName, VMs, null, null, null, null, null, null, null, null); }
public GetAzureDataDiskCmdletInfo(PersistentVM vM) { this.cmdletName = Utilities.GetAzureDataDiskCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vM)); }
public GetAzureSubnetCmdletInfo(PersistentVM vm) { this.cmdletName = Utilities.GetAzureSubnetCmdletName; this.cmdletParams.Add(new CmdletParam("VM", vm)); }