Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. private async Task CreateVirtualMachine()
  2. {
  3. DeploymentGetResponse deploymentResponse = await _computeManagementClient.Deployments.GetBySlotAsync("myservicename", DeploymentSlot.Production);
  4.  
  5. if (deploymentResponse == null)
  6. {
  7. var parameters = new VirtualMachineCreateDeploymentParameters
  8. {
  9. DeploymentSlot = DeploymentSlot.Production,
  10. Name = "mservicename",
  11. Label = "myservicename"
  12. };
  13.  
  14. parameters.Roles.Add(new Role
  15. {
  16. OSVirtualHardDisk = new OSVirtualHardDisk
  17. {
  18. HostCaching = VirtualHardDiskHostCaching.ReadWrite,
  19. SourceImageName = "imagename"
  20. },
  21.  
  22. RoleName = "vmname",
  23. RoleType = VirtualMachineRoleType.PersistentVMRole.ToString(),
  24. RoleSize = VirtualMachineRoleSize.Small,
  25. ProvisionGuestAgent = true
  26. });
  27.  
  28. parameters.Roles[0].ConfigurationSets.Add(new ConfigurationSet
  29. {
  30. ComputerName = "vmname",
  31. ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration,
  32. HostName = "vmname",
  33. AdminUserName = "adminusername",
  34. AdminPassword = "adminpass",
  35. UserName = "username",
  36. UserPassword = "userpass",
  37. DisableSshPasswordAuthentication = false,
  38.  
  39. });
  40.  
  41. parameters.Roles[0].ConfigurationSets.Add(new ConfigurationSet
  42. {
  43. ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
  44. InputEndpoints = new List<InputEndpoint>()
  45. {
  46. new InputEndpoint()
  47. {
  48. Name = "HTTP",
  49. Protocol = InputEndpointTransportProtocol.Tcp,
  50. LocalPort = 80,
  51. Port = 80
  52. }
  53. }
  54. });
  55.  
  56. var response = await _computeManagementClient.VirtualMachines.CreateDeploymentAsync("mservicename", parameters);
  57.  
  58. }
  59. else
  60. {
  61. var createParameters = new VirtualMachineCreateParameters
  62. {
  63. OSVirtualHardDisk = new OSVirtualHardDisk
  64. {
  65. HostCaching = VirtualHardDiskHostCaching.ReadWrite,
  66. SourceImageName = "imagename"
  67. },
  68.  
  69. RoleName = "vmname",
  70. RoleSize = VirtualMachineRoleSize.Small,
  71. ProvisionGuestAgent = true,
  72.  
  73. ConfigurationSets = new List<ConfigurationSet>
  74. {
  75. new ConfigurationSet
  76. {
  77.  
  78. ComputerName = "vmname",
  79. ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration,
  80. HostName = "vmname",
  81. AdminUserName = "adminusername",
  82. AdminPassword = "adminpass",
  83. UserName = "username",
  84. UserPassword = "userpass",
  85. DisableSshPasswordAuthentication = false
  86. },
  87. new ConfigurationSet
  88. {
  89. ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
  90. InputEndpoints = new List<InputEndpoint>()
  91. {
  92. new InputEndpoint()
  93. {
  94. Name = "HTTP",
  95. Protocol = InputEndpointTransportProtocol.Tcp,
  96. LocalPort = 81,
  97. Port = 81
  98. }
  99. }
  100. }
  101. }
  102. };
  103.  
  104. var responseCreate = await _computeManagementClient.VirtualMachines.CreateAsync("mservicename", deploymentResponse.Name, createParameters);
  105.  
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement