mirror of https://github.com/apache/cloudstack.git
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.
This commit is contained in:
parent
7a54cf8f7c
commit
413ec914ed
|
|
@ -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<Pair<String, Object>> response = new ArrayList<Pair<String, Object>>();
|
||||
response.add(new Pair<String, Object>("template", templateId));
|
||||
response.add(new Pair<String, Object>("url", url));
|
||||
response.add(new Pair<String, Object>("zoneid", zoneId));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), templateId));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), template.getName()));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_TEXT.getName(), template.getDisplayText()));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.URL.getName(), url));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), zoneId));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), zone.getName()));
|
||||
response.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_STATUS.getName(), "Processing"));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@
|
|||
<zones>
|
||||
<zone>
|
||||
<id>1</id>
|
||||
<name>NM</name>
|
||||
<dns1>4.2.2.2</dns1>
|
||||
<dns2>10.10.10.14</dns2>
|
||||
<internalDns1>4.2.2.2</internalDns1>
|
||||
<internalDns2>4.2.2.2</internalDns2>
|
||||
<gateway>10.91.28.1</gateway>
|
||||
<netmask>255.255.255.0</netmask>
|
||||
<vnet>560-579</vnet>
|
||||
<name>ZONE1</name>
|
||||
<dns1>72.52.126.11</dns1>
|
||||
<dns2>72.52.126.12</dns2>
|
||||
<internalDns1>192.168.10.253</internalDns1>
|
||||
<internalDns2>192.168.10.254</internalDns2>
|
||||
<gateway>172.16.0.1</gateway>
|
||||
<netmask>255.255.0.0</netmask>
|
||||
<ipAddressRange>172.16.1.1-172.16.255.253</ipAddressRange>
|
||||
<guestNetworkCidr>10.1.1.0/24</guestNetworkCidr>
|
||||
</zone>
|
||||
</zones>
|
||||
|
|
@ -35,45 +35,24 @@
|
|||
<pods>
|
||||
<pod>
|
||||
<id>1</id>
|
||||
<name>NM</name>
|
||||
<name>POD1</name>
|
||||
<zoneId>1</zoneId>
|
||||
<gateway>10.91.28.1</gateway>
|
||||
<cidr>10.91.28.0/24</cidr>
|
||||
<ipAddressRange>10.91.28.160-10.91.28.179</ipAddressRange>
|
||||
<gateway>192.168.2.1</gateway>
|
||||
<cidr>192.168.2.0/24</cidr>
|
||||
<ipAddressRange>192.168.2.20-192.168.2.170</ipAddressRange>
|
||||
</pod>
|
||||
</pods>
|
||||
|
||||
<storagePools>
|
||||
<storagePool>
|
||||
<zoneId>1</zoneId>
|
||||
<podId>1</podId>
|
||||
<name>idc-ss</name>
|
||||
<hostAddress>10.91.28.6</hostAddress>
|
||||
<hostPath>/export/home/nitin/primary</hostPath>
|
||||
</storagePool>
|
||||
</storagePools>
|
||||
|
||||
<!--
|
||||
<secondaryStorages>
|
||||
<secondaryStorage>
|
||||
<zoneId>1</zoneId>
|
||||
<podId>1</podId>
|
||||
<url>nfs://10.91.28.6/export/home/nitin/secondary</url>
|
||||
</secondaryStorage>
|
||||
</secondaryStorages>
|
||||
-->
|
||||
|
||||
<!--
|
||||
<vlans>
|
||||
<vlan>
|
||||
<zoneId>1</zoneId>
|
||||
<vlanId>30</vlanId>
|
||||
<vlanType>VirtualNetwork</vlanType>
|
||||
<gateway>10.91.30.1</gateway>
|
||||
<gateway>192.168.30.1</gateway>
|
||||
<netmask>255.255.255.0</netmask>
|
||||
<ipAddressRange>10.91.30.160-10.91.30.179</ipAddressRange>
|
||||
<ipAddressRange>192.168.30.10-192.168.30.19</ipAddressRange>
|
||||
</vlan>
|
||||
</vlans>
|
||||
<!--
|
||||
<vlan>
|
||||
<zoneId>1</zoneId>
|
||||
<vlanId>31</vlanId>
|
||||
|
|
@ -82,6 +61,7 @@
|
|||
<netmask>255.255.255.0</netmask>
|
||||
<ipAddressRange>192.168.31.10-192.168.31.19</ipAddressRange>
|
||||
</vlan>
|
||||
</vlans>
|
||||
-->
|
||||
<!--
|
||||
* id is the unique id of the service offering
|
||||
|
|
|
|||
Loading…
Reference in New Issue