public void GetSepcificResourcesGroupDeployment() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { DeploymentName = deploymentName, ResourceGroupName = resourceGroupName }; FilterResourceGroupDeploymentOptions actual = new FilterResourceGroupDeploymentOptions(); List <PSResourceGroupDeployment> result = new List <PSResourceGroupDeployment>(); PSResourceGroupDeployment expected = new PSResourceGroupDeployment() { DeploymentName = deploymentName, CorrelationId = "123", ResourceGroupName = resourceGroupName, Mode = DeploymentMode.Incremental }; result.Add(expected); resourcesClientMock.Setup(f => f.FilterResourceGroupDeployments(It.IsAny <FilterResourceGroupDeploymentOptions>())) .Returns(result) .Callback((FilterResourceGroupDeploymentOptions o) => { actual = o; }); cmdlet.ResourceGroupName = resourceGroupName; cmdlet.Name = deploymentName; cmdlet.ExecuteCmdlet(); commandRuntimeMock.Verify(f => f.WriteObject(result, true), Times.Once()); Assert.Equal(options.DeploymentName, actual.DeploymentName); Assert.Equal(options.ExcludedProvisioningStates, actual.ExcludedProvisioningStates); Assert.Equal(options.ProvisioningStates, actual.ProvisioningStates); Assert.Equal(options.ResourceGroupName, actual.ResourceGroupName); }
public override void ExecuteCmdlet() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
protected override void ProcessRecord() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
public override void ExecuteCmdlet() { WriteWarning("The output object type of this cmdlet will be modified in a future release."); FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)) }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
public override void ExecuteCmdlet() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName, DeploymentName = Name, ProvisioningStates = string.IsNullOrEmpty(ProvisioningState) ? new List <string>() : new List <string>() { ProvisioningState } }; WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
protected override void ProcessRecord() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(Id), DeploymentName = Name ?? (string.IsNullOrEmpty(Id) ? null : ResourceIdUtility.GetResourceName(Id)), ProvisioningStates = string.IsNullOrEmpty(ProvisioningState) ? new List <string>() : new List <string>() { ProvisioningState } }; if (!string.IsNullOrEmpty(ProvisioningState)) { WriteWarning("The ProvisioningState parameter is being deprecated and will be removed in a future release."); } WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
public override void ExecuteCmdlet() { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions() { ResourceGroupName = ResourceGroupName, DeploymentName = Name, ProvisioningStates = string.IsNullOrEmpty(ProvisioningState) ? new List <string>() : new List <string>() { ProvisioningState } }; if (!string.IsNullOrEmpty(ProvisioningState)) { WriteWarning("The ProvisioningState parameter is being deprecated and will be removed in a future release."); } WriteObject(ResourcesClient.FilterResourceGroupDeployments(options), true); }
/// <summary> /// Cancels the active deployment. /// </summary> /// <param name="resourceGroup">The resource group name</param> /// <param name="deploymentName">Deployment name</param> public virtual void CancelDeployment(string resourceGroup, string deploymentName) { FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions { DeploymentName = deploymentName, ResourceGroupName = resourceGroup }; if (string.IsNullOrEmpty(deploymentName)) { options.ExcludedProvisioningStates = new List <string> { ProvisioningState.Failed.ToString(), ProvisioningState.Succeeded.ToString() }; } List <PSResourceGroupDeployment> deployments = FilterResourceGroupDeployments(options); if (deployments.Count == 0) { if (string.IsNullOrEmpty(deploymentName)) { throw new ArgumentException(string.Format(ProjectResources.NoDeploymentToCancel, deploymentName)); } else { throw new ArgumentException(string.Format(ProjectResources.NoRunningDeployments, resourceGroup)); } } else if (deployments.Count == 1) { ResourceManagementClient.Deployments.Cancel(resourceGroup, deployments.First().DeploymentName); } else { throw new ArgumentException(ProjectResources.MultipleRunningDeployment); } }
/// <summary> /// Filters the resource group deployments /// </summary> /// <param name="options">The filtering options</param> /// <returns>The filtered list of deployments</returns> public virtual List <PSResourceGroupDeployment> FilterResourceGroupDeployments(FilterResourceGroupDeploymentOptions options) { List <PSResourceGroupDeployment> deployments = new List <PSResourceGroupDeployment>(); string resourceGroup = options.ResourceGroupName; string name = options.DeploymentName; List <string> excludedProvisioningStates = options.ExcludedProvisioningStates ?? new List <string>(); if (!string.IsNullOrEmpty(resourceGroup) && !string.IsNullOrEmpty(name)) { deployments.Add(ResourceManagementClient.Deployments.Get(resourceGroup, name).ToPSResourceGroupDeployment(options.ResourceGroupName)); } else if (!string.IsNullOrEmpty(resourceGroup)) { var result = ResourceManagementClient.Deployments.List(resourceGroup, null); deployments.AddRange(result.Select(d => d.ToPSResourceGroupDeployment(options.ResourceGroupName))); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = ResourceManagementClient.Deployments.ListNext(result.NextPageLink); deployments.AddRange(result.Select(d => d.ToPSResourceGroupDeployment(options.ResourceGroupName))); } } if (excludedProvisioningStates.Count > 0) { return(deployments.Where(d => excludedProvisioningStates .All(s => !s.Equals(d.ProvisioningState, StringComparison.OrdinalIgnoreCase))).ToList()); } else { return(deployments); } }