From 82132bf0ad14b86432135d170b057f8a25a7ba39 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Thu, 18 Jun 2020 16:46:41 -0700 Subject: [PATCH 01/18] add BYOIP models --- .../Common/NetworkResourceManagerProfile.cs | 9 +++++ .../Network/Models/BYOIP/PSCustomIpPrefix.cs | 34 ++++++++++++++++++ .../Models/BYOIP/PSMasterCustomIpPrefix.cs | 36 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs create mode 100644 src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs diff --git a/src/Network/Network/Common/NetworkResourceManagerProfile.cs b/src/Network/Network/Common/NetworkResourceManagerProfile.cs index 8b3db64da9a2..f0b74388e0d3 100644 --- a/src/Network/Network/Common/NetworkResourceManagerProfile.cs +++ b/src/Network/Network/Common/NetworkResourceManagerProfile.cs @@ -394,6 +394,15 @@ private static void Initialize() cfg.CreateMap(); cfg.CreateMap(); + // BYOIP (MasterCustomIpPrefix and CustomIpPrefix) + // CNM to MNM + cfg.CreateMap(); + cfg.CreateMap(); + + // MNM to CNM + cfg.CreateMap(); + cfg.CreateMap(); + // NetworkInterface // CNM to MNM cfg.CreateMap(); diff --git a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs new file mode 100644 index 000000000000..9b5746f454ec --- /dev/null +++ b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs @@ -0,0 +1,34 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network.Models +{ + using Newtonsoft.Json; + using System.Collections.Generic; + + public class PSCustomIpPrefix : PSTopLevelResource + { + public string Cidr { get; set; } + + public string ProvisioningState { get; set; } + + public string OriginalValidationMessage { get; set; } + + public string SignedValidationMessage { get; set; } + + public string Geography { get; set; } + + public List PublicIpAddresses { get; set; } + } +} diff --git a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs new file mode 100644 index 000000000000..be13b0f0a0c9 --- /dev/null +++ b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs @@ -0,0 +1,36 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network.Models +{ + using Newtonsoft.Json; + using System.Collections.Generic; + + public class PSMasterCustomIpPrefix : PSTopLevelResource + { + public string Cidr { get; set; } + + public string ProvisioningState { get; set; } + + public string OriginalValidationMessage { get; set; } + + public string SignedValidationMessage { get; set; } + + public string Geography { get; set; } + + public List CustomIpPrefixes { get; set; } + + public string ValidationState { get; set; } + } +} From a8b5d673cedeb637d900edb030782c8720f14ffc Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Fri, 19 Jun 2020 02:03:28 -0700 Subject: [PATCH 02/18] first cherry pick batch --- .../GetAzureMasterCustomIpPrefixCommand.cs | 118 ++++++++++++++ .../BYOIP/MasterCustomIpPrefixBaseCmdlet.cs | 72 +++++++++ .../NewAzureMasterCustomIpPrefixCommand.cs | 146 ++++++++++++++++++ .../RemoveAzureMasterCustomIpPrefixCommand.cs | 119 ++++++++++++++ .../SetAzureMasterCustomIpPrefixCommand.cs | 62 ++++++++ 5 files changed, 517 insertions(+) create mode 100644 src/Network/Network/BYOIP/GetAzureMasterCustomIpPrefixCommand.cs create mode 100644 src/Network/Network/BYOIP/MasterCustomIpPrefixBaseCmdlet.cs create mode 100644 src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs create mode 100644 src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs create mode 100644 src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs diff --git a/src/Network/Network/BYOIP/GetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/GetAzureMasterCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..d40446560375 --- /dev/null +++ b/src/Network/Network/BYOIP/GetAzureMasterCustomIpPrefixCommand.cs @@ -0,0 +1,118 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Network; + using System.Collections.Generic; + using System.Management.Automation; + using Microsoft.Azure.Management.Network.Models; + using Microsoft.Rest.Azure; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.WindowsAzure.Commands.Utilities.Common; + using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; + + [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PublicIpPrefix", DefaultParameterSetName = GetAzurePublicIpPrefixParameterSetNames.List), OutputType(typeof(PSPublicIpPrefix))] + public class GetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet + { + [Alias("ResourceName")] + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.", + ParameterSetName = GetAzurePublicIpPrefixParameterSetNames.List)] + [ResourceNameCompleter("Microsoft.Network/publicIPPrefixes", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", + ParameterSetName = GetAzurePublicIpPrefixParameterSetNames.List)] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + ParameterSetName = GetAzurePublicIpPrefixParameterSetNames.GetByResourceId)] + [ValidateNotNullOrEmpty] + public virtual string ResourceId { get; set; } + + public override void Execute() + { + base.Execute(); + + if (this.IsParameterBound(c => c.ResourceId)) + { + var resourceIdentifier = new ResourceIdentifier(this.ResourceId); + this.ResourceGroupName = resourceIdentifier.ResourceGroupName; + this.Name = resourceIdentifier.ResourceName; + } + + if (ShouldGetByName(ResourceGroupName, Name)) + { + PSPublicIpPrefix publicIpPrefix; + + publicIpPrefix = this.GetPublicIpPrefix(this.ResourceGroupName, this.Name); + + WriteObject(publicIpPrefix); + } + else + { + IPage publicipprefixPage; + if (ShouldListByResourceGroup(ResourceGroupName, Name)) + { + publicipprefixPage = this.PublicIpPrefixClient.List(this.ResourceGroupName); + } + else + { + publicipprefixPage = this.PublicIpPrefixClient.ListAll(); + } + + // Get all resources by polling on next page link + List publicIPPrefixList; + + publicIPPrefixList = ListNextLink.GetAllResourcesByPollingNextLink(publicipprefixPage, this.PublicIpPrefixClient.ListNext); + + var psPublicIpPrefixes = new List(); + + // populate the publicIpPrefixes with the ResourceGroupName + foreach (var publicIpPrefix in publicIPPrefixList) + { + var psPublicIpPrefix = this.ToPsPublicIpPrefix(publicIpPrefix); + psPublicIpPrefix.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(publicIpPrefix.Id); + psPublicIpPrefixes.Add(psPublicIpPrefix); + } + + WriteObject(TopLevelWildcardFilter(ResourceGroupName, Name, psPublicIpPrefixes), true); + } + } + } + + public static class GetAzurePublicIpPrefixParameterSetNames + { + public const string GetByResourceId = "GetByResourceIdParameterSet"; + public const string List = "ListParameterSet"; + + // The Default + public const string Default = List; + } +} diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefixBaseCmdlet.cs new file mode 100644 index 000000000000..d086099b18b3 --- /dev/null +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefixBaseCmdlet.cs @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Network; + using Microsoft.Azure.Management.Network.Models; + using System.Net; + + public abstract class MasterCustomIpPrefixBaseCmdlet : NetworkBaseCmdlet + { + public IMasterCustomIPPrefixesOperations MasterCustomIpPrefixClient + { + get + { + return NetworkClient.NetworkManagementClient.MasterCustomIPPrefixes; + } + } + + public bool IsMasterCustomIpPrefixPresent(string resourceGroupName, string name) + { + try + { + GetMasterCustomIpPrefix(resourceGroupName, name); + } + catch (Microsoft.Rest.Azure.CloudException exception) + { + if (exception.Response.StatusCode == HttpStatusCode.NotFound) + { + // Resource is not present + return false; + } + + throw; + } + + return true; + } + + public PSMasterCustomIpPrefix GetMasterCustomIpPrefix(string resourceGroupName, string name, string expandResource = null) + { + var masterCustomIpPrefix = this.MasterCustomIpPrefixClient.Get(resourceGroupName, name, expandResource); + + var psMasterCustomIpPrefix = ToPsMasterCustomIpPrefix(masterCustomIpPrefix); + //psMasterCustomIpPrefix.ResourceGroupName = resourceGroupName; + + return psMasterCustomIpPrefix; + } + + public PSMasterCustomIpPrefix ToPsMasterCustomIpPrefix(MasterCustomIpPrefix publicIpPrefix) + { + var psMasterCustomIpPrefix = NetworkResourceManagerProfile.Mapper.Map(publicIpPrefix); + + psMasterCustomIpPrefix.Tag = TagsConversionHelper.CreateTagHashtable(publicIpPrefix.Tags); + + return psMasterCustomIpPrefix; + } + } +} diff --git a/src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..8487d88dfd99 --- /dev/null +++ b/src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs @@ -0,0 +1,146 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Network; + using System.Collections; + using System.Linq; + using System.Management.Automation; + using MNM = Microsoft.Azure.Management.Network.Models; + using System; + + [Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] + public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet + { + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.")] + [ValidateNotNullOrEmpty] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The master custom IP prefix location.")] + [LocationCompleter("Microsoft.Network/masterCustomIpPrefix")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The geography of edge routers this prefix range will be advertised on.")] + [ValidateNotNullOrEmpty] + [ValidateSet( + MNM.RIR.NorthAmerica, + MNM.RIR.Europe, + MNM.RIR.Asia, + MNM.RIR.SouthAmerica, + MNM.RIR.Africa, + MNM.RIR.Global, + IgnoreCase = true)] + public string Geography { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The CIDR of the master custom IP prefix")] + [ValidateNotNullOrEmpty] + public string Cidr { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The message for master custom IP prefix validation.")] + [ValidateNotNullOrEmpty] + public string ValidationMessage { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The message for master custom IP prefix validation signed with public key.")] + [ValidateNotNullOrEmpty] + public string SignedValidationMessage { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "A hashtable which represents resource tags.")] + public Hashtable Tag { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + var present = this.IsMasterCustomIpPrefixPresent(this.ResourceGroupName, this.Name); + ConfirmAction( + false, + string.Format(Properties.Resources.OverwritingResource, Name), + Properties.Resources.CreatingResourceMessage, + Name, + () => + { + var masterCustomIpPrefix = CreateMasterCustomIpPrefix(); + if (masterCustomIpPrefix != null) + { + WriteObject(masterCustomIpPrefix); + } + }, + () => present); + } + + private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() + { + var masterCustomIpPrefix = new PSMasterCustomIpPrefix(); + masterCustomIpPrefix.Name = this.Name; + masterCustomIpPrefix.Location = this.Location; + masterCustomIpPrefix.Geography = this.Geography; + masterCustomIpPrefix.Cidr = this.Cidr; + masterCustomIpPrefix.OriginalValidationMessage = this.ValidationMessage; + masterCustomIpPrefix.SignedValidationMessage = this.SignedValidationMessage; + + + var theModel = NetworkResourceManagerProfile.Mapper.Map(masterCustomIpPrefix); + + theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); + + if (this.ShouldProcess(this.Name, $"Creating a new PublicIpPrefix in ResourceGroup {this.ResourceGroupName} with Name {this.Name}")) + { + this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, theModel); + + var getMasterCustomIpPrefix = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); + + return getMasterCustomIpPrefix; + } + + return null; + } + } +} diff --git a/src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..ce40280a911a --- /dev/null +++ b/src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs @@ -0,0 +1,119 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; + using Microsoft.Azure.Management.Network; + using Microsoft.WindowsAzure.Commands.Utilities.Common; + using System.Management.Automation; + + [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PublicIpPrefix", SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.Default), OutputType(typeof(bool))] + public class RemoveAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet + { + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.", + ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.RemoveByName)] + [ResourceNameCompleter("Microsoft.Network/publicIPPrefixes", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", + ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.RemoveByName)] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.DeleteByResourceId)] + [ValidateNotNullOrEmpty] + public virtual string ResourceId { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipeline = true, + ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.DeleteByInputObject)] + [ValidateNotNull] + public PSPublicIpPrefix InputObject + { + get; set; + } + + [Parameter( + Mandatory = false, + HelpMessage = "Do not ask for confirmation.")] + public SwitchParameter Force { get; set; } + + [Parameter(Mandatory = false)] + public SwitchParameter PassThru { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + + if (this.IsParameterBound(c => c.InputObject)) + { + this.ResourceGroupName = this.InputObject.ResourceGroupName; + this.Name = this.InputObject.Name; + } + + if (this.IsParameterBound(c => c.ResourceId)) + { + var resourceIdentifier = new ResourceIdentifier(this.ResourceId); + this.ResourceGroupName = resourceIdentifier.ResourceGroupName; + this.Name = resourceIdentifier.ResourceName; + } + + ConfirmAction( + Force.IsPresent, + string.Format(Microsoft.Azure.Commands.Network.Properties.Resources.RemovingResource, Name), + Microsoft.Azure.Commands.Network.Properties.Resources.RemoveResourceMessage, + Name, + () => + { + if (this.ShouldProcess(this.Name, $"Deleting PublicIpPrefix {this.Name} in ResourceGroup {this.ResourceGroupName}")) + { + this.PublicIpPrefixClient.Delete(this.ResourceGroupName, this.Name); + if (PassThru) + { + WriteObject(true); + } + } + }); + } + } + + public static class RemoveAzurePublicIpPrefixParameterSetNames + { + public const string RemoveByName = "RemoveByNameParameterSet"; + public const string DeleteByResourceId = "DeleteByResourceIdParameterSet"; + public const string DeleteByInputObject = "DeleteByInputObjectParameterSet"; + + // The Default + public const string Default = RemoveAzurePublicIpPrefixParameterSetNames.RemoveByName; + } +} diff --git a/src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..20d2373bdd00 --- /dev/null +++ b/src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs @@ -0,0 +1,62 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using AutoMapper; + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; + using Microsoft.Azure.Management.Network; + using Microsoft.WindowsAzure.Commands.Utilities.Common; + using System; + using System.Management.Automation; + using MNM = Microsoft.Azure.Management.Network.Models; + + [Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PublicIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSPublicIpPrefix))] + public class SetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet + { + [Parameter( + Mandatory = true, + ValueFromPipeline = true, + HelpMessage = "The PublicIpPrefix")] + public PSPublicIpPrefix PublicIpPrefix { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + + if (!this.IsPublicIpPrefixPresent(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name)) + { + throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); + } + + // Map to the sdk object + var theModel = NetworkResourceManagerProfile.Mapper.Map(this.PublicIpPrefix); + theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.PublicIpPrefix.Tag, validate: true); + + if (this.ShouldProcess(this.PublicIpPrefix.Name, $"Setting PublicIpPrefix Name:{this.PublicIpPrefix.Name} in ResourceGroup: {this.PublicIpPrefix.ResourceGroupName}")) + { + this.PublicIpPrefixClient.CreateOrUpdate(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name, theModel); + + var getPublicIpPrefix = this.GetPublicIpPrefix(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name); + + WriteObject(getPublicIpPrefix); + } + } + } +} From f22ad6cf583cbad8d9da28b1a5b77c3ba14648ff Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Sun, 28 Jun 2020 16:00:18 -0700 Subject: [PATCH 03/18] cherrypick second batch --- src/Network/Network/Az.Network.psd1 | 3 + .../CustomIpPrefixBaseCmdlet.cs | 52 +++++++ .../GetAzureCustomIpPrefixCommand.cs | 113 ++++++++++++++ .../NewAzureCustomIpPrefixCommand.cs | 123 +++++++++++++++ .../RemoveAzureCustomIpPrefixCommand.cs | 110 ++++++++++++++ .../SetAzureCustomIpPrefixCommand.cs | 140 ++++++++++++++++++ .../GetAzureMasterCustomIpPrefixCommand.cs | 0 .../MasterCustomIpPrefixBaseCmdlet.cs | 0 .../NewAzureMasterCustomIpPrefixCommand.cs | 42 +++--- .../RemoveAzureMasterCustomIpPrefixCommand.cs | 2 +- .../SetAzureMasterCustomIpPrefixCommand.cs | 6 +- .../Network/Models/BYOIP/PSCustomIpPrefix.cs | 12 +- .../Network/Properties/Resources.Designer.cs | 9 ++ src/Network/Network/Properties/Resources.resx | 3 + 14 files changed, 588 insertions(+), 27 deletions(-) create mode 100644 src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs create mode 100644 src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs create mode 100644 src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs create mode 100644 src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs create mode 100644 src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs rename src/Network/Network/BYOIP/{ => MasterCustomIpPrefix}/GetAzureMasterCustomIpPrefixCommand.cs (100%) rename src/Network/Network/BYOIP/{ => MasterCustomIpPrefix}/MasterCustomIpPrefixBaseCmdlet.cs (100%) rename src/Network/Network/BYOIP/{ => MasterCustomIpPrefix}/NewAzureMasterCustomIpPrefixCommand.cs (77%) rename src/Network/Network/BYOIP/{ => MasterCustomIpPrefix}/RemoveAzureMasterCustomIpPrefixCommand.cs (98%) rename src/Network/Network/BYOIP/{ => MasterCustomIpPrefix}/SetAzureMasterCustomIpPrefixCommand.cs (86%) diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index 30758b6bd350..83c29bc830b1 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -501,6 +501,9 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'New-AzOffice365PolicyProperty', 'Get-AzNetworkVirtualApplianceSku', 'New-AzVirtualApplianceSkuProperty' + 'New-AzCustomIpPrefix','Set-AzCustomIpPrefix', + 'Get-AzCustomIpPrefix','Remove-AzCustomIpPrefix' +>>>>>>> 18ca1a0bbb... add customIpPrefix cmdlets # Variables to export from this module # VariablesToExport = @() diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs new file mode 100644 index 000000000000..69fc66cb0469 --- /dev/null +++ b/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs @@ -0,0 +1,52 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Network; + using Microsoft.Azure.Management.Network.Models; + using System.Net; + + public abstract class CustomIpPrefixBaseCmdlet : NetworkBaseCmdlet + { + public ICustomIPPrefixesOperations CustomIpPrefixClient + { + get + { + return NetworkClient.NetworkManagementClient.CustomIPPrefixes; + } + } + + public PSCustomIpPrefix GetCustomIpPrefix(string resourceGroupName, string name, string expandResource = null) + { + var sdkModel = this.CustomIpPrefixClient.Get(resourceGroupName, name, expandResource); + + var psModel = ToPsCustomIpPrefix(sdkModel); + //psMasterCustomIpPrefix.ResourceGroupName = resourceGroupName; + + return psModel; + } + + public PSCustomIpPrefix ToPsCustomIpPrefix(CustomIpPrefix publicIpPrefix) + { + var psModel = NetworkResourceManagerProfile.Mapper.Map(publicIpPrefix); + + psModel.Tag = TagsConversionHelper.CreateTagHashtable(publicIpPrefix.Tags); + + return psModel; + } + } +} diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..677d59444ef7 --- /dev/null +++ b/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs @@ -0,0 +1,113 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Network; + using System.Collections.Generic; + using System.Management.Automation; + using Microsoft.Azure.Management.Network.Models; + using Microsoft.Rest.Azure; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.WindowsAzure.Commands.Utilities.Common; + using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; + + [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSMasterCustomIpPrefix))] + public class GetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet + { + private const string ListParameterSet = "ListParameterSet"; + private const string GetByNameParameterSet = "GetByNameParameterSet"; + private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet"; + + [Alias("ResourceName")] + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.", + ParameterSetName = GetByNameParameterSet)] + [ResourceNameCompleter("Microsoft.Network/customIpPrefix", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", + ParameterSetName = GetByNameParameterSet)] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + ParameterSetName = GetByResourceIdParameterSet)] + [ValidateNotNullOrEmpty] + public virtual string ResourceId { get; set; } + + public override void Execute() + { + base.Execute(); + + if (this.IsParameterBound(c => c.ResourceId)) + { + var resourceIdentifier = new ResourceIdentifier(this.ResourceId); + this.ResourceGroupName = resourceIdentifier.ResourceGroupName; + this.Name = resourceIdentifier.ResourceName; + } + + if (ShouldGetByName(this.ResourceGroupName, this.Name)) + { + PSCustomIpPrefix psModel; + + psModel = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); + + WriteObject(psModel); + } + else + { + IPage page; + if (ShouldListByResourceGroup(this.ResourceGroupName, this.Name)) + { + page = this.CustomIpPrefixClient.List(this.ResourceGroupName); + } + else + { + page = this.CustomIpPrefixClient.ListAll(); + } + + // Get all resources by polling on next page link + List sdkModelList; + + sdkModelList = ListNextLink.GetAllResourcesByPollingNextLink(page, this.CustomIpPrefixClient.ListNext); + + var psModelList = new List(); + + // populate the publicIpPrefixes with the ResourceGroupName + foreach (var sdkModel in sdkModelList) + { + var psModel = this.ToPsCustomIpPrefix(sdkModel); + psModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(psModel.Id); + psModelList.Add(psModel); + } + + WriteObject(TopLevelWildcardFilter(this.ResourceGroupName, this.Name, psModelList), true); + } + } + } +} diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..5f6489ebaf9e --- /dev/null +++ b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs @@ -0,0 +1,123 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Network; + using System.Collections; + using System.Linq; + using System.Management.Automation; + using MNM = Microsoft.Azure.Management.Network.Models; + + [Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSCustomIpPrefix))] + public class NewAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet + { + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.")] + [ValidateNotNullOrEmpty] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.")] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The MasterCustomIpPrefix that this CustomIpPrefix is associated with")] + public PSMasterCustomIpPrefix MasterCustomIpPrefix { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The master custom IP prefix location.")] + [LocationCompleter("Microsoft.Network/customIpPrefix")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The CIDR of the master custom IP prefix")] + [ValidateNotNullOrEmpty] + public string Cidr { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "A list of availability zones denoting the IP allocated for the resource needs to come from.", + ValueFromPipelineByPropertyName = true)] + public string[] Zone { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "A hashtable which represents resource tags.")] + public Hashtable Tag { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + var resourceExists = IsResourcePresent(() => GetCustomIpPrefix(this.ResourceGroupName, this.Name)); + + if (resourceExists) + { + throw new System.Exception(string.Format("A CustomIpPrefix with name '{0}' in resource group '{1}' already exists. Please use Set-AzCustomIpPrefix to update an existing CustomIpPrefix.", this.Name, this.ResourceGroupName)); + } + + var psModel = CreateCustomIpPrefix(); + if (psModel != null) + { + WriteObject(psModel); + } + } + + private PSCustomIpPrefix CreateCustomIpPrefix() + { + var psModel = new PSCustomIpPrefix() + { + Name = this.Name, + ResourceGroupName = this.ResourceGroupName, + Location = this.Location, + MasterCustomIpPrefix = this.MasterCustomIpPrefix, + Cidr = this.Cidr, + Zones = this.Zone?.ToList() + }; + + var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); + + sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); + + if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Create new MasterCustomIpPrefix")) + { + var createdSdkModel = this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + return this.ToPsCustomIpPrefix(createdSdkModel); + } + + return null; + } + } +} \ No newline at end of file diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..1651702becdd --- /dev/null +++ b/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs @@ -0,0 +1,110 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; + using Microsoft.Azure.Management.Network; + using Microsoft.WindowsAzure.Commands.Utilities.Common; + using System.Management.Automation; + + [Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true, DefaultParameterSetName = DeleteByNameParameterSet), OutputType(typeof(bool))] + public class RemoveAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet + { + private const string DeleteByNameParameterSet = "DeleteByNameParameterSet"; + private const string DeleteByInputObjectParameterSet = "DeleteByInputObjectParameterSet"; + private const string DeleteByResourceIdParameterSet = "DeleteByResourceIdParameterSet"; + + [Alias("ResourceName")] + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.", + ParameterSetName = DeleteByNameParameterSet)] + [ResourceNameCompleter("Microsoft.Network/customIpPrefix", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", + ParameterSetName = DeleteByNameParameterSet)] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + ParameterSetName = DeleteByResourceIdParameterSet)] + [ValidateNotNullOrEmpty] + public virtual string ResourceId { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipeline = true, + ParameterSetName = DeleteByInputObjectParameterSet)] + [ValidateNotNull] + public PSCustomIpPrefix InputObject { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "Do not ask for confirmation.")] + public SwitchParameter Force { get; set; } + + [Parameter(Mandatory = false)] + public SwitchParameter PassThru { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + + if (this.IsParameterBound(c => c.InputObject)) + { + this.ResourceGroupName = this.InputObject.ResourceGroupName; + this.Name = this.InputObject.Name; + } + + if (this.IsParameterBound(c => c.ResourceId)) + { + var resourceIdentifier = new ResourceIdentifier(this.ResourceId); + this.ResourceGroupName = resourceIdentifier.ResourceGroupName; + this.Name = resourceIdentifier.ResourceName; + } + + ConfirmAction( + Force.IsPresent, + string.Format(Microsoft.Azure.Commands.Network.Properties.Resources.RemovingResource, Name), + Microsoft.Azure.Commands.Network.Properties.Resources.RemoveResourceMessage, + Name, + () => + { + if (this.ShouldProcess(this.Name, $"Deleting CustomIpPrefix: {this.Name} in ResourceGroup: {this.ResourceGroupName}")) + { + this.CustomIpPrefixClient.Delete(this.ResourceGroupName, this.Name); + if (PassThru) + { + WriteObject(true); + } + } + }); + } + } +} diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs new file mode 100644 index 000000000000..0d7709f5076b --- /dev/null +++ b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs @@ -0,0 +1,140 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Network +{ + using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; + using Microsoft.Azure.Commands.ResourceManager.Common.Tags; + using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; + using Microsoft.Azure.Management.Network; + using Microsoft.WindowsAzure.Commands.Utilities.Common; + using System; + using System.Collections; + using System.Management.Automation; + using MNM = Microsoft.Azure.Management.Network.Models; + + [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] + public class SetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet + { + private const string SetByNameParameterSet = "SetByNameParameterSet"; + private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; + private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.", ParameterSetName = SetByNameParameterSet)] + [ResourceNameCompleter("Microsoft.Network/customIpPrefix", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", ParameterSetName = SetByNameParameterSet)] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string ResourceGroupName { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipeline = true, + HelpMessage = "The MasterCustomIpPrefix to set.", ParameterSetName = SetByInputObjectParameterSet)] + public PSMasterCustomIpPrefix InputObject { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource Id.", ParameterSetName = SetByResourceIdParameterSet)] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string ResourceId { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter Commission { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter Decomission { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "A hashtable which represents resource tags.", + ParameterSetName = SetByNameParameterSet)] + [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] + public Hashtable Tag { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] + public SwitchParameter AsJob { get; set; } + + public override void Execute() + { + base.Execute(); + + if (this.IsParameterBound(c => c.ResourceId)) + { + var resourceInfo = new ResourceIdentifier(ResourceId); + this.ResourceGroupName = resourceInfo.ResourceGroupName; + this.Name = resourceInfo.ResourceName; + } + else if (this.IsParameterBound(c => c.InputObject)) + { + this.ResourceGroupName = InputObject.ResourceGroupName; + this.Name = InputObject.Name; + } + + var existingResourcePsModel = GetCustomIpPrefix(this.ResourceGroupName, this.Name); + if (existingResourcePsModel == null) + { + throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); + } + + if (Commission && Decomission) + { + throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.CommissioningStateConflict); + } + + var psModel = new PSCustomIpPrefix() + { + Name = InputObject.Name, + ResourceGroupName = InputObject.ResourceGroupName + }; + if (Commission || Decomission) + { + psModel.CommissionedState = Commission ? "Commissioning" : "Decomissioning"; + } + + var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); + + if (this.IsParameterBound(c => c.InputObject)) + { + sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.IsParameterBound(c => c.Tag) ? this.Tag : InputObject.Tag, validate: true); + } + else + { + sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); + } + + if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) + { + // Execute the PUT MasterCustomIpPrefix Policy call + var modifiedSdkModel = this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + WriteObject(this.ToPsCustomIpPrefix(modifiedSdkModel)); + } + } + } +} diff --git a/src/Network/Network/BYOIP/GetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs similarity index 100% rename from src/Network/Network/BYOIP/GetAzureMasterCustomIpPrefixCommand.cs rename to src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs similarity index 100% rename from src/Network/Network/BYOIP/MasterCustomIpPrefixBaseCmdlet.cs rename to src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs diff --git a/src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs similarity index 77% rename from src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs rename to src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs index 8487d88dfd99..48b2021000ef 100644 --- a/src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs @@ -46,7 +46,7 @@ public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The master custom IP prefix location.")] + HelpMessage = "The MasterCustomIpPrefix location.")] [LocationCompleter("Microsoft.Network/masterCustomIpPrefix")] [ValidateNotNullOrEmpty] public string Location { get; set; } @@ -69,21 +69,21 @@ public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The CIDR of the master custom IP prefix")] + HelpMessage = "The CIDR of the MasterCustomIpPrefix")] [ValidateNotNullOrEmpty] public string Cidr { get; set; } [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The message for master custom IP prefix validation.")] + HelpMessage = "The message for MasterCustomIpPrefix validation.")] [ValidateNotNullOrEmpty] public string ValidationMessage { get; set; } [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The message for master custom IP prefix validation signed with public key.")] + HelpMessage = "The message for MasterCustomIpPrefix validation signed with public key.")] [ValidateNotNullOrEmpty] public string SignedValidationMessage { get; set; } @@ -99,21 +99,18 @@ public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle public override void Execute() { base.Execute(); - var present = this.IsMasterCustomIpPrefixPresent(this.ResourceGroupName, this.Name); - ConfirmAction( - false, - string.Format(Properties.Resources.OverwritingResource, Name), - Properties.Resources.CreatingResourceMessage, - Name, - () => - { - var masterCustomIpPrefix = CreateMasterCustomIpPrefix(); - if (masterCustomIpPrefix != null) - { - WriteObject(masterCustomIpPrefix); - } - }, - () => present); + var resourceExists = NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name)); + + if (resourceExists) + { + throw new System.Exception(string.Format("A MasterCustomIpPrefix with name '{0}' in resource group '{1}' already exists. Please use Set-AzMasterCustomIpPrefix to update an existing MasterCustomIpPrefix.", this.Name, this.ResourceGroupName)); + } + + var psModel = CreateMasterCustomIpPrefix(); + if (psModel != null) + { + WriteObject(psModel); + } } private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() @@ -131,6 +128,7 @@ private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); +<<<<<<< HEAD:src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs if (this.ShouldProcess(this.Name, $"Creating a new PublicIpPrefix in ResourceGroup {this.ResourceGroupName} with Name {this.Name}")) { this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, theModel); @@ -138,6 +136,12 @@ private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() var getMasterCustomIpPrefix = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); return getMasterCustomIpPrefix; +======= + if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Creating a new MasterCustomIpPrefix")) + { + var createdSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + return this.ToPsMasterCustomIpPrefix(createdSdkModel); +>>>>>>> 18ca1a0bbb... add customIpPrefix cmdlets:src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs } return null; diff --git a/src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs similarity index 98% rename from src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs rename to src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs index ce40280a911a..d7940e1587d4 100644 --- a/src/Network/Network/BYOIP/RemoveAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs @@ -95,7 +95,7 @@ public override void Execute() Name, () => { - if (this.ShouldProcess(this.Name, $"Deleting PublicIpPrefix {this.Name} in ResourceGroup {this.ResourceGroupName}")) + if (this.ShouldProcess(this.Name, $"Deleting MasterCustomIpPrefix: {this.Name} in ResourceGroup: {this.ResourceGroupName}")) { this.PublicIpPrefixClient.Delete(this.ResourceGroupName, this.Name); if (PassThru) diff --git a/src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs similarity index 86% rename from src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs rename to src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs index 20d2373bdd00..1e621b93e762 100644 --- a/src/Network/Network/BYOIP/SetAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs @@ -55,7 +55,11 @@ public override void Execute() var getPublicIpPrefix = this.GetPublicIpPrefix(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name); - WriteObject(getPublicIpPrefix); + if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) + { + // Execute the PUT MasterCustomIpPrefix Policy call + var modifiedSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + WriteObject(this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name)); } } } diff --git a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs index 9b5746f454ec..edc90a7e7d23 100644 --- a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs +++ b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs @@ -21,14 +21,14 @@ public class PSCustomIpPrefix : PSTopLevelResource { public string Cidr { get; set; } - public string ProvisioningState { get; set; } + public PSResourceId MasterCustomIpPrefix { get; set; } + + public string CommissionedState { get; set; } - public string OriginalValidationMessage { get; set; } + public List PublicIpPrefixes { get; set; } - public string SignedValidationMessage { get; set; } - - public string Geography { get; set; } + public List Zones { get; set; } - public List PublicIpAddresses { get; set; } + public string ProvisioningState { get; set; } } } diff --git a/src/Network/Network/Properties/Resources.Designer.cs b/src/Network/Network/Properties/Resources.Designer.cs index 80d069c1b285..b68f61a384c4 100644 --- a/src/Network/Network/Properties/Resources.Designer.cs +++ b/src/Network/Network/Properties/Resources.Designer.cs @@ -267,6 +267,15 @@ internal static string ChildResourceAlreadyPresentInResourceGroup { } } + /// + /// Looks up a localized string similar to Cannot have both 'Commission' and 'Decomission' flags set. + /// + internal static string CommissioningStateConflict { + get { + return ResourceManager.GetString("CommissioningStateConflict", resourceCulture); + } + } + /// /// Looks up a localized string similar to Connection monitor test group contains duplicates in destination endpoint names. Destination endpoint names in testGroup must be unique.. /// diff --git a/src/Network/Network/Properties/Resources.resx b/src/Network/Network/Properties/Resources.resx index 36e06c980d34..3b1cc46ef2f0 100644 --- a/src/Network/Network/Properties/Resources.resx +++ b/src/Network/Network/Properties/Resources.resx @@ -691,5 +691,8 @@ A valid HubRouteTable reference is required. + + Cannot have both 'Commission' and 'Decomission' flags set + Error message for setting the customIpPrefix \ No newline at end of file From b87b907b6ccffb275c7f920bda891ccb9bfbf8b5 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Sun, 19 Jul 2020 13:15:41 -0700 Subject: [PATCH 04/18] remove geography tag from MasterCustomIpPrefix --- src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs index be13b0f0a0c9..27cb7f72369f 100644 --- a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs +++ b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs @@ -27,8 +27,6 @@ public class PSMasterCustomIpPrefix : PSTopLevelResource public string SignedValidationMessage { get; set; } - public string Geography { get; set; } - public List CustomIpPrefixes { get; set; } public string ValidationState { get; set; } From c25cdcc70eb48d429b7a3de2a17785572de4275b Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Fri, 26 Jun 2020 10:32:36 -0700 Subject: [PATCH 05/18] cherrypick 3rd batch --- src/Network/Network.Test/NrpTeamAlias.cs | 3 + .../MasterCustomIpPrefixTests.cs | 37 ++++ .../MasterCustomIpPrefixTests.ps1 | 197 ++++++++++++++++++ src/Network/Network/Az.Network.psd1 | 1 - .../GetAzureMasterCustomIpPrefixCommand.cs | 55 +++-- .../MasterCustomIpPrefixBaseCmdlet.cs | 20 -- .../NewAzureMasterCustomIpPrefixCommand.cs | 63 +++--- .../RemoveAzureMasterCustomIpPrefixCommand.cs | 33 ++- .../SetAzureMasterCustomIpPrefixCommand.cs | 85 ++++++-- 9 files changed, 374 insertions(+), 120 deletions(-) create mode 100644 src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs create mode 100644 src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 diff --git a/src/Network/Network.Test/NrpTeamAlias.cs b/src/Network/Network.Test/NrpTeamAlias.cs index e01c2d64539a..3cb7c501f650 100644 --- a/src/Network/Network.Test/NrpTeamAlias.cs +++ b/src/Network/Network.Test/NrpTeamAlias.cs @@ -64,5 +64,8 @@ class NrpTeamAlias // Azure Network IPAM dev team public const string ipam = "ipamdev"; + + // Azure Network Billing and Telemetry team + public const string billingandtelemetry = "azurenetworkbilling"; } } diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs new file mode 100644 index 000000000000..1ba47082e1be --- /dev/null +++ b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs @@ -0,0 +1,37 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Network.Test.ScenarioTests; +using Microsoft.WindowsAzure.Commands.ScenarioTest; +using Xunit; + +namespace Commands.Network.Test.ScenarioTests +{ + + public class MasterCustomIpPrefixTests : NetworkTestRunner + { + public MasterCustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output) + : base(output) + { + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)] + public void TestPublicIpPrefixCRUD() + { + TestRunner.RunTestScript("Test-MasterCustomIpPrefixCRUD"); + } + } +} diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 new file mode 100644 index 000000000000..d90b36077015 --- /dev/null +++ b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 @@ -0,0 +1,197 @@ +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +<# +.SYNOPSIS +Tests creating new simple masterCustomIpPrefix. +#> +function Test-MasterCustomIpPrefixCRUD +{ + # Setup + $rgname = Get-ResourceGroupName + $rname = Get-ResourceName + $rglocation = Get-ProviderLocation ResourceManagement + $resourceTypeParent = "Microsoft.Network/publicIpPrefixes" + $location = Get-ProviderLocation $resourceTypeParent "West Europe" + $ipTagType = "NetworkDomain" + $ipTagTag = "test" + + try + { + # Create the resource group + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" } + + $ipTag = New-Object -TypeName Microsoft.Azure.Commands.Network.Models.PSPublicIpPrefixTag + $ipTag.IpTagType = $ipTagType + $ipTag.Tag = $ipTagTag + + # Create publicIpPrefix + $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -IpAddressVersion IPv4 -IpTag $ipTag -AsJob + $job | Wait-Job + $actual = $job | Receive-Job + $expected = Get-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname + Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $expected.Name $actual.Name + Assert-AreEqual $expected.Location $actual.Location + Assert-AreEqual 30 $expected.PrefixLength + Assert-NotNull $expected.ResourceGuid + Assert-AreEqual "Succeeded" $expected.ProvisioningState + Assert-AreEqual $ipTagType $expected.IpTags[0].IpTagType + Assert-AreEqual $ipTagTag $expected.IpTags[0].Tag + + # list + $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname + Assert-AreEqual 1 @($list).Count + Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $list[0].Name $actual.Name + Assert-AreEqual $list[0].Location $actual.Location + Assert-AreEqual 30 $list[0].PrefixLength + Assert-AreEqual "Succeeded" $list[0].ProvisioningState + + $expected = Get-AzPublicIpPrefix -ResourceId $actual.Id + Assert-AreEqual 1 @($list).Count + Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $list[0].Name $actual.Name + Assert-AreEqual $list[0].Location $actual.Location + Assert-AreEqual 30 $list[0].PrefixLength + Assert-AreEqual "Succeeded" $list[0].ProvisioningState + + #$list = Get-AzPublicIpPrefix + #Assert-NotNull $list + + <#$list = Get-AzPublicIpPrefix -ResourceGroupName "*" + Assert-True { $list.Count -ge 0 } + + $list = Get-AzPublicIpPrefix -Name "*" + Assert-True { $list.Count -ge 0 } + + $list = Get-AzPublicIpPrefix -ResourceGroupName "*" -Name "*" + Assert-True { $list.Count -ge 0 }#> + + $expected.Tag = @{ testtag = "testvalSet" } + + $job = Set-AzPublicIpPrefix -PublicIpPrefix $expected -AsJob + $job | Wait-Job + $actual = $job | Receive-Job + + # delete + $job = Remove-AzPublicIpPrefix -InputObject $actual -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete + + $list = Get-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual 0 @($list).Count + + # Try setting unexisting + Assert-ThrowsLike { Set-AzPublicIpPrefix -PublicIpPrefix $expected } "*not found*" + + # Create one more time to test deletion with another parameter set + $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -AsJob + $job | Wait-Job + $actual = $job | Receive-Job + + $job = Remove-AzPublicIpPrefix -ResourceId $actual.Id -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete + } + finally + { + # Cleanup + Clean-ResourceGroup $rgname + } +} + +<# +.SYNOPSIS +Tests creating new simple publicIpPrefix and allocating Ip from it. +#> +function Test-PublicIpPrefixAllocatePublicIpAddress +{ + # Setup + $rgname = Get-ResourceGroupName + $rname = Get-ResourceName + $pipname = $rname+"pip" + $domainNameLabel = Get-ResourceName + $rglocation = Get-ProviderLocation ResourceManagement + $resourceTypeParent = "Microsoft.Network/publicIpPrefixes" + $location = Get-ProviderLocation $resourceTypeParent "West Europe" + + try + { + # Create the resource group + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" } + + # Create publicIpPrefix + $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -AsJob + $job | Wait-Job + $actual = $job | Receive-Job + $expected = Get-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname + Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName "AreEqual ResourceGroupName" + Assert-AreEqual $expected.Name $actual.Name "AreEqual Name" + Assert-AreEqual $expected.Location $actual.Location "AreEqual Location" + Assert-AreEqual $expected.PrefixLength $actual.PrefixLength "AreEqual PrefixLength" + Assert-NotNull $expected.ResourceGuid "AreEqual ResourceGuid" + Assert-AreEqual "Succeeded" $expected.ProvisioningState "AreEqual ProvisioningState" + + # list + $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname + Assert-AreEqual 1 @($list).Count "List PublicIpPrefix AreEqual Count 1" + Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName "List PublicIpPrefix AreEqual ResourceGroupName" + Assert-AreEqual $list[0].Name $actual.Name "List PublicIpPrefix AreEqual Name" + Assert-AreEqual $list[0].Location $actual.Location "List PublicIpPrefix AreEqual Location" + Assert-AreEqual 30 $list[0].PrefixLength "List PublicIpPrefix AreEqual PrefixLength 30" + Assert-AreEqual "Succeeded" $list[0].ProvisioningState "List PublicIpPrefix ProvisioningState" + Assert-NotNull $list[0].IPPrefix "List PublicIpPrefix NotNull IPPrefix" + $PublicIpPrefix = $list[0] + + # Allocate publicIpAddress + $job=New-AzPublicIpAddress -ResourceGroupName $rgname -AllocationMethod Static -IpAddressVersion IPv4 -PublicIpPrefix $PublicIpPrefix -ResourceName $pipname -location $location -Sku Standard -DomainNameLabel $domainNameLabel -AsJob + $job | Wait-Job + $actualIpAddress = $job | Receive-Job + $expected = Get-AzPublicIpAddress -ResourceGroupName $rgname -name $pipname + Assert-AreEqual $expected.ResourceGroupName $actualIpAddress.ResourceGroupName "PublicIpAddress AreEqual ResourceGroupName" + Assert-AreEqual $expected.Name $actualIpAddress.Name "PublicIpAddress AreEqual Name" + Assert-AreEqual $expected.Location $actualIpAddress.Location "PublicIpAddress AreEqual Location" + Assert-AreEqual "Static" $expected.PublicIpAllocationMethod "PublicIpAddress AreEqual PublicIpAllocationMethod Static" + Assert-NotNull $expected.ResourceGuid "PublicIpAddress AreEqual ResourceGuid" + Assert-AreEqual "Succeeded" $expected.ProvisioningState "PublicIpAddress AreEqual ProvisioningState Succeeded" + Assert-AreEqual $domainNameLabel $expected.DnsSettings.DomainNameLabel "PublicIpAddress AreEqual DomainNameLabel" + + # list again + $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname + Assert-AreEqual 1 @($list[0].PublicIpAddresses).Count "List2 PublicIpAddresses AreEqual Count 1" + + # delete address - should Succeed + $job = Remove-AzPublicIpAddress -ResourceGroupName $actual.ResourceGroupName -name $pipname -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete "Delete PublicIpAddress failed" + + # delete prefix - should succeed + $job = Remove-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete "Delete PublicIpPrefix failed" + + $list = Get-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual 0 @($list).Count "Hmmmm PublicIpPrefix is still present after delete" + } + finally + { + # Cleanup + Clean-ResourceGroup $rgname + } +} \ No newline at end of file diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index 83c29bc830b1..979d1e28d3d4 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -503,7 +503,6 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'New-AzVirtualApplianceSkuProperty' 'New-AzCustomIpPrefix','Set-AzCustomIpPrefix', 'Get-AzCustomIpPrefix','Remove-AzCustomIpPrefix' ->>>>>>> 18ca1a0bbb... add customIpPrefix cmdlets # Variables to export from this module # VariablesToExport = @() diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs index d40446560375..039441637c2c 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs @@ -25,16 +25,20 @@ namespace Microsoft.Azure.Commands.Network using Microsoft.WindowsAzure.Commands.Utilities.Common; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; - [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PublicIpPrefix", DefaultParameterSetName = GetAzurePublicIpPrefixParameterSetNames.List), OutputType(typeof(PSPublicIpPrefix))] + [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSMasterCustomIpPrefix))] public class GetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet { + private const string ListParameterSet = "ListParameterSet"; + private const string GetByNameParameterSet = "GetByNameParameterSet"; + private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet"; + [Alias("ResourceName")] [Parameter( Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name.", - ParameterSetName = GetAzurePublicIpPrefixParameterSetNames.List)] - [ResourceNameCompleter("Microsoft.Network/publicIPPrefixes", "ResourceGroupName")] + ParameterSetName = GetByNameParameterSet)] + [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string Name { get; set; } @@ -43,7 +47,7 @@ public class GetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.", - ParameterSetName = GetAzurePublicIpPrefixParameterSetNames.List)] + ParameterSetName = GetByNameParameterSet)] [ResourceGroupCompleter] [ValidateNotNullOrEmpty] [SupportsWildcards] @@ -52,7 +56,7 @@ public class GetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - ParameterSetName = GetAzurePublicIpPrefixParameterSetNames.GetByResourceId)] + ParameterSetName = GetByResourceIdParameterSet)] [ValidateNotNullOrEmpty] public virtual string ResourceId { get; set; } @@ -67,52 +71,43 @@ public override void Execute() this.Name = resourceIdentifier.ResourceName; } - if (ShouldGetByName(ResourceGroupName, Name)) + if (ShouldGetByName(this.ResourceGroupName, this.Name)) { - PSPublicIpPrefix publicIpPrefix; + PSMasterCustomIpPrefix psModel; - publicIpPrefix = this.GetPublicIpPrefix(this.ResourceGroupName, this.Name); + psModel = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); - WriteObject(publicIpPrefix); + WriteObject(psModel); } else { - IPage publicipprefixPage; - if (ShouldListByResourceGroup(ResourceGroupName, Name)) + IPage page; + if (ShouldListByResourceGroup(this.ResourceGroupName, this.Name)) { - publicipprefixPage = this.PublicIpPrefixClient.List(this.ResourceGroupName); + page = this.MasterCustomIpPrefixClient.List(this.ResourceGroupName); } else { - publicipprefixPage = this.PublicIpPrefixClient.ListAll(); + page = this.MasterCustomIpPrefixClient.ListAll(); } // Get all resources by polling on next page link - List publicIPPrefixList; + List sdkModelList; - publicIPPrefixList = ListNextLink.GetAllResourcesByPollingNextLink(publicipprefixPage, this.PublicIpPrefixClient.ListNext); + sdkModelList = ListNextLink.GetAllResourcesByPollingNextLink(page, this.MasterCustomIpPrefixClient.ListNext); - var psPublicIpPrefixes = new List(); + var psModelList = new List(); // populate the publicIpPrefixes with the ResourceGroupName - foreach (var publicIpPrefix in publicIPPrefixList) + foreach (var sdkModel in sdkModelList) { - var psPublicIpPrefix = this.ToPsPublicIpPrefix(publicIpPrefix); - psPublicIpPrefix.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(publicIpPrefix.Id); - psPublicIpPrefixes.Add(psPublicIpPrefix); + var psModel = this.ToPsMasterCustomIpPrefix(sdkModel); + psModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(psModel.Id); + psModelList.Add(psModel); } - WriteObject(TopLevelWildcardFilter(ResourceGroupName, Name, psPublicIpPrefixes), true); + WriteObject(TopLevelWildcardFilter(this.ResourceGroupName, this.Name, psModelList), true); } } } - - public static class GetAzurePublicIpPrefixParameterSetNames - { - public const string GetByResourceId = "GetByResourceIdParameterSet"; - public const string List = "ListParameterSet"; - - // The Default - public const string Default = List; - } } diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs index d086099b18b3..a9351466f551 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs @@ -30,26 +30,6 @@ public IMasterCustomIPPrefixesOperations MasterCustomIpPrefixClient } } - public bool IsMasterCustomIpPrefixPresent(string resourceGroupName, string name) - { - try - { - GetMasterCustomIpPrefix(resourceGroupName, name); - } - catch (Microsoft.Rest.Azure.CloudException exception) - { - if (exception.Response.StatusCode == HttpStatusCode.NotFound) - { - // Resource is not present - return false; - } - - throw; - } - - return true; - } - public PSMasterCustomIpPrefix GetMasterCustomIpPrefix(string resourceGroupName, string name, string expandResource = null) { var masterCustomIpPrefix = this.MasterCustomIpPrefixClient.Get(resourceGroupName, name, expandResource); diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs index 48b2021000ef..e1763f328e79 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs @@ -19,10 +19,8 @@ namespace Microsoft.Azure.Commands.Network using Microsoft.Azure.Commands.ResourceManager.Common.Tags; using Microsoft.Azure.Management.Network; using System.Collections; - using System.Linq; using System.Management.Automation; using MNM = Microsoft.Azure.Management.Network.Models; - using System; [Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet @@ -99,52 +97,47 @@ public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle public override void Execute() { base.Execute(); - var resourceExists = NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name)); - - if (resourceExists) - { - throw new System.Exception(string.Format("A MasterCustomIpPrefix with name '{0}' in resource group '{1}' already exists. Please use Set-AzMasterCustomIpPrefix to update an existing MasterCustomIpPrefix.", this.Name, this.ResourceGroupName)); - } - - var psModel = CreateMasterCustomIpPrefix(); - if (psModel != null) - { - WriteObject(psModel); - } + var present = NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name)); + ConfirmAction( + false, + string.Format(Properties.Resources.OverwritingResource, Name), + Properties.Resources.CreatingResourceMessage, + Name, + () => + { + var masterCustomIpPrefix = CreateMasterCustomIpPrefix(); + if (masterCustomIpPrefix != null) + { + WriteObject(masterCustomIpPrefix); + } + }, + () => present); } private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() { - var masterCustomIpPrefix = new PSMasterCustomIpPrefix(); - masterCustomIpPrefix.Name = this.Name; - masterCustomIpPrefix.Location = this.Location; - masterCustomIpPrefix.Geography = this.Geography; - masterCustomIpPrefix.Cidr = this.Cidr; - masterCustomIpPrefix.OriginalValidationMessage = this.ValidationMessage; - masterCustomIpPrefix.SignedValidationMessage = this.SignedValidationMessage; - - - var theModel = NetworkResourceManagerProfile.Mapper.Map(masterCustomIpPrefix); - - theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); - -<<<<<<< HEAD:src/Network/Network/BYOIP/NewAzureMasterCustomIpPrefixCommand.cs - if (this.ShouldProcess(this.Name, $"Creating a new PublicIpPrefix in ResourceGroup {this.ResourceGroupName} with Name {this.Name}")) + var psModel = new PSMasterCustomIpPrefix() { - this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, theModel); + Name = this.Name, + ResourceGroupName = this.ResourceGroupName, + Location = this.Location, + Geography = this.Geography, + Cidr = this.Cidr, + OriginalValidationMessage = this.ValidationMessage, + SignedValidationMessage = this.SignedValidationMessage + }; + + var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); - var getMasterCustomIpPrefix = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); + sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); - return getMasterCustomIpPrefix; -======= if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Creating a new MasterCustomIpPrefix")) { var createdSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); return this.ToPsMasterCustomIpPrefix(createdSdkModel); ->>>>>>> 18ca1a0bbb... add customIpPrefix cmdlets:src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs } return null; } } -} +} \ No newline at end of file diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs index d7940e1587d4..28a582c42b9c 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs @@ -21,16 +21,20 @@ namespace Microsoft.Azure.Commands.Network using Microsoft.WindowsAzure.Commands.Utilities.Common; using System.Management.Automation; - [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PublicIpPrefix", SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.Default), OutputType(typeof(bool))] + [Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true, DefaultParameterSetName = DeleteByNameParameterSet), OutputType(typeof(bool))] public class RemoveAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet { + private const string DeleteByNameParameterSet = "DeleteByNameParameterSet"; + private const string DeleteByInputObjectParameterSet = "DeleteByInputObjectParameterSet"; + private const string DeleteByResourceIdParameterSet = "DeleteByResourceIdParameterSet"; + [Alias("ResourceName")] [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name.", - ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.RemoveByName)] - [ResourceNameCompleter("Microsoft.Network/publicIPPrefixes", "ResourceGroupName")] + ParameterSetName = DeleteByNameParameterSet)] + [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] [ValidateNotNullOrEmpty] public virtual string Name { get; set; } @@ -38,7 +42,7 @@ public class RemoveAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCm Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.", - ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.RemoveByName)] + ParameterSetName = DeleteByNameParameterSet)] [ResourceGroupCompleter] [ValidateNotNullOrEmpty] public virtual string ResourceGroupName { get; set; } @@ -46,19 +50,16 @@ public class RemoveAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCm [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.DeleteByResourceId)] + ParameterSetName = DeleteByResourceIdParameterSet)] [ValidateNotNullOrEmpty] public virtual string ResourceId { get; set; } [Parameter( Mandatory = true, ValueFromPipeline = true, - ParameterSetName = RemoveAzurePublicIpPrefixParameterSetNames.DeleteByInputObject)] + ParameterSetName = DeleteByInputObjectParameterSet)] [ValidateNotNull] - public PSPublicIpPrefix InputObject - { - get; set; - } + public PSMasterCustomIpPrefix InputObject { get; set; } [Parameter( Mandatory = false, @@ -97,7 +98,7 @@ public override void Execute() { if (this.ShouldProcess(this.Name, $"Deleting MasterCustomIpPrefix: {this.Name} in ResourceGroup: {this.ResourceGroupName}")) { - this.PublicIpPrefixClient.Delete(this.ResourceGroupName, this.Name); + this.MasterCustomIpPrefixClient.Delete(this.ResourceGroupName, this.Name); if (PassThru) { WriteObject(true); @@ -106,14 +107,4 @@ public override void Execute() }); } } - - public static class RemoveAzurePublicIpPrefixParameterSetNames - { - public const string RemoveByName = "RemoveByNameParameterSet"; - public const string DeleteByResourceId = "DeleteByResourceIdParameterSet"; - public const string DeleteByInputObject = "DeleteByInputObjectParameterSet"; - - // The Default - public const string Default = RemoveAzurePublicIpPrefixParameterSetNames.RemoveByName; - } } diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs index 1e621b93e762..49c85c491065 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs @@ -14,24 +14,63 @@ namespace Microsoft.Azure.Commands.Network { - using AutoMapper; using Microsoft.Azure.Commands.Network.Models; + using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using Microsoft.Azure.Commands.ResourceManager.Common.Tags; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; using Microsoft.Azure.Management.Network; using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; + using System.Collections; using System.Management.Automation; using MNM = Microsoft.Azure.Management.Network.Models; - [Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "PublicIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSPublicIpPrefix))] + [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] public class SetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet { + private const string SetByNameParameterSet = "SetByNameParameterSet"; + private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; + private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource name.", ParameterSetName = SetByNameParameterSet)] + [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string Name { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource group name.", ParameterSetName = SetByNameParameterSet)] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string ResourceGroupName { get; set; } + [Parameter( Mandatory = true, ValueFromPipeline = true, - HelpMessage = "The PublicIpPrefix")] - public PSPublicIpPrefix PublicIpPrefix { get; set; } + HelpMessage = "The MasterCustomIpPrefix to set.", ParameterSetName = SetByInputObjectParameterSet)] + public PSMasterCustomIpPrefix InputObject { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource Id.", ParameterSetName = SetByResourceIdParameterSet)] + [ValidateNotNullOrEmpty] + [SupportsWildcards] + public virtual string ResourceId { get; set; } + + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "A hashtable which represents resource tags.", + ParameterSetName = SetByNameParameterSet)] + [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] + public Hashtable Tag { get; set; } [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } @@ -40,26 +79,46 @@ public override void Execute() { base.Execute(); - if (!this.IsPublicIpPrefixPresent(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name)) + if (this.IsParameterBound(c => c.ResourceId)) + { + var resourceInfo = new ResourceIdentifier(ResourceId); + this.ResourceGroupName = resourceInfo.ResourceGroupName; + this.Name = resourceInfo.ResourceName; + } + else if (this.IsParameterBound(c => c.InputObject)) + { + this.ResourceGroupName = InputObject.ResourceGroupName; + this.Name = InputObject.Name; + } + + if (!NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name))) { throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); } - // Map to the sdk object - var theModel = NetworkResourceManagerProfile.Mapper.Map(this.PublicIpPrefix); - theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.PublicIpPrefix.Tag, validate: true); - if (this.ShouldProcess(this.PublicIpPrefix.Name, $"Setting PublicIpPrefix Name:{this.PublicIpPrefix.Name} in ResourceGroup: {this.PublicIpPrefix.ResourceGroupName}")) + var psModel = new PSMasterCustomIpPrefix() { - this.PublicIpPrefixClient.CreateOrUpdate(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name, theModel); + Name = InputObject.Name, + ResourceGroupName = InputObject.ResourceGroupName + }; + var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); - var getPublicIpPrefix = this.GetPublicIpPrefix(this.PublicIpPrefix.ResourceGroupName, this.PublicIpPrefix.Name); + if (this.IsParameterBound(c => c.InputObject)) + { + sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.IsParameterBound(c => c.Tag) ? this.Tag : InputObject.Tag, validate: true); + } + else + { + sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); + } if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call - var modifiedSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); - WriteObject(this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name)); + this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + var masterCustomIpPrefix = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); + WriteObject(masterCustomIpPrefix); } } } From cac5f466d405dd1647025baca3ef76262ca6cfe3 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Mon, 27 Jul 2020 12:31:22 -0700 Subject: [PATCH 06/18] updated swagger to allow setting the commissioned state property, corresponding powershell updates --- .../ScenarioTests/CustomIpPrefixTests.cs | 37 +++++ .../MasterCustomIpPrefixTests.cs | 4 +- .../CustomIpPrefixBaseCmdlet.cs | 6 +- .../SetAzureCustomIpPrefixCommand.cs | 18 +-- .../NewAzureMasterCustomIpPrefixCommand.cs | 16 --- .../Network/Models/BYOIP/PSCustomIpPrefix.cs | 6 + .../Models/BYOIP/PSMasterCustomIpPrefix.cs | 6 + .../Network/Models/PSPublicIpPrefix.cs | 2 + src/Network/Network/Network.format.ps1xml | 132 ++++++++++++++++++ .../NewAzurePublicIpPrefixCommand.cs | 8 ++ 10 files changed, 207 insertions(+), 28 deletions(-) create mode 100644 src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs diff --git a/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs new file mode 100644 index 000000000000..a9c48891b254 --- /dev/null +++ b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs @@ -0,0 +1,37 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Network.Test.ScenarioTests; +using Microsoft.WindowsAzure.Commands.ScenarioTest; +using Xunit; + +namespace Commands.Network.Test.ScenarioTests +{ + + public class CustomIpPrefixTests : NetworkTestRunner + { + public CustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output) + : base(output) + { + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)] + public void TestCustomIpPrefixCRUD() + { + TestRunner.RunTestScript("Test-CustomIpPrefixCRUD"); + } + } +} diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs index 1ba47082e1be..13b813735568 100644 --- a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs +++ b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs @@ -13,7 +13,9 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.Network.Test.ScenarioTests; +using Microsoft.Rest.ClientRuntime.Azure.TestFramework; using Microsoft.WindowsAzure.Commands.ScenarioTest; +using System; using Xunit; namespace Commands.Network.Test.ScenarioTests @@ -29,7 +31,7 @@ public MasterCustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output) [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] [Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)] - public void TestPublicIpPrefixCRUD() + public void TestMasterCustomIpPrefixCRUD() { TestRunner.RunTestScript("Test-MasterCustomIpPrefixCRUD"); } diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs index 69fc66cb0469..f9e24b19e654 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs @@ -40,11 +40,11 @@ public PSCustomIpPrefix GetCustomIpPrefix(string resourceGroupName, string name, return psModel; } - public PSCustomIpPrefix ToPsCustomIpPrefix(CustomIpPrefix publicIpPrefix) + public PSCustomIpPrefix ToPsCustomIpPrefix(CustomIpPrefix customIpPrefix) { - var psModel = NetworkResourceManagerProfile.Mapper.Map(publicIpPrefix); + var psModel = NetworkResourceManagerProfile.Mapper.Map(customIpPrefix); - psModel.Tag = TagsConversionHelper.CreateTagHashtable(publicIpPrefix.Tags); + psModel.Tag = TagsConversionHelper.CreateTagHashtable(customIpPrefix.Tags); return psModel; } diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs index 0d7709f5076b..95e1176ed75b 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs @@ -70,11 +70,11 @@ public class SetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet public SwitchParameter Decomission { get; set; } [Parameter( - Mandatory = true, + Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hashtable which represents resource tags.", ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = SetByResourceIdParameterSet)] [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] public Hashtable Tag { get; set; } @@ -108,17 +108,19 @@ public override void Execute() throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.CommissioningStateConflict); } - var psModel = new PSCustomIpPrefix() + PSCustomIpPrefix customIpPrefixToUpdate = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); + + if (customIpPrefixToUpdate == null) { - Name = InputObject.Name, - ResourceGroupName = InputObject.ResourceGroupName - }; + throw new PSArgumentException(Properties.Resources.ResourceNotFound, this.Name); + } + if (Commission || Decomission) { - psModel.CommissionedState = Commission ? "Commissioning" : "Decomissioning"; + customIpPrefixToUpdate.CommissionedState = Commission ? "Commissioning" : "Decomissioning"; } - var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); + var sdkModel = NetworkResourceManagerProfile.Mapper.Map(customIpPrefixToUpdate); if (this.IsParameterBound(c => c.InputObject)) { diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs index e1763f328e79..26e4cfb00069 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs @@ -49,21 +49,6 @@ public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle [ValidateNotNullOrEmpty] public string Location { get; set; } - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The geography of edge routers this prefix range will be advertised on.")] - [ValidateNotNullOrEmpty] - [ValidateSet( - MNM.RIR.NorthAmerica, - MNM.RIR.Europe, - MNM.RIR.Asia, - MNM.RIR.SouthAmerica, - MNM.RIR.Africa, - MNM.RIR.Global, - IgnoreCase = true)] - public string Geography { get; set; } - [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, @@ -121,7 +106,6 @@ private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() Name = this.Name, ResourceGroupName = this.ResourceGroupName, Location = this.Location, - Geography = this.Geography, Cidr = this.Cidr, OriginalValidationMessage = this.ValidationMessage, SignedValidationMessage = this.SignedValidationMessage diff --git a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs index edc90a7e7d23..97b14abba449 100644 --- a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs +++ b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs @@ -30,5 +30,11 @@ public class PSCustomIpPrefix : PSTopLevelResource public List Zones { get; set; } public string ProvisioningState { get; set; } + + [JsonIgnore] + public string MasterCustomIpPrefixText + { + get { return JsonConvert.SerializeObject(MasterCustomIpPrefix, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } + } } } diff --git a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs index 27cb7f72369f..41087f922946 100644 --- a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs +++ b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs @@ -30,5 +30,11 @@ public class PSMasterCustomIpPrefix : PSTopLevelResource public List CustomIpPrefixes { get; set; } public string ValidationState { get; set; } + + [JsonIgnore] + public string CustomIpPrefixesText + { + get { return JsonConvert.SerializeObject(CustomIpPrefixes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } + } } } diff --git a/src/Network/Network/Models/PSPublicIpPrefix.cs b/src/Network/Network/Models/PSPublicIpPrefix.cs index 03d6e14fffa7..d85c109fb5b4 100644 --- a/src/Network/Network/Models/PSPublicIpPrefix.cs +++ b/src/Network/Network/Models/PSPublicIpPrefix.cs @@ -35,6 +35,8 @@ public class PSPublicIpPrefix : PSTopLevelResource public List PublicIpAddresses { get; set; } + public PSResourceId CustomIpPrefix { get; set; } + [JsonIgnore] public string PublicIpAddressesText { diff --git a/src/Network/Network/Network.format.ps1xml b/src/Network/Network/Network.format.ps1xml index 1b4e14954873..c22fd5c2edf4 100644 --- a/src/Network/Network/Network.format.ps1xml +++ b/src/Network/Network/Network.format.ps1xml @@ -1492,6 +1492,138 @@ + + + Microsoft.Azure.Commands.Network.Models.PSMasterCustomIpPrefix + + Microsoft.Azure.Commands.Network.Models.PSMasterCustomIpPrefix + + + + + + + + Name + + + + ResourceGroupName + + + + Location + + + + Id + + + + Etag + + + + ResourceGuid + + + + ProvisioningState + + + + TagsTable + + + + Cidr + + + + ValidationState + + + + OriginalValidationMessage + + + + SignedValidationMessage + + + + CustomIpPrefixesText + + + + Zones + + + + + + + + Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + + Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + + + + + + + + Name + + + + ResourceGroupName + + + + Location + + + + Id + + + + Etag + + + + ResourceGuid + + + + ProvisioningState + + + + TagsTable + + + + Cidr + + + + CommissionedState + + + + MasterCustomIpPrefixText + + + + Zones + + + + + Microsoft.Azure.Commands.Network.Models.PSPublicIpPrefix diff --git a/src/Network/Network/PublicIpPrefix/NewAzurePublicIpPrefixCommand.cs b/src/Network/Network/PublicIpPrefix/NewAzurePublicIpPrefixCommand.cs index 6dd865e2ee2b..6494f3449007 100644 --- a/src/Network/Network/PublicIpPrefix/NewAzurePublicIpPrefixCommand.cs +++ b/src/Network/Network/PublicIpPrefix/NewAzurePublicIpPrefixCommand.cs @@ -96,6 +96,12 @@ public class NewAzurePublicIpPrefixCommand : PublicIpPrefixBaseCmdlet ValueFromPipelineByPropertyName = true)] public string[] Zone { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The CustomIpPrefix that this PublicIpPrefix will be associated with")] + public PSCustomIpPrefix CustomIpPrefix { get; set; } + [Parameter( Mandatory = false, ValueFromPipelineByPropertyName = true, @@ -165,6 +171,8 @@ private PSPublicIpPrefix CreatePublicIpPrefix() publicIpPrefix.IpTags = this.IpTag?.ToList(); } + publicIpPrefix.CustomIpPrefix = this.CustomIpPrefix; + var theModel = NetworkResourceManagerProfile.Mapper.Map(publicIpPrefix); theModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); From df074a27d60d4ca8631710e8ef7424f0ddd96838 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Tue, 28 Jul 2020 16:26:28 -0700 Subject: [PATCH 07/18] cherrypick #4 --- .../ScenarioTests/CustomIpPrefixTests.ps1 | 97 ++++++++++ .../MasterCustomIpPrefixTests.ps1 | 179 +++--------------- .../CustomIpPrefixBaseCmdlet.cs | 2 +- .../NewAzureCustomIpPrefixCommand.cs | 7 +- .../SetAzureCustomIpPrefixCommand.cs | 9 +- .../MasterCustomIpPrefixBaseCmdlet.cs | 2 +- .../NewAzureMasterCustomIpPrefixCommand.cs | 4 +- .../SetAzureMasterCustomIpPrefixCommand.cs | 43 +++-- .../Network/Models/BYOIP/PSCustomIpPrefix.cs | 6 + src/Network/Network/Network.format.ps1xml | 8 +- 10 files changed, 181 insertions(+), 176 deletions(-) create mode 100644 src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 diff --git a/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 new file mode 100644 index 000000000000..d859f85afb08 --- /dev/null +++ b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 @@ -0,0 +1,97 @@ +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +<# +.SYNOPSIS +Tests CRUD operations on a simple customIpPrefix. +#> +function Test-CustomIpPrefixCRUD +{ + # Setup + $rgname = "powershell-test-rg" + $rname = "testCip" + + # currently in private preview, updated binaries are on test slice in canary only + $location = "eastus2euap" + + try + { + # Create the resource group + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" } + + # Create the masterCustomIpPrefix + $job = New-AzMasterCustomIpPrefix -Name $rname -ResourceGroupName $rgname -Cidr "40.40.40.0/22" -ValidationMessage "123" -SignedValidationMessage "456" -Location $location -AsJob + $job | Wait-Job + $mcip = $job | Receive-Job + + # Create customIpPrefix + $job = New-AzCustomIpPrefix -Name $rname -ResourceGroupName $rgname -location $location -Cidr "40.40.40.0/24" -MasterCustomIpPrefix $mcip -AsJob + $job | Wait-Job + $actual = $job | Receive-Job + $expected = Get-AzCustomIpPrefix -ResourceGroupName $rgname -name $rname + Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $expected.Name $actual.Name + Assert-AreEqual $expected.Location $actual.Location + Assert-AreEqual $expected.Cidr $actual.Cidr + Assert-AreEqual 0 $expected.PublicIpPrefixes.Count + Assert-NotNull $expected.ResourceGuid + Assert-AreEqual "Succeeded" $expected.ProvisioningState + + # list + $list = Get-AzCustomIpPrefix -ResourceGroupName $rgname + Assert-AreEqual 1 @($list).Count + Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $list[0].Name $actual.Name + Assert-AreEqual $list[0].Location $actual.Location + Assert-AreEqual $list[0].Cidr $actual.Cidr + Assert-AreEqual $list[0].PublicIpPrefixes.Count 0 + Assert-AreEqual "Succeeded" $list[0].ProvisioningState + + $list = Get-AzCustomIpPrefix -ResourceId $actual.Id + Assert-AreEqual 1 @($list).Count + Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $list[0].Name $actual.Name + Assert-AreEqual $list[0].Location $actual.Location + Assert-AreEqual $list[0].Cidr $actual.Cidr + Assert-AreEqual $list[0].PublicIpPrefixes.Count 0 + Assert-AreEqual "Succeeded" $list[0].ProvisioningState + + # delete + $job = Remove-AzCustomIpPrefix -InputObject $actual -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete + + $list = Get-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual 0 @($list).Count + + # Try setting unexisting + Assert-ThrowsLike { Set-AzPublicIpPrefix -PublicIpPrefix $expected } "*not found*" + + # Create one more time to test deletion with another parameter set + $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -AsJob + $job | Wait-Job + $actual = $job | Receive-Job + + $job = Remove-AzPublicIpPrefix -ResourceId $actual.Id -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete + } + finally + { + # Cleanup + Clean-ResourceGroup $rgname + } +} \ No newline at end of file diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 index d90b36077015..18cca7422655 100644 --- a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 @@ -14,180 +14,57 @@ <# .SYNOPSIS -Tests creating new simple masterCustomIpPrefix. +Tests CRUD operations on a simple masterCustomIpPrefix. #> function Test-MasterCustomIpPrefixCRUD { # Setup - $rgname = Get-ResourceGroupName - $rname = Get-ResourceName - $rglocation = Get-ProviderLocation ResourceManagement - $resourceTypeParent = "Microsoft.Network/publicIpPrefixes" - $location = Get-ProviderLocation $resourceTypeParent "West Europe" - $ipTagType = "NetworkDomain" - $ipTagTag = "test" + $rgname = "powershell-test-rg" + $rname = "testMcip" + + # currently in private preview, updated binaries are on test slice in canary only + $location = "eastus2euap" try { # Create the resource group - $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" } - - $ipTag = New-Object -TypeName Microsoft.Azure.Commands.Network.Models.PSPublicIpPrefixTag - $ipTag.IpTagType = $ipTagType - $ipTag.Tag = $ipTagTag - - # Create publicIpPrefix - $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -IpAddressVersion IPv4 -IpTag $ipTag -AsJob + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $location + + # Create masterCustomIpPrefix + $job = New-AzMasterCustomIpPrefix -Name $rname -ResourceGroupName $rgname -Cidr "40.40.40.0/22" -ValidationMessage "123" -SignedValidationMessage "456" -Location $location -AsJob $job | Wait-Job $actual = $job | Receive-Job - $expected = Get-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname - Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $expected.Name $actual.Name + $expected = Get-AzMasterCustomIpPrefix -ResourceGroupName $rgname -Name $rname + Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $expected.Name $actual.Name Assert-AreEqual $expected.Location $actual.Location - Assert-AreEqual 30 $expected.PrefixLength + Assert-AreEqual $expected.Cidr $actual.Cidr + Assert-AreEqual $expected.ValidationMessage $actual.ValidationMessage + Assert-AreEqual $expected.SignedValidationMessage $actual.SignedValidationMessage + Assert-AreEqual $expected.ValidationState "Validating" + Assert-AreEqual 0 $expected.CustomIpPrefixes.Count Assert-NotNull $expected.ResourceGuid Assert-AreEqual "Succeeded" $expected.ProvisioningState - Assert-AreEqual $ipTagType $expected.IpTags[0].IpTagType - Assert-AreEqual $ipTagTag $expected.IpTags[0].Tag # list - $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname - Assert-AreEqual 1 @($list).Count - Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $list[0].Name $actual.Name - Assert-AreEqual $list[0].Location $actual.Location - Assert-AreEqual 30 $list[0].PrefixLength - Assert-AreEqual "Succeeded" $list[0].ProvisioningState - - $expected = Get-AzPublicIpPrefix -ResourceId $actual.Id + $list = Get-AzMasterCustomIpPrefix -ResourceGroupName $rgname Assert-AreEqual 1 @($list).Count - Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $list[0].Name $actual.Name + Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName + Assert-AreEqual $list[0].Name $actual.Name Assert-AreEqual $list[0].Location $actual.Location - Assert-AreEqual 30 $list[0].PrefixLength + Assert-AreEqual $list[0].Cidr $actual.Cidr + Assert-AreEqual $list[0].ValidationMessage $actual.ValidationMessage + Assert-AreEqual $list[0].SignedValidationMessage $actual.SignedValidationMessage Assert-AreEqual "Succeeded" $list[0].ProvisioningState - - #$list = Get-AzPublicIpPrefix - #Assert-NotNull $list - - <#$list = Get-AzPublicIpPrefix -ResourceGroupName "*" - Assert-True { $list.Count -ge 0 } - - $list = Get-AzPublicIpPrefix -Name "*" - Assert-True { $list.Count -ge 0 } - - $list = Get-AzPublicIpPrefix -ResourceGroupName "*" -Name "*" - Assert-True { $list.Count -ge 0 }#> - - $expected.Tag = @{ testtag = "testvalSet" } - - $job = Set-AzPublicIpPrefix -PublicIpPrefix $expected -AsJob - $job | Wait-Job - $actual = $job | Receive-Job - + # delete - $job = Remove-AzPublicIpPrefix -InputObject $actual -PassThru -Force -AsJob + $job = Remove-AzMasterCustomIpPrefix -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob $job | Wait-Job $delete = $job | Receive-Job Assert-AreEqual true $delete - - $list = Get-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName + + $list = Get-AzMasterCustomIpPrefix -ResourceGroupName $actual.ResourceGroupName Assert-AreEqual 0 @($list).Count - - # Try setting unexisting - Assert-ThrowsLike { Set-AzPublicIpPrefix -PublicIpPrefix $expected } "*not found*" - - # Create one more time to test deletion with another parameter set - $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -AsJob - $job | Wait-Job - $actual = $job | Receive-Job - - $job = Remove-AzPublicIpPrefix -ResourceId $actual.Id -PassThru -Force -AsJob - $job | Wait-Job - $delete = $job | Receive-Job - Assert-AreEqual true $delete - } - finally - { - # Cleanup - Clean-ResourceGroup $rgname - } -} - -<# -.SYNOPSIS -Tests creating new simple publicIpPrefix and allocating Ip from it. -#> -function Test-PublicIpPrefixAllocatePublicIpAddress -{ - # Setup - $rgname = Get-ResourceGroupName - $rname = Get-ResourceName - $pipname = $rname+"pip" - $domainNameLabel = Get-ResourceName - $rglocation = Get-ProviderLocation ResourceManagement - $resourceTypeParent = "Microsoft.Network/publicIpPrefixes" - $location = Get-ProviderLocation $resourceTypeParent "West Europe" - - try - { - # Create the resource group - $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" } - - # Create publicIpPrefix - $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -AsJob - $job | Wait-Job - $actual = $job | Receive-Job - $expected = Get-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname - Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName "AreEqual ResourceGroupName" - Assert-AreEqual $expected.Name $actual.Name "AreEqual Name" - Assert-AreEqual $expected.Location $actual.Location "AreEqual Location" - Assert-AreEqual $expected.PrefixLength $actual.PrefixLength "AreEqual PrefixLength" - Assert-NotNull $expected.ResourceGuid "AreEqual ResourceGuid" - Assert-AreEqual "Succeeded" $expected.ProvisioningState "AreEqual ProvisioningState" - - # list - $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname - Assert-AreEqual 1 @($list).Count "List PublicIpPrefix AreEqual Count 1" - Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName "List PublicIpPrefix AreEqual ResourceGroupName" - Assert-AreEqual $list[0].Name $actual.Name "List PublicIpPrefix AreEqual Name" - Assert-AreEqual $list[0].Location $actual.Location "List PublicIpPrefix AreEqual Location" - Assert-AreEqual 30 $list[0].PrefixLength "List PublicIpPrefix AreEqual PrefixLength 30" - Assert-AreEqual "Succeeded" $list[0].ProvisioningState "List PublicIpPrefix ProvisioningState" - Assert-NotNull $list[0].IPPrefix "List PublicIpPrefix NotNull IPPrefix" - $PublicIpPrefix = $list[0] - - # Allocate publicIpAddress - $job=New-AzPublicIpAddress -ResourceGroupName $rgname -AllocationMethod Static -IpAddressVersion IPv4 -PublicIpPrefix $PublicIpPrefix -ResourceName $pipname -location $location -Sku Standard -DomainNameLabel $domainNameLabel -AsJob - $job | Wait-Job - $actualIpAddress = $job | Receive-Job - $expected = Get-AzPublicIpAddress -ResourceGroupName $rgname -name $pipname - Assert-AreEqual $expected.ResourceGroupName $actualIpAddress.ResourceGroupName "PublicIpAddress AreEqual ResourceGroupName" - Assert-AreEqual $expected.Name $actualIpAddress.Name "PublicIpAddress AreEqual Name" - Assert-AreEqual $expected.Location $actualIpAddress.Location "PublicIpAddress AreEqual Location" - Assert-AreEqual "Static" $expected.PublicIpAllocationMethod "PublicIpAddress AreEqual PublicIpAllocationMethod Static" - Assert-NotNull $expected.ResourceGuid "PublicIpAddress AreEqual ResourceGuid" - Assert-AreEqual "Succeeded" $expected.ProvisioningState "PublicIpAddress AreEqual ProvisioningState Succeeded" - Assert-AreEqual $domainNameLabel $expected.DnsSettings.DomainNameLabel "PublicIpAddress AreEqual DomainNameLabel" - - # list again - $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname - Assert-AreEqual 1 @($list[0].PublicIpAddresses).Count "List2 PublicIpAddresses AreEqual Count 1" - - # delete address - should Succeed - $job = Remove-AzPublicIpAddress -ResourceGroupName $actual.ResourceGroupName -name $pipname -PassThru -Force -AsJob - $job | Wait-Job - $delete = $job | Receive-Job - Assert-AreEqual true $delete "Delete PublicIpAddress failed" - - # delete prefix - should succeed - $job = Remove-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob - $job | Wait-Job - $delete = $job | Receive-Job - Assert-AreEqual true $delete "Delete PublicIpPrefix failed" - - $list = Get-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual 0 @($list).Count "Hmmmm PublicIpPrefix is still present after delete" } finally { diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs index f9e24b19e654..d7566500d63b 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/CustomIpPrefixBaseCmdlet.cs @@ -35,7 +35,7 @@ public PSCustomIpPrefix GetCustomIpPrefix(string resourceGroupName, string name, var sdkModel = this.CustomIpPrefixClient.Get(resourceGroupName, name, expandResource); var psModel = ToPsCustomIpPrefix(sdkModel); - //psMasterCustomIpPrefix.ResourceGroupName = resourceGroupName; + psModel.ResourceGroupName = resourceGroupName; return psModel; } diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs index 5f6489ebaf9e..959cbe792001 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs @@ -113,8 +113,11 @@ private PSCustomIpPrefix CreateCustomIpPrefix() if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Create new MasterCustomIpPrefix")) { - var createdSdkModel = this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); - return this.ToPsCustomIpPrefix(createdSdkModel); + this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + + var customIpPrefix = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); + + return customIpPrefix; } return null; diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs index 95e1176ed75b..0a48fdd1a15e 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs @@ -53,7 +53,7 @@ public class SetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet Mandatory = true, ValueFromPipeline = true, HelpMessage = "The MasterCustomIpPrefix to set.", ParameterSetName = SetByInputObjectParameterSet)] - public PSMasterCustomIpPrefix InputObject { get; set; } + public PSCustomIpPrefix InputObject { get; set; } [Parameter( Mandatory = true, @@ -134,8 +134,11 @@ public override void Execute() if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call - var modifiedSdkModel = this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); - WriteObject(this.ToPsCustomIpPrefix(modifiedSdkModel)); + this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + + var customIpPrefix = this.GetCustomIpPrefix(this.ResourceGroupName, this.Name); + + WriteObject(customIpPrefix); } } } diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs index a9351466f551..581dbc3ca5d0 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs @@ -35,7 +35,7 @@ public PSMasterCustomIpPrefix GetMasterCustomIpPrefix(string resourceGroupName, var masterCustomIpPrefix = this.MasterCustomIpPrefixClient.Get(resourceGroupName, name, expandResource); var psMasterCustomIpPrefix = ToPsMasterCustomIpPrefix(masterCustomIpPrefix); - //psMasterCustomIpPrefix.ResourceGroupName = resourceGroupName; + psMasterCustomIpPrefix.ResourceGroupName = resourceGroupName; return psMasterCustomIpPrefix; } diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs index 26e4cfb00069..0dc1fd7729f5 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs @@ -118,7 +118,9 @@ private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Creating a new MasterCustomIpPrefix")) { var createdSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); - return this.ToPsMasterCustomIpPrefix(createdSdkModel); + var createdPsModel = this.ToPsMasterCustomIpPrefix(createdSdkModel); + createdPsModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(createdPsModel.Id); + return createdPsModel; } return null; diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs index 49c85c491065..bc51093b5582 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs @@ -33,36 +33,50 @@ public class SetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; [Parameter( - Mandatory = true, + Mandatory = false, ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource name.", ParameterSetName = SetByNameParameterSet)] + HelpMessage = "The resource name.", + ParameterSetName = SetByNameParameterSet)] [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string Name { get; set; } [Parameter( - Mandatory = true, + Mandatory = false, ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource group name.", ParameterSetName = SetByNameParameterSet)] + HelpMessage = "The resource group name.", + ParameterSetName = SetByNameParameterSet)] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string ResourceGroupName { get; set; } [Parameter( - Mandatory = true, + Mandatory = false, ValueFromPipeline = true, - HelpMessage = "The MasterCustomIpPrefix to set.", ParameterSetName = SetByInputObjectParameterSet)] + HelpMessage = "The MasterCustomIpPrefix to set.", + ParameterSetName = SetByInputObjectParameterSet)] public PSMasterCustomIpPrefix InputObject { get; set; } [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource Id.", ParameterSetName = SetByResourceIdParameterSet)] + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource Id.", + ParameterSetName = SetByResourceIdParameterSet)] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string ResourceId { get; set; } + [Parameter( + Mandatory = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The MasterCustomIpPrefix location.", + ParameterSetName = SetByResourceIdParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] + [LocationCompleter("Microsoft.Network/masterCustomIpPrefix")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, @@ -89,6 +103,7 @@ public override void Execute() { this.ResourceGroupName = InputObject.ResourceGroupName; this.Name = InputObject.Name; + this.Location = this.IsParameterBound(c => c.Location) ? Location : InputObject.Location; } if (!NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name))) @@ -100,7 +115,8 @@ public override void Execute() var psModel = new PSMasterCustomIpPrefix() { Name = InputObject.Name, - ResourceGroupName = InputObject.ResourceGroupName + ResourceGroupName = InputObject.ResourceGroupName, + Location = this.Location, }; var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); @@ -116,9 +132,10 @@ public override void Execute() if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call - this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); - var masterCustomIpPrefix = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); - WriteObject(masterCustomIpPrefix); + var modifiedSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + var modifiedPsModel = this.ToPsMasterCustomIpPrefix(modifiedSdkModel); + modifiedPsModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(modifiedPsModel.Id); + WriteObject(modifiedPsModel); } } } diff --git a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs index 97b14abba449..1b92e222816d 100644 --- a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs +++ b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs @@ -36,5 +36,11 @@ public string MasterCustomIpPrefixText { get { return JsonConvert.SerializeObject(MasterCustomIpPrefix, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } } + + [JsonIgnore] + public string PublicIpPrefixesText + { + get { return JsonConvert.SerializeObject(PublicIpPrefixes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } + } } } diff --git a/src/Network/Network/Network.format.ps1xml b/src/Network/Network/Network.format.ps1xml index c22fd5c2edf4..5152b425a577 100644 --- a/src/Network/Network/Network.format.ps1xml +++ b/src/Network/Network/Network.format.ps1xml @@ -1554,10 +1554,6 @@ CustomIpPrefixesText - - - Zones - @@ -1615,6 +1611,10 @@ MasterCustomIpPrefixText + + + + PublicIpPrefixesText From b83c2bdce4b56bf6566f71d597aabacbedc6de92 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Wed, 29 Jul 2020 11:57:55 -0700 Subject: [PATCH 08/18] cherrypick #5 --- ...teAzureMasterCustomIpPrefixTagsCommand.cs} | 62 +++++++++---------- 1 file changed, 29 insertions(+), 33 deletions(-) rename src/Network/Network/BYOIP/MasterCustomIpPrefix/{SetAzureMasterCustomIpPrefixCommand.cs => UpdateAzureMasterCustomIpPrefixTagsCommand.cs} (68%) diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs similarity index 68% rename from src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs rename to src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs index bc51093b5582..11e7935202ee 100644 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/SetAzureMasterCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs @@ -19,24 +19,26 @@ namespace Microsoft.Azure.Commands.Network using Microsoft.Azure.Commands.ResourceManager.Common.Tags; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; using Microsoft.Azure.Management.Network; + using Microsoft.Azure.Management.Network.Models; using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; using System.Collections; using System.Management.Automation; using MNM = Microsoft.Azure.Management.Network.Models; - [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] - public class SetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet + [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefixTags", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] + public class UpdateAzureMasterCustomIpPrefixTagsCommand : MasterCustomIpPrefixBaseCmdlet { - private const string SetByNameParameterSet = "SetByNameParameterSet"; - private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; - private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; + private const string UpdateByNameParameterSet = "UpdateByNameParameterSet"; + private const string UpdateByInputObjectParameterSet = "UpdateByInputObjectParameterSet"; + private const string UpdateByResourceIdParameterSet = "UpdateByResourceIdParameterSet"; + [Alias("ResourceName")] [Parameter( Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name.", - ParameterSetName = SetByNameParameterSet)] + ParameterSetName = UpdateByNameParameterSet)] [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] [ValidateNotNullOrEmpty] [SupportsWildcards] @@ -46,7 +48,7 @@ public class SetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.", - ParameterSetName = SetByNameParameterSet)] + ParameterSetName = UpdateByNameParameterSet)] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string ResourceGroupName { get; set; } @@ -55,35 +57,25 @@ public class SetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdle Mandatory = false, ValueFromPipeline = true, HelpMessage = "The MasterCustomIpPrefix to set.", - ParameterSetName = SetByInputObjectParameterSet)] + ParameterSetName = UpdateByInputObjectParameterSet)] public PSMasterCustomIpPrefix InputObject { get; set; } [Parameter( Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource Id.", - ParameterSetName = SetByResourceIdParameterSet)] + ParameterSetName = UpdateByResourceIdParameterSet)] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string ResourceId { get; set; } - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The MasterCustomIpPrefix location.", - ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] - [LocationCompleter("Microsoft.Network/masterCustomIpPrefix")] - [ValidateNotNullOrEmpty] - public string Location { get; set; } - [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A hashtable which represents resource tags.", - ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] + ParameterSetName = UpdateByNameParameterSet)] + [Parameter(Mandatory = true, ParameterSetName = UpdateByResourceIdParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = UpdateByInputObjectParameterSet)] public Hashtable Tag { get; set; } [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] @@ -103,21 +95,24 @@ public override void Execute() { this.ResourceGroupName = InputObject.ResourceGroupName; this.Name = InputObject.Name; - this.Location = this.IsParameterBound(c => c.Location) ? Location : InputObject.Location; } - if (!NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name))) + PSMasterCustomIpPrefix psModel; + if (this.IsParameterBound(c => c.InputObject)) { - throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound); + psModel = InputObject; } - - - var psModel = new PSMasterCustomIpPrefix() + else { - Name = InputObject.Name, - ResourceGroupName = InputObject.ResourceGroupName, - Location = this.Location, - }; + var existingPsModel = GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); + + psModel = new PSMasterCustomIpPrefix() + { + Name = this.Name, + ResourceGroupName = this.ResourceGroupName, + Location = existingPsModel.Location, + }; + } var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); if (this.IsParameterBound(c => c.InputObject)) @@ -132,7 +127,8 @@ public override void Execute() if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call - var modifiedSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); + TagsObject tagsObj = new TagsObject(sdkModel.Tags); + var modifiedSdkModel = this.MasterCustomIpPrefixClient.UpdateTags(this.ResourceGroupName, this.Name, tagsObj); var modifiedPsModel = this.ToPsMasterCustomIpPrefix(modifiedSdkModel); modifiedPsModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(modifiedPsModel.Id); WriteObject(modifiedPsModel); From e988093f844f1df0269037bf39d30f96353a82e7 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Wed, 29 Jul 2020 12:09:51 -0700 Subject: [PATCH 09/18] update MasterCustomIpPrefix test --- .../MasterCustomIpPrefixTests.ps1 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 index 18cca7422655..cc8251f2751c 100644 --- a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 @@ -42,9 +42,9 @@ function Test-MasterCustomIpPrefixCRUD Assert-AreEqual $expected.ValidationMessage $actual.ValidationMessage Assert-AreEqual $expected.SignedValidationMessage $actual.SignedValidationMessage Assert-AreEqual $expected.ValidationState "Validating" - Assert-AreEqual 0 $expected.CustomIpPrefixes.Count - Assert-NotNull $expected.ResourceGuid - Assert-AreEqual "Succeeded" $expected.ProvisioningState + Assert-AreEqual $expected.CustomIpPrefixes.Count 0 + Assert-NotNull $expected.ResourceGuid + Assert-AreEqual $expected.ProvisioningState "Succeeded" # list $list = Get-AzMasterCustomIpPrefix -ResourceGroupName $rgname @@ -55,8 +55,17 @@ function Test-MasterCustomIpPrefixCRUD Assert-AreEqual $list[0].Cidr $actual.Cidr Assert-AreEqual $list[0].ValidationMessage $actual.ValidationMessage Assert-AreEqual $list[0].SignedValidationMessage $actual.SignedValidationMessage - Assert-AreEqual "Succeeded" $list[0].ProvisioningState - + Assert-AreEqual $list[0].CustomIpPrefixes.Count 0 + Assert-NotNull $list[0].ResourceGuid + Assert-AreEqual $list[0].ProvisioningState "Succeeded" + + # update tags + $tags = @{"test" = "tag"} + $job = Update-AzMasterCustomIpPrefix -ResourceGroupName $rgname -Name $rname -Tag $tags -AsJob + $job | Wait-Job + $updatedPrefix = $job | Receive-Job + Assert-AreEqual $updatedPrefix.Tag $tag + # delete $job = Remove-AzMasterCustomIpPrefix -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob $job | Wait-Job From 9d9664898b561f375dbe85076b034d8b42800ee4 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Tue, 4 Aug 2020 16:11:43 -0700 Subject: [PATCH 10/18] cherrypick #6 --- .../MasterCustomIpPrefixTests.cs | 39 ----- .../MasterCustomIpPrefixTests.ps1 | 83 ----------- .../GetAzureCustomIpPrefixCommand.cs | 2 +- .../NewAzureCustomIpPrefixCommand.cs | 7 - .../SetAzureCustomIpPrefixCommand.cs | 2 +- .../GetAzureMasterCustomIpPrefixCommand.cs | 113 -------------- .../MasterCustomIpPrefixBaseCmdlet.cs | 52 ------- .../RemoveAzureMasterCustomIpPrefixCommand.cs | 110 -------------- ...ateAzureMasterCustomIpPrefixTagsCommand.cs | 138 ------------------ .../Common/NetworkResourceManagerProfile.cs | 4 +- .../Network/Models/BYOIP/PSCustomIpPrefix.cs | 8 - .../Models/BYOIP/PSMasterCustomIpPrefix.cs | 40 ----- src/Network/Network/Network.format.ps1xml | 70 +-------- 13 files changed, 5 insertions(+), 663 deletions(-) delete mode 100644 src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs delete mode 100644 src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 delete mode 100644 src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs delete mode 100644 src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs delete mode 100644 src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs delete mode 100644 src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs delete mode 100644 src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs deleted file mode 100644 index 13b813735568..000000000000 --- a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.cs +++ /dev/null @@ -1,39 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -using Microsoft.Azure.Commands.Network.Test.ScenarioTests; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using Xunit; - -namespace Commands.Network.Test.ScenarioTests -{ - - public class MasterCustomIpPrefixTests : NetworkTestRunner - { - public MasterCustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output) - : base(output) - { - } - - [Fact] - [Trait(Category.AcceptanceType, Category.CheckIn)] - [Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)] - public void TestMasterCustomIpPrefixCRUD() - { - TestRunner.RunTestScript("Test-MasterCustomIpPrefixCRUD"); - } - } -} diff --git a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 b/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 deleted file mode 100644 index cc8251f2751c..000000000000 --- a/src/Network/Network.Test/ScenarioTests/MasterCustomIpPrefixTests.ps1 +++ /dev/null @@ -1,83 +0,0 @@ -# ---------------------------------------------------------------------------------- -# -# Copyright Microsoft Corporation -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ---------------------------------------------------------------------------------- - -<# -.SYNOPSIS -Tests CRUD operations on a simple masterCustomIpPrefix. -#> -function Test-MasterCustomIpPrefixCRUD -{ - # Setup - $rgname = "powershell-test-rg" - $rname = "testMcip" - - # currently in private preview, updated binaries are on test slice in canary only - $location = "eastus2euap" - - try - { - # Create the resource group - $resourceGroup = New-AzResourceGroup -Name $rgname -Location $location - - # Create masterCustomIpPrefix - $job = New-AzMasterCustomIpPrefix -Name $rname -ResourceGroupName $rgname -Cidr "40.40.40.0/22" -ValidationMessage "123" -SignedValidationMessage "456" -Location $location -AsJob - $job | Wait-Job - $actual = $job | Receive-Job - $expected = Get-AzMasterCustomIpPrefix -ResourceGroupName $rgname -Name $rname - Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $expected.Name $actual.Name - Assert-AreEqual $expected.Location $actual.Location - Assert-AreEqual $expected.Cidr $actual.Cidr - Assert-AreEqual $expected.ValidationMessage $actual.ValidationMessage - Assert-AreEqual $expected.SignedValidationMessage $actual.SignedValidationMessage - Assert-AreEqual $expected.ValidationState "Validating" - Assert-AreEqual $expected.CustomIpPrefixes.Count 0 - Assert-NotNull $expected.ResourceGuid - Assert-AreEqual $expected.ProvisioningState "Succeeded" - - # list - $list = Get-AzMasterCustomIpPrefix -ResourceGroupName $rgname - Assert-AreEqual 1 @($list).Count - Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $list[0].Name $actual.Name - Assert-AreEqual $list[0].Location $actual.Location - Assert-AreEqual $list[0].Cidr $actual.Cidr - Assert-AreEqual $list[0].ValidationMessage $actual.ValidationMessage - Assert-AreEqual $list[0].SignedValidationMessage $actual.SignedValidationMessage - Assert-AreEqual $list[0].CustomIpPrefixes.Count 0 - Assert-NotNull $list[0].ResourceGuid - Assert-AreEqual $list[0].ProvisioningState "Succeeded" - - # update tags - $tags = @{"test" = "tag"} - $job = Update-AzMasterCustomIpPrefix -ResourceGroupName $rgname -Name $rname -Tag $tags -AsJob - $job | Wait-Job - $updatedPrefix = $job | Receive-Job - Assert-AreEqual $updatedPrefix.Tag $tag - - # delete - $job = Remove-AzMasterCustomIpPrefix -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob - $job | Wait-Job - $delete = $job | Receive-Job - Assert-AreEqual true $delete - - $list = Get-AzMasterCustomIpPrefix -ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual 0 @($list).Count - } - finally - { - # Cleanup - Clean-ResourceGroup $rgname - } -} \ No newline at end of file diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs index 677d59444ef7..59810cd267f9 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.Network using Microsoft.WindowsAzure.Commands.Utilities.Common; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; - [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSMasterCustomIpPrefix))] + [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSCustomIpPrefix))] public class GetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet { private const string ListParameterSet = "ListParameterSet"; diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs index 959cbe792001..8706b2dd6973 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs @@ -42,12 +42,6 @@ public class NewAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [ValidateNotNullOrEmpty] public virtual string ResourceGroupName { get; set; } - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The MasterCustomIpPrefix that this CustomIpPrefix is associated with")] - public PSMasterCustomIpPrefix MasterCustomIpPrefix { get; set; } - [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, @@ -102,7 +96,6 @@ private PSCustomIpPrefix CreateCustomIpPrefix() Name = this.Name, ResourceGroupName = this.ResourceGroupName, Location = this.Location, - MasterCustomIpPrefix = this.MasterCustomIpPrefix, Cidr = this.Cidr, Zones = this.Zone?.ToList() }; diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs index 0a48fdd1a15e..1eb7247a443a 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.Network using System.Management.Automation; using MNM = Microsoft.Azure.Management.Network.Models; - [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] + [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSCustomIpPrefix))] public class SetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet { private const string SetByNameParameterSet = "SetByNameParameterSet"; diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs deleted file mode 100644 index 039441637c2c..000000000000 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/GetAzureMasterCustomIpPrefixCommand.cs +++ /dev/null @@ -1,113 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.Commands.Network -{ - using Microsoft.Azure.Commands.Network.Models; - using Microsoft.Azure.Commands.ResourceManager.Common.Tags; - using Microsoft.Azure.Management.Network; - using System.Collections.Generic; - using System.Management.Automation; - using Microsoft.Azure.Management.Network.Models; - using Microsoft.Rest.Azure; - using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; - using Microsoft.WindowsAzure.Commands.Utilities.Common; - using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; - - [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSMasterCustomIpPrefix))] - public class GetAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet - { - private const string ListParameterSet = "ListParameterSet"; - private const string GetByNameParameterSet = "GetByNameParameterSet"; - private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet"; - - [Alias("ResourceName")] - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource name.", - ParameterSetName = GetByNameParameterSet)] - [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] - [ValidateNotNullOrEmpty] - [SupportsWildcards] - public virtual string Name { get; set; } - - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource group name.", - ParameterSetName = GetByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - [SupportsWildcards] - public virtual string ResourceGroupName { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - ParameterSetName = GetByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public virtual string ResourceId { get; set; } - - public override void Execute() - { - base.Execute(); - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.Name = resourceIdentifier.ResourceName; - } - - if (ShouldGetByName(this.ResourceGroupName, this.Name)) - { - PSMasterCustomIpPrefix psModel; - - psModel = this.GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); - - WriteObject(psModel); - } - else - { - IPage page; - if (ShouldListByResourceGroup(this.ResourceGroupName, this.Name)) - { - page = this.MasterCustomIpPrefixClient.List(this.ResourceGroupName); - } - else - { - page = this.MasterCustomIpPrefixClient.ListAll(); - } - - // Get all resources by polling on next page link - List sdkModelList; - - sdkModelList = ListNextLink.GetAllResourcesByPollingNextLink(page, this.MasterCustomIpPrefixClient.ListNext); - - var psModelList = new List(); - - // populate the publicIpPrefixes with the ResourceGroupName - foreach (var sdkModel in sdkModelList) - { - var psModel = this.ToPsMasterCustomIpPrefix(sdkModel); - psModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(psModel.Id); - psModelList.Add(psModel); - } - - WriteObject(TopLevelWildcardFilter(this.ResourceGroupName, this.Name, psModelList), true); - } - } - } -} diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs deleted file mode 100644 index 581dbc3ca5d0..000000000000 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/MasterCustomIpPrefixBaseCmdlet.cs +++ /dev/null @@ -1,52 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.Commands.Network -{ - using Microsoft.Azure.Commands.Network.Models; - using Microsoft.Azure.Commands.ResourceManager.Common.Tags; - using Microsoft.Azure.Management.Network; - using Microsoft.Azure.Management.Network.Models; - using System.Net; - - public abstract class MasterCustomIpPrefixBaseCmdlet : NetworkBaseCmdlet - { - public IMasterCustomIPPrefixesOperations MasterCustomIpPrefixClient - { - get - { - return NetworkClient.NetworkManagementClient.MasterCustomIPPrefixes; - } - } - - public PSMasterCustomIpPrefix GetMasterCustomIpPrefix(string resourceGroupName, string name, string expandResource = null) - { - var masterCustomIpPrefix = this.MasterCustomIpPrefixClient.Get(resourceGroupName, name, expandResource); - - var psMasterCustomIpPrefix = ToPsMasterCustomIpPrefix(masterCustomIpPrefix); - psMasterCustomIpPrefix.ResourceGroupName = resourceGroupName; - - return psMasterCustomIpPrefix; - } - - public PSMasterCustomIpPrefix ToPsMasterCustomIpPrefix(MasterCustomIpPrefix publicIpPrefix) - { - var psMasterCustomIpPrefix = NetworkResourceManagerProfile.Mapper.Map(publicIpPrefix); - - psMasterCustomIpPrefix.Tag = TagsConversionHelper.CreateTagHashtable(publicIpPrefix.Tags); - - return psMasterCustomIpPrefix; - } - } -} diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs deleted file mode 100644 index 28a582c42b9c..000000000000 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/RemoveAzureMasterCustomIpPrefixCommand.cs +++ /dev/null @@ -1,110 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.Commands.Network -{ - using Microsoft.Azure.Commands.Network.Models; - using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; - using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; - using Microsoft.Azure.Management.Network; - using Microsoft.WindowsAzure.Commands.Utilities.Common; - using System.Management.Automation; - - [Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true, DefaultParameterSetName = DeleteByNameParameterSet), OutputType(typeof(bool))] - public class RemoveAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet - { - private const string DeleteByNameParameterSet = "DeleteByNameParameterSet"; - private const string DeleteByInputObjectParameterSet = "DeleteByInputObjectParameterSet"; - private const string DeleteByResourceIdParameterSet = "DeleteByResourceIdParameterSet"; - - [Alias("ResourceName")] - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource name.", - ParameterSetName = DeleteByNameParameterSet)] - [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] - [ValidateNotNullOrEmpty] - public virtual string Name { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource group name.", - ParameterSetName = DeleteByNameParameterSet)] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public virtual string ResourceGroupName { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - ParameterSetName = DeleteByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - public virtual string ResourceId { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipeline = true, - ParameterSetName = DeleteByInputObjectParameterSet)] - [ValidateNotNull] - public PSMasterCustomIpPrefix InputObject { get; set; } - - [Parameter( - Mandatory = false, - HelpMessage = "Do not ask for confirmation.")] - public SwitchParameter Force { get; set; } - - [Parameter(Mandatory = false)] - public SwitchParameter PassThru { get; set; } - - [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] - public SwitchParameter AsJob { get; set; } - - public override void Execute() - { - base.Execute(); - - if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = this.InputObject.ResourceGroupName; - this.Name = this.InputObject.Name; - } - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceIdentifier = new ResourceIdentifier(this.ResourceId); - this.ResourceGroupName = resourceIdentifier.ResourceGroupName; - this.Name = resourceIdentifier.ResourceName; - } - - ConfirmAction( - Force.IsPresent, - string.Format(Microsoft.Azure.Commands.Network.Properties.Resources.RemovingResource, Name), - Microsoft.Azure.Commands.Network.Properties.Resources.RemoveResourceMessage, - Name, - () => - { - if (this.ShouldProcess(this.Name, $"Deleting MasterCustomIpPrefix: {this.Name} in ResourceGroup: {this.ResourceGroupName}")) - { - this.MasterCustomIpPrefixClient.Delete(this.ResourceGroupName, this.Name); - if (PassThru) - { - WriteObject(true); - } - } - }); - } - } -} diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs deleted file mode 100644 index 11e7935202ee..000000000000 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/UpdateAzureMasterCustomIpPrefixTagsCommand.cs +++ /dev/null @@ -1,138 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.Commands.Network -{ - using Microsoft.Azure.Commands.Network.Models; - using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; - using Microsoft.Azure.Commands.ResourceManager.Common.Tags; - using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; - using Microsoft.Azure.Management.Network; - using Microsoft.Azure.Management.Network.Models; - using Microsoft.WindowsAzure.Commands.Utilities.Common; - using System; - using System.Collections; - using System.Management.Automation; - using MNM = Microsoft.Azure.Management.Network.Models; - - [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefixTags", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] - public class UpdateAzureMasterCustomIpPrefixTagsCommand : MasterCustomIpPrefixBaseCmdlet - { - private const string UpdateByNameParameterSet = "UpdateByNameParameterSet"; - private const string UpdateByInputObjectParameterSet = "UpdateByInputObjectParameterSet"; - private const string UpdateByResourceIdParameterSet = "UpdateByResourceIdParameterSet"; - - [Alias("ResourceName")] - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource name.", - ParameterSetName = UpdateByNameParameterSet)] - [ResourceNameCompleter("Microsoft.Network/masterCustomIpPrefix", "ResourceGroupName")] - [ValidateNotNullOrEmpty] - [SupportsWildcards] - public virtual string Name { get; set; } - - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource group name.", - ParameterSetName = UpdateByNameParameterSet)] - [ValidateNotNullOrEmpty] - [SupportsWildcards] - public virtual string ResourceGroupName { get; set; } - - [Parameter( - Mandatory = false, - ValueFromPipeline = true, - HelpMessage = "The MasterCustomIpPrefix to set.", - ParameterSetName = UpdateByInputObjectParameterSet)] - public PSMasterCustomIpPrefix InputObject { get; set; } - - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource Id.", - ParameterSetName = UpdateByResourceIdParameterSet)] - [ValidateNotNullOrEmpty] - [SupportsWildcards] - public virtual string ResourceId { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "A hashtable which represents resource tags.", - ParameterSetName = UpdateByNameParameterSet)] - [Parameter(Mandatory = true, ParameterSetName = UpdateByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = UpdateByInputObjectParameterSet)] - public Hashtable Tag { get; set; } - - [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] - public SwitchParameter AsJob { get; set; } - - public override void Execute() - { - base.Execute(); - - if (this.IsParameterBound(c => c.ResourceId)) - { - var resourceInfo = new ResourceIdentifier(ResourceId); - this.ResourceGroupName = resourceInfo.ResourceGroupName; - this.Name = resourceInfo.ResourceName; - } - else if (this.IsParameterBound(c => c.InputObject)) - { - this.ResourceGroupName = InputObject.ResourceGroupName; - this.Name = InputObject.Name; - } - - PSMasterCustomIpPrefix psModel; - if (this.IsParameterBound(c => c.InputObject)) - { - psModel = InputObject; - } - else - { - var existingPsModel = GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name); - - psModel = new PSMasterCustomIpPrefix() - { - Name = this.Name, - ResourceGroupName = this.ResourceGroupName, - Location = existingPsModel.Location, - }; - } - var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); - - if (this.IsParameterBound(c => c.InputObject)) - { - sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.IsParameterBound(c => c.Tag) ? this.Tag : InputObject.Tag, validate: true); - } - else - { - sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); - } - - if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) - { - // Execute the PUT MasterCustomIpPrefix Policy call - TagsObject tagsObj = new TagsObject(sdkModel.Tags); - var modifiedSdkModel = this.MasterCustomIpPrefixClient.UpdateTags(this.ResourceGroupName, this.Name, tagsObj); - var modifiedPsModel = this.ToPsMasterCustomIpPrefix(modifiedSdkModel); - modifiedPsModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(modifiedPsModel.Id); - WriteObject(modifiedPsModel); - } - } - } -} diff --git a/src/Network/Network/Common/NetworkResourceManagerProfile.cs b/src/Network/Network/Common/NetworkResourceManagerProfile.cs index f0b74388e0d3..937f397acf37 100644 --- a/src/Network/Network/Common/NetworkResourceManagerProfile.cs +++ b/src/Network/Network/Common/NetworkResourceManagerProfile.cs @@ -394,13 +394,11 @@ private static void Initialize() cfg.CreateMap(); cfg.CreateMap(); - // BYOIP (MasterCustomIpPrefix and CustomIpPrefix) + // CustomIpPrefix // CNM to MNM - cfg.CreateMap(); cfg.CreateMap(); // MNM to CNM - cfg.CreateMap(); cfg.CreateMap(); // NetworkInterface diff --git a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs index 1b92e222816d..2a21f05cc322 100644 --- a/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs +++ b/src/Network/Network/Models/BYOIP/PSCustomIpPrefix.cs @@ -21,8 +21,6 @@ public class PSCustomIpPrefix : PSTopLevelResource { public string Cidr { get; set; } - public PSResourceId MasterCustomIpPrefix { get; set; } - public string CommissionedState { get; set; } public List PublicIpPrefixes { get; set; } @@ -31,12 +29,6 @@ public class PSCustomIpPrefix : PSTopLevelResource public string ProvisioningState { get; set; } - [JsonIgnore] - public string MasterCustomIpPrefixText - { - get { return JsonConvert.SerializeObject(MasterCustomIpPrefix, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } - } - [JsonIgnore] public string PublicIpPrefixesText { diff --git a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs b/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs deleted file mode 100644 index 41087f922946..000000000000 --- a/src/Network/Network/Models/BYOIP/PSMasterCustomIpPrefix.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.Commands.Network.Models -{ - using Newtonsoft.Json; - using System.Collections.Generic; - - public class PSMasterCustomIpPrefix : PSTopLevelResource - { - public string Cidr { get; set; } - - public string ProvisioningState { get; set; } - - public string OriginalValidationMessage { get; set; } - - public string SignedValidationMessage { get; set; } - - public List CustomIpPrefixes { get; set; } - - public string ValidationState { get; set; } - - [JsonIgnore] - public string CustomIpPrefixesText - { - get { return JsonConvert.SerializeObject(CustomIpPrefixes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } - } - } -} diff --git a/src/Network/Network/Network.format.ps1xml b/src/Network/Network/Network.format.ps1xml index 5152b425a577..0e65a349dc1e 100644 --- a/src/Network/Network/Network.format.ps1xml +++ b/src/Network/Network/Network.format.ps1xml @@ -1493,73 +1493,7 @@ - - Microsoft.Azure.Commands.Network.Models.PSMasterCustomIpPrefix - - Microsoft.Azure.Commands.Network.Models.PSMasterCustomIpPrefix - - - - - - - - Name - - - - ResourceGroupName - - - - Location - - - - Id - - - - Etag - - - - ResourceGuid - - - - ProvisioningState - - - - TagsTable - - - - Cidr - - - - ValidationState - - - - OriginalValidationMessage - - - - SignedValidationMessage - - - - CustomIpPrefixesText - - - - - - - + Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix @@ -1612,7 +1546,7 @@ MasterCustomIpPrefixText - + PublicIpPrefixesText From d4b39941b347340e7c1ac055f9adb428e0d5f6ba Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Wed, 12 Aug 2020 17:12:19 -0700 Subject: [PATCH 11/18] cherry pick #7 --- .../ScenarioTests/CustomIpPrefixTests.ps1 | 90 +++++++++++-------- src/Network/Network/Az.Network.psd1 | 2 +- ...cs => UpdateAzureCustomIpPrefixCommand.cs} | 6 +- 3 files changed, 59 insertions(+), 39 deletions(-) rename src/Network/Network/BYOIP/CustomIpPrefix/{SetAzureCustomIpPrefixCommand.cs => UpdateAzureCustomIpPrefixCommand.cs} (95%) diff --git a/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 index d859f85afb08..5a6eb17630f5 100644 --- a/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.ps1 @@ -15,38 +15,57 @@ <# .SYNOPSIS Tests CRUD operations on a simple customIpPrefix. + +NOTE: This feature is currently in private preview, so updated binaries are on test slice in canary only and is currently un-reacheable via the production manifest. +Testing has been done locally using the brazilus ARM endpoint and a specific subscription that has the necessary flags to run these cmdlets. #> function Test-CustomIpPrefixCRUD { # Setup $rgname = "powershell-test-rg" - $rname = "testCip" - - # currently in private preview, updated binaries are on test slice in canary only + $rname = "testCustomIpPrefix" $location = "eastus2euap" + $cidr = "40.40.40.0/24" try { # Create the resource group - $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" } - - # Create the masterCustomIpPrefix - $job = New-AzMasterCustomIpPrefix -Name $rname -ResourceGroupName $rgname -Cidr "40.40.40.0/22" -ValidationMessage "123" -SignedValidationMessage "456" -Location $location -AsJob - $job | Wait-Job - $mcip = $job | Receive-Job + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation # Create customIpPrefix - $job = New-AzCustomIpPrefix -Name $rname -ResourceGroupName $rgname -location $location -Cidr "40.40.40.0/24" -MasterCustomIpPrefix $mcip -AsJob + $job = New-AzCustomIpPrefix -Name $rname -ResourceGroupName $rgname -location $location -Cidr $cidr -AsJob $job | Wait-Job - $actual = $job | Receive-Job - $expected = Get-AzCustomIpPrefix -ResourceGroupName $rgname -name $rname - Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $expected.Name $actual.Name - Assert-AreEqual $expected.Location $actual.Location - Assert-AreEqual $expected.Cidr $actual.Cidr - Assert-AreEqual 0 $expected.PublicIpPrefixes.Count - Assert-NotNull $expected.ResourceGuid - Assert-AreEqual "Succeeded" $expected.ProvisioningState + $job | Receive-Job + + # get by name and resource group + $actual = Get-AzCustomIpPrefix -ResourceGroupName $rgname -name $rname + Assert-AreEqual $actual.ResourceGroupName $rgname + Assert-AreEqual $actual.Name $rname + Assert-AreEqual $actual.Location $location + Assert-AreEqual $actual.Cidr $cidr + Assert-AreEqual $actual.PublicIpPrefixes.Count 0 + Assert-NotNull $actual.ResourceGuid + Assert-AreEqual $actual.ProvisioningState "Succeeded" + + # get by resource id + $actual = Get-AzCustomIpPrefix -ResourceId $actual.Id + Assert-AreEqual $actual.ResourceGroupName $rgname + Assert-AreEqual $actual.Name $rname + Assert-AreEqual $actual.Location $location + Assert-AreEqual $actual.Cidr $cidr + Assert-AreEqual $actual.PublicIpPrefixes.Count 0 + Assert-NotNull $actual.ResourceGuid + Assert-AreEqual $actual.ProvisioningState "Succeeded" + + # get by input object + $actual = Get-AzCustomIpPrefix -InputObject $actual + Assert-AreEqual $actual.ResourceGroupName $rgname + Assert-AreEqual $actual.Name $rname + Assert-AreEqual $actual.Location $location + Assert-AreEqual $actual.Cidr $cidr + Assert-AreEqual $actual.PublicIpPrefixes.Count 0 + Assert-NotNull $actual.ResourceGuid + Assert-AreEqual $actual.ProvisioningState "Succeeded" # list $list = Get-AzCustomIpPrefix -ResourceGroupName $rgname @@ -56,16 +75,7 @@ function Test-CustomIpPrefixCRUD Assert-AreEqual $list[0].Location $actual.Location Assert-AreEqual $list[0].Cidr $actual.Cidr Assert-AreEqual $list[0].PublicIpPrefixes.Count 0 - Assert-AreEqual "Succeeded" $list[0].ProvisioningState - - $list = Get-AzCustomIpPrefix -ResourceId $actual.Id - Assert-AreEqual 1 @($list).Count - Assert-AreEqual $list[0].ResourceGroupName $actual.ResourceGroupName - Assert-AreEqual $list[0].Name $actual.Name - Assert-AreEqual $list[0].Location $actual.Location - Assert-AreEqual $list[0].Cidr $actual.Cidr - Assert-AreEqual $list[0].PublicIpPrefixes.Count 0 - Assert-AreEqual "Succeeded" $list[0].ProvisioningState + Assert-AreEqual $list[0].ProvisioningState "Succeeded" # delete $job = Remove-AzCustomIpPrefix -InputObject $actual -PassThru -Force -AsJob @@ -73,18 +83,28 @@ function Test-CustomIpPrefixCRUD $delete = $job | Receive-Job Assert-AreEqual true $delete - $list = Get-AzPublicIpPrefix -ResourceGroupName $actual.ResourceGroupName + $list = Get-AzPublicIpPrefix -ResourceGroupName $rgname Assert-AreEqual 0 @($list).Count # Try setting unexisting - Assert-ThrowsLike { Set-AzPublicIpPrefix -PublicIpPrefix $expected } "*not found*" + Assert-ThrowsLike { Update-AzPublicIpPrefix -PublicIpPrefix $expected } "*not found*" + + # Create one more time to test deletion with resource id parameter set + $job = New-AzCustomIpPrefix -Name $rname -ResourceGroupName $rgname -location $location -Cidr $cidr -AsJob + $job | Wait-Job + $expected = $job | Receive-Job + + $job = Remove-AzPublicIpPrefix -ResourceId $expected.Id -PassThru -Force -AsJob + $job | Wait-Job + $delete = $job | Receive-Job + Assert-AreEqual true $delete - # Create one more time to test deletion with another parameter set - $job = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $rname -location $location -Sku Standard -PrefixLength 30 -AsJob + # Create one more time to test deletion with resource group and name + $job = New-AzCustomIpPrefix -Name $rname -ResourceGroupName $rgname -location $location -Cidr $cidr -AsJob $job | Wait-Job - $actual = $job | Receive-Job + $expected = $job | Receive-Job - $job = Remove-AzPublicIpPrefix -ResourceId $actual.Id -PassThru -Force -AsJob + $job = Remove-AzPublicIpPrefix -Name $rname -ResourceGroupName $rgname $job | Wait-Job $delete = $job | Receive-Job Assert-AreEqual true $delete diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index 979d1e28d3d4..8d0bf998c892 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -501,7 +501,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'New-AzOffice365PolicyProperty', 'Get-AzNetworkVirtualApplianceSku', 'New-AzVirtualApplianceSkuProperty' - 'New-AzCustomIpPrefix','Set-AzCustomIpPrefix', + 'New-AzCustomIpPrefix','Update-AzCustomIpPrefix', 'Get-AzCustomIpPrefix','Remove-AzCustomIpPrefix' # Variables to export from this module diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs similarity index 95% rename from src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs rename to src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs index 1eb7247a443a..83d923e1e740 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/SetAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs @@ -25,8 +25,8 @@ namespace Microsoft.Azure.Commands.Network using System.Management.Automation; using MNM = Microsoft.Azure.Management.Network.Models; - [Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSCustomIpPrefix))] - public class SetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet + [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSCustomIpPrefix))] + public class UpdateAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet { private const string SetByNameParameterSet = "SetByNameParameterSet"; private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; @@ -131,7 +131,7 @@ public override void Execute() sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); } - if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Set existing MasterCustomIpPrefix")) + if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Update existing MasterCustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); From fa7906a961ef0a478fc205374526e85be533a2f5 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Thu, 13 Aug 2020 11:04:07 -0700 Subject: [PATCH 12/18] fix some text typos and added the help files --- .../GetAzureCustomIpPrefixCommand.cs | 6 +- .../NewAzureCustomIpPrefixCommand.cs | 4 +- .../RemoveAzureCustomIpPrefixCommand.cs | 6 +- .../UpdateAzureCustomIpPrefixCommand.cs | 24 +- src/Network/Network/Network.format.ps1xml | 4 - .../Network/help/Get-AzCustomIpPrefix.md | 133 +++++++++ .../Network/help/New-AzCustomIpPrefix.md | 209 ++++++++++++++ .../Network/help/Remove-AzCustomIpPrefix.md | 220 +++++++++++++++ .../Network/help/Update-AzCustomIpPrefix.md | 263 ++++++++++++++++++ 9 files changed, 846 insertions(+), 23 deletions(-) create mode 100644 src/Network/Network/help/Get-AzCustomIpPrefix.md create mode 100644 src/Network/Network/help/New-AzCustomIpPrefix.md create mode 100644 src/Network/Network/help/Remove-AzCustomIpPrefix.md create mode 100644 src/Network/Network/help/Update-AzCustomIpPrefix.md diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs index 59810cd267f9..9efaa748a400 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/GetAzureCustomIpPrefixCommand.cs @@ -25,10 +25,9 @@ namespace Microsoft.Azure.Commands.Network using Microsoft.WindowsAzure.Commands.Utilities.Common; using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; - [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", DefaultParameterSetName = ListParameterSet), OutputType(typeof(PSCustomIpPrefix))] + [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", DefaultParameterSetName = GetByNameParameterSet), OutputType(typeof(PSCustomIpPrefix))] public class GetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet { - private const string ListParameterSet = "ListParameterSet"; private const string GetByNameParameterSet = "GetByNameParameterSet"; private const string GetByResourceIdParameterSet = "GetByResourceIdParameterSet"; @@ -55,7 +54,8 @@ public class GetAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [Parameter( Mandatory = true, - ValueFromPipelineByPropertyName = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource id.", ParameterSetName = GetByResourceIdParameterSet)] [ValidateNotNullOrEmpty] public virtual string ResourceId { get; set; } diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs index 8706b2dd6973..63afddc7253a 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/NewAzureCustomIpPrefixCommand.cs @@ -45,7 +45,7 @@ public class NewAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The master custom IP prefix location.")] + HelpMessage = "The customIpPrefix location.")] [LocationCompleter("Microsoft.Network/customIpPrefix")] [ValidateNotNullOrEmpty] public string Location { get; set; } @@ -53,7 +53,7 @@ public class NewAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The CIDR of the master custom IP prefix")] + HelpMessage = "The customIpPrefix CIDR.")] [ValidateNotNullOrEmpty] public string Cidr { get; set; } diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs index 1651702becdd..e2d522db9b9f 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/RemoveAzureCustomIpPrefixCommand.cs @@ -49,14 +49,16 @@ public class RemoveAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [Parameter( Mandatory = true, - ValueFromPipelineByPropertyName = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The resource id.", ParameterSetName = DeleteByResourceIdParameterSet)] [ValidateNotNullOrEmpty] public virtual string ResourceId { get; set; } [Parameter( Mandatory = true, - ValueFromPipeline = true, + ValueFromPipeline = true, + HelpMessage = "A customIpPrefix object.", ParameterSetName = DeleteByInputObjectParameterSet)] [ValidateNotNull] public PSCustomIpPrefix InputObject { get; set; } diff --git a/src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs index 83d923e1e740..a69b15d86a84 100644 --- a/src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs +++ b/src/Network/Network/BYOIP/CustomIpPrefix/UpdateAzureCustomIpPrefixCommand.cs @@ -25,17 +25,17 @@ namespace Microsoft.Azure.Commands.Network using System.Management.Automation; using MNM = Microsoft.Azure.Management.Network.Models; - [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSCustomIpPrefix))] + [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "CustomIpPrefix", SupportsShouldProcess = true, DefaultParameterSetName = UpdateByNameParameterSet), OutputType(typeof(PSCustomIpPrefix))] public class UpdateAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet { - private const string SetByNameParameterSet = "SetByNameParameterSet"; - private const string SetByInputObjectParameterSet = "SetByInputObjectParameterSet"; - private const string SetByResourceIdParameterSet = "SetByResourceIdParameterSet"; + private const string UpdateByNameParameterSet = "UpdateByNameParameterSet"; + private const string UpdateByInputObjectParameterSet = "UpdateByInputObjectParameterSet"; + private const string UpdateByResourceIdParameterSet = "UpdateByResourceIdParameterSet"; [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource name.", ParameterSetName = SetByNameParameterSet)] + HelpMessage = "The resource name.", ParameterSetName = UpdateByNameParameterSet)] [ResourceNameCompleter("Microsoft.Network/customIpPrefix", "ResourceGroupName")] [ValidateNotNullOrEmpty] [SupportsWildcards] @@ -44,7 +44,7 @@ public class UpdateAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource group name.", ParameterSetName = SetByNameParameterSet)] + HelpMessage = "The resource group name.", ParameterSetName = UpdateByNameParameterSet)] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string ResourceGroupName { get; set; } @@ -52,13 +52,13 @@ public class UpdateAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet [Parameter( Mandatory = true, ValueFromPipeline = true, - HelpMessage = "The MasterCustomIpPrefix to set.", ParameterSetName = SetByInputObjectParameterSet)] + HelpMessage = "The CustomIpPrefix to set.", ParameterSetName = UpdateByInputObjectParameterSet)] public PSCustomIpPrefix InputObject { get; set; } [Parameter( Mandatory = true, ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource Id.", ParameterSetName = SetByResourceIdParameterSet)] + HelpMessage = "The resource Id.", ParameterSetName = UpdateByResourceIdParameterSet)] [ValidateNotNullOrEmpty] [SupportsWildcards] public virtual string ResourceId { get; set; } @@ -73,9 +73,9 @@ public class UpdateAzureCustomIpPrefixCommand : CustomIpPrefixBaseCmdlet Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hashtable which represents resource tags.", - ParameterSetName = SetByNameParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByResourceIdParameterSet)] - [Parameter(Mandatory = false, ParameterSetName = SetByInputObjectParameterSet)] + ParameterSetName = UpdateByNameParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = UpdateByResourceIdParameterSet)] + [Parameter(Mandatory = false, ParameterSetName = UpdateByInputObjectParameterSet)] public Hashtable Tag { get; set; } [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] @@ -131,7 +131,7 @@ public override void Execute() sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); } - if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Update existing MasterCustomIpPrefix")) + if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Update existing CustomIpPrefix")) { // Execute the PUT MasterCustomIpPrefix Policy call this.CustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); diff --git a/src/Network/Network/Network.format.ps1xml b/src/Network/Network/Network.format.ps1xml index 0e65a349dc1e..7b7d01d8bc8c 100644 --- a/src/Network/Network/Network.format.ps1xml +++ b/src/Network/Network/Network.format.ps1xml @@ -1541,10 +1541,6 @@ CommissionedState - - - - MasterCustomIpPrefixText diff --git a/src/Network/Network/help/Get-AzCustomIpPrefix.md b/src/Network/Network/help/Get-AzCustomIpPrefix.md new file mode 100644 index 000000000000..986cde1c4e40 --- /dev/null +++ b/src/Network/Network/help/Get-AzCustomIpPrefix.md @@ -0,0 +1,133 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml +Module Name: Az.Network +online version: +schema: 2.0.0 +--- + +# Get-AzCustomIpPrefix + +## SYNOPSIS +Gets a CustomIpPrefix resource + +## SYNTAX + +### GetByNameParameterSet (Default) +``` +Get-AzCustomIpPrefix [-Name ] [-ResourceGroupName ] [-DefaultProfile ] + [] +``` + +### GetByResourceIdParameterSet +``` +Get-AzCustomIpPrefix -ResourceId [-DefaultProfile ] [] +``` + +## DESCRIPTION +The **Get-AzCustomIpPrefix** cmdlet gets one or more CustomIpPrefixes given the set of input parameters + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-AzPublicIpPrefix -ResourceGroupName myRg -Name myCustomIpPrefix + +Name : myCustomIpPrefix +ResourceGroupName : myRg +Location : westus +Id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/byoip-test-rg/providers/Micro + soft.Network/customIPPrefixes/testCustomIpPrefix +Etag : W/"00000000-0000-0000-0000-000000000000" +ResourceGuid : 00000000-0000-0000-0000-000000000000 +ProvisioningState : Succeeded +Tags : +Cidr : 111.111.111.111/24 +CommissionedState : Provisioning +PublicIpPrefixes : [] +Zones : {} +``` + +This command gets a CustomIpPrefix resource named myCustomIpPrefix in resource group myRg + +## PARAMETERS + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +The resource name. + +```yaml +Type: String +Parameter Sets: GetByNameParameterSet +Aliases: ResourceName + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceGroupName +The resource group name. + +```yaml +Type: String +Parameter Sets: GetByNameParameterSet +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceId +The resource id. + +```yaml +Type: String +Parameter Sets: GetByResourceIdParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + +## NOTES + +## RELATED LINKS + +[New-AzCustomIpPrefix](./New-AzCustomIpPrefix.md) + +[Remove-AzCustomIpPrefix](./Remove-AzCustomIpPrefix.md) + +[Update-AzCustomIpPrefix](./Update-AzCustomIpPrefix.md) \ No newline at end of file diff --git a/src/Network/Network/help/New-AzCustomIpPrefix.md b/src/Network/Network/help/New-AzCustomIpPrefix.md new file mode 100644 index 000000000000..8c977cec0fad --- /dev/null +++ b/src/Network/Network/help/New-AzCustomIpPrefix.md @@ -0,0 +1,209 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml +Module Name: Az.Network +online version: +schema: 2.0.0 +--- + +# New-AzCustomIpPrefix + +## SYNOPSIS +Creates a CustomIpPrefix resource + +## SYNTAX + +``` +New-AzCustomIpPrefix -Name -ResourceGroupName -Location -Cidr + [-Zone ] [-Tag ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] +``` + +## DESCRIPTION +The **New-AzCustomIpPrefix** cmdlet creates a CustomIpPrefix resource. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> $myCustomIpPrefix = New-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName -Cidr 40.40.40.0/24 -Location westus +``` + +This command creates a new CustomIpPrefix resource with name $prefixName in resource group $rgName with a cidr of 40.40.40.0/24 in westus + +## PARAMETERS + +### -AsJob +Run cmdlet in the background + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Cidr +The CustomIpPrefix CIDR. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Location +The CustomIpPrefix location. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Name +The resource name. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: ResourceName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceGroupName +The resource group name. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Tag +A hashtable which represents resource tags. + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Zone +A list of availability zones denoting the IP allocated for the resource needs to come from. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +### System.String[] + +### System.Collections.Hashtable + +## OUTPUTS + +### Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + +## NOTES + +## RELATED LINKS + +[Get-AzCustomIpPrefix](./Get-AzCustomIpPrefix.md) + +[Remove-AzCustomIpPrefix](./Remove-AzCustomIpPrefix.md) + +[Update-AzCustomIpPrefix](./Update-AzCustomIpPrefix.md) \ No newline at end of file diff --git a/src/Network/Network/help/Remove-AzCustomIpPrefix.md b/src/Network/Network/help/Remove-AzCustomIpPrefix.md new file mode 100644 index 000000000000..e020e24218f6 --- /dev/null +++ b/src/Network/Network/help/Remove-AzCustomIpPrefix.md @@ -0,0 +1,220 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml +Module Name: Az.Network +online version: +schema: 2.0.0 +--- + +# Remove-AzCustomIpPrefix + +## SYNOPSIS +Removes a CustomIpPrefix + +## SYNTAX + +### DeleteByNameParameterSet (Default) +``` +Remove-AzCustomIpPrefix -Name -ResourceGroupName [-Force] [-PassThru] [-AsJob] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +### DeleteByResourceIdParameterSet +``` +Remove-AzCustomIpPrefix -ResourceId [-Force] [-PassThru] [-AsJob] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +### DeleteByInputObjectParameterSet +``` +Remove-AzCustomIpPrefix -InputObject [-Force] [-PassThru] [-AsJob] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +The **Remove-AzCustomIpPrefix** cmdlet removes a CustomIpPrefix. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Remove-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName +``` + +Removes the CustomIpPrefix with Name $prefixName from resource group $rgName + +## PARAMETERS + +### -AsJob +Run cmdlet in the background + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Force +Do not ask for confirmation. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InputObject +A customIpPrefix object. + +```yaml +Type: PSCustomIpPrefix +Parameter Sets: DeleteByInputObjectParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Name +The resource name. + +```yaml +Type: String +Parameter Sets: DeleteByNameParameterSet +Aliases: ResourceName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PassThru +Returns an object representing the item with which you are working. +By default, this cmdlet does not generate any output. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ResourceGroupName +The resource group name. + +```yaml +Type: String +Parameter Sets: DeleteByNameParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceId +The resource id. + +```yaml +Type: String +Parameter Sets: DeleteByResourceIdParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +### Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + +## OUTPUTS + +### System.Boolean + +## NOTES + +## RELATED LINKS + +[Get-AzCustomIpPrefix](./Get-AzCustomIpPrefix.md) + +[New-AzCustomIpPrefix](./New-AzCustomIpPrefix.md) + +[Update-AzCustomIpPrefix](./Update-AzCustomIpPrefix.md) \ No newline at end of file diff --git a/src/Network/Network/help/Update-AzCustomIpPrefix.md b/src/Network/Network/help/Update-AzCustomIpPrefix.md new file mode 100644 index 000000000000..701b0c0fb587 --- /dev/null +++ b/src/Network/Network/help/Update-AzCustomIpPrefix.md @@ -0,0 +1,263 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml +Module Name: Az.Network +online version: +schema: 2.0.0 +--- + +# Update-AzCustomIpPrefix + +## SYNOPSIS +Updates a CustomIpPrefix + +## SYNTAX + +### UpdateByNameParameterSet +``` +Update-AzCustomIpPrefix -Name -ResourceGroupName [-Commission] [-Decomission] + [-Tag ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] +``` + +### UpdateByInputObjectParameterSet +``` +Update-AzCustomIpPrefix -InputObject [-Commission] [-Decomission] [-Tag ] + [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +### UpdateByResourceIdParameterSet +``` +Update-AzCustomIpPrefix -ResourceId [-Commission] [-Decomission] [-Tag ] [-AsJob] + [-DefaultProfile ] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +The **Update-AzCustomIpPrefix** cmdlet allows the user to either commission or decommission their CustomIpPrefix, or edit the tags of the resource. + +## EXAMPLES + +### Example 1 : Commission the CustomIpPrefix +```powershell +PS C:\> Update-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName -Commission +``` + +The above command will start the commissioning process of the CustomIpPrefix. + +### Example 2 : Decommission the CustomIpPrefix +```powershell +PS C:\> Update-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName -Decommission +``` + +The above command will start the de-commissioning process of the CustomIpPrefix. + +### Example 3 : Update tags for the CustomIpPrefix +```powershell +PS C:\> Update-AzCustomIpPrefix -Name $prefixName -ResourceGroupName $rgName -Tag $tags +``` + +The above command will update the tags for the CustomIpPrefix. + +## PARAMETERS + +### -AsJob +Run cmdlet in the background + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Commission +Run cmdlet in the background + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Decomission +Run cmdlet in the background + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InputObject +The CustomIpPrefix to set. + +```yaml +Type: PSCustomIpPrefix +Parameter Sets: SetByInputObjectParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Name +The resource name. + +```yaml +Type: String +Parameter Sets: SetByNameParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceGroupName +The resource group name. + +```yaml +Type: String +Parameter Sets: SetByNameParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -ResourceId +The resource Id. + +```yaml +Type: String +Parameter Sets: SetByResourceIdParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Tag +A hashtable which represents resource tags. + +```yaml +Type: Hashtable +Parameter Sets: SetByNameParameterSet +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +```yaml +Type: Hashtable +Parameter Sets: SetByInputObjectParameterSet, SetByResourceIdParameterSet +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +### Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + +### System.Collections.Hashtable + +## OUTPUTS + +### Microsoft.Azure.Commands.Network.Models.PSCustomIpPrefix + +## NOTES + +## RELATED LINKS + +[Get-AzCustomIpPrefix](./Get-AzCustomIpPrefix.md) + +[New-AzCustomIpPrefix](./New-AzCustomIpPrefix.md) + +[Remove-AzCustomIpPrefix](./Remove-AzCustomIpPrefix.md) \ No newline at end of file From 6d9c5367f9c9f5759a87d06ebab2aece279bd66e Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Wed, 19 Aug 2020 15:48:39 -0700 Subject: [PATCH 13/18] clean up issues form cherry picking --- src/Network/Network/Az.Network.psd1 | 6 +- .../NewAzureMasterCustomIpPrefixCommand.cs | 129 ------------------ src/Network/Network/Properties/Resources.resx | 1 + 3 files changed, 4 insertions(+), 132 deletions(-) delete mode 100644 src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index 8d0bf998c892..325b2624f2b8 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -500,9 +500,9 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'Update-AzVirtualApplianceSite', 'New-AzOffice365PolicyProperty', 'Get-AzNetworkVirtualApplianceSku', - 'New-AzVirtualApplianceSkuProperty' - 'New-AzCustomIpPrefix','Update-AzCustomIpPrefix', - 'Get-AzCustomIpPrefix','Remove-AzCustomIpPrefix' + 'New-AzVirtualApplianceSkuProperty', + 'New-AzCustomIpPrefix', 'Update-AzCustomIpPrefix', + 'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix' # Variables to export from this module # VariablesToExport = @() diff --git a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs b/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs deleted file mode 100644 index 0dc1fd7729f5..000000000000 --- a/src/Network/Network/BYOIP/MasterCustomIpPrefix/NewAzureMasterCustomIpPrefixCommand.cs +++ /dev/null @@ -1,129 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.Commands.Network -{ - using Microsoft.Azure.Commands.Network.Models; - using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; - using Microsoft.Azure.Commands.ResourceManager.Common.Tags; - using Microsoft.Azure.Management.Network; - using System.Collections; - using System.Management.Automation; - using MNM = Microsoft.Azure.Management.Network.Models; - - [Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "MasterCustomIpPrefix", SupportsShouldProcess = true), OutputType(typeof(PSMasterCustomIpPrefix))] - public class NewAzureMasterCustomIpPrefixCommand : MasterCustomIpPrefixBaseCmdlet - { - [Alias("ResourceName")] - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource name.")] - [ValidateNotNullOrEmpty] - public virtual string Name { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The resource group name.")] - [ResourceGroupCompleter] - [ValidateNotNullOrEmpty] - public virtual string ResourceGroupName { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The MasterCustomIpPrefix location.")] - [LocationCompleter("Microsoft.Network/masterCustomIpPrefix")] - [ValidateNotNullOrEmpty] - public string Location { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The CIDR of the MasterCustomIpPrefix")] - [ValidateNotNullOrEmpty] - public string Cidr { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The message for MasterCustomIpPrefix validation.")] - [ValidateNotNullOrEmpty] - public string ValidationMessage { get; set; } - - [Parameter( - Mandatory = true, - ValueFromPipelineByPropertyName = true, - HelpMessage = "The message for MasterCustomIpPrefix validation signed with public key.")] - [ValidateNotNullOrEmpty] - public string SignedValidationMessage { get; set; } - - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "A hashtable which represents resource tags.")] - public Hashtable Tag { get; set; } - - [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] - public SwitchParameter AsJob { get; set; } - - public override void Execute() - { - base.Execute(); - var present = NetworkBaseCmdlet.IsResourcePresent(() => GetMasterCustomIpPrefix(this.ResourceGroupName, this.Name)); - ConfirmAction( - false, - string.Format(Properties.Resources.OverwritingResource, Name), - Properties.Resources.CreatingResourceMessage, - Name, - () => - { - var masterCustomIpPrefix = CreateMasterCustomIpPrefix(); - if (masterCustomIpPrefix != null) - { - WriteObject(masterCustomIpPrefix); - } - }, - () => present); - } - - private PSMasterCustomIpPrefix CreateMasterCustomIpPrefix() - { - var psModel = new PSMasterCustomIpPrefix() - { - Name = this.Name, - ResourceGroupName = this.ResourceGroupName, - Location = this.Location, - Cidr = this.Cidr, - OriginalValidationMessage = this.ValidationMessage, - SignedValidationMessage = this.SignedValidationMessage - }; - - var sdkModel = NetworkResourceManagerProfile.Mapper.Map(psModel); - - sdkModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true); - - if (this.ShouldProcess($"Name: {this.Name} ResourceGroup: {this.ResourceGroupName}", "Creating a new MasterCustomIpPrefix")) - { - var createdSdkModel = this.MasterCustomIpPrefixClient.CreateOrUpdate(this.ResourceGroupName, this.Name, sdkModel); - var createdPsModel = this.ToPsMasterCustomIpPrefix(createdSdkModel); - createdPsModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(createdPsModel.Id); - return createdPsModel; - } - - return null; - } - } -} \ No newline at end of file diff --git a/src/Network/Network/Properties/Resources.resx b/src/Network/Network/Properties/Resources.resx index 3b1cc46ef2f0..bd9e39a440a1 100644 --- a/src/Network/Network/Properties/Resources.resx +++ b/src/Network/Network/Properties/Resources.resx @@ -691,6 +691,7 @@ A valid HubRouteTable reference is required. + Cannot have both 'Commission' and 'Decomission' flags set Error message for setting the customIpPrefix From 664fd68451e5e0e9db38457be221cda1a9d5fbf0 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Mon, 24 Aug 2020 10:10:20 -0700 Subject: [PATCH 14/18] update the csproj --- src/Network/Network/Network.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Network/Network/Network.csproj b/src/Network/Network/Network.csproj index f88a5f0a86ea..9c4e1afa7bee 100644 --- a/src/Network/Network/Network.csproj +++ b/src/Network/Network/Network.csproj @@ -14,7 +14,7 @@ - + @@ -40,4 +40,4 @@ - + \ No newline at end of file From 11f3deff3c191a7b3e9af37994a2ba479815628e Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Mon, 24 Aug 2020 10:11:10 -0700 Subject: [PATCH 15/18] update sdk nuget package --- src/Network/Network/Network.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Network/Network/Network.csproj b/src/Network/Network/Network.csproj index 9c4e1afa7bee..6be8b37c7aff 100644 --- a/src/Network/Network/Network.csproj +++ b/src/Network/Network/Network.csproj @@ -14,7 +14,7 @@ - + From 37cd92a99000cd9c95b51b9c78fb912700c716eb Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Mon, 24 Aug 2020 11:20:48 -0700 Subject: [PATCH 16/18] add online version url for help files --- src/Network/Network/help/Get-AzCustomIpPrefix.md | 2 +- src/Network/Network/help/New-AzCustomIpPrefix.md | 2 +- src/Network/Network/help/Remove-AzCustomIpPrefix.md | 2 +- src/Network/Network/help/Update-AzCustomIpPrefix.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Network/Network/help/Get-AzCustomIpPrefix.md b/src/Network/Network/help/Get-AzCustomIpPrefix.md index 986cde1c4e40..eeddad27a690 100644 --- a/src/Network/Network/help/Get-AzCustomIpPrefix.md +++ b/src/Network/Network/help/Get-AzCustomIpPrefix.md @@ -1,7 +1,7 @@ --- external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml Module Name: Az.Network -online version: +online version: https://docs.microsoft.com/en-us/powershell/module/az.network/get-azcustomipprefix schema: 2.0.0 --- diff --git a/src/Network/Network/help/New-AzCustomIpPrefix.md b/src/Network/Network/help/New-AzCustomIpPrefix.md index 8c977cec0fad..66bb3d91032c 100644 --- a/src/Network/Network/help/New-AzCustomIpPrefix.md +++ b/src/Network/Network/help/New-AzCustomIpPrefix.md @@ -1,7 +1,7 @@ --- external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml Module Name: Az.Network -online version: +online version: https://docs.microsoft.com/en-us/powershell/module/az.network/new-azcustomipprefix schema: 2.0.0 --- diff --git a/src/Network/Network/help/Remove-AzCustomIpPrefix.md b/src/Network/Network/help/Remove-AzCustomIpPrefix.md index e020e24218f6..d99134751767 100644 --- a/src/Network/Network/help/Remove-AzCustomIpPrefix.md +++ b/src/Network/Network/help/Remove-AzCustomIpPrefix.md @@ -1,7 +1,7 @@ --- external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml Module Name: Az.Network -online version: +online version: https://docs.microsoft.com/en-us/powershell/module/az.network/remove-azcustomipprefix schema: 2.0.0 --- diff --git a/src/Network/Network/help/Update-AzCustomIpPrefix.md b/src/Network/Network/help/Update-AzCustomIpPrefix.md index 701b0c0fb587..a37b5cf8901d 100644 --- a/src/Network/Network/help/Update-AzCustomIpPrefix.md +++ b/src/Network/Network/help/Update-AzCustomIpPrefix.md @@ -1,7 +1,7 @@ --- external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml Module Name: Az.Network -online version: +online version: https://docs.microsoft.com/en-us/powershell/module/az.network/update-azcustomipprefix schema: 2.0.0 --- From 87dd48684ab4dcd477a6f6d206c0654169ad1921 Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Mon, 24 Aug 2020 11:27:55 -0700 Subject: [PATCH 17/18] update Network.Test.csproj sdk reference --- src/Network/Network.Test/Network.Test.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Network/Network.Test/Network.Test.csproj b/src/Network/Network.Test/Network.Test.csproj index 772200db410d..ca40f9cb5694 100644 --- a/src/Network/Network.Test/Network.Test.csproj +++ b/src/Network/Network.Test/Network.Test.csproj @@ -14,9 +14,9 @@ - + - + From 4a0f72dd3a7a8cb5c66d10fbd34d5482dd61a23c Mon Sep 17 00:00:00 2001 From: Dennis Xiang Date: Fri, 28 Aug 2020 11:14:12 -0700 Subject: [PATCH 18/18] skip CustomIpPrefix tests --- src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs index a9c48891b254..e78ab7c7c2c8 100644 --- a/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs +++ b/src/Network/Network.Test/ScenarioTests/CustomIpPrefixTests.cs @@ -26,7 +26,7 @@ public CustomIpPrefixTests(Xunit.Abstractions.ITestOutputHelper output) { } - [Fact] + [Fact(Skip = "Resource currently in private preview, testing requires very specific conditions, will implement these tests in future.")] [Trait(Category.AcceptanceType, Category.CheckIn)] [Trait(Category.Owner, NrpTeamAlias.billingandtelemetry)] public void TestCustomIpPrefixCRUD()