示例#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));
            }
        }
示例#2
0
        public static async Task <DeploymentExtended> CreateTemplateDeploymentAsync(
            Microsoft.Rest.TokenCredentials credential,
            string groupName,
            string deploymentName,
            string subscriptionId,
            object template,
            object parameters)
        {
            var resourceManagementClient = new ResourceManagementClient(credential)
            {
                SubscriptionId = subscriptionId
            };

            var deployment = new Microsoft.Azure.Management.ResourceManager.Models.Deployment();

            deployment.Properties = new DeploymentProperties
            {
                Mode       = Microsoft.Azure.Management.ResourceManager.Models.DeploymentMode.Incremental,
                Template   = template,
                Parameters = parameters
            };

            return(await resourceManagementClient.Deployments.CreateOrUpdateAsync(
                       groupName,
                       deploymentName,
                       deployment
                       ));
        }
        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;
            }
        }