diff --git a/src/Network/Network.Test/ScenarioTests/AvailableAliasTests.cs b/src/Network/Network.Test/ScenarioTests/AvailableAliasTests.cs new file mode 100644 index 000000000000..3f62f16eb004 --- /dev/null +++ b/src/Network/Network.Test/ScenarioTests/AvailableAliasTests.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. +// ---------------------------------------------------------------------------------- + +using Microsoft.Azure.Commands.Network.Test.ScenarioTests; +using Microsoft.WindowsAzure.Commands.ScenarioTest; +using Xunit; + +namespace Commands.Network.Test.ScenarioTests +{ + public class AvailableAliasTests :NetworkTestRunner + { + public AvailableAliasTests(Xunit.Abstractions.ITestOutputHelper output) + : base(output) + { + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(Category.Owner, NrpTeamAlias.sdnnrp)] + public void TestAvailableAliasList() + { + TestRunner.RunTestScript( "Test-GetAvailableAliasList"); + } + } +} diff --git a/src/Network/Network.Test/ScenarioTests/AvailableAliasTests.ps1 b/src/Network/Network.Test/ScenarioTests/AvailableAliasTests.ps1 new file mode 100644 index 000000000000..08a27ea31b0c --- /dev/null +++ b/src/Network/Network.Test/ScenarioTests/AvailableAliasTests.ps1 @@ -0,0 +1,33 @@ +# ---------------------------------------------------------------------------------- +# +# 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 checking API to list available Alias. +#> +function Test-GetAvailableAliasList +{ + $location = Get-ProviderLocation ResourceManagement + + try + { + $results = Get-AzAvailableServiceAlias -Location $location; + Assert-NotNull $results; + } + finally + { + # Cleanup + Clean-ResourceGroup $rgname + } +} diff --git a/src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AvailableAliasTests/TestAvailableAliasList.json b/src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AvailableAliasTests/TestAvailableAliasList.json new file mode 100644 index 000000000000..c61a6d091fde --- /dev/null +++ b/src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AvailableAliasTests/TestAvailableAliasList.json @@ -0,0 +1,75 @@ +{ + "Entries": [ + { + "RequestUri": "/subscriptions/947d47b4-7883-4bb9-9d85-c5e8e2f572ce/providers/Microsoft.Network/locations/West%20Central%20US/availableServiceAliases?api-version=2019-08-01", + "EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvOTQ3ZDQ3YjQtNzg4My00YmI5LTlkODUtYzVlOGUyZjU3MmNlL3Byb3ZpZGVycy9NaWNyb3NvZnQuTmV0d29yay9sb2NhdGlvbnMvV2VzdCUyMENlbnRyYWwlMjBVUy9hdmFpbGFibGVTZXJ2aWNlQWxpYXNlcz9hcGktdmVyc2lvbj0yMDE5LTA4LTAx", + "RequestMethod": "GET", + "RequestBody": "", + "RequestHeaders": { + "x-ms-client-request-id": [ + "bb89b196-039e-470b-9c61-c5e3b7a8ad20" + ], + "Accept-Language": [ + "en-US" + ], + "User-Agent": [ + "FxVersion/4.6.27817.01", + "OSName/Windows", + "OSVersion/Microsoft.Windows.10.0.18362.", + "Microsoft.Azure.Management.Network.NetworkManagementClient/19.16.0.0" + ] + }, + "ResponseHeaders": { + "Cache-Control": [ + "no-cache" + ], + "Pragma": [ + "no-cache" + ], + "x-ms-request-id": [ + "32791b33-78e3-4611-8d4f-91fdce3eac56" + ], + "x-ms-correlation-request-id": [ + "cf783df8-e0a8-4743-9b55-98a450937f2a" + ], + "x-ms-arm-service-request-id": [ + "138ace78-6c17-4b70-8794-bf455e2f1f53" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubDomains" + ], + "Server": [ + "Microsoft-HTTPAPI/2.0", + "Microsoft-HTTPAPI/2.0" + ], + "x-ms-ratelimit-remaining-subscription-reads": [ + "11999" + ], + "x-ms-routing-request-id": [ + "WESTUS:20191004T202417Z:cf783df8-e0a8-4743-9b55-98a450937f2a" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Fri, 04 Oct 2019 20:24:16 GMT" + ], + "Content-Length": [ + "632" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Expires": [ + "-1" + ] + }, + "ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"name\": \"servicesAzure\",\r\n \"id\": \"/subscriptions/947d47b4-7883-4bb9-9d85-c5e8e2f572ce/providers/Microsoft.Network/AvailableServiceAliases/servicesAzure\",\r\n \"type\": \"Microsoft.Network/AvailableServiceAliases\",\r\n \"resourceName\": \"/services/Azure\"\r\n },\r\n {\r\n \"name\": \"servicesAzureManagedInstance\",\r\n \"id\": \"/subscriptions/947d47b4-7883-4bb9-9d85-c5e8e2f572ce/providers/Microsoft.Network/AvailableServiceAliases/servicesAzureManagedInstance\",\r\n \"type\": \"Microsoft.Network/AvailableServiceAliases\",\r\n \"resourceName\": \"/services/Azure/ManagedInstance\"\r\n }\r\n ]\r\n}", + "StatusCode": 200 + } + ], + "Names": {}, + "Variables": { + "SubscriptionId": "947d47b4-7883-4bb9-9d85-c5e8e2f572ce" + } +} \ No newline at end of file diff --git a/src/Network/Network/AvailableAlias/GetAzureAvailableServiceAlias.cs b/src/Network/Network/AvailableAlias/GetAzureAvailableServiceAlias.cs new file mode 100644 index 000000000000..70ce7502d72c --- /dev/null +++ b/src/Network/Network/AvailableAlias/GetAzureAvailableServiceAlias.cs @@ -0,0 +1,52 @@ +// +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// 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 System.Collections.Generic; +using System.Management.Automation; +using Microsoft.Azure.Commands.Network.Models; +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Management.Network; +using CNM = Microsoft.Azure.Commands.Network.Models; + +namespace Microsoft.Azure.Commands.Network.Automation +{ + [Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AvailableServiceAlias"), OutputType(typeof(PsAvailableServiceAlias))] + public partial class GetAzureAvailableServiceAliasCommand : NetworkBaseCmdlet + { + [Parameter( + Mandatory = true, + HelpMessage = "The location.", + ValueFromPipelineByPropertyName = true)] + [LocationCompleter("Microsoft.Network/locations/availableServiceAliases")] + [ValidateNotNullOrEmpty] + public string Location { get; set; } + + public override void Execute() + { + base.Execute(); + + var availableServiceAliasList = this.NetworkClient.NetworkManagementClient.AvailableServiceAliases.List(Location); + List psAvailableServiceAlias = new List(); + + foreach (var availableServiceAlias in availableServiceAliasList) + { + psAvailableServiceAlias.Add(NetworkResourceManagerProfile.Mapper.Map(availableServiceAlias)); + } + + WriteObject(psAvailableServiceAlias, true); + } + } +} diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index 1ef188052125..b4ac8dda535a 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -416,6 +416,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'Deny-AzPrivateEndpointConnection', 'Get-AzAvailablePrivateEndpointType', 'Get-AzAvailablePrivateEndpointType', + 'Get-AzAvailableServiceAlias', 'New-AzBastion', 'Get-AzBastion', 'Remove-AzBastion', 'Start-AzVirtualNetworkGatewayPacketCapture', 'Stop-AzVirtualNetworkGatewayPacketCapture', diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 0cffca301598..3af40336859f 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -19,6 +19,7 @@ ---> ## Upcoming Release +* Add new cmdlet Get-AzAvailableServiceAlias which can be called to get the aliases that can be used for Service Endpoint Policies. * Added support for the adding traffic selectors to Virtual Network Gateway Connections - New cmdlets added: - New-AzureRmTrafficSelectorPolicy diff --git a/src/Network/Network/Common/NetworkResourceManagerProfile.cs b/src/Network/Network/Common/NetworkResourceManagerProfile.cs index f37abc1acced..c52c5fbaac79 100644 --- a/src/Network/Network/Common/NetworkResourceManagerProfile.cs +++ b/src/Network/Network/Common/NetworkResourceManagerProfile.cs @@ -232,6 +232,13 @@ private static void Initialize() // MNM to CNM cfg.CreateMap(); + // Available subnet aliases + // CNM to MNM + cfg.CreateMap(); + + // MNM to CNM + cfg.CreateMap(); + // VirtualNetwork Peering // CNM to MNM cfg.CreateMap() diff --git a/src/Network/Network/Models/PSAvailableServiceAlias.cs b/src/Network/Network/Models/PSAvailableServiceAlias.cs new file mode 100644 index 000000000000..5d6eb43dc379 --- /dev/null +++ b/src/Network/Network/Models/PSAvailableServiceAlias.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using Microsoft.WindowsAzure.Commands.Common.Attributes; + +namespace Microsoft.Azure.Commands.Network.Models +{ + public class PsAvailableServiceAlias + { + [Ps1Xml(Label = "Name", Target = ViewControl.Table, Position = 1)] + public string Name { get; set; } + + public string Id { get; set; } + + [Ps1Xml(Target = ViewControl.Table)] + public string Type { get; set; } + + public string ResourceName { get; set; } + } +} diff --git a/src/Network/Network/help/Az.Network.md b/src/Network/Network/help/Az.Network.md index df68c9232c73..0058103246f2 100644 --- a/src/Network/Network/help/Az.Network.md +++ b/src/Network/Network/help/Az.Network.md @@ -230,6 +230,9 @@ Gets an array of private link service id that can be linked to a private end poi ### [Get-AzAvailablePrivateEndpointType](Get-AzAvailablePrivateEndpointType.md) Return available private end point types in the location +### [Get-AzAvailableServiceAlias](Get-AzAvailableServiceAlias.md) +Get available service aliases in the region. + ### [Get-AzAvailableServiceDelegation](Get-AzAvailableServiceDelegation.md) Get available service delegations in the region. diff --git a/src/Network/Network/help/Get-AzAvailableServiceAlias.md b/src/Network/Network/help/Get-AzAvailableServiceAlias.md new file mode 100644 index 000000000000..3b4d54e20831 --- /dev/null +++ b/src/Network/Network/help/Get-AzAvailableServiceAlias.md @@ -0,0 +1,80 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml +Module Name: Az.Network +online version: https://docs.microsoft.com/en-us/powershell/module/az.network/get-azavailableservicealias +schema: 2.0.0 +--- + +# Get-AzAvailableServiceAlias + +## SYNOPSIS +Get available service aliases in the region. + +## SYNTAX + +``` +Get-AzAvailableServiceAlias -Location [-DefaultProfile ] [] +``` + +## DESCRIPTION +The **Get-AzAvailableServiceAlias** cmdlet allows you to retrieve all of the available service aliases for a subnet in the provided location. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-AzAvailableServiceAliases -Location "westus" + +Name Id Type ResourceName +---- -- ---- ------------ +servicesAzure /subscriptions/61dc4623-b5f8-41a0-acfc-29537dcf6e5d/providers/Microsoft.Network/AvailableServiceAliases/servicesAzure Microsoft.Network/AvailableServiceAliases /services/Azure +servicesAzureManagedInstance /subscriptions/61dc4623-b5f8-41a0-acfc-29537dcf6e5d/providers/Microsoft.Network/AvailableServiceAliases/servicesAzureManagedInstance Microsoft.Network/AvailableServiceAliases /services/Azure/ManagedInstance + +``` + +## PARAMETERS + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.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 location. + +```yaml +Type: System.String +Parameter Sets: (All) +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.PsAvailableServiceAlias + +## NOTES + +## RELATED LINKS