@Override public NetworkInterface getPrimaryNetworkInterface() { return this.networkManager.networkInterfaces().getById(primaryNetworkInterfaceId()); }
/** * Remove the IP name. * * @param resourceGroupName * @param vmName * @throws AzureCloudException */ public void removeIPName(String resourceGroupName, String vmName) throws AzureCloudException { final String nic = vmName + "NIC"; try { LOGGER.log(Level.INFO, "Remove NIC {0}", nic); azureClient.networkInterfaces().deleteByResourceGroup(resourceGroupName, nic); } catch (Exception e) { LOGGER.log(Level.WARNING, "AzureVMManagementServiceDelegate: removeIPName: while deleting NIC", e); } final String ip = vmName + "IPName"; try { LOGGER.log(Level.INFO, "Remove IP {0}", ip); azureClient.publicIPAddresses().deleteByResourceGroup(resourceGroupName, ip); } catch (Exception e) { LOGGER.log(Level.WARNING, "AzureVMManagementServiceDelegate: removeIPName: while deleting IPName", e); } }
@Override public VirtualMachineScaleSetNetworkInterface getNetworkInterfaceByInstanceId(String instanceId, String name) { return this.networkManager.networkInterfaces().getByVirtualMachineScaleSetInstanceId(this.resourceGroupName(), this.name(), instanceId, name); }
private NetworkInterface.DefinitionStages.WithPrimaryNetwork preparePrimaryNetworkInterface(String name) { NetworkInterface.DefinitionStages.WithGroup definitionWithGroup = this.networkManager.networkInterfaces() .define(name) .withRegion(this.regionName()); NetworkInterface.DefinitionStages.WithPrimaryNetwork definitionAfterGroup; if (this.creatableGroup != null) { definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); } else { definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); } return definitionAfterGroup; }
@Override public PagedList<VirtualMachineScaleSetNetworkInterface> listNetworkInterfaces() { return this.networkManager.networkInterfaces() .listByVirtualMachineScaleSet(this.resourceGroupName(), this.name()); }
@Override public PagedList<VirtualMachineScaleSetNetworkInterface> listNetworkInterfacesByInstanceId(String virtualMachineInstanceId) { return this.networkManager.networkInterfaces() .listByVirtualMachineScaleSetInstanceId(this.resourceGroupName(), this.name(), virtualMachineInstanceId); }
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 NetworkInterface.DefinitionStages.WithPrimaryNetwork preparePrimaryNetworkInterface(String name) { NetworkInterface.DefinitionStages.WithGroup definitionWithGroup = this.networkManager.networkInterfaces() .define(name) .withRegion(this.regionName()); NetworkInterface.DefinitionStages.WithPrimaryNetwork definitionAfterGroup; if (this.creatableGroup != null) { definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); } else { definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); } return definitionAfterGroup; }
@Override public PagedList<VirtualMachineScaleSetNetworkInterface> listNetworkInterfaces() { return this.networkManager.networkInterfaces() .listByVirtualMachineScaleSet(this.resourceGroupName(), this.name()); }
@Override public PagedList<VirtualMachineScaleSetNetworkInterface> listNetworkInterfacesByInstanceId(String virtualMachineInstanceId) { return this.networkManager.networkInterfaces() .listByVirtualMachineScaleSetInstanceId(this.resourceGroupName(), this.name(), virtualMachineInstanceId); }
@Override public NetworkInterface getPrimaryNetworkInterface() { return this.networkManager.networkInterfaces().getById(primaryNetworkInterfaceId()); }
private NetworkInterface.DefinitionStages.WithPrimaryPublicIPAddress prepareNetworkInterface(String name) { NetworkInterface.DefinitionStages.WithGroup definitionWithGroup = this.networkManager .networkInterfaces() .define(name) .withRegion(this.regionName()); NetworkInterface.DefinitionStages.WithPrimaryNetwork definitionWithNetwork; if (this.creatableGroup != null) { definitionWithNetwork = definitionWithGroup.withNewResourceGroup(this.creatableGroup); } else { definitionWithNetwork = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); } return definitionWithNetwork .withNewPrimaryNetwork("vnet" + name) .withPrimaryPrivateIPAddressDynamic(); }
@Override public VirtualMachineScaleSetNetworkInterface getNetworkInterfaceByInstanceId(String instanceId, String name) { return this.networkManager.networkInterfaces().getByVirtualMachineScaleSetInstanceId(this.resourceGroupName(), this.name(), instanceId, name); }
@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; }
private NetworkInterface.DefinitionStages.WithPrimaryPublicIPAddress prepareNetworkInterface(String name) { NetworkInterface.DefinitionStages.WithGroup definitionWithGroup = this.networkManager .networkInterfaces() .define(name) .withRegion(this.regionName()); NetworkInterface.DefinitionStages.WithPrimaryNetwork definitionWithNetwork; if (this.creatableGroup != null) { definitionWithNetwork = definitionWithGroup.withNewResourceGroup(this.creatableGroup); } else { definitionWithNetwork = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); } return definitionWithNetwork .withNewPrimaryNetwork("vnet" + name) .withPrimaryPrivateIPAddressDynamic(); }
@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; }
@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(); } }
if (nic == null) { nic = this.parent().manager().networkInterfaces().getById(nicID);
@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(); } }
if (nic == null) { nic = this.parent().manager().networkInterfaces().getById(nicID);