예제 #1
0
        public async Task <Deployment> BeginDeploymentAsync(IDeployable deployment)
        {
            using (var client = await _managementClientProvider.CreateResourceManagementClient(deployment.SubscriptionId))
            {
                await client.ResourceGroups.CreateOrUpdateAsync(
                    deployment.ResourceGroupName,
                    new ResourceGroup {
                    Location = deployment.Location
                });

                var templateParams = deployment.DeploymentParameters;

                var properties = new Microsoft.Azure.Management.ResourceManager.Models.Deployment
                {
                    Properties = new DeploymentProperties
                    {
                        Template   = await _templateProvider.GetTemplate(deployment.TemplateName),
                        Parameters = _templateProvider.GetParameters(templateParams),
                        Mode       = DeploymentMode.Incremental
                    }
                };

                // Start the ARM deployment
                var deploymentResult = await client.Deployments.BeginCreateOrUpdateAsync(
                    deployment.ResourceGroupName,
                    deployment.DeploymentName,
                    properties);

                return(ToDeploymentStatus(deploymentResult));
            }
        }
        private async Task DeployRepository(AssetRepository repository)
        {
            try
            {
                using (var client = await _clientProvider.CreateResourceManagementClient(repository.SubscriptionId))
                {
                    await client.ResourceGroups.CreateOrUpdateAsync(repository.ResourceGroupName,
                                                                    new ResourceGroup { Location = repository.Subnet.Location });

                    var templateParams = repository.GetTemplateParameters();

                    var properties = new Microsoft.Azure.Management.ResourceManager.Models.Deployment
                    {
                        Properties = new DeploymentProperties
                        {
                            Template   = await _templateProvider.GetTemplate(repository.GetTemplateName()),
                            Parameters = _templateProvider.GetParameters(templateParams),
                            Mode       = DeploymentMode.Incremental
                        }
                    };

                    // Start the ARM deployment
                    await client.Deployments.BeginCreateOrUpdateAsync(
                        repository.Deployment.ResourceGroupName,
                        repository.Deployment.DeploymentName,
                        properties);

                    // TODO re-enable below for background monitoring.
                    // Queue a request for the background host to monitor the deployment
                    // and update the state and IP address when it's done.
                    //await _deploymentQueue.Add(new ActiveDeployment
                    //{
                    //    FileServerName = repository.Name,
                    //    StartTime = DateTime.UtcNow,
                    //});

                    repository.State      = StorageState.Creating;
                    repository.InProgress = false;

                    await UpdateRepository(repository);
                }
            }
            catch (CloudException ex)
            {
                _logger.LogError(ex, $"Failed to deploy storage server: {ex.Message}.");
                throw;
            }
        }
        private async Task DeployFileServer(NfsFileServer repository, IManagementClientProvider managementClientProvider)
        {
            try
            {
                using (var client = await managementClientProvider.CreateResourceManagementClient(repository.SubscriptionId))
                {
                    await client.ResourceGroups.CreateOrUpdateAsync(repository.ResourceGroupName,
                                                                    new ResourceGroup { Location = repository.Subnet.Location });

                    var templateParams = GetTemplateParameters(repository);

                    var properties = new Deployment
                    {
                        Properties = new DeploymentProperties
                        {
                            Template   = await _templateProvider.GetTemplate("linux-file-server.json"),
                            Parameters = _templateProvider.GetParameters(templateParams),
                            Mode       = DeploymentMode.Incremental
                        }
                    };

                    // Start the ARM deployment
                    await client.Deployments.BeginCreateOrUpdateAsync(
                        repository.ResourceGroupName,
                        repository.DeploymentName,
                        properties);

                    // Queue a request for the background host to monitor the deployment
                    // and update the state and IP address when it's done.
                    await _deploymentQueue.Add(new ActiveDeployment
                    {
                        FileServerName = repository.Name,
                        StartTime      = DateTime.UtcNow,
                    });

                    repository.ProvisioningState = ProvisioningState.Running;
                    repository.InProgress        = false;

                    await UpdateRepository(repository);
                }
            }
            catch (CloudException ex)
            {
                _logger.LogError(ex, $"Failed to deploy NFS server: {ex.Message}.");
                throw;
            }
        }