public DeploymentInfoContext(Microsoft.Samples.WindowsAzure.ServiceManagement.Deployment innerDeployment)
        {
            this.innerDeployment = innerDeployment;

            if (this.innerDeployment.RoleInstanceList != null)
            {
                this.RoleInstanceList = new List<RoleInstance>();
                foreach (var roleInstance in this.innerDeployment.RoleInstanceList)
                {
                    this.RoleInstanceList.Add(new RoleInstance(roleInstance));
                }
            }

            if (!string.IsNullOrEmpty(this.innerDeployment.Configuration))
            {
                string xmlString = ServiceManagementHelper.DecodeFromBase64String(this.innerDeployment.Configuration);
                
                // Ensure that the readers are properly disposed
                StringReader stringReader = null;
                try
                {
                    stringReader = new StringReader(xmlString);
                
                    using (var reader = XmlReader.Create(stringReader))
                    {
                        stringReader = null;

                        XDocument 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));
                        }
                    }
                }
                finally
                {
                    if (stringReader != null)
                    {
                        stringReader.Dispose();
                    }
                }
            }
        }
예제 #2
0
        public DeploymentInfoContext(Microsoft.Samples.WindowsAzure.ServiceManagement.Deployment innerDeployment)
        {
            this.innerDeployment = innerDeployment;

            if (this.innerDeployment.RoleInstanceList != null)
            {
                this.RoleInstanceList = new List <RoleInstance>();
                foreach (var roleInstance in this.innerDeployment.RoleInstanceList)
                {
                    this.RoleInstanceList.Add(new RoleInstance(roleInstance));
                }
            }

            if (!string.IsNullOrEmpty(this.innerDeployment.Configuration))
            {
                string xmlString = ServiceManagementHelper.DecodeFromBase64String(this.innerDeployment.Configuration);

                // Ensure that the readers are properly disposed
                StringReader stringReader = null;
                try
                {
                    stringReader = new StringReader(xmlString);

                    using (var reader = XmlReader.Create(stringReader))
                    {
                        stringReader = null;

                        XDocument 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));
                        }
                    }
                }
                finally
                {
                    if (stringReader != null)
                    {
                        stringReader.Dispose();
                    }
                }
            }
        }
        protected override void ExecuteActivity(CodeActivityContext context)
        {
            var hostedServiceName = context.GetValue<string>(HostedServiceName);
            var slot = context.GetValue(Slot).Description();

            var deployment = new Microsoft.Samples.WindowsAzure.ServiceManagement.Deployment();

            try
            {
                deployment = this.RetryCall(s => this.channel.GetDeploymentBySlot(s, hostedServiceName, slot));
            }
            catch (EndpointNotFoundException)
            {
                // Empty Deployment
            }
            catch (CommunicationException ex)
            {
                throw new CommunicationExceptionEx(ex);
            }

            context.SetValue(Deployment,deployment );
        }
        public void SetDeploymentStatusProcessTest()
        {
            SimpleServiceManagement channel = new SimpleServiceManagement();
            string newStatus = DeploymentStatus.Suspended;
            string currentStatus = DeploymentStatus.Running;
            bool statusUpdated = false;
            Deployment expectedDeployment = new Deployment(serviceName, slot, newStatus);
            channel.UpdateDeploymentStatusBySlotThunk = ar =>
            {
                statusUpdated = true;
                channel.GetDeploymentBySlotThunk = ar2 => expectedDeployment;
            };
            channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, currentStatus);

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                var deploymentManager = new DeploymentStatusManager(channel);
                deploymentManager.ShareChannel = true;
                deploymentManager.CommandRuntime = new MockCommandRuntime();
                deploymentManager.PassThru = true;
                deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionNames[0], serviceName);

                Assert.IsTrue(statusUpdated);
                Deployment actual = ((MockCommandRuntime)deploymentManager.CommandRuntime).OutputPipeline[0] as Deployment;
                Assert.AreEqual<string>(expectedDeployment.Name, actual.Name);
                Assert.AreEqual<string>(expectedDeployment.Status, actual.Status);
                Assert.AreEqual<string>(expectedDeployment.DeploymentSlot, actual.DeploymentSlot);
            }
        }
        public DeploymentInfoContext(Deployment deployment)
        {
            this.Slot = deployment.DeploymentSlot;
            this.Name = deployment.Name;
            this.DeploymentName = deployment.Name;
            this.Url = deployment.Url;
            this.Status = deployment.Status;
            this.DeploymentId = deployment.PrivateID;
            this.VNetName = deployment.VirtualNetworkName;
            this.SdkVersion = deployment.SdkVersion;
            this.DnsSettings = deployment.Dns;

            if (deployment.RollbackAllowed.HasValue)
            {
                this.RollbackAllowed = deployment.RollbackAllowed;
            }

            if (deployment.UpgradeStatus != null)
            {
                this.CurrentUpgradeDomain = deployment.UpgradeStatus.CurrentUpgradeDomain;
                this.CurrentUpgradeDomainState = deployment.UpgradeStatus.CurrentUpgradeDomainState;
                this.UpgradeType = deployment.UpgradeStatus.UpgradeType;
            }

            this.Configuration = string.IsNullOrEmpty(deployment.Configuration) ?
                                    string.Empty :
                                    ServiceManagementHelper.DecodeFromBase64String(deployment.Configuration);

            this.Label = string.IsNullOrEmpty(deployment.Label) ?
                            string.Empty :
                            ServiceManagementHelper.DecodeFromBase64String(deployment.Label);

            if (deployment.RoleInstanceList != null)
            {
                this.RoleInstanceList = new List<RoleInstance>();
                foreach (var roleInstance in deployment.RoleInstanceList)
                {
                    this.RoleInstanceList.Add(roleInstance);
                }
            }

            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));
                }
            }
        }
 public IAsyncResult BeginCreateDeployment(string subscriptionId, string serviceName, Deployment deployment, AsyncCallback callback, object state)
 {
     throw new NotImplementedException();
 }
예제 #7
0
		public DeploymentInfoContext(Deployment deployment)
		{
			XDocument xDocument;
			string empty;
			string str;
			string value;
			this.ns = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration";
			this.Slot = deployment.DeploymentSlot;
			this.Name = deployment.Name;
			this.DeploymentName = deployment.Name;
			this.Url = deployment.Url;
			this.Status = deployment.Status;
			this.DeploymentId = deployment.PrivateID;
			this.VNetName = deployment.VirtualNetworkName;
			this.SdkVersion = deployment.SdkVersion;
			this.DnsSettings = deployment.Dns;
			bool? rollbackAllowed = deployment.RollbackAllowed;
			if (rollbackAllowed.HasValue)
			{
				this.RollbackAllowed = deployment.RollbackAllowed;
			}
			if (deployment.UpgradeStatus != null)
			{
				this.CurrentUpgradeDomain = deployment.UpgradeStatus.CurrentUpgradeDomain;
				this.CurrentUpgradeDomainState = deployment.UpgradeStatus.CurrentUpgradeDomainState;
				this.UpgradeType = deployment.UpgradeStatus.UpgradeType;
			}
			DeploymentInfoContext deploymentInfoContext = this;
			if (string.IsNullOrEmpty(deployment.Configuration))
			{
				empty = string.Empty;
			}
			else
			{
				empty = ServiceManagementHelper.DecodeFromBase64String(deployment.Configuration);
			}
			deploymentInfoContext.Configuration = empty;
			DeploymentInfoContext deploymentInfoContext1 = this;
			if (string.IsNullOrEmpty(deployment.Label))
			{
				str = string.Empty;
			}
			else
			{
				str = ServiceManagementHelper.DecodeFromBase64String(deployment.Label);
			}
			deploymentInfoContext1.Label = str;
			if (deployment.RoleInstanceList != null)
			{
				this.RoleInstanceList = new List<RoleInstance>();
				foreach (RoleInstance roleInstanceList in deployment.RoleInstanceList)
				{
					this.RoleInstanceList.Add(roleInstanceList);
				}
			}
			if (!string.IsNullOrEmpty(deployment.Configuration))
			{
				string configuration = this.Configuration;
				using (StringReader stringReader = new StringReader(configuration))
				{
					XmlReader xmlReader = XmlReader.Create(stringReader);
					xDocument = XDocument.Load(xmlReader);
				}
				DeploymentInfoContext deploymentInfoContext2 = this;
				if (xDocument.Root.Attribute("osVersion") != null)
				{
					value = xDocument.Root.Attribute("osVersion").Value;
				}
				else
				{
					value = string.Empty;
				}
				deploymentInfoContext2.OSVersion = value;
				this.RolesConfiguration = new Dictionary<string, RoleConfiguration>();
				IEnumerable<XElement> xElements = xDocument.Root.Descendants(this.ns + "Role");
				foreach (XElement xElement in xElements)
				{
					this.RolesConfiguration.Add(xElement.Attribute("name").Value, new RoleConfiguration(xElement));
				}
			}
		}
예제 #8
0
		public void NewAzureVMProcess()
		{
			NewAzureVMCommand.NewAzureVMCommand variable = null;
			int num;
			List<PersistentVMRole> persistentVMRoles = new List<PersistentVMRole>();
			NewAzureVMCommand persistentVMRoles1 = this;
			var persistentVMs = new List<PersistentVMRole>();
			SubscriptionData currentSubscription = CmdletSubscriptionExtensions.GetCurrentSubscription(this);
			PersistentVM[] vMs = this.VMs;
			for (int i = 0; i < (int)vMs.Length; i++)
			{
				PersistentVM uri = vMs[i];
				if (uri.OSVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(uri.OSVirtualHardDisk.DiskName))
				{
					CloudStorageAccount currentStorageAccount = null;
					try
					{
						currentStorageAccount = currentSubscription.GetCurrentStorageAccount(base.Channel);
					}
					catch (EndpointNotFoundException endpointNotFoundException)
					{
						throw new ArgumentException("CurrentStorageAccount is not accessible. Ensure the current storage account is accessible and in the same location or affinity group as your cloud service.");
					}
					if (currentStorageAccount != null)
					{
						DateTime now = DateTime.Now;
						string roleName = uri.RoleName;
						if (uri.OSVirtualHardDisk.DiskLabel != null)
						{
							roleName = string.Concat(roleName, "-", uri.OSVirtualHardDisk.DiskLabel);
						}
						object[] serviceName = new object[6];
						serviceName[0] = this.ServiceName;
						serviceName[1] = roleName;
						serviceName[2] = now.Year;
						serviceName[3] = now.Month;
						serviceName[4] = now.Day;
						serviceName[5] = now.Millisecond;
						string str = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", serviceName);
						string absoluteUri = currentStorageAccount.BlobEndpoint.AbsoluteUri;
						if (!absoluteUri.EndsWith("/"))
						{
							absoluteUri = string.Concat(absoluteUri, "/");
						}
						uri.OSVirtualHardDisk.MediaLink = new Uri(string.Concat(absoluteUri, "vhds/", str));
					}
					else
					{
						throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storage account to set it.");
					}
				}
				foreach (DataVirtualHardDisk dataVirtualHardDisk in uri.DataVirtualHardDisks)
				{
					if (dataVirtualHardDisk.MediaLink == null && string.IsNullOrEmpty(dataVirtualHardDisk.DiskName))
					{
						CloudStorageAccount cloudStorageAccount = currentSubscription.GetCurrentStorageAccount(base.Channel);
						if (cloudStorageAccount != null)
						{
							DateTime dateTime = DateTime.Now;
							string roleName1 = uri.RoleName;
							if (dataVirtualHardDisk.DiskLabel != null)
							{
								roleName1 = string.Concat(roleName1, "-", dataVirtualHardDisk.DiskLabel);
							}
							object[] year = new object[6];
							year[0] = this.ServiceName;
							year[1] = roleName1;
							year[2] = dateTime.Year;
							year[3] = dateTime.Month;
							year[4] = dateTime.Day;
							year[5] = dateTime.Millisecond;
							string str1 = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", year);
							string absoluteUri1 = cloudStorageAccount.BlobEndpoint.AbsoluteUri;
							if (!absoluteUri1.EndsWith("/"))
							{
								absoluteUri1 = string.Concat(absoluteUri1, "/");
							}
							dataVirtualHardDisk.MediaLink = new Uri(string.Concat(absoluteUri1, "vhds/", str1));
						}
						else
						{
							throw new ArgumentException("CurrentStorageAccount is not set or not accessible. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
						}
					}
					if (uri.DataVirtualHardDisks.Count<DataVirtualHardDisk>() <= 1)
					{
						continue;
					}
					Thread.Sleep(1);
				}
				PersistentVMRole persistentVMRole = new PersistentVMRole();
				persistentVMRole.AvailabilitySetName = uri.AvailabilitySetName;
				persistentVMRole.ConfigurationSets = uri.ConfigurationSets;
				persistentVMRole.DataVirtualHardDisks = uri.DataVirtualHardDisks;
				persistentVMRole.OSVirtualHardDisk = uri.OSVirtualHardDisk;
				persistentVMRole.RoleName = uri.RoleName;
				persistentVMRole.RoleSize = uri.RoleSize;
				persistentVMRole.RoleType = uri.RoleType;
				persistentVMRole.Label = uri.Label;
				PersistentVMRole persistentVMRole1 = persistentVMRole;
				persistentVMRoles1.persistentVMs.Add(persistentVMRole1);
			}
			new List<string>();
			Operation operation = null;
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
			{
				try
				{
					if (base.ParameterSetName.Equals("CreateService", StringComparison.OrdinalIgnoreCase))
					{
						CreateHostedServiceInput createHostedServiceInput = new CreateHostedServiceInput();
						createHostedServiceInput.AffinityGroup = this.AffinityGroup;
						createHostedServiceInput.Location = this.Location;
						createHostedServiceInput.ServiceName = this.ServiceName;
						if (this.ServiceDescription != null)
						{
							createHostedServiceInput.Description = this.ServiceDescription;
						}
						else
						{
							DateTime now1 = DateTime.Now;
							DateTime universalTime = now1.ToUniversalTime();
							string str2 = string.Format("Implicitly created hosted service{0}", universalTime.ToString("yyyy-MM-dd HH:mm"));
							createHostedServiceInput.Description = str2;
						}
						if (this.ServiceLabel != null)
						{
							createHostedServiceInput.Label = ServiceManagementHelper.EncodeToBase64String(this.ServiceLabel);
						}
						else
						{
							createHostedServiceInput.Label = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
						}
						CmdletExtensions.WriteVerboseOutputForObject(this, createHostedServiceInput);
						base.RetryCall((string s) => base.Channel.CreateHostedService(s, createHostedServiceInput));
						Operation operation1 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create Cloud Service"));
						ManagementOperationContext managementOperationContext = new ManagementOperationContext();
						managementOperationContext.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create Cloud Service"));
						managementOperationContext.set_OperationId(operation1.OperationTrackingId);
						managementOperationContext.set_OperationStatus(operation1.Status);
						ManagementOperationContext managementOperationContext1 = managementOperationContext;
						base.WriteObject(managementOperationContext1, true);
					}
				}
				catch (CommunicationException communicationException1)
				{
					CommunicationException communicationException = communicationException1;
					this.WriteErrorDetails(communicationException);
					return;
				}
			}
			if (operation == null || string.Compare(operation.Status, "Failed", StringComparison.OrdinalIgnoreCase) != 0)
			{
				if (base.CurrentDeployment != null)
				{
					if (this.VNetName != null || this.DnsSettings != null || !string.IsNullOrEmpty(this.DeploymentLabel) || !string.IsNullOrEmpty(this.DeploymentName))
					{
						base.WriteWarning("VNetName, DnsSettings, DeploymentLabel or DeploymentName Name can only be specified on new deployments.");
					}
				}
				else
				{
					using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
					{
						try
						{
							if (string.IsNullOrEmpty(this.DeploymentName))
							{
								this.DeploymentName = this.ServiceName;
							}
							if (string.IsNullOrEmpty(this.DeploymentLabel))
							{
								this.DeploymentLabel = this.ServiceName;
							}
							Deployment deployment = new Deployment();
							deployment.DeploymentSlot = "Production";
							deployment.Name = this.DeploymentName;
							deployment.Label = this.DeploymentLabel;
							List<Role> roles = new List<Role>();
							roles.Add(persistentVMRoles1.persistentVMs[0]);
							deployment.RoleList = new RoleList(roles);
							deployment.VirtualNetworkName = this.VNetName;
							Deployment dnsSetting = deployment;
							if (this.DnsSettings != null)
							{
								dnsSetting.Dns = new DnsSettings();
								dnsSetting.Dns.DnsServers = new DnsServerList();
								DnsServer[] dnsSettings = this.DnsSettings;
								for (int j = 0; j < (int)dnsSettings.Length; j++)
								{
									DnsServer dnsServer = dnsSettings[j];
									dnsSetting.Dns.DnsServers.Add(dnsServer);
								}
							}
							CmdletExtensions.WriteVerboseOutputForObject(this, dnsSetting);
							base.RetryCall((string s) => base.Channel.CreateDeployment(s, this.ServiceName, dnsSetting));
							Operation operation2 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create Deployment with VM ", persistentVMRoles1.persistentVMs[0].RoleName));
							ManagementOperationContext managementOperationContext2 = new ManagementOperationContext();
							managementOperationContext2.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create Deployment with VM ", persistentVMRoles1.persistentVMs[0].RoleName));
							managementOperationContext2.set_OperationId(operation2.OperationTrackingId);
							managementOperationContext2.set_OperationStatus(operation2.Status);
							ManagementOperationContext managementOperationContext3 = managementOperationContext2;
							base.WriteObject(managementOperationContext3, true);
						}
						catch (CommunicationException communicationException3)
						{
							CommunicationException communicationException2 = communicationException3;
							if (communicationException2 as EndpointNotFoundException == null)
							{
								this.WriteErrorDetails(communicationException2);
								return;
							}
							else
							{
								throw new Exception("Cloud Service does not exist. Specify -Location or -AffinityGroup to create one.");
							}
						}
						this.createdDeployment = true;
					}
				}
				if (!this.createdDeployment && base.CurrentDeployment != null)
				{
					this.DeploymentName = base.CurrentDeployment.Name;
				}
				if (this.createdDeployment)
				{
					num = 1;
				}
				else
				{
					num = 0;
				}
				int num1 = num;
				Action<string> action = null;
				while (num1 < persistentVMRoles1.persistentVMs.Count)
				{
					if (operation == null || string.Compare(operation.Status, "Failed", StringComparison.OrdinalIgnoreCase) != 0)
					{
						using (OperationContextScope operationContextScope2 = new OperationContextScope((IContextChannel)base.Channel))
						{
							try
							{
								CmdletExtensions.WriteVerboseOutputForObject(this, persistentVMRoles1.persistentVMs[num1]);
								NewAzureVMCommand newAzureVMCommand = this;
								if (action == null)
								{
									action = (string s) => base.Channel.AddRole(s, this.ServiceName, this.DeploymentName, persistentVMRoles[num1]);
								}
								((CmdletBase<IServiceManagement>)newAzureVMCommand).RetryCall(action);
								Operation operation3 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create VM ", persistentVMRoles1.persistentVMs[num1].RoleName));
								ManagementOperationContext managementOperationContext4 = new ManagementOperationContext();
								managementOperationContext4.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create VM ", persistentVMRoles1.persistentVMs[num1].RoleName));
								managementOperationContext4.set_OperationId(operation3.OperationTrackingId);
								managementOperationContext4.set_OperationStatus(operation3.Status);
								ManagementOperationContext managementOperationContext5 = managementOperationContext4;
								base.WriteObject(managementOperationContext5, true);
							}
							catch (CommunicationException communicationException5)
							{
								CommunicationException communicationException4 = communicationException5;
								this.WriteErrorDetails(communicationException4);
								return;
							}
						}
						NewAzureVMCommand.NewAzureVMCommand variable1 = variable;
						variable1.i = variable1.i + 1;
					}
					else
					{
						return;
					}
				}
				return;
			}
		}
예제 #9
0
파일: NewQuickVM.cs 프로젝트: nickchal/pash
		public void NewAzureVMProcess()
		{
			NewQuickVM.NewQuickVM variable = null;
			string serviceName;
			string instanceSize;
			Uri uri;
			string name;
			string str;
			Action<string> action = null;
			SubscriptionData currentSubscription = CmdletSubscriptionExtensions.GetCurrentSubscription(this);
			CloudStorageAccount currentStorageAccount = null;
			try
			{
				currentStorageAccount = currentSubscription.GetCurrentStorageAccount(base.Channel);
			}
			catch (EndpointNotFoundException endpointNotFoundException)
			{
				throw new ArgumentException("CurrentStorageAccount is not accessible. Ensure the current storage account is accessible and in the same location or affinity group as your cloud service.");
			}
			if (currentStorageAccount != null)
			{
				NewQuickVM.NewQuickVM variable1 = variable;
				PersistentVMRole persistentVMRole = new PersistentVMRole();
				persistentVMRole.AvailabilitySetName = this.AvailabilitySetName;
				persistentVMRole.ConfigurationSets = new Collection<ConfigurationSet>();
				persistentVMRole.DataVirtualHardDisks = new Collection<DataVirtualHardDisk>();
				PersistentVMRole persistentVMRole1 = persistentVMRole;
				if (string.IsNullOrEmpty(this.Name))
				{
					serviceName = this.ServiceName;
				}
				else
				{
					serviceName = this.Name;
				}
				persistentVMRole1.RoleName = serviceName;
				PersistentVMRole persistentVMRole2 = persistentVMRole;
				if (string.IsNullOrEmpty(this.InstanceSize))
				{
					instanceSize = null;
				}
				else
				{
					instanceSize = this.InstanceSize;
				}
				persistentVMRole2.RoleSize = instanceSize;
				persistentVMRole.RoleType = "PersistentVMRole";
				persistentVMRole.Label = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
				variable1.vm = persistentVMRole;
				PersistentVMRole persistentVMRole3 = uri1;
				OSVirtualHardDisk oSVirtualHardDisk = new OSVirtualHardDisk();
				oSVirtualHardDisk.DiskName = null;
				oSVirtualHardDisk.SourceImageName = this.ImageName;
				OSVirtualHardDisk oSVirtualHardDisk1 = oSVirtualHardDisk;
				if (string.IsNullOrEmpty(this.MediaLocation))
				{
					uri = null;
				}
				else
				{
					uri = new Uri(this.MediaLocation);
				}
				oSVirtualHardDisk1.MediaLink = uri;
				oSVirtualHardDisk.HostCaching = this.HostCaching;
				persistentVMRole3.OSVirtualHardDisk = oSVirtualHardDisk;
				if (oSVirtualHardDisk1.MediaLink == null && string.IsNullOrEmpty(oSVirtualHardDisk1.DiskName))
				{
					DateTime now = DateTime.Now;
					object[] roleName = new object[6];
					roleName[0] = this.ServiceName;
					roleName[1] = uri1.RoleName;
					roleName[2] = now.Year;
					roleName[3] = now.Month;
					roleName[4] = now.Day;
					roleName[5] = now.Millisecond;
					string str1 = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.vhd", roleName);
					string absoluteUri = currentStorageAccount.BlobEndpoint.AbsoluteUri;
					if (!absoluteUri.EndsWith("/"))
					{
						absoluteUri = string.Concat(absoluteUri, "/");
					}
					oSVirtualHardDisk1.MediaLink = new Uri(string.Concat(absoluteUri, "vhds/", str1));
				}
				NetworkConfigurationSet networkConfigurationSet = new NetworkConfigurationSet();
				networkConfigurationSet.InputEndpoints = new Collection<InputEndpoint>();
				if (this.SubnetNames != null)
				{
					networkConfigurationSet.SubnetNames = new SubnetNamesCollection();
					string[] subnetNames = this.SubnetNames;
					for (int i = 0; i < (int)subnetNames.Length; i++)
					{
						string str2 = subnetNames[i];
						networkConfigurationSet.SubnetNames.Add(str2);
					}
				}
				if (!base.ParameterSetName.Equals("Windows", StringComparison.OrdinalIgnoreCase))
				{
					LinuxProvisioningConfigurationSet linuxProvisioningConfigurationSet = new LinuxProvisioningConfigurationSet();
					LinuxProvisioningConfigurationSet linuxProvisioningConfigurationSet1 = linuxProvisioningConfigurationSet;
					if (string.IsNullOrEmpty(this.Name))
					{
						name = this.ServiceName;
					}
					else
					{
						name = this.Name;
					}
					linuxProvisioningConfigurationSet1.HostName = name;
					linuxProvisioningConfigurationSet.UserName = this.LinuxUser;
					linuxProvisioningConfigurationSet.UserPassword = this.Password;
					linuxProvisioningConfigurationSet.DisableSshPasswordAuthentication = new bool?(false);
					if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 || this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0)
					{
						linuxProvisioningConfigurationSet.SSH = new LinuxProvisioningConfigurationSet.SSHSettings();
						linuxProvisioningConfigurationSet.SSH.PublicKeys = this.SSHPublicKeys;
						linuxProvisioningConfigurationSet.SSH.KeyPairs = this.SSHKeyPairs;
					}
					InputEndpoint inputEndpoint = new InputEndpoint();
					inputEndpoint.LocalPort = 22;
					inputEndpoint.Protocol = "tcp";
					inputEndpoint.Name = "SSH";
					networkConfigurationSet.InputEndpoints.Add(inputEndpoint);
					uri1.ConfigurationSets.Add(linuxProvisioningConfigurationSet);
					uri1.ConfigurationSets.Add(networkConfigurationSet);
				}
				else
				{
					WindowsProvisioningConfigurationSet windowsProvisioningConfigurationSet = new WindowsProvisioningConfigurationSet();
					windowsProvisioningConfigurationSet.AdminPassword = this.Password;
					WindowsProvisioningConfigurationSet windowsProvisioningConfigurationSet1 = windowsProvisioningConfigurationSet;
					if (string.IsNullOrEmpty(this.Name))
					{
						str = this.ServiceName;
					}
					else
					{
						str = this.Name;
					}
					windowsProvisioningConfigurationSet1.ComputerName = str;
					windowsProvisioningConfigurationSet.EnableAutomaticUpdates = new bool?(true);
					windowsProvisioningConfigurationSet.ResetPasswordOnFirstLogon = false;
					windowsProvisioningConfigurationSet.StoredCertificateSettings = this.Certificates;
					InputEndpoint inputEndpoint1 = new InputEndpoint();
					inputEndpoint1.LocalPort = 0xd3d;
					inputEndpoint1.Protocol = "tcp";
					inputEndpoint1.Name = "RemoteDesktop";
					networkConfigurationSet.InputEndpoints.Add(inputEndpoint1);
					uri1.ConfigurationSets.Add(windowsProvisioningConfigurationSet);
					uri1.ConfigurationSets.Add(networkConfigurationSet);
				}
				new List<string>();
				Operation operation = null;
				bool flag = this.DoesCloudServiceExist(this.ServiceName);
				using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
				{
					try
					{
						DateTime dateTime = DateTime.Now;
						DateTime universalTime = dateTime.ToUniversalTime();
						string str3 = string.Format("Implicitly created hosted service{0}", universalTime.ToString("yyyy-MM-dd HH:mm"));
						if (!string.IsNullOrEmpty(this.Location) || !string.IsNullOrEmpty(this.AffinityGroup) || !string.IsNullOrEmpty(this.VNetName) && !flag)
						{
							CreateHostedServiceInput createHostedServiceInput = new CreateHostedServiceInput();
							createHostedServiceInput.AffinityGroup = this.AffinityGroup;
							createHostedServiceInput.Location = this.Location;
							createHostedServiceInput.ServiceName = this.ServiceName;
							createHostedServiceInput.Description = str3;
							createHostedServiceInput.Label = ServiceManagementHelper.EncodeToBase64String(this.ServiceName);
							CmdletExtensions.WriteVerboseOutputForObject(this, createHostedServiceInput);
							base.RetryCall((string s) => base.Channel.CreateHostedService(s, createHostedServiceInput));
							Operation operation1 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create Cloud Service"));
							ManagementOperationContext managementOperationContext = new ManagementOperationContext();
							managementOperationContext.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create Cloud Service"));
							managementOperationContext.set_OperationId(operation1.OperationTrackingId);
							managementOperationContext.set_OperationStatus(operation1.Status);
							ManagementOperationContext managementOperationContext1 = managementOperationContext;
							base.WriteObject(managementOperationContext1, true);
						}
					}
					catch (CommunicationException communicationException1)
					{
						CommunicationException communicationException = communicationException1;
						this.WriteErrorDetails(communicationException);
						return;
					}
				}
				if (operation == null || string.Compare(operation.Status, "Failed", StringComparison.OrdinalIgnoreCase) != 0)
				{
					if (base.CurrentDeployment != null)
					{
						if (this.VNetName != null || this.DnsSettings != null)
						{
							base.WriteWarning("VNetName or DnsSettings can only be specified on new deployments.");
						}
					}
					else
					{
						using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
						{
							try
							{
								Deployment deployment = new Deployment();
								deployment.DeploymentSlot = "Production";
								deployment.Name = this.ServiceName;
								deployment.Label = this.ServiceName;
								List<Role> roles = new List<Role>();
								roles.Add(uri1);
								deployment.RoleList = new RoleList(roles);
								deployment.VirtualNetworkName = this.VNetName;
								Deployment dnsSetting = deployment;
								if (this.DnsSettings != null)
								{
									dnsSetting.Dns = new DnsSettings();
									dnsSetting.Dns.DnsServers = new DnsServerList();
									DnsServer[] dnsSettings = this.DnsSettings;
									for (int j = 0; j < (int)dnsSettings.Length; j++)
									{
										DnsServer dnsServer = dnsSettings[j];
										dnsSetting.Dns.DnsServers.Add(dnsServer);
									}
								}
								CmdletExtensions.WriteVerboseOutputForObject(this, dnsSetting);
								base.RetryCall((string s) => base.Channel.CreateDeployment(s, this.ServiceName, dnsSetting));
								Operation operation2 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create Deployment with VM ", uri1.RoleName));
								ManagementOperationContext managementOperationContext2 = new ManagementOperationContext();
								managementOperationContext2.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create Deployment with VM ", uri1.RoleName));
								managementOperationContext2.set_OperationId(operation2.OperationTrackingId);
								managementOperationContext2.set_OperationStatus(operation2.Status);
								ManagementOperationContext managementOperationContext3 = managementOperationContext2;
								base.WriteObject(managementOperationContext3, true);
							}
							catch (CommunicationException communicationException3)
							{
								CommunicationException communicationException2 = communicationException3;
								if (communicationException2 as EndpointNotFoundException == null)
								{
									this.WriteErrorDetails(communicationException2);
									return;
								}
								else
								{
									throw new Exception("Cloud Service does not exist. Specify -Location or -Affinity group to create one.");
								}
							}
							this.CreatedDeployment = true;
						}
					}
					if (operation == null || string.Compare(operation.Status, "Failed", StringComparison.OrdinalIgnoreCase) != 0)
					{
						if (!this.CreatedDeployment)
						{
							using (OperationContextScope operationContextScope2 = new OperationContextScope((IContextChannel)base.Channel))
							{
								try
								{
									CmdletExtensions.WriteVerboseOutputForObject(this, uri1);
									NewQuickVM newQuickVM = this;
									if (action == null)
									{
										action = (string s) => base.Channel.AddRole(s, this.ServiceName, this.ServiceName, uri1);
									}
									((CmdletBase<IServiceManagement>)newQuickVM).RetryCall(action);
									Operation operation3 = base.WaitForOperation(string.Concat(base.CommandRuntime.ToString(), " - Create VM ", uri1.RoleName));
									ManagementOperationContext managementOperationContext4 = new ManagementOperationContext();
									managementOperationContext4.set_OperationDescription(string.Concat(base.CommandRuntime.ToString(), " - Create VM ", uri1.RoleName));
									managementOperationContext4.set_OperationId(operation3.OperationTrackingId);
									managementOperationContext4.set_OperationStatus(operation3.Status);
									ManagementOperationContext managementOperationContext5 = managementOperationContext4;
									base.WriteObject(managementOperationContext5, true);
								}
								catch (CommunicationException communicationException5)
								{
									CommunicationException communicationException4 = communicationException5;
									this.WriteErrorDetails(communicationException4);
									return;
								}
							}
						}
						return;
					}
					else
					{
						return;
					}
				}
				return;
			}
			else
			{
				throw new ArgumentException("CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.");
			}
		}
예제 #10
0
 public static void CreateDeployment(this IServiceManagement proxy, string subscriptionId, string serviceName, Deployment deployment)
 {
     proxy.EndCreateDeployment(proxy.BeginCreateDeployment(subscriptionId, serviceName, deployment, null, null));
 }
예제 #11
0
                return;
            }

            Console.WriteLine("RoleList contains {0} item(s).", roleList.Count);
            foreach (Role r in roleList)
            {
                Console.WriteLine("    RoleName: {0}", r.RoleName);
                Console.WriteLine("    OperatingSystemVersion : {0}", r.OsVersion);
            }
        }

        internal static void LogObject(RoleInstanceList roleInstanceList)
        {
            if (roleInstanceList == null)
                return;

            Console.WriteLine("RoleInstanceList contains {0} item(s).", roleInstanceList.Count);
예제 #12
0
        internal static void LogObject(Deployment deployment)
        {
            if (deployment == null)
                return;

            //Console.WriteLine("Name:{0}", deployment.Name);
            //Console.WriteLine("Label:{0}", ServiceManagementHelper.DecodeFromBase64String(deployment.Label));
            //Console.WriteLine("Url:{0}", deployment.Url.ToString());
            //Console.WriteLine("Status:{0}", deployment.Status);
            //Console.WriteLine("DeploymentSlot:{0}", deployment.DeploymentSlot);
            //Console.WriteLine("PrivateID:{0}", deployment.PrivateID);
            //Console.WriteLine("UpgradeDomainCount:{0}", deployment.UpgradeDomainCount);
            Console.WriteLine(new System.Text.ASCIIEncoding().GetString(Convert.FromBase64String(deployment.Configuration)));

            //LogObject(deployment.RoleList);
            //LogObject(deployment.RoleInstanceList);
            //LogObject(deployment.UpgradeStatus);
        }
 public static void CreateDeployment(this IServiceManagement proxy, string subscriptionId, string serviceName, Deployment deployment)
 {
     proxy.EndCreateDeployment(proxy.BeginCreateDeployment(subscriptionId, serviceName, deployment, null, null));
 }