Skip to content

Commit

Permalink
Merge pull request Azure#1140 from martinsawicki/martin-plumbing
Browse files Browse the repository at this point in the history
fixing issues in Subnet., Network, NIC
  • Loading branch information
Martin Sawicki authored Sep 30, 2016
2 parents 08f4761 + 6d19f8e commit 13e8c08
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface Network extends
/**
* @return list of DNS server IP addresses associated with this virtual network
*/
List<String> dnsServerIPs();
List<String> dnsServerIps();

/**
* @return subnets of this virtual network as a map indexed by subnet name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface Subnet extends
* <p>
* Note that this method will result in a call to Azure each time it is invoked.
*/
NetworkSecurityGroup networkSecurityGroup();
NetworkSecurityGroup getNetworkSecurityGroup();

/**
* Grouping of subnet definition stages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
package com.microsoft.azure.management.network.implementation;

import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.network.AddressSpace;
import com.microsoft.azure.management.network.DhcpOptions;
import com.microsoft.azure.management.network.Network;
import com.microsoft.azure.management.network.Subnet;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl;
import rx.Observable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -80,6 +83,14 @@ NetworkManager manager() {

@Override
public NetworkImpl withDnsServer(String ipAddress) {
if (this.inner().dhcpOptions() == null) {
this.inner().withDhcpOptions(new DhcpOptions());
}

if (this.inner().dhcpOptions().dnsServers() == null) {
this.inner().dhcpOptions().withDnsServers(new ArrayList<String>());
}

this.inner().dhcpOptions().dnsServers().add(ipAddress);
return this;
}
Expand Down Expand Up @@ -108,6 +119,14 @@ public NetworkImpl withoutSubnet(String name) {

@Override
public NetworkImpl withAddressSpace(String cidr) {
if (this.inner().addressSpace() == null) {
this.inner().withAddressSpace(new AddressSpace());
}

if (this.inner().addressSpace().addressPrefixes() == null) {
this.inner().addressSpace().withAddressPrefixes(new ArrayList<String>());
}

this.inner().addressSpace().addressPrefixes().add(cidr);
return this;
}
Expand All @@ -123,12 +142,26 @@ public SubnetImpl defineSubnet(String name) {

@Override
public List<String> addressSpaces() {
return Collections.unmodifiableList(this.inner().addressSpace().addressPrefixes());
List<String> addressSpaces = new ArrayList<String>();
if (this.inner().addressSpace() == null) {
return Collections.unmodifiableList(addressSpaces);
} else if (this.inner().addressSpace().addressPrefixes() == null) {
return Collections.unmodifiableList(addressSpaces);
} else {
return Collections.unmodifiableList(this.inner().addressSpace().addressPrefixes());
}
}

@Override
public List<String> dnsServerIPs() {
return Collections.unmodifiableList(this.inner().dhcpOptions().dnsServers());
public List<String> dnsServerIps() {
List<String> ips = new ArrayList<String>();
if (this.inner().dhcpOptions() == null) {
return Collections.unmodifiableList(ips);
} else if (this.inner().dhcpOptions().dnsServers() == null) {
return Collections.unmodifiableList(ips);
} else {
return this.inner().dhcpOptions().dnsServers();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,29 @@ public String macAddress() {

@Override
public String internalDnsNameLabel() {
return this.inner().dnsSettings().internalDnsNameLabel();
return (this.inner().dnsSettings() != null) ? this.inner().dnsSettings().internalDnsNameLabel() : null;
}

@Override
public String internalDomainNameSuffix() {
return this.inner().dnsSettings().internalDomainNameSuffix();
return (this.inner().dnsSettings() != null) ? this.inner().dnsSettings().internalDomainNameSuffix() : null;
}

@Override
public List<String> appliedDnsServers() {
return Collections.unmodifiableList(this.inner().dnsSettings().appliedDnsServers());
List<String> dnsServers = new ArrayList<String>();
if (this.inner().dnsSettings() == null) {
return Collections.unmodifiableList(dnsServers);
} else if (this.inner().dnsSettings().appliedDnsServers() == null) {
return Collections.unmodifiableList(dnsServers);
} else {
return Collections.unmodifiableList(this.inner().dnsSettings().appliedDnsServers());
}
}

@Override
public String internalFqdn() {
return this.inner().dnsSettings().internalFqdn();
return (this.inner().dnsSettings() != null) ? this.inner().dnsSettings().internalFqdn() : null;
}

@Override
Expand All @@ -325,10 +332,7 @@ public Map<String, NicIpConfiguration> ipConfigurations() {

@Override
public String networkSecurityGroupId() {
if (this.inner().networkSecurityGroup() != null) {
return this.inner().networkSecurityGroup().id();
}
return null;
return (this.inner().networkSecurityGroup() != null) ? this.inner().networkSecurityGroup().id() : null;
}

@Override
Expand Down Expand Up @@ -370,10 +374,14 @@ public NicIpConfigurationImpl primaryIpConfiguration() {
* @return the list of DNS server IPs from the DNS settings
*/
private List<String> dnsServerIps() {
if (this.inner().dnsSettings().dnsServers() == null) {
this.inner().dnsSettings().withDnsServers(new ArrayList<String>());
List<String> dnsServers = new ArrayList<String>();
if (this.inner().dnsSettings() == null) {
return dnsServers;
} else if (this.inner().dnsSettings().dnsServers() == null) {
return dnsServers;
} else {
return this.inner().dnsSettings().dnsServers();
}
return this.inner().dnsSettings().dnsServers();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,13 @@ public String subnetName() {
@Override
public String networkId() {
SubResource subnetRef = this.inner().subnet();
if (subnetRef != null) {
return ResourceUtils.parentResourcePathFromResourceId(subnetRef.id());
} else {
return null;
}
return (subnetRef != null) ? ResourceUtils.parentResourcePathFromResourceId(subnetRef.id()) : null;
}

@Override
public Network getNetwork() {
String id = this.networkId();
return this.networkManager.networks().getById(id);
return (id != null) ? this.networkManager.networks().getById(id) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SubnetImpl
Subnet.UpdateDefinition<Network.Update>,
Subnet.Update {

protected SubnetImpl(SubnetInner inner, NetworkImpl parent) {
SubnetImpl(SubnetInner inner, NetworkImpl parent) {
super(inner, parent);
}

Expand All @@ -40,7 +40,7 @@ public String name() {
}

@Override
public NetworkSecurityGroup networkSecurityGroup() {
public NetworkSecurityGroup getNetworkSecurityGroup() {
SubResource nsgResource = this.inner().networkSecurityGroup();
if (nsgResource == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ public static void print(Network resource) throws CloudException, IOException {
.append("\n\tRegion: ").append(resource.region())
.append("\n\tTags: ").append(resource.tags())
.append("\n\tAddress spaces: ").append(resource.addressSpaces())
.append("\n\tDNS server IPs: ").append(resource.dnsServerIPs());
.append("\n\tDNS server IPs: ").append(resource.dnsServerIps());

// Output subnets
for (Subnet subnet : resource.subnets().values()) {
info.append("\n\tSubnet: ").append(subnet.name())
.append("\n\t\tAddress prefix: ").append(subnet.addressPrefix());
NetworkSecurityGroup subnetNsg = subnet.networkSecurityGroup();
NetworkSecurityGroup subnetNsg = subnet.getNetworkSecurityGroup();
if (subnetNsg != null) {
info.append("\n\t\tNetwork security group: ").append(subnetNsg.id());
}
Expand Down
4 changes: 2 additions & 2 deletions azure/src/test/java/com/microsoft/azure/TestNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void print(Network resource) {
.append("\n\tRegion: ").append(resource.region())
.append("\n\tTags: ").append(resource.tags())
.append("\n\tAddress spaces: ").append(resource.addressSpaces())
.append("\n\tDNS server IPs: ").append(resource.dnsServerIPs());
.append("\n\tDNS server IPs: ").append(resource.dnsServerIps());

// Output subnets
for (Subnet subnet : resource.subnets().values()) {
Expand All @@ -104,7 +104,7 @@ public void print(Network resource) {

NetworkSecurityGroup nsg;
try {
nsg = subnet.networkSecurityGroup();
nsg = subnet.getNetworkSecurityGroup();
} catch (Exception e) {
nsg = null;
}
Expand Down

0 comments on commit 13e8c08

Please sign in to comment.