@Override public boolean removeSecurityGroup(String id) { checkNotNull(id, "id"); ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id); String zone = zoneAndId.getZone(); String groupId = zoneAndId.getId(); Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupExtensionForZone(zone); if (!sgApi.isPresent()) { return false; } if (sgApi.get().get(groupId) == null) { return false; } sgApi.get().delete(groupId); // TODO: test this clear happens groupCreator.invalidate(new ZoneSecurityGroupNameAndPorts(zone, groupId, ImmutableSet.<Integer> of())); return true; }
@Override public boolean removeSecurityGroup(String id) { checkNotNull(id, "id"); RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region); if (!sgApi.isPresent()) { return false; } if (sgApi.get().get(groupId) == null) { return false; } sgApi.get().delete(groupId); // TODO: test this clear happens groupCreator.invalidate(new RegionSecurityGroupNameAndPorts(region, groupId, ImmutableSet.<Integer> of())); return true; }
@Override public boolean removeSecurityGroup(String id) { checkNotNull(id, "id"); RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region); if (!sgApi.isPresent()) { return false; } // Would be nice to delete the group and invalidate the cache atomically - i.e. use a mutex. // Will make sure that a create operation in parallel won't see inconsistent state. boolean deleted = sgApi.get().delete(groupId); for (SecurityGroup cachedSg : groupCreator.asMap().values()) { if (id.equals(cachedSg.getId())) { String groupName = cachedSg.getName(); groupCreator.invalidate(new RegionSecurityGroupNameAndPorts(region, groupName, ImmutableSet.<Integer>of())); break; } } return deleted; }
@Override public boolean removeSecurityGroup(String id) { checkNotNull(id, "id"); RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id); String region = regionAndId.getRegion(); String groupId = regionAndId.getId(); Optional<? extends SecurityGroupApi> sgApi = api.getSecurityGroupApi(region); if (!sgApi.isPresent()) { return false; } // Would be nice to delete the group and invalidate the cache atomically - i.e. use a mutex. // Will make sure that a create operation in parallel won't see inconsistent state. boolean deleted = sgApi.get().delete(groupId); for (SecurityGroup cachedSg : groupCreator.asMap().values()) { if (id.equals(cachedSg.getId())) { String groupName = cachedSg.getName(); groupCreator.invalidate(new RegionSecurityGroupNameAndPorts(region, groupName, ImmutableSet.<Integer>of())); break; } } return deleted; }
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) { Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId); if (securityGroupApi.isPresent()) { for (String group : groups) { for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(), SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", zoneAndName); securityGroupApi.get().delete(securityGroup.getId()); // TODO: test this clear happens securityGroupMap.invalidate(zoneAndName); logger.debug("<< deleted securityGroup(%s)", zoneAndName); } } } }
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) { Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId); if (securityGroupApi.isPresent()) { for (String group : groups) { for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(), SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", zoneAndName); securityGroupApi.get().delete(securityGroup.getId()); // TODO: test this clear happens securityGroupMap.invalidate(zoneAndName); logger.debug("<< deleted securityGroup(%s)", zoneAndName); } } } }
private void cleanupOrphanedSecurityGroupsInZone(Set<String> groups, String zoneId) { Optional<? extends SecurityGroupApi> securityGroupApi = novaApi.getSecurityGroupExtensionForZone(zoneId); if (securityGroupApi.isPresent()) { for (String group : groups) { for (SecurityGroup securityGroup : Iterables.filter(securityGroupApi.get().list(), SecurityGroupPredicates.nameMatches(namingConvention.create().containsGroup(group)))) { ZoneAndName zoneAndName = ZoneAndName.fromZoneAndName(zoneId, securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", zoneAndName); securityGroupApi.get().delete(securityGroup.getId()); // TODO: test this clear happens securityGroupMap.invalidate(zoneAndName); logger.debug("<< deleted securityGroup(%s)", zoneAndName); } } } }
NovaApi novaApi = ContextBuilder .newBuilder("openstack-nova") .credentials("username", "api_key") .buildApi(NovaApi.class); Ingress ingress = Ingress.builder().fromPort(80).toPort(80).ipProtocol(IpProtocol.TCP).build(); SecurityGroupApi securityGroupApi = novaApi.getSecurityGroupExtensionForZone("RegionOne").get(); SecurityGroup securityGroup = securityGroupApi.createWithDescription("name", "description"); SecurityGroupRule rule = securityGroupApi.createRuleAllowingCidrBlock(securityGroup.getName(), ingress, "0.0.0.0/0"); securityGroupApi.delete(securityGroup.getId());
public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception { HttpRequest delete = HttpRequest.builder().method("DELETE").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups/160")) .headers( ImmutableMultimap.<String, String> builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse deleteResponse = HttpResponse.builder().statusCode(202).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete, deleteResponse); assertTrue(apiWhenServersExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get() .delete("160")); }
public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception { HttpRequest delete = HttpRequest.builder().method("DELETE").endpoint( URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/os-security-groups/160")) .headers( ImmutableMultimap.<String, String> builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse deleteResponse = HttpResponse.builder().statusCode(202).build(); NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete, deleteResponse); assertTrue(apiWhenServersExist.getSecurityGroupApi("az-1.region-a.geo-1").get() .delete("160")); }
public void createGetAndDeleteSecurityGroup() throws Exception { for (String zoneId : api.getConfiguredZones()) { SecurityGroupApi securityGroupApi = api.getSecurityGroupExtensionForZone(zoneId).get(); SecurityGroup securityGroup = null; String id; try { securityGroup = securityGroupApi .createWithDescription(SECURITY_GROUP_NAME, "test security group"); assertNotNull(securityGroup); id = securityGroup.getId(); SecurityGroup theGroup = securityGroupApi.get(id); assertNotNull(theGroup); } finally { if (securityGroup != null) { securityGroupApi.delete(securityGroup.getId()); } } } }
public void createGetAndDeleteSecurityGroup() throws Exception { for (String regionId : api.getConfiguredRegions()) { SecurityGroupApi securityGroupApi = api.getSecurityGroupApi(regionId).get(); SecurityGroup securityGroup = null; String id; try { securityGroup = securityGroupApi .createWithDescription(SECURITY_GROUP_NAME, "test security group"); assertNotNull(securityGroup); id = securityGroup.getId(); SecurityGroup theGroup = securityGroupApi.get(id); assertNotNull(theGroup); } finally { if (securityGroup != null) { securityGroupApi.delete(securityGroup.getId()); } } } }
RegionAndName regionAndName = RegionAndName.fromRegionAndName(regionAndId.getRegion(), securityGroup.getName()); logger.debug(">> deleting securityGroup(%s)", regionAndName); novaApi.getSecurityGroupApi(regionAndId.getRegion()).get().delete(securityGroup.getId());
securityGroupApi.delete(securityGroup.getId());
securityGroupApi.delete(securityGroup.getId());