use of com.microsoft.azure.management.network.Network in project azure-tools-for-java by Microsoft.
the class SettingsStep method getVirtualNetworkModel.
private DefaultComboBoxModel getVirtualNetworkModel(Network selectedVN, final String selectedSN) {
DefaultComboBoxModel refreshedVNModel = new DefaultComboBoxModel(filterVN().toArray()) {
@Override
public void setSelectedItem(final Object o) {
super.setSelectedItem(o);
if (CREATE_NEW.equals(o)) {
showNewVirtualNetworkForm();
} else {
if (o instanceof Network) {
if (((DefaultComboBoxModel) networkComboBox.getModel()).getIndexOf(CREATE_NEW) > 0) {
// new virtual network name at 0 position
((DefaultComboBoxModel) networkComboBox.getModel()).removeElementAt(0);
}
model.setWithNewNetwork(false);
model.setVirtualNetwork((Network) o);
model.setNewNetwork(null);
AzureTaskManager.getInstance().runAndWait(() -> {
subnetComboBox.setEnabled(false);
boolean validSubnet = false;
subnetComboBox.removeAllItems();
for (String subnet : ((Network) o).subnets().keySet()) {
subnetComboBox.addItem(subnet);
if (subnet.equals(selectedSN)) {
validSubnet = true;
}
}
if (validSubnet) {
subnetComboBox.setSelectedItem(selectedSN);
} else {
model.setSubnet(null);
subnetComboBox.setSelectedItem(null);
}
subnetComboBox.setEnabled(true);
}, AzureTask.Modality.ANY);
} else if (o instanceof String) {
// new virtual network
if (model.getNewNetwork() != null) {
subnetComboBox.setEnabled(false);
subnetComboBox.removeAllItems();
subnetComboBox.addItem(model.getNewNetwork().subnet.name);
subnetComboBox.setSelectedIndex(0);
model.setSubnet(model.getNewNetwork().subnet.name);
}
} else {
model.setVirtualNetwork(null);
AzureTaskManager.getInstance().runAndWait(() -> {
subnetComboBox.removeAllItems();
subnetComboBox.setEnabled(false);
}, AzureTask.Modality.ANY);
}
}
}
};
refreshedVNModel.insertElementAt(CREATE_NEW, 0);
if (selectedVN != null && virtualNetworks.contains(selectedVN)) {
refreshedVNModel.setSelectedItem(selectedVN);
} else {
model.setVirtualNetwork(null);
refreshedVNModel.setSelectedItem(null);
}
return refreshedVNModel;
}
use of com.microsoft.azure.management.network.Network in project cloudbreak by hortonworks.
the class AzurePlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AzureClient client = azureClientService.getClient(cloudCredential);
Map<String, Set<CloudNetwork>> result = new HashMap<>();
for (Network network : client.getNetworks()) {
String actualRegion = network.region().label();
if (regionMatch(actualRegion, region)) {
Map<String, String> subnets = new HashMap<>();
for (Entry<String, Subnet> subnet : network.subnets().entrySet()) {
subnets.put(subnet.getKey(), subnet.getKey());
}
Map<String, Object> properties = new HashMap<>();
properties.put("addressSpaces", network.addressSpaces());
properties.put("dnsServerIPs", network.dnsServerIPs());
properties.put("resourceGroupName", network.resourceGroupName());
CloudNetwork cloudNetwork = new CloudNetwork(network.name(), network.id(), subnets, properties);
result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudNetwork);
}
}
if (result.isEmpty() && Objects.nonNull(region)) {
result.put(region.value(), new HashSet<>());
}
return new CloudNetworks(result);
}
Aggregations