From 413ec914ed4849705cab6a856e30b7116d784ee3 Mon Sep 17 00:00:00 2001 From: nit Date: Wed, 8 Sep 2010 18:35:07 +0530 Subject: [PATCH] bug 4286: Reverting server-setup.xml checked in accidentally, added more tags to extract template and put in a user and domain check for executing the command. --- .../api/commands/ExtractTemplateCmd.java | 45 +++++++++------- setup/db/server-setup.xml | 52 ++++++------------- 2 files changed, 41 insertions(+), 56 deletions(-) diff --git a/server/src/com/cloud/api/commands/ExtractTemplateCmd.java b/server/src/com/cloud/api/commands/ExtractTemplateCmd.java index d6f9edebaac..a73c291bbcd 100644 --- a/server/src/com/cloud/api/commands/ExtractTemplateCmd.java +++ b/server/src/com/cloud/api/commands/ExtractTemplateCmd.java @@ -9,6 +9,8 @@ import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; import com.cloud.api.ServerApiException; +import com.cloud.dc.DataCenterVO; +import com.cloud.server.ManagementServer; import com.cloud.storage.VMTemplateVO; import com.cloud.user.Account; import com.cloud.utils.Pair; @@ -34,41 +36,44 @@ public class ExtractTemplateCmd extends BaseCmd { Long zoneId = (Long) params.get(BaseCmd.Properties.ZONE_ID.getName()); Account account = (Account) params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); - VMTemplateVO template = getManagementServer().findTemplateById(templateId.longValue()); + ManagementServer managementServer = getManagementServer(); + VMTemplateVO template = managementServer.findTemplateById(templateId.longValue()); if (template == null) { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Unable to find template with id " + templateId); } + if (template.getName().startsWith("xs-tools") ){ + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Unable to extract the template " + template.getName() + " It is not supported yet"); + } if(url.toLowerCase().contains("file://")){ throw new ServerApiException(BaseCmd.PARAM_ERROR, "file:// type urls are currently unsupported"); } - - boolean isAdmin; - if (account == null) { - // Admin API call - isAdmin = true; - } else { - // User API call - isAdmin = isAdmin(account.getType()); - } - - if(!isAdmin){ - if (template.getAccountId() != account.getId()){ - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find template with ID: " + templateId + " for account: " + account.getAccountName()); + + if (account != null) { + if(!isAdmin(account.getType())){ + if (template.getAccountId() != account.getId()){ + throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find template with ID: " + templateId + " for account: " + account.getAccountName()); + } + }else if(!managementServer.isChildDomain(account.getDomainId(), managementServer.findDomainIdByAccountId(template.getAccountId())) ) { + throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to extract template " + templateId + " to " + url + ", permission denied."); } } try { - getManagementServer().extractTemplate(url, templateId, zoneId); + managementServer.extractTemplate(url, templateId, zoneId); } catch (Exception e) { s_logger.error(e.getMessage(), e); throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal Error Extracting the template " + e.getMessage()); - } - + } + DataCenterVO zone = managementServer.getDataCenterBy(zoneId); List> response = new ArrayList>(); - response.add(new Pair("template", templateId)); - response.add(new Pair("url", url)); - response.add(new Pair("zoneid", zoneId)); + response.add(new Pair(BaseCmd.Properties.TEMPLATE_ID.getName(), templateId)); + response.add(new Pair(BaseCmd.Properties.NAME.getName(), template.getName())); + response.add(new Pair(BaseCmd.Properties.DISPLAY_TEXT.getName(), template.getDisplayText())); + response.add(new Pair(BaseCmd.Properties.URL.getName(), url)); + response.add(new Pair(BaseCmd.Properties.ZONE_ID.getName(), zoneId)); + response.add(new Pair(BaseCmd.Properties.ZONE_NAME.getName(), zone.getName())); + response.add(new Pair(BaseCmd.Properties.TEMPLATE_STATUS.getName(), "Processing")); return response; } diff --git a/setup/db/server-setup.xml b/setup/db/server-setup.xml index 5c39a986f30..7db947bee0b 100755 --- a/setup/db/server-setup.xml +++ b/setup/db/server-setup.xml @@ -12,14 +12,14 @@ 1 - NM - 4.2.2.2 - 10.10.10.14 - 4.2.2.2 - 4.2.2.2 - 10.91.28.1 - 255.255.255.0 - 560-579 + ZONE1 + 72.52.126.11 + 72.52.126.12 + 192.168.10.253 + 192.168.10.254 + 172.16.0.1 + 255.255.0.0 + 172.16.1.1-172.16.255.253 10.1.1.0/24 @@ -35,45 +35,24 @@ 1 - NM + POD1 1 - 10.91.28.1 - 10.91.28.0/24 - 10.91.28.160-10.91.28.179 + 192.168.2.1 + 192.168.2.0/24 + 192.168.2.20-192.168.2.170 - - -1 -1 -idc-ss -10.91.28.6 -/export/home/nitin/primary - - - - - +