public Network getNetwork() { String id = this.networkId(); if (id == null) { return null; } return this.networkManager.networks().getById(id); }
/** * Returns virtual network site properties. * * @param virtualNetworkName * @param resourceGroupName * @return */ public Network getVirtualNetwork(String virtualNetworkName, String resourceGroupName) { try { return azureClient.networks().getByResourceGroup(resourceGroupName, virtualNetworkName); } catch (Exception e) { LOGGER.log(Level.SEVERE, "AzureVMManagementServiceDelegate: getVirtualNetworkInfo: " + "Got exception while getting virtual network info: ", e); } return null; }
@Override public Observable<Network> getRemoteNetworkAsync() { final NetworkPeeringImpl self = this; if (self.remoteNetwork != null) { return Observable.just(self.remoteNetwork); } else if (this.isSameSubscription()) { // Fetch the remote network if within the same subscription return this.manager().networks().getByIdAsync(this.remoteNetworkId()) .doOnNext(new Action1<Network>() { @Override public void call(Network network) { self.remoteNetwork = network; } }); } else { // Otherwise bail out self.remoteNetwork = null; return Observable.just(null); } }
private Creatable<Network> ensureDefaultNetworkDefinition() { if (this.creatableNetwork == null) { final String vnetName = SdkContext.randomResourceName("vnet", 10); this.creatableNetwork = this.manager().networks().define(vnetName) .withRegion(this.region()) .withExistingResourceGroup(this.resourceGroupName()) .withAddressSpace("10.0.0.0/24") .withSubnet(DEFAULT, "10.0.0.0/25") .withSubnet("apps", "10.0.0.128/25"); } return this.creatableNetwork; }
vnet = azureClient.networks().getByResourceGroup(vnetResourceGroupName, vnetName); } else { .define(newHost.hostVM.vnetName) .withRegion(newHost.hostVM.region) .withExistingResourceGroup(resourceGroupName)
@Override public Set<String> listAvailablePrivateIPAddresses() { Set<String> ipAddresses = new TreeSet<>(); String cidr = this.addressPrefix(); if (cidr == null) { return ipAddresses; // Should never happen, but just in case } String takenIPAddress = cidr.split("/")[0]; IPAddressAvailabilityResultInner result = this.parent().manager().networks().inner().checkIPAddressAvailability( this.parent().resourceGroupName(), this.parent().name(), takenIPAddress); if (result == null) { return ipAddresses; } ipAddresses.addAll(result.availableIPAddresses()); return ipAddresses; } }
public static Map<String, Pair<String, List<String>>> getVirtualNetworks(Azure azureClient, String region) { Map<String, Pair<String, List<String>>> result = new HashMap<>(); if (azureClient != null) { for (Network vnet : azureClient.networks().list()) { if (vnet.regionName().toLowerCase().equals(region) || vnet.regionName().toLowerCase().equals(region)) { List<String> subnets = new ArrayList<>(); subnets.addAll(vnet.subnets().keySet()); result.put(vnet.id(), new Pair<>(vnet.name(), subnets)); } } } return result; }
return this.manager().networks() .getByResourceGroupAsync(groupName, parentName)
public static void deleteDockerHostAll(Azure azureClient, String resourceGroup, String vmName) { if (azureClient == null || resourceGroup == null || vmName == null ) { throw new AzureDockerException("Unexpected param values; Azure instance, resource group and VM name cannot be null"); } VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName); if (vm == null) { throw new AzureDockerException(String.format("Unexpected error retrieving VM %s from Azure", vmName)); } try { PublicIPAddress publicIp = vm.getPrimaryPublicIPAddress(); NicIPConfiguration nicIPConfiguration = publicIp.getAssignedNetworkInterfaceIPConfiguration(); Network vnet = nicIPConfiguration.getNetwork(); NetworkInterface nic = vm.getPrimaryNetworkInterface(); azureClient.virtualMachines().deleteById(vm.id()); azureClient.networkInterfaces().deleteById(nic.id()); azureClient.publicIPAddresses().deleteById(publicIp.id()); azureClient.networks().deleteById(vnet.id()); } catch (Exception e) { throw new AzureDockerException(String.format("Unexpected error while deleting VM %s and its associated resources", vmName)); } }
private Creatable<Network> ensureDefaultNetworkDefinition() { if (this.creatableNetwork == null) { final String vnetName = SdkContext.randomResourceName("vnet", 10); this.creatableNetwork = this.manager().networks().define(vnetName) .withRegion(this.region()) .withExistingResourceGroup(this.resourceGroupName()) .withAddressSpace("10.0.0.0/24") .withSubnet(DEFAULT, "10.0.0.0/25") .withSubnet("apps", "10.0.0.128/25"); } return this.creatableNetwork; }
@Override public Set<String> listAvailablePrivateIPAddresses() { Set<String> ipAddresses = new TreeSet<>(); String cidr = this.addressPrefix(); if (cidr == null) { return ipAddresses; // Should never happen, but just in case } String takenIPAddress = cidr.split("/")[0]; IPAddressAvailabilityResultInner result = this.parent().manager().networks().inner().checkIPAddressAvailability( this.parent().resourceGroupName(), this.parent().name(), takenIPAddress); if (result == null) { return ipAddresses; } ipAddresses.addAll(result.availableIPAddresses()); return ipAddresses; } }
public static List<AzureDockerVnet> getVirtualNetworks(Azure azureClient) { List<AzureDockerVnet> result = new ArrayList<>(); if (azureClient != null) { for (Network net : azureClient.networks().list()) { AzureDockerVnet vnet = new AzureDockerVnet(); vnet.name = net.name(); vnet.addrSpace = net.addressSpaces().get(0); vnet.id = net.id(); vnet.region = net.regionName().toLowerCase(); vnet.resourceGroup = net.resourceGroupName(); vnet.subnets = new ArrayList<>(); for (Subnet subnet : net.subnets().values()) { vnet.subnets.add(subnet.name()); } result.add(vnet); } } return result; }
return this.manager().networks() .getByResourceGroupAsync(groupName, parentName)
public Network getNetwork() { String id = this.networkId(); if (id == null) { return null; } return this.networkManager.networks().getById(id); }
@Override public VirtualNetworkGatewayImpl withNewNetwork(String name, String addressSpace, String subnetAddressSpaceCidr) { Network.DefinitionStages.WithGroup definitionWithGroup = this.manager().networks() .define(name) .withRegion(this.regionName()); Network.DefinitionStages.WithCreate definitionAfterGroup; if (this.newGroup() != null) { definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.newGroup()); } else { definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); } Creatable<Network> network = definitionAfterGroup.withAddressSpace(addressSpace).withSubnet(GATEWAY_SUBNET, subnetAddressSpaceCidr); return withNewNetwork(network); }
private IPAddressAvailabilityResultInner checkIPAvailability(String ipAddress) { if (ipAddress == null) { return null; } IPAddressAvailabilityResultInner result = null; try { result = this.manager().networks().inner().checkIPAddressAvailability( this.resourceGroupName(), this.name(), ipAddress); } catch (CloudException e) { if (!e.body().code().equalsIgnoreCase("PrivateIPAddressNotInAnySubnet")) { throw e; // Rethrow if the exception reason is anything other than IP address not found } } return result; }
@Override public Observable<Network> getRemoteNetworkAsync() { final NetworkPeeringImpl self = this; if (self.remoteNetwork != null) { return Observable.just(self.remoteNetwork); } else if (this.isSameSubscription()) { // Fetch the remote network if within the same subscription return this.manager().networks().getByIdAsync(this.remoteNetworkId()) .doOnNext(new Action1<Network>() { @Override public void call(Network network) { self.remoteNetwork = network; } }); } else { // Otherwise bail out self.remoteNetwork = null; return Observable.just(null); } }
List<Subnet> listAssociatedSubnets(List<SubnetInner> subnetRefs) { final Map<String, Network> networks = new HashMap<>(); final List<Subnet> subnets = new ArrayList<>(); if (subnetRefs != null) { for (SubnetInner subnetRef : subnetRefs) { String networkId = ResourceUtils.parentResourceIdFromResourceId(subnetRef.id()); Network network = networks.get(networkId.toLowerCase()); if (network == null) { network = this.networks().getById(networkId); networks.put(networkId.toLowerCase(), network); } String subnetName = ResourceUtils.nameFromResourceId(subnetRef.id()); subnets.add(network.subnets().get(subnetName)); } } return Collections.unmodifiableList(subnets); }
@Override public VirtualNetworkGatewayImpl withNewNetwork(String name, String addressSpace, String subnetAddressSpaceCidr) { Network.DefinitionStages.WithGroup definitionWithGroup = this.manager().networks() .define(name) .withRegion(this.regionName()); Network.DefinitionStages.WithCreate definitionAfterGroup; if (this.newGroup() != null) { definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.newGroup()); } else { definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); } Creatable<Network> network = definitionAfterGroup.withAddressSpace(addressSpace).withSubnet(GATEWAY_SUBNET, subnetAddressSpaceCidr); return withNewNetwork(network); }
private IPAddressAvailabilityResultInner checkIPAvailability(String ipAddress) { if (ipAddress == null) { return null; } IPAddressAvailabilityResultInner result = null; try { result = this.manager().networks().inner().checkIPAddressAvailability( this.resourceGroupName(), this.name(), ipAddress); } catch (CloudException e) { if (!e.body().code().equalsIgnoreCase("PrivateIPAddressNotInAnySubnet")) { throw e; // Rethrow if the exception reason is anything other than IP address not found } } return result; }