Skip to content

Commit

Permalink
mgmt, support network profile (#21883)
Browse files Browse the repository at this point in the history
* base codegen

* support network profile
  • Loading branch information
weidongxu-microsoft authored May 28, 2021
1 parent 37d1049 commit 73ad63d
Show file tree
Hide file tree
Showing 9 changed files with 590 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.5.0-beta.1 (Unreleased)

- Updated `api-version` to `2020-11-01`
- Supported `NetworkProfile`

## 2.4.0 (2021-04-28)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.azure.resourcemanager.network.implementation.LoadBalancersImpl;
import com.azure.resourcemanager.network.implementation.LocalNetworkGatewaysImpl;
import com.azure.resourcemanager.network.implementation.NetworkInterfacesImpl;
import com.azure.resourcemanager.network.implementation.NetworkProfilesImpl;
import com.azure.resourcemanager.network.implementation.NetworkSecurityGroupsImpl;
import com.azure.resourcemanager.network.implementation.NetworkUsagesImpl;
import com.azure.resourcemanager.network.implementation.NetworkWatchersImpl;
Expand All @@ -32,6 +33,7 @@
import com.azure.resourcemanager.network.models.LoadBalancers;
import com.azure.resourcemanager.network.models.LocalNetworkGateways;
import com.azure.resourcemanager.network.models.NetworkInterfaces;
import com.azure.resourcemanager.network.models.NetworkProfiles;
import com.azure.resourcemanager.network.models.NetworkSecurityGroups;
import com.azure.resourcemanager.network.models.NetworkUsages;
import com.azure.resourcemanager.network.models.NetworkWatchers;
Expand Down Expand Up @@ -70,6 +72,7 @@ public final class NetworkManager extends Manager<NetworkManagementClient> {
private DdosProtectionPlans ddosProtectionPlans;
private ExpressRouteCrossConnections expressRouteCrossConnections;
private PrivateEndpoints privateEndpoints;
private NetworkProfiles networkProfiles;

/**
* Get a Configurable instance that can be used to create {@link NetworkManager} with optional configuration.
Expand Down Expand Up @@ -276,4 +279,12 @@ public PrivateEndpoints privateEndpoints() {
}
return this.privateEndpoints;
}

/** @return entry point to network profiles management */
public NetworkProfiles networkProfiles() {
if (this.networkProfiles == null) {
this.networkProfiles = new NetworkProfilesImpl(this);
}
return this.networkProfiles;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.network.implementation;

import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.network.fluent.models.IpConfigurationProfileInner;
import com.azure.resourcemanager.network.fluent.models.NetworkProfileInner;
import com.azure.resourcemanager.network.fluent.models.SubnetInner;
import com.azure.resourcemanager.network.models.ContainerNetworkInterfaceConfiguration;
import com.azure.resourcemanager.network.models.NetworkProfile;
import com.azure.resourcemanager.network.models.Subnet;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.List;

final class NetworkProfileImpl extends
GroupableParentResourceWithTagsImpl<NetworkProfile, NetworkProfileInner, NetworkProfileImpl, NetworkManager>
implements NetworkProfile, NetworkProfile.Definition, NetworkProfile.Update {

NetworkProfileImpl(String name, NetworkProfileInner innerObject, NetworkManager manager) {
super(name, innerObject, manager);
}

@Override
public List<ContainerNetworkInterfaceConfiguration> containerNetworkInterfaceConfigurations() {
List<ContainerNetworkInterfaceConfiguration> inner =
this.innerModel().containerNetworkInterfaceConfigurations();
if (inner != null) {
return Collections.unmodifiableList(inner);
} else {
return Collections.emptyList();
}
}

@Override
protected Mono<NetworkProfileInner> applyTagsToInnerAsync() {
return this
.manager()
.serviceClient()
.getNetworkProfiles()
.updateTagsAsync(resourceGroupName(), name(), innerModel().tags());
}

@Override
protected Mono<NetworkProfileInner> createInner() {
return this
.manager()
.serviceClient()
.getNetworkProfiles()
.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.innerModel());
}

@Override
protected void initializeChildrenFromInner() {
}

@Override
protected Mono<NetworkProfileInner> getInnerAsync() {
return this
.manager()
.serviceClient()
.getNetworkProfiles()
.getByResourceGroupAsync(this.resourceGroupName(), this.name());
}


@Override
public NetworkProfileImpl withContainerNetworkInterfaceConfiguration(
String name, String ipConfigName, String virtualNetworkId, String subnetName) {
String subnetId = String.format("%s/subnets/%s", virtualNetworkId, subnetName);
return withContainerNetworkInterfaceConfiguration(name, ipConfigName, subnetId);
}

@Override
public NetworkProfileImpl withContainerNetworkInterfaceConfiguration(
String name, String ipConfigName, Subnet subnet) {
return withContainerNetworkInterfaceConfiguration(name, ipConfigName, subnet.id());
}

private NetworkProfileImpl withContainerNetworkInterfaceConfiguration(
String name, String ipConfigName, String subnetId) {
this.innerModel().withContainerNetworkInterfaceConfigurations(
Collections
.singletonList(
new ContainerNetworkInterfaceConfiguration()
.withName(name)
.withIpConfigurations(
Collections
.singletonList(
new IpConfigurationProfileInner()
.withName(ipConfigName)
.withSubnet(new SubnetInner().withId(subnetId))))));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.network.implementation;

import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.network.fluent.NetworkProfilesClient;
import com.azure.resourcemanager.network.fluent.models.NetworkProfileInner;
import com.azure.resourcemanager.network.models.NetworkProfile;
import com.azure.resourcemanager.network.models.NetworkProfiles;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl;

public final class NetworkProfilesImpl extends
TopLevelModifiableResourcesImpl<NetworkProfile, NetworkProfileImpl, NetworkProfileInner, NetworkProfilesClient,
NetworkManager>
implements NetworkProfiles {

public NetworkProfilesImpl(final NetworkManager networkManager) {
super(networkManager.serviceClient().getNetworkProfiles(), networkManager);
}

@Override
public NetworkProfileImpl define(String name) {
return wrapModel(name);
}

@Override
protected NetworkProfileImpl wrapModel(String name) {
return new NetworkProfileImpl(name, new NetworkProfileInner(), this.manager());
}

@Override
protected NetworkProfileImpl wrapModel(NetworkProfileInner inner) {
if (inner == null) {
return null;
}
return new NetworkProfileImpl(inner.name(), inner, this.manager());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.network.models;

import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.network.fluent.models.NetworkProfileInner;
import com.azure.resourcemanager.resources.fluentcore.arm.models.GroupableResource;
import com.azure.resourcemanager.resources.fluentcore.arm.models.Resource;
import com.azure.resourcemanager.resources.fluentcore.model.Appliable;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.resourcemanager.resources.fluentcore.model.Refreshable;
import com.azure.resourcemanager.resources.fluentcore.model.Updatable;

import java.util.List;

/** An immutable client-side representation of NetworkProfile. */
public interface NetworkProfile extends
GroupableResource<NetworkManager, NetworkProfileInner>,
Refreshable<NetworkProfile>,
Updatable<NetworkProfile.Update>,
UpdatableWithTags<NetworkProfile> {

/**
* Gets the containerNetworkInterfaceConfigurations property: List of chid container network interface
* configurations.
*
* @return the containerNetworkInterfaceConfigurations value.
*/
List<ContainerNetworkInterfaceConfiguration> containerNetworkInterfaceConfigurations();

/** The entirety of the NetworkProfile definition. */
interface Definition
extends DefinitionStages.Blank,
DefinitionStages.WithGroup,
DefinitionStages.WithContainerNetworkInterfaceConfigurations,
DefinitionStages.WithCreate {
}
/** The NetworkProfile definition stages. */
interface DefinitionStages {
/**
* The first stage of the NetworkProfile definition.
*/
interface Blank extends
GroupableResource.DefinitionWithRegion<NetworkProfile.DefinitionStages.WithGroup> {
}

/**
* The stage of the NetworkProfile definition allowing to specify parent resource.
*/
interface WithGroup extends
GroupableResource.DefinitionStages.WithGroup
<NetworkProfile.DefinitionStages.WithContainerNetworkInterfaceConfigurations> {
}

/**
* The stage of the NetworkProfile definition which contains all the minimum required properties for the
* resource to be created, but also allows for any other optional properties to be specified.
*/
interface WithCreate
extends Creatable<NetworkProfile>,
Resource.DefinitionWithTags<NetworkProfile.DefinitionStages.WithCreate> {
}

/**
* The stage of the NetworkProfile definition allowing to specify network interface configurations for
* container.
*/
interface WithContainerNetworkInterfaceConfigurations {
/**
* Specifies the network interface configuration for container.
*
* @param name the name
* @param ipConfigName the name of ip configuration
* @param virtualNetworkId the ID of the virtual network
* @param subnetName the name of the subnet
* @return the next stage
*/
WithCreate withContainerNetworkInterfaceConfiguration(
String name, String ipConfigName, String virtualNetworkId, String subnetName);

/**
* Specifies the network interface configuration for container.
*
* @param name the name
* @param ipConfigName the name of ip configuration
* @param subnet the Subnet resource
* @return the next stage
*/
WithCreate withContainerNetworkInterfaceConfiguration(
String name, String ipConfigName, Subnet subnet);
}
}

/** The template for NetworkProfile update. */
interface Update extends
Appliable<NetworkProfile>,
Resource.UpdateWithTags<NetworkProfile.Update> {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.network.models;

import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.SupportsDeletingByResourceGroup;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.SupportsGettingById;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.SupportsGettingByResourceGroup;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.SupportsListingByResourceGroup;
import com.azure.resourcemanager.resources.fluentcore.arm.models.HasManager;
import com.azure.resourcemanager.resources.fluentcore.collection.SupportsCreating;
import com.azure.resourcemanager.resources.fluentcore.collection.SupportsDeletingById;
import com.azure.resourcemanager.resources.fluentcore.collection.SupportsListing;

/** Resource collection API of NetworkProfiles. */
public interface NetworkProfiles extends
SupportsCreating<NetworkProfile.DefinitionStages.Blank>,
SupportsListing<NetworkProfile>,
SupportsListingByResourceGroup<NetworkProfile>,
SupportsGettingByResourceGroup<NetworkProfile>,
SupportsGettingById<NetworkProfile>,
SupportsDeletingById,
SupportsDeletingByResourceGroup,
HasManager<NetworkManager> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.network;

import com.azure.core.management.Region;
import com.azure.resourcemanager.network.models.ContainerNetworkInterfaceConfiguration;
import com.azure.resourcemanager.network.models.Network;
import com.azure.resourcemanager.network.models.NetworkProfile;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class NetworkProfileTests extends NetworkManagementTest {

@Test
public void canCRUDNetworkProfile() {
Network network = networkManager.networks().define("vnet1")
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.withAddressSpace("10.0.0.0/24")
.withSubnet("default", "10.0.0.0/24")
.create();

NetworkProfile networkProfile = networkManager.networkProfiles().define("profile1")
.withRegion(Region.US_EAST)
.withExistingResourceGroup(rgName)
.withContainerNetworkInterfaceConfiguration("eth1", "ipconfig1", network.id(), "default")
.withTag("tag.1", "value.1")
.create();

Assertions.assertEquals(1, networkProfile.containerNetworkInterfaceConfigurations().size());
ContainerNetworkInterfaceConfiguration configuration = networkProfile.containerNetworkInterfaceConfigurations().iterator().next();
Assertions.assertEquals("eth1", configuration.name());
Assertions.assertEquals("ipconfig1", configuration.ipConfigurations().iterator().next().name());
Assertions.assertEquals(network.subnets().get("default").id(), configuration.ipConfigurations().iterator().next().subnet().id());

Assertions.assertEquals(1, networkManager.networkProfiles().listByResourceGroup(rgName).stream().count());
Assertions.assertEquals(networkProfile.name(), networkManager.networkProfiles().getById(networkProfile.id()).name());

networkProfile.update()
.withTag("tag.2", "value.2")
.apply();

Assertions.assertEquals(1, networkProfile.containerNetworkInterfaceConfigurations().size());
}
}
Loading

0 comments on commit 73ad63d

Please sign in to comment.