protected override void ExecuteCommand() { ServiceManagementProfile.Initialize(); base.ExecuteCommand(); if (this.CurrentDeploymentNewSM == null) { return; } string[] inputRoleNames = (this.ParameterSetName == "ByName") ? this.Name : this.VM.Select(vm => vm.GetInstance().RoleName).ToArray(); // Generate a list of role names matching wildcard patterns or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, inputRoleNames); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name)); } var parameters = new VirtualMachineStartRolesParameters(); foreach (var r in roleNames) { parameters.Roles.Add(r); } this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.StartRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameters)); }
protected void SetProvisioningConfiguration(LinuxProvisioningConfigurationSet provisioningConfiguration) { provisioningConfiguration.UserName = LinuxUser; provisioningConfiguration.UserPassword = SecureStringHelper.GetSecureString(Password); if (NoSSHPassword.IsPresent) { provisioningConfiguration.UserPassword = SecureStringHelper.GetSecureString(String.Empty); } if (DisableSSH.IsPresent || NoSSHPassword.IsPresent) { provisioningConfiguration.DisableSshPasswordAuthentication = true; } else { provisioningConfiguration.DisableSshPasswordAuthentication = false; } if (SSHKeyPairs != null && SSHKeyPairs.Count > 0 || SSHPublicKeys != null && SSHPublicKeys.Count > 0) { provisioningConfiguration.SSH = new LinuxProvisioningConfigurationSet.SSHSettings { PublicKeys = SSHPublicKeys, KeyPairs = SSHKeyPairs }; } if (!string.IsNullOrEmpty(CustomDataFile)) { string fileName = this.TryResolvePath(this.CustomDataFile); provisioningConfiguration.CustomData = PersistentVMHelper.ConvertCustomDataFileToBase64(fileName); } }
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); } }
private Management.Compute.Models.Role CreatePersistentVMRole(Tuple <Model.PersistentVM, bool, bool> tuple, CloudStorageAccount currentStorage) { Model.PersistentVM persistentVM = tuple.Item1; bool isVMImage = tuple.Item3; var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, persistentVM.RoleName); if (!isVMImage) { 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 = isVMImage ? null : 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, VMImageName = isVMImage ? persistentVM.OSVirtualHardDisk.SourceImageName : null }; if (result.OSVirtualHardDisk != null) { result.OSVirtualHardDisk.IOType = null; } if (persistentVM.DataVirtualHardDisks != null && persistentVM.DataVirtualHardDisks.Any()) { persistentVM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map(c, new Microsoft.WindowsAzure.Management.Compute.Models.DataVirtualHardDisk()); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; result.DataVirtualHardDisks.Add(dataDisk); }); result.DataVirtualHardDisks.ForEach(d => d.IOType = null); } else { result.DataVirtualHardDisks = null; } if (persistentVM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(persistentVM.ConfigurationSets).ForEach(c => result.ConfigurationSets.Add(c)); } return(result); }
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); }
private T CreateVMContext <T>(string serviceName, NSM.Role vmRole, NSM.RoleInstance roleInstance, NSM.DeploymentGetResponse deployment) where T : PVM.PersistentVMRoleContext, new() { var vmContext = new T { ServiceName = serviceName, DeploymentName = deployment == null ? string.Empty : deployment.Name, DNSName = deployment == null || deployment.Uri == null ? string.Empty : deployment.Uri.AbsoluteUri, Name = vmRole == null ? string.Empty : vmRole.RoleName, AvailabilitySetName = vmRole == null ? string.Empty : vmRole.AvailabilitySetName, Label = vmRole == null ? string.Empty : vmRole.Label, InstanceSize = vmRole == null ? string.Empty : vmRole.RoleSize, InstanceStatus = roleInstance == null ? string.Empty : roleInstance.InstanceStatus, IpAddress = roleInstance == null ? string.Empty : roleInstance.IPAddress, PublicIPAddress = roleInstance == null ? string.Empty : roleInstance.PublicIPs == null || !roleInstance.PublicIPs.Any() ? string.Empty : roleInstance.PublicIPs.First().Address, PublicIPName = roleInstance == null ? string.Empty : roleInstance.PublicIPs == null || !roleInstance.PublicIPs.Any() ? string.Empty : !string.IsNullOrEmpty(roleInstance.PublicIPs.First().Name) ? roleInstance.PublicIPs.First().Name : PersistentVMHelper.GetPublicIPName(vmRole), InstanceStateDetails = roleInstance == null ? string.Empty : roleInstance.InstanceStateDetails, PowerState = roleInstance == null ? string.Empty : roleInstance.PowerState.ToString(), HostName = roleInstance == null ? string.Empty : roleInstance.HostName, InstanceErrorCode = roleInstance == null ? string.Empty : roleInstance.InstanceErrorCode, InstanceName = roleInstance == null ? string.Empty : roleInstance.InstanceName, InstanceFaultDomain = roleInstance == null ? string.Empty : roleInstance.InstanceFaultDomain.HasValue ? roleInstance.InstanceFaultDomain.Value.ToString(CultureInfo.InvariantCulture) : null, InstanceUpgradeDomain = roleInstance == null ? string.Empty : roleInstance.InstanceUpgradeDomain.HasValue ? roleInstance.InstanceUpgradeDomain.Value.ToString(CultureInfo.InvariantCulture) : null, Status = roleInstance == null ? string.Empty : roleInstance.InstanceStatus, GuestAgentStatus = roleInstance == null ? null : Mapper.Map <PVM.GuestAgentStatus>(roleInstance.GuestAgentStatus), ResourceExtensionStatusList = roleInstance == null ? null : Mapper.Map <List <PVM.ResourceExtensionStatus> >(roleInstance.ResourceExtensionStatusList), OperationId = deployment == null ? string.Empty : deployment.RequestId, OperationStatus = deployment == null ? string.Empty : deployment.StatusCode.ToString(), OperationDescription = CommandRuntime.ToString(), NetworkInterfaces = roleInstance == null ? null : Mapper.Map <PVM.NetworkInterfaceList>(roleInstance.NetworkInterfaces), VirtualNetworkName = deployment == null ? null : deployment.VirtualNetworkName, VM = new PVM.PersistentVM { AvailabilitySetName = vmRole == null ? string.Empty : vmRole.AvailabilitySetName, Label = vmRole == null ? string.Empty : vmRole.Label, RoleName = vmRole == null ? string.Empty : vmRole.RoleName, RoleSize = vmRole == null ? string.Empty : vmRole.RoleSize, RoleType = vmRole == null ? string.Empty : vmRole.RoleType, DefaultWinRmCertificateThumbprint = vmRole == null ? string.Empty : vmRole.DefaultWinRmCertificateThumbprint, ProvisionGuestAgent = vmRole == null ? null : vmRole.ProvisionGuestAgent, ResourceExtensionReferences = vmRole == null ? null : Mapper.Map <PVM.ResourceExtensionReferenceList>(vmRole.ResourceExtensionReferences), DataVirtualHardDisks = vmRole == null ? null : Mapper.Map <Collection <PVM.DataVirtualHardDisk> >(vmRole.DataVirtualHardDisks), OSVirtualHardDisk = vmRole == null ? null : Mapper.Map <PVM.OSVirtualHardDisk>(vmRole.OSVirtualHardDisk), ConfigurationSets = vmRole == null ? null : PersistentVMHelper.MapConfigurationSets(vmRole.ConfigurationSets) } }; return(vmContext); }
private T GetContext <T>( string serviceName, Role vmRole, RoleInstance roleInstance, DeploymentGetResponse deployment) where T : PersistentVMRoleContext, new() { var vmContext = new T { ServiceName = serviceName, Name = vmRole.RoleName, DeploymentName = deployment.Name, AvailabilitySetName = vmRole.AvailabilitySetName, Label = vmRole.Label, InstanceSize = vmRole.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, Status = roleInstance.InstanceStatus, OperationDescription = CommandRuntime.ToString(), OperationId = deployment.RequestId, OperationStatus = deployment.StatusCode.ToString(), GuestAgentStatus = Mapper.Map <PVM.GuestAgentStatus>(roleInstance.GuestAgentStatus), ResourceExtensionStatusList = Mapper.Map <List <PVM.ResourceExtensionStatus> >(roleInstance.ResourceExtensionStatusList), VM = new PersistentVM { AvailabilitySetName = vmRole.AvailabilitySetName, ConfigurationSets = PersistentVMHelper.MapConfigurationSets(vmRole.ConfigurationSets), DataVirtualHardDisks = Mapper.Map(vmRole.DataVirtualHardDisks, new Collection <DataVirtualHardDisk>()), Label = vmRole.Label, OSVirtualHardDisk = Mapper.Map(vmRole.OSVirtualHardDisk, new OSVirtualHardDisk()), RoleName = vmRole.RoleName, RoleSize = vmRole.RoleSize.ToString(), RoleType = vmRole.RoleType, DefaultWinRmCertificateThumbprint = vmRole.DefaultWinRmCertificateThumbprint, ProvisionGuestAgent = vmRole.ProvisionGuestAgent, ResourceExtensionReferences = Mapper.Map <PVM.ResourceExtensionReferenceList>(vmRole.ResourceExtensionReferences) } }; if (deployment != null) { vmContext.DNSName = deployment.Uri.AbsoluteUri; } return(vmContext); }
protected override void ProcessRecord() { try { base.ProcessRecord(); PersistentVM persistentVM = PersistentVMHelper.LoadStateFromFile(this.Path); base.WriteObject(persistentVM, true); } catch (Exception exception1) { Exception exception = exception1; base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null)); } }
internal override void ExecuteCommand() { base.ExecuteCommand(); if (CurrentDeployment == null) { return; } string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName; // Generate a list of role names matching wildcard patterns or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(CurrentDeployment.RoleInstanceList, roleName); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name)); } if (roleNames.Count == 1) { ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.StartRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0])); } else { var startRolesOperation = new StartRolesOperation() { Roles = roleNames }; ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.StartRoles(s, this.ServiceName, CurrentDeployment.Name, startRolesOperation)); } }
protected void SetProvisioningConfiguration(WindowsProvisioningConfigurationSet provisioningConfiguration) { provisioningConfiguration.AdminUsername = AdminUsername; provisioningConfiguration.AdminPassword = SecureStringHelper.GetSecureString(Password); provisioningConfiguration.ResetPasswordOnFirstLogon = ResetPasswordOnFirstLogon.IsPresent; provisioningConfiguration.StoredCertificateSettings = CertUtilsNewSM.GetCertificateSettings(Certificates, X509Certificates); provisioningConfiguration.EnableAutomaticUpdates = !DisableAutomaticUpdates.IsPresent; if (provisioningConfiguration.StoredCertificateSettings == null) { provisioningConfiguration.StoredCertificateSettings = new CertificateSettingList(); } if (!string.IsNullOrEmpty(TimeZone)) { provisioningConfiguration.TimeZone = TimeZone; } if (WindowsDomainParameterSetName.Equals(ParameterSetName, StringComparison.OrdinalIgnoreCase)) { provisioningConfiguration.DomainJoin = new WindowsProvisioningConfigurationSet.DomainJoinSettings { Credentials = new WindowsProvisioningConfigurationSet.DomainJoinCredentials { Username = DomainUserName, Password = SecureStringHelper.GetSecureString(DomainPassword), Domain = Domain }, MachineObjectOU = MachineObjectOU, JoinDomain = JoinDomain }; } if (!string.IsNullOrEmpty(CustomDataFile)) { string fileName = this.TryResolvePath(this.CustomDataFile); provisioningConfiguration.CustomData = PersistentVMHelper.ConvertCustomDataFileToBase64(fileName); } }
internal void ExecuteCommand() { PersistentVM role = PersistentVMHelper.LoadStateFromFile(Path); WriteObject(role, true); }
protected override void ExecuteCommand() { base.ExecuteCommand(); ServiceManagementProfile.Initialize(); if (this.CurrentDeploymentNewSM == null) { return; } string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName; // Generate a list of role names matching regular expressions or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, roleName); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, this.Name)); } // Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified. if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent)) { throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards); } if (roleNames.Count == 1) { if (this.StayProvisioned.IsPresent) { ProcessStaticIPAddressWarningInfo(roleNames[0]); this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.Stopped }), (s, response) => this.ContextFactory <OperationStatusResponse, ManagementOperationContext>(response, s)); } else { if (!this.Force.IsPresent && this.IsLastVmInDeployment(roleNames.Count)) { this.ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.StoppedDeallocated }), (s, response) => ContextFactory <OperationStatusResponse, ManagementOperationContext>(response, s))); } else { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.StoppedDeallocated }), (s, response) => this.ContextFactory <OperationStatusResponse, ManagementOperationContext>(response, s)); } } } else { if (this.StayProvisioned.IsPresent) { var parameter = new VirtualMachineShutdownRolesParameters(); foreach (var role in roleNames) { ProcessStaticIPAddressWarningInfo(role); parameter.Roles.Add(role); } parameter.PostShutdownAction = PostShutdownAction.Stopped; this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter)); } else { var parameter = new VirtualMachineShutdownRolesParameters(); foreach (var role in roleNames) { parameter.Roles.Add(role); } parameter.PostShutdownAction = PostShutdownAction.StoppedDeallocated; if (!this.Force.IsPresent && this.IsLastVmInDeployment(roleNames.Count)) { this.ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter))); } else { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter)); } } } }
public void GetRoleProcess() { OperationStatusResponse getDeploymentOperation; var currentDeployment = this.GetCurrentDeployment(out getDeploymentOperation); if (currentDeployment != null) { if (this.InstanceDetails.IsPresent) { Collection <RoleInstanceContext> instanceContexts = new Collection <RoleInstanceContext>(); IList <RoleInstance> roleInstances = null; if (string.IsNullOrEmpty(this.RoleName)) { roleInstances = currentDeployment.RoleInstances; } else { roleInstances = new List <RoleInstance>(currentDeployment.RoleInstances.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase))); } foreach (var role in roleInstances) { var vmRole = currentDeployment.Roles == null || !currentDeployment.Roles.Any() ? null : currentDeployment.Roles.FirstOrDefault(r => string.Equals(r.RoleName, role.RoleName, StringComparison.OrdinalIgnoreCase)); instanceContexts.Add(new RoleInstanceContext { ServiceName = this.ServiceName, OperationId = getDeploymentOperation.Id, OperationDescription = this.CommandRuntime.ToString(), OperationStatus = getDeploymentOperation.Status.ToString(), InstanceErrorCode = role.InstanceErrorCode, InstanceFaultDomain = role.InstanceFaultDomain, InstanceName = role.InstanceName, InstanceSize = role.InstanceSize, InstanceStateDetails = role.InstanceStateDetails, InstanceStatus = role.InstanceStatus, InstanceUpgradeDomain = role.InstanceUpgradeDomain, RoleName = role.RoleName, IPAddress = role.IPAddress, PublicIPAddress = role.PublicIPs == null || !role.PublicIPs.Any() ? null : role.PublicIPs.First().Address, PublicIPName = role.PublicIPs == null || !role.PublicIPs.Any() ? null : !string.IsNullOrEmpty(role.PublicIPs.First().Name) ? role.PublicIPs.First().Name : PersistentVMHelper.GetPublicIPName(vmRole), DeploymentID = currentDeployment.PrivateId, InstanceEndpoints = Mapper.Map <PVM.InstanceEndpointList>(role.InstanceEndpoints) }); } WriteObject(instanceContexts, true); } else { var roleContexts = new Collection <RoleContext>(); IList <Role> roles = null; if (string.IsNullOrEmpty(this.RoleName)) { roles = currentDeployment.Roles; } else { roles = new List <Role>(currentDeployment.Roles.Where(r => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase))); } foreach (var r in roles.Select(role => new RoleContext { InstanceCount = currentDeployment.RoleInstances.Count(ri => ri.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)), RoleName = role.RoleName, OperationDescription = this.CommandRuntime.ToString(), OperationStatus = getDeploymentOperation.Status.ToString(), OperationId = getDeploymentOperation.Id, ServiceName = this.ServiceName, DeploymentID = currentDeployment.PrivateId })) { roleContexts.Add(r); } WriteObject(roleContexts, true); } } }
internal void ExecuteCommandNewSM() { ServiceManagementProfile.Initialize(); base.ExecuteCommand(); WindowsAzureSubscription currentSubscription = CurrentSubscription; if (CurrentDeploymentNewSM == null) { throw new ApplicationException(String.Format(Resources.CouldNotFindDeployment, ServiceName, Model.PersistentVMModel.DeploymentSlotType.Production)); } // Auto generate disk names based off of default storage account foreach (var datadisk in this.VM.DataVirtualHardDisks) { if (datadisk.MediaLink == null && string.IsNullOrEmpty(datadisk.DiskName)) { CloudStorageAccount currentStorage = currentSubscription.GetCloudStorageAccount(); if (currentStorage == null) { throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible); } DateTime dateTimeCreated = DateTime.Now; string diskPartName = VM.RoleName; if (datadisk.DiskLabel != null) { diskPartName += "-" + datadisk.DiskLabel; } string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", 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 (VM.DataVirtualHardDisks.Count > 1) { // To avoid duplicate disk names System.Threading.Thread.Sleep(1); } } var parameters = new VirtualMachineUpdateParameters { AvailabilitySetName = VM.AvailabilitySetName, Label = VM.Label, OSVirtualHardDisk = Mapper.Map <OSVirtualHardDisk>(VM.OSVirtualHardDisk), RoleName = VM.RoleName, RoleSize = VM.RoleSize, ProvisionGuestAgent = VM.ProvisionGuestAgent, ResourceExtensionReferences = VM.ProvisionGuestAgent != null && VM.ProvisionGuestAgent.Value ? Mapper.Map <List <ResourceExtensionReference> >(VM.ResourceExtensionReferences) : null }; if (VM.DataVirtualHardDisks != null) { VM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map <DataVirtualHardDisk>(c); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; parameters.DataVirtualHardDisks.Add(dataDisk); }); } if (VM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(VM.ConfigurationSets).ForEach(c => parameters.ConfigurationSets.Add(c)); } if (VM.DataVirtualHardDisksToBeDeleted != null && VM.DataVirtualHardDisksToBeDeleted.Any()) { var vmRole = CurrentDeploymentNewSM.Roles.First(r => r.RoleName == this.Name); if (vmRole != null) { foreach (var dataDiskToBeDeleted in VM.DataVirtualHardDisksToBeDeleted) { int lun = dataDiskToBeDeleted.Lun; try { this.ComputeClient.VirtualMachineDisks.DeleteDataDisk( this.ServiceName, CurrentDeploymentNewSM.Name, vmRole.RoleName, lun, true); } catch (CloudException ex) { WriteWarning(string.Format(Resources.CannotDeleteVirtualMachineDataDiskForLUN, lun)); if (ex.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } } } } ExecuteClientActionNewSM( parameters, CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Update(this.ServiceName, CurrentDeploymentNewSM.Name, this.Name, parameters)); }
private Management.Compute.Models.Role CreatePersistenVMRole(CloudStorageAccount currentStorage) { var vm = new Management.Compute.Models.Role { AvailabilitySetName = AvailabilitySetName, RoleName = String.IsNullOrEmpty(Name) ? ServiceName : Name, // default like the portal RoleSize = string.IsNullOrEmpty(InstanceSize) ? null : (VirtualMachineRoleSize?)Enum.Parse(typeof(VirtualMachineRoleSize), InstanceSize, true), RoleType = "PersistentVMRole", Label = ServiceName, OSVirtualHardDisk = Mapper.Map(new OSVirtualHardDisk { DiskName = null, SourceImageName = ImageName, MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation), HostCaching = HostCaching }, new Management.Compute.Models.OSVirtualHardDisk()) }; if (vm.OSVirtualHardDisk.MediaLink == null && String.IsNullOrEmpty(vm.OSVirtualHardDisk.DiskName)) { var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, vm.RoleName); vm.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } var netConfig = CreateNetworkConfigurationSet(); if (ParameterSetName.Equals("Windows", StringComparison.OrdinalIgnoreCase)) { var windowsConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.WindowsProvisioningConfigurationSet { AdminUsername = this.AdminUsername, AdminPassword = Password, ComputerName = string.IsNullOrEmpty(Name) ? ServiceName : Name, EnableAutomaticUpdates = true, ResetPasswordOnFirstLogon = false, StoredCertificateSettings = CertUtilsNewSM.GetCertificateSettings(this.Certificates, this.X509Certificates), WinRM = GetWinRmConfiguration() }; if (windowsConfig.StoredCertificateSettings == null) { windowsConfig.StoredCertificateSettings = new Model.PersistentVMModel.CertificateSettingList(); } netConfig.InputEndpoints.Add(new InputEndpoint {LocalPort = 3389, Protocol = "tcp", Name = "RemoteDesktop"}); if (!this.NoWinRMEndpoint.IsPresent && !this.DisableWinRMHttps.IsPresent) { netConfig.InputEndpoints.Add(new InputEndpoint {LocalPort = WinRMConstants.HttpsListenerPort, Protocol = "tcp", Name = WinRMConstants.EndpointName}); } var configurationSets = new Collection<ConfigurationSet>{windowsConfig, netConfig}; PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c)); } else { var linuxConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.LinuxProvisioningConfigurationSet { HostName = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name, UserName = this.LinuxUser, UserPassword = this.Password, DisableSshPasswordAuthentication = false }; if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 || this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0) { linuxConfig.SSH = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.LinuxProvisioningConfigurationSet.SSHSettings { PublicKeys = this.SSHPublicKeys, KeyPairs = this.SSHKeyPairs }; } var rdpEndpoint = new InputEndpoint {LocalPort = 22, Protocol = "tcp", Name = "SSH"}; netConfig.InputEndpoints.Add(rdpEndpoint); var configurationSets = new Collection<ConfigurationSet> { linuxConfig, netConfig }; PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c)); } return vm; }
private Management.Compute.Models.Role CreatePersistenVMRole(CloudStorageAccount currentStorage) { var vm = new Management.Compute.Models.Role { AvailabilitySetName = AvailabilitySetName, RoleName = String.IsNullOrEmpty(Name) ? ServiceName : Name, // default like the portal RoleSize = InstanceSize, RoleType = "PersistentVMRole", Label = ServiceName, OSVirtualHardDisk = _isVMImage ? null : Mapper.Map <Management.Compute.Models.OSVirtualHardDisk>( new OSVirtualHardDisk { DiskName = null, SourceImageName = ImageName, MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation), HostCaching = HostCaching }), VMImageName = _isVMImage ? this.ImageName : null, MediaLocation = _isVMImage && !string.IsNullOrEmpty(this.MediaLocation) ? new Uri(this.MediaLocation) : null, ProvisionGuestAgent = !this.DisableGuestAgent, ResourceExtensionReferences = this.DisableGuestAgent ? null : Mapper.Map <List <Management.Compute.Models.ResourceExtensionReference> >( new VirtualMachineExtensionImageFactory(this.ComputeClient).MakeList( VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultPublisher, VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultName, VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultVersion)) }; if (!_isVMImage && vm.OSVirtualHardDisk.MediaLink == null && String.IsNullOrEmpty(vm.OSVirtualHardDisk.Name)) { var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, vm.RoleName); vm.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create(); } string customDataBase64Str = null; if (!string.IsNullOrEmpty(this.CustomDataFile)) { string fileName = this.TryResolvePath(this.CustomDataFile); customDataBase64Str = PersistentVMHelper.ConvertCustomDataFileToBase64(fileName); } var configurationSets = new Collection <ConfigurationSet>(); var netConfig = CreateNetworkConfigurationSet(); if (ParameterSetName.Equals(WindowsParamSet, StringComparison.OrdinalIgnoreCase)) { if (this.AdminUsername != null && this.Password != null) { var windowsConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.WindowsProvisioningConfigurationSet { AdminUsername = this.AdminUsername, AdminPassword = SecureStringHelper.GetSecureString(Password), ComputerName = string.IsNullOrEmpty(Name) ? ServiceName : Name, EnableAutomaticUpdates = true, ResetPasswordOnFirstLogon = false, StoredCertificateSettings = CertUtilsNewSM.GetCertificateSettings(this.Certificates, this.X509Certificates), WinRM = GetWinRmConfiguration(), CustomData = customDataBase64Str }; if (windowsConfig.StoredCertificateSettings == null) { windowsConfig.StoredCertificateSettings = new Model.CertificateSettingList(); } configurationSets.Add(windowsConfig); } netConfig.InputEndpoints.Add(new InputEndpoint { LocalPort = 3389, Protocol = "tcp", Name = "RemoteDesktop" }); if (!this.NoWinRMEndpoint.IsPresent && !this.DisableWinRMHttps.IsPresent) { netConfig.InputEndpoints.Add(new InputEndpoint { LocalPort = WinRMConstants.HttpsListenerPort, Protocol = "tcp", Name = WinRMConstants.EndpointName }); } configurationSets.Add(netConfig); } else if (ParameterSetName.Equals(LinuxParamSet, StringComparison.OrdinalIgnoreCase)) { if (this.LinuxUser != null && this.Password != null) { var linuxConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LinuxProvisioningConfigurationSet { HostName = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name, UserName = this.LinuxUser, UserPassword = SecureStringHelper.GetSecureString(this.Password), DisableSshPasswordAuthentication = false, CustomData = customDataBase64Str }; if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 || this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0) { linuxConfig.SSH = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LinuxProvisioningConfigurationSet.SSHSettings { PublicKeys = this.SSHPublicKeys, KeyPairs = this.SSHKeyPairs }; } configurationSets.Add(linuxConfig); } var rdpEndpoint = new InputEndpoint { LocalPort = 22, Protocol = "tcp", Name = "SSH" }; netConfig.InputEndpoints.Add(rdpEndpoint); configurationSets.Add(netConfig); } PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c)); return(vm); }
protected override void SaveRoleState(PersistentVM role) { PersistentVMHelper.SaveStateToFile(role, this.Path); }
internal override void ExecuteCommand() { base.ExecuteCommand(); if (CurrentDeployment == null) { return; } string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName; // Generate a list of role names matching regular expressions or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(CurrentDeployment.RoleInstanceList, roleName); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name)); } // Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified. if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!StayProvisioned.IsPresent) && (!Force.IsPresent)) { throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards); } if (roleNames.Count == 1) { if (StayProvisioned.IsPresent) { ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.Stopped)); } else { if (!Force.IsPresent && IsLastVmInDeployment(roleNames.Count)) { ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.StoppedDeallocated))); } else { ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.StoppedDeallocated)); } } } else { var shutdownRolesOperation = new ShutdownRolesOperation() { Roles = roleNames }; if (StayProvisioned.IsPresent) { shutdownRolesOperation.PostShutdownAction = PostShutdownAction.Stopped; ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation)); } else { shutdownRolesOperation.PostShutdownAction = PostShutdownAction.StoppedDeallocated; if (!Force.IsPresent && IsLastVmInDeployment(shutdownRolesOperation.Roles.Count)) { ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation))); } else { ExecuteClientActionInOCS( null, CommandRuntime.ToString(), s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation)); } } } }
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 void ExecuteCommandNewSM() { ServiceManagementProfile.Initialize(); base.ExecuteCommand(); AzureSubscription currentSubscription = Profile.Context.Subscription; if (CurrentDeploymentNewSM == null) { throw new ApplicationException(String.Format(Resources.CouldNotFindDeployment, ServiceName, Model.DeploymentSlotType.Production)); } // Auto generate disk names based off of default storage account foreach (var datadisk in this.VM.DataVirtualHardDisks) { if (datadisk.MediaLink == null && string.IsNullOrEmpty(datadisk.DiskName)) { CloudStorageAccount currentStorage = currentSubscription.GetCloudStorageAccount(Profile); if (currentStorage == null) { throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible); } string diskPartName = VM.RoleName; if (datadisk.DiskLabel != null) { diskPartName += "-" + datadisk.DiskLabel; } var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, diskPartName); datadisk.MediaLink = mediaLinkFactory.Create(); } if (VM.DataVirtualHardDisks.Count > 1) { // To avoid duplicate disk names System.Threading.Thread.Sleep(1); } } var parameters = new VirtualMachineUpdateParameters { AvailabilitySetName = VM.AvailabilitySetName, Label = VM.Label, OSVirtualHardDisk = Mapper.Map <OSVirtualHardDisk>(VM.OSVirtualHardDisk), RoleName = VM.RoleName, RoleSize = VM.RoleSize, ProvisionGuestAgent = VM.ProvisionGuestAgent, ResourceExtensionReferences = VM.ProvisionGuestAgent != null && VM.ProvisionGuestAgent.Value ? Mapper.Map <List <ResourceExtensionReference> >(VM.ResourceExtensionReferences) : null }; if (parameters.OSVirtualHardDisk != null) { parameters.OSVirtualHardDisk.IOType = null; } if (VM.DataVirtualHardDisks != null) { parameters.DataVirtualHardDisks = new List <DataVirtualHardDisk>(); VM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map <DataVirtualHardDisk>(c); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; parameters.DataVirtualHardDisks.Add(dataDisk); }); parameters.DataVirtualHardDisks.ForEach(d => d.IOType = null); } if (VM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(VM.ConfigurationSets).ForEach(c => parameters.ConfigurationSets.Add(c)); } if (VM.DataVirtualHardDisksToBeDeleted != null && VM.DataVirtualHardDisksToBeDeleted.Any()) { var vmRole = CurrentDeploymentNewSM.Roles.First(r => r.RoleName == this.Name); if (vmRole != null) { foreach (var dataDiskToBeDeleted in VM.DataVirtualHardDisksToBeDeleted) { int lun = dataDiskToBeDeleted.Lun; try { this.ComputeClient.VirtualMachineDisks.DeleteDataDisk( this.ServiceName, CurrentDeploymentNewSM.Name, vmRole.RoleName, lun, true); } catch (CloudException ex) { WriteWarning(string.Format(Resources.CannotDeleteVirtualMachineDataDiskForLUN, lun)); if (ex.Response.StatusCode != System.Net.HttpStatusCode.NotFound) { throw; } } } } } if (VM.DebugSettings != null) { parameters.DebugSettings = new DebugSettings { BootDiagnosticsEnabled = VM.DebugSettings.BootDiagnosticsEnabled }; } ExecuteClientActionNewSM( parameters, CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Update(this.ServiceName, CurrentDeploymentNewSM.Name, this.Name, parameters)); }
internal void ExecuteCommandNewSM() { ServiceManagementProfile.Initialize(); base.ExecuteCommand(); WindowsAzureSubscription currentSubscription = CurrentSubscription; if (CurrentDeploymentNewSM == null) { return; } // Auto generate disk names based off of default storage account foreach (var datadisk in this.VM.DataVirtualHardDisks) { if (datadisk.MediaLink == null && string.IsNullOrEmpty(datadisk.DiskName)) { CloudStorageAccount currentStorage = currentSubscription.GetCloudStorageAccount(); if (currentStorage == null) { throw new ArgumentException(Resources.CurrentStorageAccountIsNotAccessible); } DateTime dateTimeCreated = DateTime.Now; string diskPartName = VM.RoleName; if (datadisk.DiskLabel != null) { diskPartName += "-" + datadisk.DiskLabel; } string vhdname = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", 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 (VM.DataVirtualHardDisks.Count > 1) { // To avoid duplicate disk names System.Threading.Thread.Sleep(1); } } var parameters = new VirtualMachineUpdateParameters { AvailabilitySetName = VM.AvailabilitySetName, Label = VM.Label, OSVirtualHardDisk = Mapper.Map <OSVirtualHardDisk>(VM.OSVirtualHardDisk), RoleName = VM.RoleName, RoleSize = string.IsNullOrEmpty(VM.RoleSize) ? null : (VirtualMachineRoleSize?)Enum.Parse(typeof(VirtualMachineRoleSize), VM.RoleSize, true), }; if (VM.DataVirtualHardDisks != null) { VM.DataVirtualHardDisks.ForEach(c => { var dataDisk = Mapper.Map <DataVirtualHardDisk>(c); dataDisk.LogicalUnitNumber = dataDisk.LogicalUnitNumber; parameters.DataVirtualHardDisks.Add(dataDisk); }); } if (VM.ConfigurationSets != null) { PersistentVMHelper.MapConfigurationSets(VM.ConfigurationSets).ForEach(c => parameters.ConfigurationSets.Add(c)); } ExecuteClientActionNewSM( parameters, CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Update(this.ServiceName, CurrentDeploymentNewSM.Name, this.Name, parameters)); }