You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by za...@apache.org on 2016/05/19 17:09:06 UTC
jclouds git commit: Fix cleanup when the security group extension is
not available.
Repository: jclouds
Updated Branches:
refs/heads/master 0e41b45af -> c96cfb617
Fix cleanup when the security group extension is not available.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/c96cfb61
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/c96cfb61
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/c96cfb61
Branch: refs/heads/master
Commit: c96cfb61762bc633846f924a9c45e8d54b6988bd
Parents: 0e41b45
Author: Zack Shoylev <za...@rackspace.com>
Authored: Wed May 18 21:04:40 2016 -0500
Committer: Zack Shoylev <za...@rackspace.com>
Committed: Thu May 19 12:08:36 2016 -0500
----------------------------------------------------------------------
.../v2_0/compute/functions/CleanupServer.java | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/c96cfb61/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CleanupServer.java
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CleanupServer.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CleanupServer.java
index a12c17f..5a922e8 100644
--- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CleanupServer.java
+++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/CleanupServer.java
@@ -30,6 +30,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.openstack.nova.v2_0.domain.ServerWithSecurityGroups;
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndId;
import org.jclouds.openstack.nova.v2_0.domain.regionscoped.RegionAndName;
@@ -64,7 +65,15 @@ public class CleanupServer implements Function<String, Boolean> {
@Override
public Boolean apply(String id) {
final RegionAndId regionAndId = RegionAndId.fromSlashEncoded(id);
- ServerWithSecurityGroups server = novaApi.getServerWithSecurityGroupsApi(regionAndId.getRegion()).get().get(regionAndId.getId());
+ boolean secGroupsPresent = novaApi.getServerWithSecurityGroupsApi(regionAndId.getRegion()).isPresent();
+ Server server;
+
+ if (secGroupsPresent) {
+ server = novaApi.getServerWithSecurityGroupsApi(regionAndId.getRegion()).get()
+ .get(regionAndId.getId());
+ } else {
+ server = novaApi.getServerApi(regionAndId.getRegion()).get(regionAndId.getId());
+ }
if (novaApi.getFloatingIPApi(regionAndId.getRegion()).isPresent()) {
try {
@@ -73,6 +82,7 @@ public class CleanupServer implements Function<String, Boolean> {
logger.warn(e, "<< error removing and deallocating ip from node(%s): %s", id, e.getMessage());
}
}
+
if (containsMetadata(server, JCLOUDS_KP)) {
if (novaApi.getKeyPairApi(regionAndId.getRegion()).isPresent()) {
RegionAndName regionAndName = RegionAndName.fromRegionAndName(regionAndId.getRegion(), server.getKeyName());
@@ -86,8 +96,8 @@ public class CleanupServer implements Function<String, Boolean> {
boolean serverDeleted = novaApi.getServerApi(regionAndId.getRegion()).delete(regionAndId.getId());
- if (containsMetadata(server, JCLOUDS_SG)) {
- for (final String securityGroupName : server.getSecurityGroupNames()) {
+ if (containsMetadata(server, JCLOUDS_SG) && secGroupsPresent) {
+ for (final String securityGroupName : ((ServerWithSecurityGroups)server).getSecurityGroupNames()) {
for (SecurityGroup securityGroup : novaApi.getSecurityGroupApi(regionAndId.getRegion()).get().list().toList()) {
if (securityGroup.getName().equalsIgnoreCase(securityGroupName)) {
if (novaApi.getSecurityGroupApi(regionAndId.getRegion()).isPresent()) {
@@ -105,7 +115,7 @@ public class CleanupServer implements Function<String, Boolean> {
return serverDeleted;
}
- private boolean containsMetadata(ServerWithSecurityGroups server, String key) {
+ private boolean containsMetadata(Server server, String key) {
if (server == null || server.getMetadata() == null || server.getMetadata().get("jclouds_tags") == null)
return false;
return server.getMetadata().get("jclouds_tags").contains(key);