/// <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); List <ResourceManagementError> errors = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment); if (errors.Count != 0) { int counter = 1; string errorFormat = "Error {0}: Code={1}; Message={2}\r\n"; StringBuilder errorsString = new StringBuilder(); errors.ForEach(e => errorsString.AppendFormat(errorFormat, counter++, e.Code, e.Message)); throw new ArgumentException(errorsString.ToString()); } else { WriteVerbose(Resources.TemplateValid); } 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)); }
public void CreatesNewPSResourceGroupDeploymentWithUserTemplate() { CreatePSResourceGroupDeploymentParameters expectedParameters = new CreatePSResourceGroupDeploymentParameters() { TemplateFile = templateFile, DeploymentName = deploymentName, StorageAccountName = storageAccountName, TemplateVersion = "1.0" }; CreatePSResourceGroupDeploymentParameters actualParameters = new CreatePSResourceGroupDeploymentParameters(); PSResourceGroupDeployment expected = new PSResourceGroupDeployment() { Mode = DeploymentMode.Incremental, DeploymentName = deploymentName, CorrelationId = "123", Outputs = new Dictionary<string, DeploymentVariable>() { { "Variable1", new DeploymentVariable() { Value = "true", Type = "bool" } }, { "Variable2", new DeploymentVariable() { Value = "10", Type = "int" } }, { "Variable3", new DeploymentVariable() { Value = "hello world", Type = "string" } } }, Parameters = new Dictionary<string, DeploymentVariable>() { { "Parameter1", new DeploymentVariable() { Value = "true", Type = "bool" } }, { "Parameter2", new DeploymentVariable() { Value = "10", Type = "int" } }, { "Parameter3", new DeploymentVariable() { Value = "hello world", Type = "string" } } }, ProvisioningState = ProvisioningState.Succeeded, ResourceGroupName = resourceGroupName, TemplateLink = new TemplateLink() { ContentVersion = "1.0", Uri = new Uri("http://mytemplate.com") }, Timestamp = new DateTime(2014, 2, 13) }; resourcesClientMock.Setup(f => f.ExecuteDeployment( It.IsAny<CreatePSResourceGroupDeploymentParameters>())) .Returns(expected) .Callback((CreatePSResourceGroupDeploymentParameters p) => { actualParameters = p; }); cmdlet.ResourceGroupName = resourceGroupName; cmdlet.Name = expectedParameters.DeploymentName; cmdlet.TemplateFile = expectedParameters.TemplateFile; cmdlet.TemplateVersion = expectedParameters.TemplateVersion; cmdlet.ExecuteCmdlet(); Assert.Equal(expectedParameters.DeploymentName, actualParameters.DeploymentName); Assert.Equal(expectedParameters.GalleryTemplateIdentity, actualParameters.GalleryTemplateIdentity); Assert.Equal(expectedParameters.TemplateFile, actualParameters.TemplateFile); Assert.NotNull(actualParameters.TemplateParameterObject); Assert.Equal(expectedParameters.TemplateVersion, actualParameters.TemplateVersion); commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); }
public override void ExecuteCmdlet() { CreatePSResourceGroupDeploymentParameters parameters = new CreatePSResourceGroupDeploymentParameters() { ResourceGroupName = ResourceGroupName, DeploymentName = Name, GalleryTemplateIdentity = GalleryTemplateIdentity, TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile), TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject), TemplateVersion = TemplateVersion, StorageAccountName = StorageAccountName }; WriteObject(ResourcesClient.ExecuteDeployment(parameters)); }
private string GenerateDeploymentName(CreatePSResourceGroupDeploymentParameters parameters) { if (!string.IsNullOrEmpty(parameters.DeploymentName)) { return(parameters.DeploymentName); } else if (!string.IsNullOrEmpty(parameters.TemplateFile)) { return(Path.GetFileNameWithoutExtension(parameters.TemplateFile)); } else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity)) { return(parameters.GalleryTemplateIdentity); } else { return(Guid.NewGuid().ToString()); } }
private string GenerateDeploymentName(CreatePSResourceGroupDeploymentParameters parameters) { if (!string.IsNullOrEmpty(parameters.DeploymentName)) { return parameters.DeploymentName; } else if (!string.IsNullOrEmpty(parameters.TemplateFile)) { return Path.GetFileNameWithoutExtension(parameters.TemplateFile); } else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity)) { return parameters.GalleryTemplateIdentity; } else { return Guid.NewGuid().ToString(); } }
/// <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); List<ResourceManagementError> errors = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment); if (errors.Count != 0) { int counter = 1; string errorFormat = "Error {0}: Code={1}; Message={2}\r\n"; StringBuilder errorsString = new StringBuilder(); errors.ForEach(e => errorsString.AppendFormat(errorFormat, counter++, e.Code, e.Message)); throw new ArgumentException(errorsString.ToString()); } else { WriteVerbose(Resources.TemplateValid); } 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); }