internal Deployment(DeploymentGetResponse response) : this() { if (response.PersistentVMDowntime != null) { PersistentVMDowntime = new PersistentVMDowntimeInfo(response.PersistentVMDowntime); } Name = response.Name; DeploymentSlot = response.DeploymentSlot == Management.Compute.Models.DeploymentSlot.Staging ? "Staging" : "Production"; PrivateID = response.PrivateId; Status = DeploymentStatusFactory.From(response.Status); Label = response.Label; Url = response.Uri; Configuration = response.Configuration; foreach (var roleInstance in response.RoleInstances.Select(ri => new RoleInstance(ri))) { RoleInstanceList.Add(roleInstance); } if (response.UpgradeStatus != null) { UpgradeStatus = new UpgradeStatus(response.UpgradeStatus); } UpgradeDomainCount = response.UpgradeDomainCount; if (response.Roles != null) { foreach (var role in response.Roles.Select(r => new Role(r))) { RoleList.Add(role); } } SdkVersion = response.SdkVersion; Locked = response.Locked; RollbackAllowed = response.RollbackAllowed; VirtualNetworkName = response.VirtualNetworkName; CreatedTime = response.CreatedTime; LastModifiedTime = response.LastModifiedTime; if (response.ExtendedProperties != null) { foreach (var prop in response.ExtendedProperties.Keys) { ExtendedProperties[prop] = response.ExtendedProperties[prop]; } } if (response.DnsSettings != null) { Dns = new DnsSettings(response.DnsSettings); } if (response.VirtualIPAddresses != null) { foreach (var vip in response.VirtualIPAddresses.Select(v => new VirtualIP(v))) { VirtualIPs.Add(vip); } } }
internal static void LogObject(this TestEasyLog log, DeploymentGetResponse deployment) { if (deployment == null) return; log.Info(string.Format("Name:{0}", deployment.Name)); log.Info(string.Format("Label:{0}", Base64EncodingHelper.DecodeFromBase64String(deployment.Label))); log.Info(string.Format("Url:{0}", deployment.Uri)); log.Info(string.Format("Status:{0}", deployment.Status)); log.Info(string.Format("DeploymentSlot:{0}", deployment.DeploymentSlot)); log.Info(string.Format("PrivateID:{0}", deployment.PrivateId)); log.Info(string.Format("UpgradeDomainCount:{0}", deployment.UpgradeDomainCount)); LogObject(log, deployment.Roles); LogObject(log, deployment.RoleInstances); LogObject(log, deployment.UpgradeStatus); }
public ExtensionConfiguration Set(DeploymentGetResponse currentDeployment, DeploymentGetResponse peerDeployment, ExtensionConfigurationInput[] inputs, string slot) { string errorConfigInput = null; if (!Validate(inputs, out errorConfigInput)) { throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, errorConfigInput)); } ExtensionConfigurationBuilder configBuilder = this.GetBuilder(); foreach (ExtensionConfigurationInput context in inputs) { if (context != null) { ExtensionConfiguration currentConfig = this.InstallExtension(context, slot, currentDeployment, peerDeployment); foreach (var r in currentConfig.AllRoles) { if (currentDeployment == null || !this.GetBuilder(currentDeployment.ExtensionConfiguration).ExistAny(r.Id)) { configBuilder.AddDefault(r.Id); } } foreach (var r in currentConfig.NamedRoles) { foreach (var e in r.Extensions) { if (currentDeployment == null || !this.GetBuilder(currentDeployment.ExtensionConfiguration).ExistAny(e.Id)) { configBuilder.Add(r.RoleName, e.Id); } } } } } var extConfig = configBuilder.ToConfiguration(); return extConfig; }
public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot, DeploymentGetResponse deployment, DeploymentGetResponse peerDeployment) { Func<DeploymentGetResponse, ExtensionConfiguration> func = (d) => d == null ? null : d.ExtensionConfiguration; ExtensionConfiguration extConfig = func(deployment); ExtensionConfiguration secondSlotExtConfig = func(peerDeployment); return InstallExtension(context, slot, extConfig, secondSlotExtConfig); }
private Task<DeploymentGetResponse> CreateDeploymentGetResponse(string serviceName, DeploymentSlot slot) { var service = Services.FirstOrDefault(s => s.Name == serviceName); var failedResponse = Tasks.FromException<DeploymentGetResponse>(ClientMocks.Make404Exception()); if (service == null) { return failedResponse; } if (slot == DeploymentSlot.Production && service.ProductionDeployment == null || slot == DeploymentSlot.Staging && service.StagingDeployment == null) { return failedResponse; } var response = new DeploymentGetResponse { Name = serviceName, Configuration = "config", DeploymentSlot = slot, Status = DeploymentStatus.Starting, PersistentVMDowntime = new PersistentVMDowntime { EndTime = DateTime.Now, StartTime = DateTime.Now, Status = "", }, LastModifiedTime = DateTime.Now }; return Tasks.FromResult(response); }
public DeploymentInfoContext(DeploymentGetResponse deployment) { this.Slot = deployment.DeploymentSlot.ToString(); this.Name = deployment.Name; this.DeploymentName = deployment.Name; this.Url = deployment.Uri; this.Status = deployment.Status.ToString(); this.DeploymentId = deployment.PrivateId; this.VNetName = deployment.VirtualNetworkName; this.SdkVersion = deployment.SdkVersion; this.CreatedTime = deployment.CreatedTime; this.LastModifiedTime = deployment.LastModifiedTime; this.Locked = deployment.Locked; // IP Related this.ReservedIPName = deployment.ReservedIPName; this.VirtualIPs = deployment.VirtualIPAddresses == null ? null : new PVM.VirtualIPList( deployment.VirtualIPAddresses.Select(a => new PVM.VirtualIP { Address = a.Address, IsDnsProgrammed = a.IsDnsProgrammed, Name = a.Name })); // DNS if (deployment.DnsSettings != null) { this.DnsSettings = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DnsSettings { DnsServers = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DnsServerList() }; foreach (var dns in deployment.DnsSettings.DnsServers) { var newDns = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DnsServer { Name = dns.Name, Address = dns.Address.ToString() }; this.DnsSettings.DnsServers.Add(newDns); } } this.RollbackAllowed = deployment.RollbackAllowed; if (deployment.UpgradeStatus != null) { this.CurrentUpgradeDomain = deployment.UpgradeStatus.CurrentUpgradeDomain; this.CurrentUpgradeDomainState = deployment.UpgradeStatus.CurrentUpgradeDomainState.ToString(); this.UpgradeType = deployment.UpgradeStatus.UpgradeType.ToString(); } this.Configuration = string.IsNullOrEmpty(deployment.Configuration) ? string.Empty : deployment.Configuration; this.Label = string.IsNullOrEmpty(deployment.Label) ? string.Empty : deployment.Label; this.RoleInstanceList = deployment.RoleInstances; if (!string.IsNullOrEmpty(deployment.Configuration)) { string xmlString = this.Configuration; XDocument doc; using (var stringReader = new StringReader(xmlString)) { XmlReader reader = XmlReader.Create(stringReader); doc = XDocument.Load(reader); } this.OSVersion = doc.Root.Attribute("osVersion") != null ? doc.Root.Attribute("osVersion").Value : string.Empty; this.RolesConfiguration = new Dictionary<string, RoleConfiguration>(); var roles = doc.Root.Descendants(this.ns + "Role"); foreach (var role in roles) { this.RolesConfiguration.Add(role.Attribute("name").Value, new RoleConfiguration(role)); } } // ILB if (deployment.LoadBalancers != null) { this.LoadBalancers = new PVM.LoadBalancerList( from b in deployment.LoadBalancers select new PVM.LoadBalancer { Name = b.Name, FrontEndIpConfiguration = b.FrontendIPConfiguration == null ? null : new PVM.IpConfiguration { StaticVirtualNetworkIPAddress = b.FrontendIPConfiguration.StaticVirtualNetworkIPAddress, SubnetName = b.FrontendIPConfiguration.SubnetName, Type = string.Equals( b.FrontendIPConfiguration.Type, PVM.LoadBalancerType.Private.ToString(), StringComparison.OrdinalIgnoreCase) ? PVM.LoadBalancerType.Private : PVM.LoadBalancerType.Unknown } }); this.InternalLoadBalancerName = this.LoadBalancers == null || !this.LoadBalancers.Any() ? null : this.LoadBalancers.First().Name; } }
public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot, DeploymentGetResponse deployment, DeploymentGetResponse peerDeployment) { Func<DeploymentGetResponse, ExtensionConfiguration> func = (d) => d == null ? null : d.ExtensionConfiguration; ExtensionConfiguration extConfig = func(deployment); ExtensionConfiguration secondSlotExtConfig = func(peerDeployment); ExtensionConfigurationBuilder builder = GetBuilder(extConfig); ExtensionConfigurationBuilder secondSlotConfigBuilder = null; if (secondSlotExtConfig != null) { secondSlotConfigBuilder = GetBuilder(secondSlotExtConfig); } foreach (ExtensionRole r in context.Roles) { var extensionIds = (from index in Enumerable.Range(0, ExtensionIdLiveCycleCount) select r.GetExtensionId(context.Type, slot, index)).ToList(); string availableId = (from extensionId in extensionIds where !builder.ExistAny(extensionId) && (secondSlotConfigBuilder == null || !secondSlotConfigBuilder.ExistAny(extensionId)) select extensionId).FirstOrDefault(); var extensionList = (from id in extensionIds let e = GetExtension(id) where e != null select e).ToList(); string thumbprint = context.CertificateThumbprint; string thumbprintAlgorithm = context.ThumbprintAlgorithm; if (context.X509Certificate != null) { thumbprint = context.X509Certificate.Thumbprint; } else { GetThumbprintAndAlgorithm(extensionList, availableId, ref thumbprint, ref thumbprintAlgorithm); } context.CertificateThumbprint = string.IsNullOrWhiteSpace(context.CertificateThumbprint) ? thumbprint : context.CertificateThumbprint; context.ThumbprintAlgorithm = string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm) ? thumbprintAlgorithm : context.ThumbprintAlgorithm; if (!string.IsNullOrWhiteSpace(context.CertificateThumbprint) && string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm)) { context.ThumbprintAlgorithm = ThumbprintAlgorithmStr; } else if (string.IsNullOrWhiteSpace(context.CertificateThumbprint) && !string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm)) { context.ThumbprintAlgorithm = string.Empty; } var existingExtension = extensionList.Find(e => e.Id == availableId); if (existingExtension != null) { DeleteExtension(availableId); } if (r.Default) { Cmdlet.WriteVerbose(string.Format(Resources.ServiceExtensionSettingForDefaultRole, context.Type)); } else { Cmdlet.WriteVerbose(string.Format(Resources.ServiceExtensionSettingForSpecificRole, context.Type, r.RoleName)); } AddExtension(new HostedServiceAddExtensionParameters { Id = availableId, Thumbprint = context.CertificateThumbprint, ThumbprintAlgorithm = context.ThumbprintAlgorithm, ProviderNamespace = context.ProviderNameSpace, Type = context.Type, PublicConfiguration = context.PublicConfiguration, PrivateConfiguration = context.PrivateConfiguration, Version = string.IsNullOrEmpty(context.Version) ? ExtensionDefaultVersion : context.Version }); if (r.Default) { builder.RemoveDefault(context.ProviderNameSpace, context.Type); builder.AddDefault(availableId); } else { builder.Remove(r.RoleName, context.ProviderNameSpace, context.Type); builder.Add(r.RoleName, availableId); } } return builder.ToConfiguration(); }
public Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration Add(DeploymentGetResponse deployment, ExtensionConfigurationInput[] inputs, string slot) { string errorConfigInput = null; if (!Validate(inputs, out errorConfigInput)) { throw new Exception(string.Format(Resources.ServiceExtensionCannotApplyExtensionsInSameType, errorConfigInput)); } var oldExtConfig = deployment.ExtensionConfiguration; ExtensionConfigurationBuilder configBuilder = this.GetBuilder(); foreach (ExtensionConfigurationInput context in inputs) { if (context != null) { Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration currentConfig = this.InstallExtension(context, slot, oldExtConfig); foreach (var r in currentConfig.AllRoles) { if (!this.GetBuilder(oldExtConfig).ExistAny(r.Id)) { configBuilder.AddDefault(r.Id); } } foreach (var r in currentConfig.NamedRoles) { foreach (var e in r.Extensions) { if (!this.GetBuilder(oldExtConfig).ExistAny(e.Id)) { configBuilder.Add(r.RoleName, e.Id); } } } } } var extConfig = configBuilder.ToConfiguration(); return extConfig; }
/// <summary> /// Exports list of cloudservice specific virtual machines. /// </summary> /// <param name="serviceName">CloudService name</param> /// <param name="deployment">Deployment details </param> /// <returns>List of cloudservice specific virtual machines</returns> private List<VirtualMachine> ExportVirtualMachines(string serviceName, DeploymentGetResponse deployment) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, string.Format(ProgressResources.ExportVirtualMachineStarted, serviceName), ResourceType.VirtualMachine.ToString()); try { List<VirtualMachine> virtualMachines = new List<VirtualMachine>(); ////Associated with the Task ID:3201 ////Option to choose whether Deallocated Virtual machines migrate or not ////Checking the DIP is null or not if (exportParameters.MigrateDeallocatedVms == "No") { // Retrieve roles information for PersistentVMRole type. virtualMachines = (from role in deployment.Roles from roleInstance in deployment.RoleInstances where role.RoleType == Constants.PersistentVMRole && role.RoleName == roleInstance.RoleName && roleInstance.IPAddress != null select new VirtualMachine { VirtualMachineDetails = role, IsImported = false, }).ToList(); } else { // Retrieve roles information for PersistentVMRole type. virtualMachines = (from role in deployment.Roles where role.RoleType == Constants.PersistentVMRole select new VirtualMachine { VirtualMachineDetails = role, IsImported = false, }).ToList(); } ////Associated with the Task ID:3195. ////To relosve Bug #6 i.e.VM from Custom image ////Loop through virtualMachines and set VMImagename=null to all VMs. foreach (var virtualmachine in virtualMachines) { virtualmachine.VirtualMachineDetails.VMImageName = null; } ////end Logger.Info(methodName, string.Format(ProgressResources.ExportVirtualMachineCompleted, serviceName), ResourceType.VirtualMachine.ToString()); return virtualMachines; } catch (Exception ex) { Logger.Error(methodName, ex, ResourceType.VirtualMachine.ToString()); throw; } }
/// <summary> /// Exports service specific deployment details. /// </summary> /// <param name="serviceName">CloudService name</param> /// <param name="deploymentResponse">Deployment response received from Microsoft Azure API</param> /// <returns>Cloud service specific deployment details</returns> private Deployment ExportDeployment(string serviceName, DeploymentGetResponse deploymentResponse) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, string.Format(ProgressResources.ExportDeploymentStarted, deploymentResponse.Name, serviceName), ResourceType.Deployment.ToString(), deploymentResponse.Name); try { Deployment deployment = new Deployment { DnsSettings = deploymentResponse.DnsSettings, ExtendedProperties = deploymentResponse.ExtendedProperties, Label = deploymentResponse.Label, LoadBalancers = deploymentResponse.LoadBalancers, Name = deploymentResponse.Name, ReservedIPName = deploymentResponse.ReservedIPName, VirtualIPAddresses = deploymentResponse.VirtualIPAddresses, VirtualNetworkName = deploymentResponse.VirtualNetworkName, //// Export Virtual Machines VirtualMachines = ExportVirtualMachines(serviceName, deploymentResponse), IsImported = false }; Logger.Info(methodName, string.Format(ProgressResources.ExportDeploymentCompleted, deploymentResponse.Name, serviceName), ResourceType.Deployment.ToString(), deploymentResponse.Name); return deployment; } catch (Exception ex) { Logger.Error(methodName, ex, ResourceType.Deployment.ToString(), deploymentResponse.Name); throw; } }
/// <summary> /// Create virtual machine /// </summary> /// <param name="hostedServiceName"></param> /// <param name="input"></param> /// <param name="virtualMachineName"></param> /// <returns></returns> public string CreateVirtualMachine(string hostedServiceName, DeploymentGetResponse input, string virtualMachineName) { var role = input.Roles.First(); TestEasyLog.Instance.Info(string.Format("Creating Virtual Machine... DeploymentName: {0}, Name: {1}", input.Name, virtualMachineName)); ComputeManagementClient.VirtualMachines.CreateAsync(hostedServiceName, input.Name, ConvertRoleToVirtualMachineCreateParameters(role), new CancellationToken()).Wait(); return virtualMachineName; }
/// <summary> /// Exports list of cloudservice specific virtual machines. /// </summary> /// <param name="serviceName">CloudService name</param> /// <param name="deployment">Deployment details </param> /// <returns>List of cloudservice specific virtual machines</returns> private List<VirtualMachine> ExportVirtualMachines(string serviceName, DeploymentGetResponse deployment) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, string.Format(ProgressResources.ExportVirtualMachineStarted, serviceName), ResourceType.VirtualMachine.ToString()); try { List<VirtualMachine> virtualMachines = new List<VirtualMachine>(); // Retrieve roles information for PersistentVMRole type. virtualMachines = (from role in deployment.Roles where role.RoleType == Constants.PersistentVMRole select new VirtualMachine { VirtualMachineDetails = role, IsImported = false, }).ToList(); Logger.Info(methodName, string.Format(ProgressResources.ExportVirtualMachineCompleted, serviceName), ResourceType.VirtualMachine.ToString()); return virtualMachines; } catch (Exception ex) { Logger.Error(methodName, ex, ResourceType.VirtualMachine.ToString()); throw; } }