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);