-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mgmt, support network profile (#21883)
* base codegen * support network profile
- Loading branch information
1 parent
37d1049
commit 73ad63d
Showing
9 changed files
with
590 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
97 changes: 97 additions & 0 deletions
97
...rk/src/main/java/com/azure/resourcemanager/network/implementation/NetworkProfileImpl.java
This file contains 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,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; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...k/src/main/java/com/azure/resourcemanager/network/implementation/NetworkProfilesImpl.java
This file contains 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,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()); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...anager-network/src/main/java/com/azure/resourcemanager/network/models/NetworkProfile.java
This file contains 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,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> { | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...nager-network/src/main/java/com/azure/resourcemanager/network/models/NetworkProfiles.java
This file contains 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,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> { | ||
} |
46 changes: 46 additions & 0 deletions
46
...emanager-network/src/test/java/com/azure/resourcemanager/network/NetworkProfileTests.java
This file contains 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,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()); | ||
} | ||
} |
Oops, something went wrong.