nics.put(nic.id().toLowerCase(), nic); NicIPConfiguration ipConfig = nic.ipConfigurations().get(ipConfigName); if (ipConfig == null) {
@Override protected void afterCreating() { if (this.nicsInBackends != null) { List<Exception> nicExceptions = new ArrayList<>(); // Update the NICs to point to the backend pool for (Entry<String, String> nicInBackend : this.nicsInBackends.entrySet()) { String nicId = nicInBackend.getKey(); String backendName = nicInBackend.getValue(); try { NetworkInterface nic = this.manager().networkInterfaces().getById(nicId); NicIPConfiguration nicIP = nic.primaryIPConfiguration(); nic.update() .updateIPConfiguration(nicIP.name()) .withExistingLoadBalancerBackend(this, backendName) .parent() .apply(); } catch (Exception e) { nicExceptions.add(e); } } if (!nicExceptions.isEmpty()) { throw new CompositeException(nicExceptions); } this.nicsInBackends.clear(); this.refresh(); } }
@Override public Set<String> getVirtualMachineIds() { Set<String> vmIds = new HashSet<>(); Map<String, String> nicConfigs = this.backendNicIPConfigurationNames(); if (nicConfigs != null) { for (String nicId : nicConfigs.keySet()) { try { NetworkInterface nic = this.parent().manager().networkInterfaces().getById(nicId); if (nic == null || nic.virtualMachineId() == null) { continue; } else { vmIds.add(nic.virtualMachineId()); } } catch (CloudException | IllegalArgumentException e) { continue; } } } return vmIds; }
public static AzureDockerVM getDockerVM(VirtualMachine vm) { try { NicIPConfiguration nicIPConfiguration = vm.getPrimaryNetworkInterface().primaryIPConfiguration(); PublicIPAddress publicIp = nicIPConfiguration.getPublicIPAddress(); Network vnet = nicIPConfiguration.getNetwork(); dockerVM.dnsName = dockerVM.privateIp; dockerVM.nicName = vm.getPrimaryNetworkInterface().name(); dockerVM.vnetName = vnet.name(); dockerVM.vnetAddressSpace = vnet.addressSpaces().get(0); dockerVM.subnetName = nicIPConfiguration.subnetName(); dockerVM.subnetAddressRange = vnet.subnets().get(dockerVM.subnetName).addressPrefix(); dockerVM.networkSecurityGroupName = (nicIPConfiguration.parent().networkSecurityGroupId() != null) ? ResourceUtils.nameFromResourceId(nicIPConfiguration.parent().networkSecurityGroupId()) : null; dockerVM.vmSize = vm.size().toString(); dockerVM.osDiskName = vm.storageProfile().osDisk().name();
@Override public PublicIPAddress getPrimaryPublicIPAddress() { return this.getPrimaryNetworkInterface().primaryIPConfiguration().getPublicIPAddress(); }
@Override public Completable deleteByResourceGroupAsync(String groupName, String name) { // Clear NIC references if any NetworkSecurityGroupImpl nsg = (NetworkSecurityGroupImpl) getByResourceGroup(groupName, name); if (nsg != null) { Set<String> nicIds = nsg.networkInterfaceIds(); if (nicIds != null) { for (String nicRef : nsg.networkInterfaceIds()) { NetworkInterface nic = this.manager().networkInterfaces().getById(nicRef); if (nic == null) { continue; } else if (!nsg.id().equalsIgnoreCase(nic.networkSecurityGroupId())) { continue; } else { nic.update().withoutNetworkSecurityGroup().apply(); } } } } return this.deleteInnerAsync(groupName, name); }
NetworkInterfaceReference nicReference = new NetworkInterfaceReference(); nicReference.withPrimary(true); nicReference.withId(primaryNetworkInterface.id()); this.inner().networkProfile().networkInterfaces().add(nicReference); NetworkInterfaceReference nicReference = new NetworkInterfaceReference(); nicReference.withPrimary(false); nicReference.withId(secondaryNetworkInterface.id()); this.inner().networkProfile().networkInterfaces().add(nicReference); NetworkInterfaceReference nicReference = new NetworkInterfaceReference(); nicReference.withPrimary(false); nicReference.withId(secondaryNetworkInterface.id()); this.inner().networkProfile().networkInterfaces().add(nicReference);
public static boolean isDeletingDockerHostAllSafe(Azure azureClient, String resourceGroup, String vmName) { if (azureClient == null || resourceGroup == null || vmName == null ) { return false; } VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName); if (vm == null) { return false; } PublicIPAddress publicIp = vm.getPrimaryPublicIPAddress(); NicIPConfiguration nicIPConfiguration = publicIp.getAssignedNetworkInterfaceIPConfiguration(); Network vnet = nicIPConfiguration.getNetwork(); NetworkInterface nic = vm.getPrimaryNetworkInterface(); return nic.ipConfigurations().size() == 1 && vnet.subnets().size() == 1 && vnet.subnets().values().toArray(new Subnet[1])[0].inner().ipConfigurations().size() == 1; }
try { vm.getPrimaryNetworkInterface() .update() .withNewPrimaryPublicIPAddress( azureClient.publicIPAddresses()
String privateIP = vm.getPrimaryNetworkInterface().primaryPrivateIP(); String fqdn = ""; if (publicIP == null) {
@Override public String getPrimaryPublicIPAddressId() { return this.getPrimaryNetworkInterface().primaryIPConfiguration().publicIPAddressId(); }
@Override public Completable deleteByResourceGroupAsync(String groupName, String name) { // Clear NIC references if any NetworkSecurityGroupImpl nsg = (NetworkSecurityGroupImpl) getByResourceGroup(groupName, name); if (nsg != null) { Set<String> nicIds = nsg.networkInterfaceIds(); if (nicIds != null) { for (String nicRef : nsg.networkInterfaceIds()) { NetworkInterface nic = this.manager().networkInterfaces().getById(nicRef); if (nic == null) { continue; } else if (!nsg.id().equalsIgnoreCase(nic.networkSecurityGroupId())) { continue; } else { nic.update().withoutNetworkSecurityGroup().apply(); } } } } return this.deleteInnerAsync(groupName, name); }
NetworkInterfaceReference nicReference = new NetworkInterfaceReference(); nicReference.withPrimary(true); nicReference.withId(primaryNetworkInterface.id()); this.inner().networkProfile().networkInterfaces().add(nicReference); NetworkInterfaceReference nicReference = new NetworkInterfaceReference(); nicReference.withPrimary(false); nicReference.withId(secondaryNetworkInterface.id()); this.inner().networkProfile().networkInterfaces().add(nicReference); NetworkInterfaceReference nicReference = new NetworkInterfaceReference(); nicReference.withPrimary(false); nicReference.withId(secondaryNetworkInterface.id()); this.inner().networkProfile().networkInterfaces().add(nicReference);
@Override public NicIPConfiguration getAssignedNetworkInterfaceIPConfiguration() { if (this.hasAssignedNetworkInterface()) { final String refId = this.inner().ipConfiguration().id(); final String parentId = ResourceUtils.parentResourceIdFromResourceId(refId); final NetworkInterface nic = this.myManager.networkInterfaces().getById(parentId); final String childName = ResourceUtils.nameFromResourceId(refId); return nic.ipConfigurations().get(childName); } else { return null; } }
String privateIP = vm.getPrimaryNetworkInterface().primaryPrivateIP(); String fqdn = ""; if (publicIP == null) {
@Override protected void afterCreating() { if (this.nicsInBackends != null) { List<Exception> nicExceptions = new ArrayList<>(); // Update the NICs to point to the backend pool for (Entry<String, String> nicInBackend : this.nicsInBackends.entrySet()) { String nicId = nicInBackend.getKey(); String backendName = nicInBackend.getValue(); try { NetworkInterface nic = this.manager().networkInterfaces().getById(nicId); NicIPConfiguration nicIP = nic.primaryIPConfiguration(); nic.update() .updateIPConfiguration(nicIP.name()) .withExistingLoadBalancerBackend(this, backendName) .parent() .apply(); } catch (Exception e) { nicExceptions.add(e); } } if (!nicExceptions.isEmpty()) { throw new CompositeException(nicExceptions); } this.nicsInBackends.clear(); this.refresh(); } }
nics.put(nic.id().toLowerCase(), nic); NicIPConfiguration ipConfig = nic.ipConfigurations().get(ipConfigName); if (ipConfig == null) {
@Override public PublicIPAddress getPrimaryPublicIPAddress() { return this.getPrimaryNetworkInterface().primaryIPConfiguration().getPublicIPAddress(); }
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)); } }
@Override public NicIPConfiguration getAssignedNetworkInterfaceIPConfiguration() { if (this.hasAssignedNetworkInterface()) { final String refId = this.inner().ipConfiguration().id(); final String parentId = ResourceUtils.parentResourceIdFromResourceId(refId); final NetworkInterface nic = this.myManager.networkInterfaces().getById(parentId); final String childName = ResourceUtils.nameFromResourceId(refId); return nic.ipConfigurations().get(childName); } else { return null; } }