Skip to content

Commit

Permalink
NIC simplification:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
unknown authored and unknown committed Sep 20, 2016
1 parent 6c19eb0 commit 0143034
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class VirtualMachineImpl
private List<NetworkInterface> existingSecondaryNetworkInterfacesToAssociate;
// Cached related resources
private NetworkInterface primaryNetworkInterface;
private PublicIpAddress primaryPublicIpAddress;
private VirtualMachineInstanceView virtualMachineInstanceView;
private boolean isMarketplaceLinuxImage;
// The data disks associated with the virtual machine
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1195,7 +1196,6 @@ private String getStatusCodeFromInstanceView(String codePrefix) {

private void clearCachedRelatedResources() {
this.primaryNetworkInterface = null;
this.primaryPublicIpAddress = null;
this.virtualMachineInstanceView = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@ public interface NetworkInterface extends
*/
List<String> appliedDnsServers();

/**
* Gets the public IP address associated with this network interface.
* <p>
* 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.
* <p>
* 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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -283,19 +282,6 @@ public List<String> 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();
Expand Down Expand Up @@ -392,7 +378,6 @@ private NicIpConfigurationImpl prepareNewNicIpConfiguration(String name) {
}

private void clearCachedRelatedResources() {
this.primaryPublicIp = null;
this.networkSecurityGroup = null;
this.nicPrimaryIpConfiguration = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();


//=============================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());


//============================================================
Expand Down Expand Up @@ -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());


//============================================================
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0143034

Please sign in to comment.