1 //STEP2:Construct VM Role instance 2 var vmRole = new Role() 3 { 4 RoleType = VirtualMachineRoleType.PersistentVMRole.ToString(), 5 RoleName = vmName, 6 Label = vmName, 7 RoleSize = VirtualMachineRoleSize.Small, 8 ConfigurationSets = new List<ConfigurationSet>(), 9 OSVirtualHardDisk = new OSVirtualHardDisk() 10 { 11 MediaLink = new Uri(string.Format("https://azvhd.blob.core.chinacloudapi.cn/vhds/{0}-{0}-{0}.vhd", vmName)), 12 SourceImageName = GetSourceImageNameByFamliyName("Windows Server 2012 Datacenter") 13 } 14 }; 15 ConfigurationSet configSet = new ConfigurationSet 16 { 17 ConfigurationSetType = ConfigurationSetTypes.WindowsProvisioningConfiguration, 18 EnableAutomaticUpdates = true, 19 ResetPasswordOnFirstLogon = false, 20 ComputerName = vmName, 21 AdminUserName = "UserName", 22 AdminPassword = "Password1!", 23 InputEndpoints = new List<InputEndpoint>() 24 { 25 new InputEndpoint(){LocalPort=55688,Port=55688,Name="Remote Desktop",Protocol="TCP",EnableDirectServerReturn=false}, 26 new InputEndpoint(){LocalPort=5978,Port=5978,Name="PowerShell",Protocol="TCP",EnableDirectServerReturn=false} 27 } 28 }; 29 vmRole.ConfigurationSets.Add(configSet); 30 vmRole.ResourceExtensionReferences = null; 31 //这里必须设置一下,不然之后修改VM会报错 32 vmRole.ProvisionGuestAgent = true; 33 //STEP3: Add Role instance to Deployment Parmeters 34 List<Role> roleList = new List<Role>() { vmRole }; 35 VirtualMachineCreateDeploymentParameters createDeploymentParams = new VirtualMachineCreateDeploymentParameters 36 { 37 Name = vmName, 38 Label = vmName, 39 Roles = roleList, 40 DeploymentSlot = DeploymentSlot.Production 42 }; 43 //STEP4: Create a Deployment with VM Roles. 44 client.VirtualMachines.CreateDeployment(vmName, createDeploymentParams);
这是我创建好的VM,如何加入到Network中。
Windows Azure暂不支持将已创建好的虚拟机加入到虚拟网络中,只能在创建虚机的时候指定虚拟网络。