Skip to content

Commit

Permalink
support subnet delegations (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Sep 3, 2020
1 parent 3bd716f commit bf07cd2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/ResourceManagement/Network/Domain/InterfaceImpl/SubnetImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,30 @@ Subnet.Update.IUpdate Subnet.Update.IWithAddressPrefix.WithAddressPrefix(string
{
return this.WithExistingNetworkSecurityGroup(resourceId);
}

Subnet.Definition.IWithAttach<Network.Definition.IWithCreateAndSubnet> Subnet.Definition.IWithDelegation<Network.Definition.IWithCreateAndSubnet>.WithDelegation(string serviceName)
{
return this.WithDelegation(serviceName);
}

Subnet.UpdateDefinition.IWithAttach<Network.Update.IUpdate> Subnet.UpdateDefinition.IWithDelegation<Network.Update.IUpdate>.WithDelegation(string serviceName)
{
return this.WithDelegation(serviceName);
}

Subnet.Update.IUpdate Subnet.Update.IWithDelegation.WithDelegation(string serviceName)
{
return this.WithDelegation(serviceName);
}

Subnet.Update.IUpdate Subnet.Update.IWithDelegation.WithoutDelegation(string serviceName)
{
return this.WithoutDelegation(serviceName);
}

Subnet.Update.IUpdate Subnet.Update.IWithDelegation.WithoutDelegations()
{
return this.WithoutDelegations();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ public interface IWithServiceEndpoint<ParentT> :
Microsoft.Azure.Management.Network.Fluent.Subnet.Definition.IWithAttach<ParentT> WithAccessFromService(ServiceEndpointType service);
}

/// <summary>
/// The stage of a subnet definition allowing to enable subnet delegation.
/// </summary>
/// <typeparam name="ParentT">The stage of the parent definition to return to after attaching this definition.</typeparam>
public interface IWithDelegation<ParentT> :
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IBeta
{
/// <summary>
/// Specifies a service name for subnet delegation.
/// </summary>
/// <param name="serviceName">The service name.</param>
/// <return>The next stage of the definition.</return>
Microsoft.Azure.Management.Network.Fluent.Subnet.Definition.IWithAttach<ParentT> WithDelegation(string serviceName);
}

/// <summary>
/// The first stage of the subnet definition.
/// </summary>
Expand Down Expand Up @@ -107,7 +122,8 @@ public interface IWithAttach<ParentT> :
Microsoft.Azure.Management.ResourceManager.Fluent.Core.ChildResource.Definition.IInDefinition<ParentT>,
Microsoft.Azure.Management.Network.Fluent.Subnet.Definition.IWithNetworkSecurityGroup<ParentT>,
Microsoft.Azure.Management.Network.Fluent.Subnet.Definition.IWithRouteTable<ParentT>,
Microsoft.Azure.Management.Network.Fluent.Subnet.Definition.IWithServiceEndpoint<ParentT>
Microsoft.Azure.Management.Network.Fluent.Subnet.Definition.IWithServiceEndpoint<ParentT>,
IWithDelegation<ParentT>
{
}
}
28 changes: 28 additions & 0 deletions src/ResourceManagement/Network/Domain/Subnet/Update/IUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ public interface IWithServiceEndpoint :
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IUpdate WithoutAccessFromService(ServiceEndpointType service);
}

/// <summary>
/// The stage of a subnet update allowing to enable subnet delegation.
/// </summary>
public interface IWithDelegation :
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IBeta
{
/// <summary>
/// Specifies a service name for subnet delegation.
/// </summary>
/// <param name="serviceName">The service name.</param>
/// <return>The next stage of the update.</return>
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IUpdate WithDelegation(string serviceName);

/// <summary>
/// Removes a service name for subnet delegation.
/// </summary>
/// <param name="serviceName">The service name.</param>
/// <return>The next stage of the update.</return>
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IUpdate WithoutDelegation(string serviceName);

/// <summary>
/// Removes all subnet delegations.
/// </summary>
/// <return>The next stage of the update.</return>
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IUpdate WithoutDelegations();
}

/// <summary>
/// The entirety of a subnet update as part of a network update.
/// </summary>
Expand All @@ -63,6 +90,7 @@ public interface IUpdate :
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IWithNetworkSecurityGroup,
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IWithRouteTable,
Microsoft.Azure.Management.Network.Fluent.Subnet.Update.IWithServiceEndpoint,
IWithDelegation,
Microsoft.Azure.Management.ResourceManager.Fluent.Core.ChildResourceActions.ISettable<Microsoft.Azure.Management.Network.Fluent.Network.Update.IUpdate>
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ public interface IWithServiceEndpoint<ParentT> :
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IWithAttach<ParentT> WithAccessFromService(ServiceEndpointType service);
}

/// <summary>
/// The stage of a subnet definition allowing to enable subnet delegation.
/// </summary>
/// <typeparam name="ParentT">The stage of the parent definition to return to after attaching this definition.</typeparam>
public interface IWithDelegation<ParentT> :
Microsoft.Azure.Management.ResourceManager.Fluent.Core.IBeta
{
/// <summary>
/// Specifies a service name for subnet delegation.
/// </summary>
/// <param name="serviceName">The service name.</param>
/// <return>The next stage of the definition.</return>
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IWithAttach<ParentT> WithDelegation(string serviceName);
}

/// <summary>
/// The entirety of a subnet definition as part of a virtual network update.
/// </summary>
Expand All @@ -85,7 +100,8 @@ public interface IUpdateDefinition<ParentT> :
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IBlank<ParentT>,
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IWithAddressPrefix<ParentT>,
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IWithNetworkSecurityGroup<ParentT>,
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IWithAttach<ParentT>
Microsoft.Azure.Management.Network.Fluent.Subnet.UpdateDefinition.IWithAttach<ParentT>,
IWithDelegation<ParentT>
{
}

Expand Down
36 changes: 36 additions & 0 deletions src/ResourceManagement/Network/SubnetImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

namespace Microsoft.Azure.Management.Network.Fluent
{
using Microsoft.Azure.Management.Network.Fluent.Network.Definition;
using Microsoft.Azure.Management.Network.Fluent.Subnet.Definition;
using Models;
using ResourceManager.Fluent;
using ResourceManager.Fluent.Core;
using ResourceManager.Fluent.Core.ChildResourceActions;
using System;
using System.Collections.Generic;
using System.Linq;

/// <summary>
/// Implementation for Subnet and its create and update interfaces.
Expand Down Expand Up @@ -312,5 +315,38 @@ internal ISet<string> ListAvailablePrivateIPAddresses()
ipAddresses.UnionWith(result.AvailableIPAddresses);
return ipAddresses;
}

internal SubnetImpl WithDelegation(string serviceName)
{
if (Inner.Delegations == null)
{
Inner.Delegations = new List<DelegationInner>();
}
Inner.Delegations.Add(new DelegationInner()
{
Name = serviceName,
ServiceName = serviceName
});
return this;
}

internal SubnetImpl WithoutDelegation(string serviceName)
{
if (Inner.Delegations != null)
{
Inner.Delegations = Inner.Delegations.Where(d => !d.ServiceName.Equals(serviceName)).ToList();
}
if (Inner.Delegations.Count == 0)
{
Inner.Delegations = null;
}
return this;
}

internal SubnetImpl WithoutDelegations()
{
Inner.Delegations = null;
return this;
}
}
}

0 comments on commit bf07cd2

Please sign in to comment.