@Override public Set<SecurityGroup> listSecurityGroupsForNode(String nodeId) { logger.debug(">> getting security groups for node %s...", nodeId); final ResourceGroupAndName resourceGroupAndName = ResourceGroupAndName.fromSlashEncoded(nodeId); VirtualMachine vm = api.getVirtualMachineApi(resourceGroupAndName.resourceGroup()).get( resourceGroupAndName.name()); if (vm == null) { throw new IllegalArgumentException("Node " + nodeId + " was not found"); } List<NetworkInterface> networkInterfaces = vm.properties().networkProfile().networkInterfaces(); List<NetworkSecurityGroup> networkGroups = new ArrayList<NetworkSecurityGroup>(); for (NetworkInterface networkInterfaceCardIdReference : networkInterfaces) { String nicName = extractName(networkInterfaceCardIdReference.id()); String nicResourceGroup = extractResourceGroup(networkInterfaceCardIdReference.id()); NetworkInterfaceCard card = api.getNetworkInterfaceCardApi(nicResourceGroup).get(nicName); if (card != null && card.properties().networkSecurityGroup() != null) { String secGroupName = card.properties().networkSecurityGroup().name(); String sgResourceGroup = card.properties().networkSecurityGroup().resourceGroup(); NetworkSecurityGroup group = api.getNetworkSecurityGroupApi(sgResourceGroup).get(secGroupName); networkGroups.add(group); } } return ImmutableSet.copyOf(transform(filter(networkGroups, notNull()), securityGroupConverter)); }
@Override public Set<SecurityGroup> listSecurityGroupsForNode(String nodeId) { logger.debug(">> getting security groups for node %s...", nodeId); final ResourceGroupAndName resourceGroupAndName = ResourceGroupAndName.fromSlashEncoded(nodeId); VirtualMachine vm = api.getVirtualMachineApi(resourceGroupAndName.resourceGroup()).get( resourceGroupAndName.name()); if (vm == null) { throw new IllegalArgumentException("Node " + nodeId + " was not found"); } List<NetworkInterface> networkInterfaces = vm.properties().networkProfile().networkInterfaces(); List<NetworkSecurityGroup> networkGroups = new ArrayList<NetworkSecurityGroup>(); for (NetworkInterface networkInterfaceCardIdReference : networkInterfaces) { String nicName = extractName(networkInterfaceCardIdReference.id()); String nicResourceGroup = extractResourceGroup(networkInterfaceCardIdReference.id()); NetworkInterfaceCard card = api.getNetworkInterfaceCardApi(nicResourceGroup).get(nicName); if (card != null && card.properties().networkSecurityGroup() != null) { String secGroupName = card.properties().networkSecurityGroup().name(); String sgResourceGroup = card.properties().networkSecurityGroup().resourceGroup(); NetworkSecurityGroup group = api.getNetworkSecurityGroupApi(sgResourceGroup).get(secGroupName); networkGroups.add(group); } } return ImmutableSet.copyOf(transform(filter(networkGroups, notNull()), securityGroupConverter)); }
public boolean cleanupVirtualMachineNICs(VirtualMachine virtualMachine) { boolean deleted = true; for (NetworkInterface nicRef : virtualMachine.properties().networkProfile().networkInterfaces()) { String nicResourceGroup = extractResourceGroup(nicRef.id()); String nicName = extractName(nicRef.id()); NetworkInterfaceCard nic = api.getNetworkInterfaceCardApi(nicResourceGroup).get(nicName); Iterable<IdReference> publicIps = getPublicIps(nic); logger.debug(">> destroying nic %s...", nicName); URI nicDeletionURI = api.getNetworkInterfaceCardApi(nicResourceGroup).delete(nicName); deleted &= nicDeletionURI == null || resourceDeleted.apply(nicDeletionURI); for (IdReference publicIp : publicIps) { String publicIpResourceGroup = publicIp.resourceGroup(); String publicIpName = publicIp.name(); PublicIPAddress ip = api.getPublicIPAddressApi(publicIpResourceGroup).get(publicIpName); if (ip.tags() != null && Boolean.parseBoolean(ip.tags().get(AUTOGENERATED_IP_KEY))) { logger.debug(">> deleting public ip %s...", publicIpName); deleted &= api.getPublicIPAddressApi(publicIpResourceGroup).delete(publicIpName); } } } return deleted; }
public boolean cleanupVirtualMachineNICs(VirtualMachine virtualMachine) { boolean deleted = true; for (NetworkInterface nicRef : virtualMachine.properties().networkProfile().networkInterfaces()) { String nicResourceGroup = extractResourceGroup(nicRef.id()); String nicName = extractName(nicRef.id()); NetworkInterfaceCard nic = api.getNetworkInterfaceCardApi(nicResourceGroup).get(nicName); Iterable<IdReference> publicIps = getPublicIps(nic); logger.debug(">> destroying nic %s...", nicName); URI nicDeletionURI = api.getNetworkInterfaceCardApi(nicResourceGroup).delete(nicName); deleted &= nicDeletionURI == null || resourceDeleted.apply(nicDeletionURI); for (IdReference publicIp : publicIps) { String publicIpResourceGroup = publicIp.resourceGroup(); String publicIpName = publicIp.name(); PublicIPAddress ip = api.getPublicIPAddressApi(publicIpResourceGroup).get(publicIpName); if (ip.tags() != null && Boolean.parseBoolean(ip.tags().get(AUTOGENERATED_IP_KEY))) { logger.debug(">> deleting public ip %s...", publicIpName); deleted &= api.getPublicIPAddressApi(publicIpResourceGroup).delete(publicIpName); } } } return deleted; }
builder.backendStatus(status.backendStatus()); builder.publicAddresses(getPublicIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces())); builder.privateAddresses(getPrivateIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
builder.backendStatus(status.backendStatus()); builder.publicAddresses(getPublicIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces())); builder.privateAddresses(getPrivateIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
private List<String> createVirtualMachinesInGroupAndGetNicRefs(final String group, final int count) throws RunNodesException { // To add multiple nodes in a LB they must belong to the same availability // set AvailabilitySetProperties props = AvailabilitySetProperties.builder().platformUpdateDomainCount(count) .platformFaultDomainCount(count).build(); AvailabilitySet as = AvailabilitySet.managed().name(group).properties(props).build(); Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(group, count, availabilitySet(as).resourceGroup(this.group)); List<String> nicNames = new ArrayList<String>(); for (NodeMetadata node : nodes) { ResourceGroupAndName resourceGroupAndName = ResourceGroupAndName.fromSlashEncoded(node.getId()); VirtualMachine vm = api.getVirtualMachineApi(resourceGroupAndName.resourceGroup()).get( resourceGroupAndName.name()); String nicName = extractName(vm.properties().networkProfile().networkInterfaces().get(0).id()); nicNames.add(nicName); } return nicNames; }