Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async Task CreateVirtualMachine()
- {
- DeploymentGetResponse deploymentResponse = await _computeManagementClient.Deployments.GetBySlotAsync("myservicename", DeploymentSlot.Production);
- if (deploymentResponse == null)
- {
- var parameters = new VirtualMachineCreateDeploymentParameters
- {
- DeploymentSlot = DeploymentSlot.Production,
- Name = "mservicename",
- Label = "myservicename"
- };
- parameters.Roles.Add(new Role
- {
- OSVirtualHardDisk = new OSVirtualHardDisk
- {
- HostCaching = VirtualHardDiskHostCaching.ReadWrite,
- SourceImageName = "imagename"
- },
- RoleName = "vmname",
- RoleType = VirtualMachineRoleType.PersistentVMRole.ToString(),
- RoleSize = VirtualMachineRoleSize.Small,
- ProvisionGuestAgent = true
- });
- parameters.Roles[0].ConfigurationSets.Add(new ConfigurationSet
- {
- ComputerName = "vmname",
- ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration,
- HostName = "vmname",
- AdminUserName = "adminusername",
- AdminPassword = "adminpass",
- UserName = "username",
- UserPassword = "userpass",
- DisableSshPasswordAuthentication = false,
- });
- parameters.Roles[0].ConfigurationSets.Add(new ConfigurationSet
- {
- ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
- InputEndpoints = new List<InputEndpoint>()
- {
- new InputEndpoint()
- {
- Name = "HTTP",
- Protocol = InputEndpointTransportProtocol.Tcp,
- LocalPort = 80,
- Port = 80
- }
- }
- });
- var response = await _computeManagementClient.VirtualMachines.CreateDeploymentAsync("mservicename", parameters);
- }
- else
- {
- var createParameters = new VirtualMachineCreateParameters
- {
- OSVirtualHardDisk = new OSVirtualHardDisk
- {
- HostCaching = VirtualHardDiskHostCaching.ReadWrite,
- SourceImageName = "imagename"
- },
- RoleName = "vmname",
- RoleSize = VirtualMachineRoleSize.Small,
- ProvisionGuestAgent = true,
- ConfigurationSets = new List<ConfigurationSet>
- {
- new ConfigurationSet
- {
- ComputerName = "vmname",
- ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration,
- HostName = "vmname",
- AdminUserName = "adminusername",
- AdminPassword = "adminpass",
- UserName = "username",
- UserPassword = "userpass",
- DisableSshPasswordAuthentication = false
- },
- new ConfigurationSet
- {
- ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
- InputEndpoints = new List<InputEndpoint>()
- {
- new InputEndpoint()
- {
- Name = "HTTP",
- Protocol = InputEndpointTransportProtocol.Tcp,
- LocalPort = 81,
- Port = 81
- }
- }
- }
- }
- };
- var responseCreate = await _computeManagementClient.VirtualMachines.CreateAsync("mservicename", deploymentResponse.Name, createParameters);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement