Elastacloud.AzureManagement.Fluent.Clients.WindowsVirtualMachineClient.CreateNewVirtualMachineFromTemplateGallery C# (CSharp) Method

CreateNewVirtualMachineFromTemplateGallery() public method

Creates a new virtual machine from a gallery template
public CreateNewVirtualMachineFromTemplateGallery ( WindowsVirtualMachineProperties properties ) : IVirtualMachineClient
properties Elastacloud.AzureManagement.Fluent.VirtualMachines.Classes.WindowsVirtualMachineProperties Can be any gallery template
return IVirtualMachineClient
        public IVirtualMachineClient CreateNewVirtualMachineFromTemplateGallery(WindowsVirtualMachineProperties properties)
        {
            // for the time being we're going to adopt the default powershell cmdlet behaviour and always create a new cloud services
            EnsureVirtualMachineProperties(properties);
            if (!properties.UseExistingCloudService)
            {
                var cloudServiceCommand = new CreateCloudServiceCommand(properties.CloudServiceName,"Created by Fluent Management", properties.Location)
                                              {
                                                  SubscriptionId = properties.SubscriptionId,
                                                  Certificate = properties.Certificate
                                              };
                cloudServiceCommand.Execute();
            }
            // continue to the create the virtual machine in the cloud service
            var command = new CreateWindowsVirtualMachineDeploymentCommand(properties)
            {
                SubscriptionId = properties.SubscriptionId,
                Certificate = properties.Certificate
            };
            command.Execute();
            // start the role up -- this could take a while the previous two operations are fairly lightweight
            // and the provisioning doesn't occur until the role starts not when it is created
            var startCommand = new StartVirtualMachineCommand(properties)
            {
                SubscriptionId = properties.SubscriptionId,
                Certificate = properties.Certificate
            };
            startCommand.Execute();
            // important here to force a refresh - just in case someone to conduct an operation on the VM in a single step
            Properties = properties;
            var vm = VirtualMachine;
            // create a new client and return this so that properties can be populated automatically
            return new WindowsVirtualMachineClient(properties);
        }

Usage Example

Ejemplo n.º 1
0
 public void Execute()
 {
     var properties = new WindowsVirtualMachineProperties()
                          {
                              AdministratorPassword = _applicationFactory.Password,
                              RoleName = _applicationFactory.RoleName,
                              Certificate = _applicationFactory.ManagementCertificate,
                              Location = LocationConstants.NorthEurope,
                              UseExistingCloudService = true,
                              SubscriptionId = _applicationFactory.SubscriptionId,
                              CloudServiceName = _applicationFactory.CloudServiceName,
                              PublicEndpoints = new List<InputEndpoint>(new[] {new InputEndpoint()
                              {
                                  EndpointName = "web",
                                  LocalPort = 80,
                                  Port = 80,
                                  Protocol = Protocol.TCP
                              }}),
                              VirtualMachineType = VirtualMachineTemplates.WindowsServer2008R2SP1,
                              VmSize = VmSize.Small,
                              StorageAccountName = "elastastorage",
                              DataDisks = new List<DataVirtualHardDisk>(){new DataVirtualHardDisk(){LogicalDiskSizeInGB = 100}}
                          };
     var client = new WindowsVirtualMachineClient(_applicationFactory.SubscriptionId, _applicationFactory.ManagementCertificate);
     var newClient = client.CreateNewVirtualMachineFromTemplateGallery(properties);
 }
All Usage Examples Of Elastacloud.AzureManagement.Fluent.Clients.WindowsVirtualMachineClient::CreateNewVirtualMachineFromTemplateGallery