Пример #1
0
        /// <summary>
        /// Creates new deployment using the passed template file which can be user customized or
        /// from gallery templates.
        /// </summary>
        /// <param name="parameters">The create deployment parameters</param>
        /// <returns>The created deployment instance</returns>
        public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
        {
            parameters.DeploymentName = GenerateDeploymentName(parameters);
            BasicDeployment        deployment     = CreateBasicDeployment(parameters);
            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            if (validationInfo.Errors.Count != 0)
            {
                int           counter      = 1;
                string        errorFormat  = "Error {0}: Code={1}; Message={2}\r\n";
                StringBuilder errorsString = new StringBuilder();
                validationInfo.Errors.ForEach(e => errorsString.AppendFormat(errorFormat, counter++, e.Code, e.Message));
                throw new ArgumentException(errorsString.ToString());
            }
            else
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }

            if (!string.IsNullOrEmpty(parameters.StorageAccountName))
            {
                WriteWarning("The StorageAccountName parameter is no longer used and will be removed in a future release. Please update scripts to remove this parameter.");
            }

            ResourceManagementClient.Deployments.CreateOrUpdate(parameters.ResourceGroupName, parameters.DeploymentName, deployment);
            WriteVerbose(string.Format("Create template deployment '{0}'.", parameters.DeploymentName));
            Deployment result = ProvisionDeploymentStatus(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            return(result.ToPSResourceGroupDeployment(parameters.ResourceGroupName));
        }
        /// <summary>
        /// Creates new deployment using the passed template file which can be user customized or
        /// from gallery templates.
        /// </summary>
        /// <param name="parameters">The create deployment parameters</param>
        /// <returns>The created deployment instance</returns>
        public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
        {
            parameters.DeploymentName = GenerateDeploymentName(parameters);
            BasicDeployment        deployment     = CreateBasicDeployment(parameters);
            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            if (validationInfo.Errors.Count != 0)
            {
                int           counter      = 1;
                string        errorFormat  = "Error {0}: Code={1}; Message={2}\r\n";
                StringBuilder errorsString = new StringBuilder();
                validationInfo.Errors.ForEach(e => errorsString.AppendFormat(errorFormat, counter++, e.Code, e.Message));
                throw new ArgumentException(errorsString.ToString());
            }
            else
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }

            WindowsAzureProfile.Instance.CurrentSubscription.RegisterCustomProviders(validationInfo.RequiredProviders);
            ResourceManagementClient.Deployments.CreateOrUpdate(parameters.ResourceGroupName, parameters.DeploymentName, deployment);
            WriteVerbose(string.Format("Create template deployment '{0}' using template {1}.", parameters.DeploymentName, deployment.TemplateLink.Uri));
            Deployment result = ProvisionDeploymentStatus(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            return(result.ToPSResourceGroupDeployment(parameters.ResourceGroupName));
        }
        /// <summary>
        /// Creates new deployment using the passed template file which can be user customized or
        /// from gallery templates.
        /// </summary>
        /// <param name="parameters">The create deployment parameters</param>
        /// <returns>The created deployment instance</returns>
        public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
        {
            parameters.DeploymentName = GenerateDeploymentName(parameters);
            Deployment deployment = CreateBasicDeployment(parameters, parameters.DeploymentMode, parameters.DeploymentDebugLogLevel);

            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            if (validationInfo.Errors.Count != 0)
            {
                foreach(var error in validationInfo.Errors)
                {
                    WriteError(string.Format(ErrorFormat, error.Code, error.Message));
                    if(!string.IsNullOrEmpty(error.Details))
                    {
                        DisplayDetailedErrorMessage(error.Details);
                    }
                }
                throw new InvalidOperationException("The deployment validation failed.");
            }
            else
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }

            ResourceManagementClient.Deployments.CreateOrUpdate(parameters.ResourceGroupName, parameters.DeploymentName, deployment);
            WriteVerbose(string.Format("Create template deployment '{0}'.", parameters.DeploymentName));
            DeploymentExtended result = ProvisionDeploymentStatus(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            return result.ToPSResourceGroupDeployment(parameters.ResourceGroupName);
        }
        /// <summary>
        /// Creates new deployment using the passed template file which can be user customized or
        /// from gallery templates.
        /// </summary>
        /// <param name="parameters">The create deployment parameters</param>
        /// <returns>The created deployment instance</returns>
        public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
        {
            parameters.DeploymentName = GenerateDeploymentName(parameters);
            Deployment deployment = CreateBasicDeployment(parameters, parameters.DeploymentMode, parameters.DeploymentDebugLogLevel);

            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            if (validationInfo.Errors.Count != 0)
            {
                int           counter      = 1;
                string        errorFormat  = "Error {0}: Code={1}; Message={2}\r\n";
                StringBuilder errorsString = new StringBuilder();
                validationInfo.Errors.ForEach(e => errorsString.AppendFormat(errorFormat, counter++, e.Code, e.Message));
                throw new ArgumentException(errorsString.ToString());
            }
            else
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }

            ResourceManagementClient.Deployments.CreateOrUpdate(parameters.ResourceGroupName, parameters.DeploymentName, deployment);
            WriteVerbose(string.Format("Create template deployment '{0}'.", parameters.DeploymentName));
            DeploymentExtended result = ProvisionDeploymentStatus(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

            return(result.ToPSResourceGroupDeployment(parameters.ResourceGroupName));
        }
Пример #5
0
        /// <summary>
        /// Validates a given deployment.
        /// </summary>
        /// <param name="parameters">The deployment create options</param>
        /// <returns>True if valid, false otherwise.</returns>
        public virtual List <PSResourceManagerError> ValidatePSResourceGroupDeployment(ValidatePSResourceGroupDeploymentParameters parameters)
        {
            BasicDeployment        deployment     = CreateBasicDeployment(parameters);
            TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, Guid.NewGuid().ToString(), deployment);

            if (validationInfo.Errors.Count == 0)
            {
                WriteVerbose(ProjectResources.TemplateValid);
            }
            return(validationInfo.Errors.Select(e => e.ToPSResourceManagerError()).ToList());
        }