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