Skip to content

Commit

Permalink
Fix DeleteOptions on Public Ip Address (issue#38806 NetworkInterface …
Browse files Browse the repository at this point in the history
…fix only)
  • Loading branch information
v-hongli1 committed Mar 15, 2024
1 parent 714ba60 commit c45ef75
Show file tree
Hide file tree
Showing 6 changed files with 1,122 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager-network",
"Tag": "java/resourcemanager/azure-resourcemanager-network_2b609265e1"
"Tag": "java/resourcemanager/azure-resourcemanager-network_e2a8fc6b9f"
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ class NetworkInterfaceImpl
/** the name of specified ip config name */
private Map<DeleteOptions, HashSet<String>> specifiedIpConfigNames;
private boolean isInUpdateIpConfigMode = false;
private static final String PRIMARY_IP_CONFIGURATION_NAME = "primary";

NetworkInterfaceImpl(String name, NetworkInterfaceInner innerModel, final NetworkManager networkManager) {
super(name, innerModel, networkManager);
this.nicName = name;
this.namer = this.manager().resourceManager().internalContext().createIdentifierProvider(this.nicName);
this.isInUpdateIpConfigMode = false;
this.specifiedIpConfigNames = new HashMap<DeleteOptions, HashSet<String>>();
this.ensureInUpdateIpConfigMode(false);
initializeChildrenFromInner();
}

Expand Down Expand Up @@ -151,25 +152,46 @@ public NetworkInterfaceImpl withExistingPrimaryNetwork(Network network) {

@Override
public NetworkInterfaceImpl withNewPrimaryPublicIPAddress(Creatable<PublicIpAddress> creatable) {
this.isInUpdateIpConfigMode = true;
this.primaryIPConfiguration().withNewPublicIpAddress(creatable);
return this;
}

@Override
public NetworkInterfaceImpl withNewPrimaryPublicIPAddress(Creatable<PublicIpAddress> creatable, DeleteOptions deleteOptions) {
this.primaryIPConfiguration().withNewPublicIpAddress(creatable);
this.ensureDeleteOptions(deleteOptions, PRIMARY_IP_CONFIGURATION_NAME);
this.ensureInUpdateIpConfigMode(true);
return this;
}

@Override
public NetworkInterfaceImpl withNewPrimaryPublicIPAddress() {
this.isInUpdateIpConfigMode = true;
this.primaryIPConfiguration().withNewPublicIpAddress();
return this;
}

@Override
public NetworkInterfaceImpl withNewPrimaryPublicIPAddress(DeleteOptions deleteOptions) {
this.primaryIPConfiguration().withNewPublicIpAddress();
this.ensureDeleteOptions(deleteOptions, PRIMARY_IP_CONFIGURATION_NAME);
this.ensureInUpdateIpConfigMode(true);
return this;
}

@Override
public NetworkInterfaceImpl withNewPrimaryPublicIPAddress(String leafDnsLabel) {
this.isInUpdateIpConfigMode = true;
this.primaryIPConfiguration().withNewPublicIpAddress(leafDnsLabel);
return this;
}

@Override
public NetworkInterfaceImpl withNewPrimaryPublicIPAddress(String leafDnsLabel, DeleteOptions deleteOptions) {
this.primaryIPConfiguration().withNewPublicIpAddress(leafDnsLabel);
this.ensureDeleteOptions(deleteOptions, PRIMARY_IP_CONFIGURATION_NAME);
this.ensureInUpdateIpConfigMode(true);
return this;
}

@Override
public NetworkInterfaceImpl withExistingLoadBalancerBackend(LoadBalancer loadBalancer, String backendName) {
this.primaryIPConfiguration().withExistingLoadBalancerBackend(loadBalancer, backendName);
Expand Down Expand Up @@ -209,7 +231,15 @@ public NetworkInterfaceImpl withoutPrimaryPublicIPAddress() {
public NetworkInterfaceImpl withExistingPrimaryPublicIPAddress(PublicIpAddress publicIPAddress) {
this.primaryIPConfiguration().withExistingPublicIpAddress(publicIPAddress);
this.primaryIPConfiguration().withPrivateIpVersion(publicIPAddress.version());
this.isInUpdateIpConfigMode = true;
return this;
}

@Override
public NetworkInterfaceImpl withExistingPrimaryPublicIPAddress(PublicIpAddress publicIPAddress, DeleteOptions deleteOptions) {
this.primaryIPConfiguration().withExistingPublicIpAddress(publicIPAddress);
this.primaryIPConfiguration().withPrivateIpVersion(publicIPAddress.version());
this.ensureDeleteOptions(deleteOptions, PRIMARY_IP_CONFIGURATION_NAME);
this.ensureInUpdateIpConfigMode(true);
return this;
}

Expand Down Expand Up @@ -266,7 +296,6 @@ public NetworkInterfaceImpl withoutApplicationSecurityGroup(String applicationSe

@Override
public NicIpConfigurationImpl defineSecondaryIPConfiguration(String name) {
this.isInUpdateIpConfigMode = true;
NicIpConfigurationImpl nicIpConfiguration = prepareNewNicIPConfiguration(name);

// copy application security group from primary to secondary,
Expand All @@ -283,7 +312,6 @@ public NicIpConfigurationImpl defineSecondaryIPConfiguration(String name) {

@Override
public NicIpConfigurationImpl updateIPConfiguration(String name) {
this.isInUpdateIpConfigMode = true;
return (NicIpConfigurationImpl) this.nicIPConfigurations.get(name);
}

Expand Down Expand Up @@ -438,7 +466,7 @@ public NicIpConfigurationImpl primaryIPConfiguration() {
NicIpConfigurationImpl primaryIPConfig = null;
if (this.nicIPConfigurations.size() == 0) {
// If no primary IP config found yet, then create one automatically, otherwise the NIC is in a bad state
primaryIPConfig = prepareNewNicIPConfiguration("primary");
primaryIPConfig = prepareNewNicIPConfiguration(PRIMARY_IP_CONFIGURATION_NAME);
primaryIPConfig.innerModel().withPrimary(true);
withIPConfiguration(primaryIPConfig);
} else if (this.nicIPConfigurations.size() == 1) {
Expand Down Expand Up @@ -587,14 +615,14 @@ protected void beforeCreating() {

@Override
public NetworkInterfaceImpl withPrimaryPublicIPAddressDeleteOptions(DeleteOptions deleteOptions) {
this.ensureDeleteOptions(deleteOptions, "primary");
this.ensureDeleteOptions(deleteOptions, PRIMARY_IP_CONFIGURATION_NAME);
return this;
}

@Override
public NetworkInterfaceImpl update() {
this.specifiedIpConfigNames = new HashMap<DeleteOptions, HashSet<String>>();
this.isInUpdateIpConfigMode = false;
this.ensureInUpdateIpConfigMode(false);
return super.update();
}

Expand All @@ -616,4 +644,8 @@ public void ensureDeleteOptions(DeleteOptions deleteOptions, String ipConfigName
this.specifiedIpConfigNames.put(deleteOptions, new HashSet<>(Arrays.asList(ipConfigName)));
}
}

public void ensureInUpdateIpConfigMode(boolean isInUpdateIpConfigMode) {
this.isInUpdateIpConfigMode = isInUpdateIpConfigMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,50 @@ NicIpConfigurationImpl withoutApplicationSecurityGroup(String name) {

@Override
public NicIpConfigurationImpl withPublicIPAddressDeleteOptions(DeleteOptions deleteOptions) {
this.parent().ensureDeleteOptions(deleteOptions, this.innerModel().name());
this.parent().ensureDeleteOptions(deleteOptions, this.name());
return this;
}

@Override
public NicIpConfigurationImpl withNewPublicIpAddress(Creatable<PublicIpAddress> creatable, DeleteOptions deleteOptions) {
if (this.creatablePublicIPKey == null) {
this.creatablePublicIPKey = creatable.key();
this.parent().addToCreatableDependencies(creatable);
}
this.parent().ensureDeleteOptions(deleteOptions, this.name());
this.parent().ensureInUpdateIpConfigMode(true);
return this;
}

@Override
public NicIpConfigurationImpl withNewPublicIpAddress(DeleteOptions deleteOptions) {
String name = this.parent().namer.getRandomName("pip", 15);
this.parent().ensureDeleteOptions(deleteOptions, this.name());
this.parent().ensureInUpdateIpConfigMode(true);
return withNewPublicIpAddress(prepareCreatablePublicIP(name, name));
}

@Override
public NicIpConfigurationImpl withNewPublicIpAddress(String leafDnsLabel, DeleteOptions deleteOptions) {
String name = this.parent().namer.getRandomName("pip", 15);
this.parent().ensureDeleteOptions(deleteOptions, this.name());
this.parent().ensureInUpdateIpConfigMode(true);
return withNewPublicIpAddress(
prepareCreatablePublicIP(name, leafDnsLabel));
}

@Override
public NicIpConfigurationImpl withExistingPublicIpAddress(PublicIpAddress publicIpAddress, DeleteOptions deleteOptions) {
this.parent().ensureDeleteOptions(deleteOptions, this.name());
this.parent().ensureInUpdateIpConfigMode(true);
return this.withExistingPublicIpAddress(publicIpAddress.id());
}

@Override
public NicIpConfigurationImpl withExistingPublicIpAddress(String resourceId, DeleteOptions deleteOptions) {
this.existingPublicIPAddressIdToAssociate = resourceId;
this.parent().ensureInUpdateIpConfigMode(true);
this.parent().ensureDeleteOptions(deleteOptions, this.name());
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ interface WithPrimaryPublicIPAddress {
*/
WithCreate withNewPrimaryPublicIPAddress(Creatable<PublicIpAddress> creatable);

/**
* Create a new public IP address to associate with network interface's primary IP configuration, based on
* the provided definition.
*
* @param creatable a creatable definition for a new public IP
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the definition
*/
WithCreate withNewPrimaryPublicIPAddress(Creatable<PublicIpAddress> creatable, DeleteOptions deleteOptions);

/**
* Creates a new public IP address in the same region and group as the resource and associate it with the
* network interface's primary IP configuration.
Expand All @@ -179,6 +189,18 @@ interface WithPrimaryPublicIPAddress {
*/
WithCreate withNewPrimaryPublicIPAddress();

/**
* Creates a new public IP address in the same region and group as the resource and associate it with the
* network interface's primary IP configuration.
*
* <p>the internal name and DNS label for the public IP address will be derived from the network interface
* name
*
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the definition
*/
WithCreate withNewPrimaryPublicIPAddress(DeleteOptions deleteOptions);

/**
* Creates a new public IP address in the same region and group as the resource, with the specified DNS
* label and associate it with the network interface's primary IP configuration.
Expand All @@ -190,13 +212,34 @@ interface WithPrimaryPublicIPAddress {
*/
WithCreate withNewPrimaryPublicIPAddress(String leafDnsLabel);

/**
* Creates a new public IP address in the same region and group as the resource, with the specified DNS
* label and associate it with the network interface's primary IP configuration.
*
* <p>the internal name for the public IP address will be derived from the DNS label
*
* @param leafDnsLabel the leaf domain label
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the definition
*/
WithCreate withNewPrimaryPublicIPAddress(String leafDnsLabel, DeleteOptions deleteOptions);

/**
* Associates an existing public IP address with the network interface's primary IP configuration.
*
* @param publicIPAddress an existing public IP address
* @return the next stage of the definition
*/
WithCreate withExistingPrimaryPublicIPAddress(PublicIpAddress publicIPAddress);

/**
* Associates an existing public IP address with the network interface's primary IP configuration.
*
* @param publicIPAddress an existing public IP address
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the definition
*/
WithCreate withExistingPrimaryPublicIPAddress(PublicIpAddress publicIPAddress, DeleteOptions deleteOptions);
}

/** The stage of the network interface definition allowing to associate a network security group. */
Expand Down Expand Up @@ -256,17 +299,6 @@ interface WithAcceleratedNetworking {
WithCreate withAcceleratedNetworking();
}

/** The stage of the definition allowing to specify delete options for the public ip address. */
interface WithPublicIPAddressDeleteOptions {
/**
* Sets delete options for public ip address.
*
* @param deleteOptions the delete options for primary network interfaces
* @return the next stage of the update
*/
WithCreate withPrimaryPublicIPAddressDeleteOptions(DeleteOptions deleteOptions);
}

/**
* The stage of the network interface definition which contains all the minimum required inputs for the resource
* to be created, but also allows for any other optional settings to be specified.
Expand All @@ -279,8 +311,7 @@ interface WithCreate
WithSecondaryIPConfiguration,
WithAcceleratedNetworking,
WithLoadBalancer,
WithApplicationSecurityGroup,
WithPublicIPAddressDeleteOptions {
WithApplicationSecurityGroup {
/**
* Enables IP forwarding in the network interface.
*
Expand Down Expand Up @@ -370,6 +401,19 @@ interface WithPrimaryPublicIPAddress {
*/
Update withNewPrimaryPublicIPAddress(Creatable<PublicIpAddress> creatable);

/**
* Create a new public IP address to associate the network interface's primary IP configuration, based on
* the provided definition.
*
* <p>if there is public IP associated with the primary IP configuration then that will be removed in favour
* of this
*
* @param creatable a creatable definition for a new public IP
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the network interface update
*/
Update withNewPrimaryPublicIPAddress(Creatable<PublicIpAddress> creatable, DeleteOptions deleteOptions);

/**
* Creates a new public IP address in the same region and group as the resource and associate it with the
* network interface's primary IP configuration.
Expand All @@ -381,6 +425,18 @@ interface WithPrimaryPublicIPAddress {
*/
Update withNewPrimaryPublicIPAddress();

/**
* Creates a new public IP address in the same region and group as the resource and associate it with the
* network interface's primary IP configuration.
*
* <p>the internal name and DNS label for the public IP address will be derived from the network interface
* name, if there is an existing public IP association then that will be removed in favour of this
*
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the network interface update
*/
Update withNewPrimaryPublicIPAddress(DeleteOptions deleteOptions);

/**
* Creates a new public IP address in the same region and group as the resource, with the specified DNS
* label and associate it with the network interface's primary IP configuration.
Expand All @@ -393,6 +449,19 @@ interface WithPrimaryPublicIPAddress {
*/
Update withNewPrimaryPublicIPAddress(String leafDnsLabel);

/**
* Creates a new public IP address in the same region and group as the resource, with the specified DNS
* label and associate it with the network interface's primary IP configuration.
*
* <p>the internal name for the public IP address will be derived from the DNS label, if there is an
* existing public IP association then that will be removed in favour of this
*
* @param leafDnsLabel the leaf domain label
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the network interface update
*/
Update withNewPrimaryPublicIPAddress(String leafDnsLabel, DeleteOptions deleteOptions);

/**
* Specifies that remove any public IP associated with the network interface's primary IP configuration.
*
Expand All @@ -408,6 +477,16 @@ interface WithPrimaryPublicIPAddress {
* @return the next stage of the network interface update
*/
Update withExistingPrimaryPublicIPAddress(PublicIpAddress publicIPAddress);

/**
* Associates an existing public IP address with the network interface's primary IP configuration. if there
* is an existing public IP association then that will be removed in favour of this
*
* @param publicIPAddress an existing public IP address
* @param deleteOptions what happens to the public IP address when the VM using it is deleted
* @return the next stage of the network interface update
*/
Update withExistingPrimaryPublicIPAddress(PublicIpAddress publicIPAddress, DeleteOptions deleteOptions);
}

/** The stage of the network interface update allowing to associate network security group. */
Expand Down
Loading

0 comments on commit c45ef75

Please sign in to comment.