From 0143034a94905c4ab7a418842f65e52c4883fcc7 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Sep 2016 17:17:14 -0700 Subject: [PATCH] NIC simplification: - removing primary-related accessors for PIP and Network from NIC because they are avaialable easily enough via primaryIpConfiguration() - renaming VirtualMachine#primaryPublicIpAddress() as getPrimaryPublicIpAddress() to be consistent with other methods that actually call Azure, rather than simply return a direct property (also removing the caching logic as it seems a bit unnecessary) - adding VirtualMachine#primaryPublicIpAddressId() as a shortcut --- .../management/compute/VirtualMachine.java | 7 ++++++- .../implementation/VirtualMachineImpl.java | 14 +++++++------- .../management/network/NetworkInterface.java | 18 ------------------ .../implementation/NetworkInterfaceImpl.java | 15 --------------- .../compute/samples/ManageVirtualMachine.java | 2 +- .../network/samples/ManageIPAddress.java | 6 +++--- .../azure/TestVirtualMachineNics.java | 2 +- 7 files changed, 18 insertions(+), 46 deletions(-) diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java index 21c4293598c51..d3a7c250d3db1 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachine.java @@ -137,7 +137,12 @@ public interface VirtualMachine extends * * @return the public IP of the primary network interface */ - PublicIpAddress primaryPublicIpAddress(); + PublicIpAddress getPrimaryPublicIpAddress(); + + /** + * @return the resource ID of the public IP address associated with this virtual machine's primary network interface + */ + String primaryPublicIpAddressId(); /** * Returns id to the availability set this virtual machine associated with. diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java index 852d301c0abc2..20a90e7d055b4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineImpl.java @@ -100,7 +100,6 @@ class VirtualMachineImpl private List existingSecondaryNetworkInterfacesToAssociate; // Cached related resources private NetworkInterface primaryNetworkInterface; - private PublicIpAddress primaryPublicIpAddress; private VirtualMachineInstanceView virtualMachineInstanceView; private boolean isMarketplaceLinuxImage; // The data disks associated with the virtual machine @@ -766,11 +765,13 @@ public NetworkInterface primaryNetworkInterface() { } @Override - public PublicIpAddress primaryPublicIpAddress() { - if (this.primaryPublicIpAddress == null) { - this.primaryPublicIpAddress = this.primaryNetworkInterface().primaryPublicIpAddress(); - } - return this.primaryPublicIpAddress; + public PublicIpAddress getPrimaryPublicIpAddress() { + return this.primaryNetworkInterface().primaryIpConfiguration().getPublicIpAddress(); + } + + @Override + public String primaryPublicIpAddressId() { + return this.primaryNetworkInterface().primaryIpConfiguration().publicIpAddressId(); } @Override @@ -1195,7 +1196,6 @@ private String getStatusCodeFromInstanceView(String codePrefix) { private void clearCachedRelatedResources() { this.primaryNetworkInterface = null; - this.primaryPublicIpAddress = null; this.virtualMachineInstanceView = null; } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java index 4fda73c684970..58b4e7a0bd536 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkInterface.java @@ -70,24 +70,6 @@ public interface NetworkInterface extends */ List appliedDnsServers(); - /** - * Gets the public IP address associated with this network interface. - *

- * This method makes a rest API call to fetch the public IP. - * - * @return the public IP associated with this network interface - */ - PublicIpAddress primaryPublicIpAddress(); - - /** - * Gets the virtual network associated this network interface's primary IP configuration. - *

- * This method makes a rest API call to fetch the virtual network. - * - * @return the virtual network associated with this network interface. - */ - Network getPrimaryNetwork(); - /** * Gets the private IP address allocated to this network interface's primary IP configuration. *

diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java index fe99194f640b7..2cc5328308037 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkInterfaceImpl.java @@ -60,7 +60,6 @@ class NetworkInterfaceImpl // reference to an network security group to be associated with the network interface private NetworkSecurityGroup existingNetworkSecurityGroupToAssociate; // Cached related resources. - private PublicIpAddress primaryPublicIp; private NetworkSecurityGroup networkSecurityGroup; NetworkInterfaceImpl(String name, @@ -283,19 +282,6 @@ public List dnsServers() { return this.dnsServerIps(); } - @Override - public PublicIpAddress primaryPublicIpAddress() { - if (this.primaryPublicIp == null) { - this.primaryPublicIp = this.primaryIpConfiguration().getPublicIpAddress(); - } - return primaryPublicIp; - } - - @Override - public Network getPrimaryNetwork() { - return this.primaryIpConfiguration().getNetwork(); - } - @Override public String primaryPrivateIp() { return this.primaryIpConfiguration().privateIpAddress(); @@ -392,7 +378,6 @@ private NicIpConfigurationImpl prepareNewNicIpConfiguration(String name) { } private void clearCachedRelatedResources() { - this.primaryPublicIp = null; this.networkSecurityGroup = null; this.nicPrimaryIpConfiguration = null; } diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java index ae2f06af3885b..9fa6bbd243144 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/compute/samples/ManageVirtualMachine.java @@ -200,7 +200,7 @@ public static void main(String[] args) { System.out.println("Powered OFF VM: " + windowsVM.id() + "; state = " + windowsVM.powerState()); // Get the network where Windows VM is hosted - Network network = windowsVM.primaryNetworkInterface().getPrimaryNetwork(); + Network network = windowsVM.primaryNetworkInterface().primaryIpConfiguration().getNetwork(); //============================================================= diff --git a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageIPAddress.java b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageIPAddress.java index eeb52671b9f75..dd33e3cab052a 100644 --- a/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageIPAddress.java +++ b/azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManageIPAddress.java @@ -110,7 +110,7 @@ public static void main(String[] args) { System.out.println("Public IP address associated with the VM's primary NIC [After create]"); // Print the public IP address details - Utils.print(vm.primaryPublicIpAddress()); + Utils.print(vm.getPrimaryPublicIpAddress()); //============================================================ @@ -142,7 +142,7 @@ public static void main(String[] args) { // Get the associated public IP address for a virtual machine System.out.println("Public IP address associated with the VM's primary NIC [After Update]"); vm.refresh(); - Utils.print(vm.primaryPublicIpAddress()); + Utils.print(vm.getPrimaryPublicIpAddress()); //============================================================ @@ -151,7 +151,7 @@ public static void main(String[] args) { System.out.println("Removing public IP address associated with the VM"); vm.refresh(); primaryNetworkInterface = vm.primaryNetworkInterface(); - publicIpAddress = primaryNetworkInterface.primaryPublicIpAddress(); + publicIpAddress = primaryNetworkInterface.primaryIpConfiguration().getPublicIpAddress(); primaryNetworkInterface.update() .withoutPrimaryPublicIpAddress() .apply(); diff --git a/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java b/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java index d693072f77d72..6b8f63c08be93 100644 --- a/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java +++ b/azure/src/test/java/com/microsoft/azure/TestVirtualMachineNics.java @@ -92,7 +92,7 @@ public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exc NetworkInterface primaryNetworkInterface = virtualMachine.primaryNetworkInterface(); Assert.assertEquals(primaryNetworkInterface.primaryPrivateIp(), "10.0.0.4"); - PublicIpAddress primaryPublicIpAddress = primaryNetworkInterface.primaryPublicIpAddress(); + PublicIpAddress primaryPublicIpAddress = primaryNetworkInterface.primaryIpConfiguration().getPublicIpAddress(); Assert.assertTrue(primaryPublicIpAddress.fqdn().startsWith(primaryPipName)); return virtualMachine; }