首页 新闻 会员 周边 捐助

Windows Azure如何用C#将创建好的虚拟机加入到网络中

0
悬赏园豆:5 [已解决问题] 浏览: 410次 解决于 2016-03-04 13:33
复制代码
 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中。

公羊天纵的主页 公羊天纵 | 菜鸟二级 | 园豆:203
提问于:2015-09-22 15:31
< > 字节跳动旗下AI助手豆包
分享
最佳答案
0

Windows Azure暂不支持将已创建好的虚拟机加入到虚拟网络中,只能在创建虚机的时候指定虚拟网络。

公羊天纵 | 菜鸟二级 |园豆:203 | 2016-03-03 10:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册
Top