-
Notifications
You must be signed in to change notification settings - Fork 4k
Powershell for interface endpoints #7172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
markcowl
merged 1 commit into
Azure:network-september-release
from
chandrasekarsrinivasan:interfaceendpoints
Sep 13, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...rceManager/Network/Commands.Network/InterfaceEndpoint/AzureInterfaceEndpointBaseCmdlet.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
| ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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 System.Net; | ||
using Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using System.Collections.Generic; | ||
using Microsoft.Rest.Azure; | ||
|
||
public abstract class AzureInterfaceEndpointBaseCmdlet : NetworkBaseCmdlet | ||
{ | ||
public IInterfaceEndpointsOperations InterfaceEndpointClient | ||
{ | ||
get | ||
{ | ||
return NetworkClient.NetworkManagementClient.InterfaceEndpoints; | ||
} | ||
} | ||
|
||
public bool IsServiceEndpointPolicyPresent(string resourceGroupName, string name) | ||
{ | ||
try | ||
{ | ||
GetInterfaceEndpoint(resourceGroupName, name); | ||
} | ||
catch (Microsoft.Rest.Azure.CloudException exception) | ||
{ | ||
if (exception.Response.StatusCode == HttpStatusCode.NotFound) | ||
{ | ||
// Resource is not present | ||
return false; | ||
} | ||
|
||
throw; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public PSInterfaceEndpoint GetInterfaceEndpoint(string resourceGroupName, string name, string expandResource = null) | ||
{ | ||
var interfaceEndpoint = this.InterfaceEndpointClient.Get(resourceGroupName, name, expandResource); | ||
|
||
var pSInterfaceEndpoint = ToInterfaceEndpoint(interfaceEndpoint); | ||
pSInterfaceEndpoint.ResourceGroupName = resourceGroupName; | ||
|
||
return pSInterfaceEndpoint; | ||
} | ||
|
||
public IEnumerable<PSInterfaceEndpoint> ListInterfaceEndpoints(string resourceGroupName) | ||
{ | ||
var interfaceEndpoints = this.InterfaceEndpointClient.List(resourceGroupName); | ||
|
||
List<PSInterfaceEndpoint> pSInterfaceEndpoints = new List<PSInterfaceEndpoint>(); | ||
foreach (var interfaceEndpoint in interfaceEndpoints) | ||
{ | ||
var pSInterfaceEndpoint = ToInterfaceEndpoint(interfaceEndpoint); | ||
pSInterfaceEndpoint.ResourceGroupName = resourceGroupName; | ||
pSInterfaceEndpoints.Add(pSInterfaceEndpoint); | ||
} | ||
|
||
return pSInterfaceEndpoints; | ||
} | ||
|
||
public PSInterfaceEndpoint ToInterfaceEndpoint(InterfaceEndpoint interfaceEndpoint) | ||
{ | ||
var pSInterfaceEndpoint = NetworkResourceManagerProfile.Mapper.Map<PSInterfaceEndpoint>(interfaceEndpoint); | ||
return pSInterfaceEndpoint; | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...rceManager/Network/Commands.Network/InterfaceEndpoint/GetAzureInterfaceEndpointCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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.WindowsAzure.Commands.Utilities.Common; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "InterfaceEndpoint", SupportsShouldProcess = true, DefaultParameterSetName = "GetByNameParameterSet"), OutputType(typeof(PSInterfaceEndpoint))] | ||
public class GetInterfaceEndpointCommand : AzureInterfaceEndpointBaseCmdlet | ||
{ | ||
[Parameter( | ||
Mandatory = false, | ||
ParameterSetName = "GetByNameParameterSet", | ||
HelpMessage = "The name of the interface endpoint")] | ||
[ValidateNotNullOrEmpty] | ||
public string Name { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The resource group name.", | ||
ParameterSetName = "GetByNameParameterSet")] | ||
[ResourceGroupCompleter] | ||
[ValidateNotNullOrEmpty] | ||
public virtual string ResourceGroupName { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
ValueFromPipelineByPropertyName = true, | ||
ParameterSetName = "GetByResourceIdParameterSet")] | ||
[ValidateNotNullOrEmpty] | ||
public virtual string ResourceId { get; set; } | ||
|
||
public override void Execute() | ||
{ | ||
if (this.ShouldProcess(Name, VerbsLifecycle.Restart)) | ||
{ | ||
base.Execute(); | ||
|
||
if (this.IsParameterBound(c => c.ResourceId)) | ||
{ | ||
var resourceIdentifier = new ResourceIdentifier(this.ResourceId); | ||
this.ResourceGroupName = resourceIdentifier.ResourceGroupName; | ||
this.Name = resourceIdentifier.ResourceName; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(this.Name)) | ||
{ | ||
PSInterfaceEndpoint psInterfaceEndpoint; | ||
psInterfaceEndpoint = this.GetInterfaceEndpoint(this.ResourceGroupName, this.Name); | ||
WriteObject(psInterfaceEndpoint); | ||
} | ||
else | ||
{ | ||
IEnumerable<PSInterfaceEndpoint> interfaceEndpoints = null; | ||
if (!string.IsNullOrEmpty(this.ResourceGroupName)) | ||
{ | ||
interfaceEndpoints = ListInterfaceEndpoints(this.ResourceGroupName); | ||
} | ||
|
||
WriteObject(interfaceEndpoints, true); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/ResourceManager/Network/Commands.Network/Models/PSEndpointService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) Microsoft. 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. | ||
// | ||
|
||
namespace Microsoft.Azure.Commands.Network.Models | ||
{ | ||
using Newtonsoft.Json; | ||
|
||
public class PSEndpointService | ||
{ | ||
[JsonProperty(Order = 1)] | ||
public string Id { get; set; } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to adda test case for this cmdlet. There is not test case in the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot have a test case on this. there is no way to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further details - we are not ready to expose end to end scenario for this through powershell. There is no way to set this on PS and hence a test case cannot be created. In a couple of months, we will have full support on this and then we can create New-, Set- APIs.