Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions api/src/com/cloud/agent/api/to/DatadiskTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.cloud.agent.api.to;

public class DatadiskTO {
private String path;
private long virtualSize;
private long fileSize;
boolean bootable;

public DatadiskTO() {
}

public DatadiskTO(String path, long virtualSize, long fileSize, boolean bootable) {
this.path = path;
this.virtualSize = virtualSize;
this.fileSize = fileSize;
this.bootable = bootable;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public Long getVirtualSize() {
return virtualSize;
}

public void setVirtualSize(Long virtualSize) {
this.virtualSize = virtualSize;
}

public Long getFileSize() {
return fileSize;
}

public boolean isBootable() {
return bootable;
}
}
3 changes: 2 additions & 1 deletion api/src/com/cloud/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public static enum TemplateType {
SYSTEM, /* routing, system vm template */
BUILTIN, /* buildin template */
PERHOST, /* every host has this template, don't need to install it in secondary storage */
USER /* User supplied template/iso */
USER, /* User supplied template/iso */
DATADISK /* Template corresponding to a datadisk(non root disk) present in an OVA */
}

public static enum StoragePoolType {
Expand Down
2 changes: 2 additions & 0 deletions api/src/com/cloud/template/VirtualMachineTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public enum TemplateFilter {

boolean isDynamicallyScalable();

Long getParentTemplateId();

long getUpdatedCount();

void incrUpdatedCount();
Expand Down
4 changes: 4 additions & 0 deletions api/src/com/cloud/vm/DiskProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public Long getTemplateId() {
return templateId;
}

public void setTemplateId(Long templateId) {
this.templateId = templateId;
}

/**
* @return disk offering id that the disk is based on.
*/
Expand Down
22 changes: 19 additions & 3 deletions api/src/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.cloud.host.Host;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network.IpAddresses;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.StoragePool;
import com.cloud.template.VirtualMachineTemplate;
Expand Down Expand Up @@ -195,6 +196,11 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
* @param cpuNumber
* @param customId
* @return UserVm object if successful.
* @param dataDiskTemplateToDiskOfferingMap
* - Datadisk template to Disk offering Map
* an optional parameter that creates additional data disks for the virtual machine
* For each of the templates in the map, a data disk will be created from the corresponding
* disk offering obtained from the map
*
* @throws InsufficientCapacityException
* if there is insufficient capacity to deploy the VM.
Expand All @@ -208,7 +214,7 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList,
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod,
String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp, Boolean displayVm, String keyboard,
List<Long> affinityGroupIdList, Map<String, String> customParameter, String customId) throws InsufficientCapacityException,
List<Long> affinityGroupIdList, Map<String, String> customParameter, String customId, Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;

/**
Expand Down Expand Up @@ -267,6 +273,11 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
* @param memory
* @param cpuNumber
* @param customId
* @param dataDiskTemplateToDiskOfferingMap
* - Datadisk template to Disk offering Map
* an optional parameter that creates additional data disks for the virtual machine
* For each of the templates in the map, a data disk will be created from the corresponding
* disk offering obtained from the map
* @return UserVm object if successful.
*
* @throws InsufficientCapacityException
Expand All @@ -281,7 +292,7 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard,
List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId) throws InsufficientCapacityException,
List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId, Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;

/**
Expand Down Expand Up @@ -338,6 +349,11 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
* @param memory
* @param cpuNumber
* @param customId
* @param dataDiskTemplateToDiskOfferingMap
* - Datadisk template to Disk offering Map
* an optional parameter that creates additional data disks for the virtual machine
* For each of the templates in the map, a data disk will be created from the corresponding
* disk offering obtained from the map
* @return UserVm object if successful.
*
* @throws InsufficientCapacityException
Expand All @@ -352,7 +368,7 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner,
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData,
String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList,
Map<String, String> customParameters, String customId)
Map<String, String> customParameters, String customId, Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap)

throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;

Expand Down
2 changes: 2 additions & 0 deletions api/src/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class ApiConstants {
public static final String MIN_IOPS = "miniops";
public static final String MAX_IOPS = "maxiops";
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";
public static final String DATADISKTEMPLATE_TO_DISKOFFERING_LIST = "datadisktemplatetodiskofferinglist";
public static final String DESCRIPTION = "description";
public static final String DESTINATION_ZONE_ID = "destzoneid";
public static final String DETAILS = "details";
Expand Down Expand Up @@ -183,6 +184,7 @@ public class ApiConstants {
public static final String OUTOFBANDMANAGEMENT_ENABLED = "outofbandmanagementenabled";
public static final String PARAMS = "params";
public static final String PARENT_DOMAIN_ID = "parentdomainid";
public static final String PARENT_TEMPLATE_ID = "parenttemplateid";
public static final String PASSWORD = "password";
public static final String SHOULD_UPDATE_PASSWORD = "update_passwd_on_host";
public static final String NEW_PASSWORD = "new_password";
Expand Down
2 changes: 2 additions & 0 deletions api/src/org/apache/cloudstack/api/ResponseGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ public interface ResponseGenerator {

Host findHostById(Long hostId);

DiskOffering findDiskOfferingById(Long diskOfferingId);

VpnUsersResponse createVpnUserResponse(VpnUser user);

RemoteAccessVpnResponse createRemoteAccessVpnResponse(RemoteAccessVpn vpn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "list templates by zoneId")
private Long zoneId;

@Parameter(name=ApiConstants.SHOW_REMOVED, type=CommandType.BOOLEAN, description="show removed templates as well")
@Parameter(name = ApiConstants.SHOW_REMOVED, type = CommandType.BOOLEAN, description = "show removed templates as well")
private Boolean showRemoved;

@Parameter(name = ApiConstants.PARENT_TEMPLATE_ID, type = CommandType.UUID, entityType = TemplateResponse.class, description = "list datadisk templates by parent template id", since = "4.4")
private Long parentTemplateId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -103,6 +106,10 @@ public Boolean getShowRemoved() {
return (showRemoved != null ? showRemoved : false);
}

public Long getParentTemplateId() {
return parentTemplateId;
}

public boolean listInReadyState() {

Account account = CallContext.current().getCallingAccount();
Expand Down
38 changes: 38 additions & 0 deletions api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network;
import com.cloud.network.Network.IpAddresses;
import com.cloud.offering.DiskOffering;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.uservm.UserVm;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.VirtualMachine;
Expand Down Expand Up @@ -184,6 +186,10 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "Deployment planner to use for vm allocation. Available to ROOT admin only", since = "4.4", authorized = { RoleType.Admin })
private String deploymentPlanner;

@Parameter(name = ApiConstants.DATADISKTEMPLATE_TO_DISKOFFERING_LIST, type = CommandType.MAP, since = "4.4", description = "datadisk template to disk-offering mapping;" +
" an optional parameter used to create additional data disks from datadisk templates; can't be specified with diskOfferingId parameter")
private Map dataDiskTemplateToDiskOfferingList;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -382,6 +388,38 @@ public String getKeyboard() {
return keyboard;
}


public Map<Long, DiskOffering> getDataDiskTemplateToDiskOfferingMap() {
if (diskOfferingId != null && dataDiskTemplateToDiskOfferingList != null) {
throw new InvalidParameterValueException("diskofferingid paramter can't be specified along with datadisktemplatetodiskofferinglist parameter");
}
HashMap<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap = new HashMap<Long, DiskOffering>();
if (dataDiskTemplateToDiskOfferingList != null && !dataDiskTemplateToDiskOfferingList.isEmpty()) {
Collection dataDiskTemplatesCollection = dataDiskTemplateToDiskOfferingList.values();
Iterator iter = dataDiskTemplatesCollection.iterator();
while (iter.hasNext()) {
HashMap<String, String> dataDiskTemplates = (HashMap<String, String>)iter.next();
Long dataDiskTemplateId;
DiskOffering dataDiskOffering = null;
VirtualMachineTemplate dataDiskTemplate= _entityMgr.findByUuid(VirtualMachineTemplate.class, dataDiskTemplates.get("datadisktemplateid"));
if (dataDiskTemplate == null) {
dataDiskTemplate = _entityMgr.findById(VirtualMachineTemplate.class, dataDiskTemplates.get("datadisktemplateid"));
if (dataDiskTemplate == null)
throw new InvalidParameterValueException("Unable to translate and find entity with datadisktemplateid " + dataDiskTemplates.get("datadisktemplateid"));
}
dataDiskTemplateId = dataDiskTemplate.getId();
dataDiskOffering = _entityMgr.findByUuid(DiskOffering.class, dataDiskTemplates.get("diskofferingid"));
if (dataDiskOffering == null) {
dataDiskOffering = _entityMgr.findById(DiskOffering.class, dataDiskTemplates.get("diskofferingid"));
if (dataDiskOffering == null)
throw new InvalidParameterValueException("Unable to translate and find entity with diskofferingId " + dataDiskTemplates.get("diskofferingid"));
}
dataDiskTemplateToDiskOfferingMap.put(dataDiskTemplateId, dataDiskOffering);
}
}
return dataDiskTemplateToDiskOfferingMap;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public class TemplateResponse extends BaseResponseWithTagInformation implements
@Param(description = "true if template contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory")
private Boolean isDynamicallyScalable;

@SerializedName("parenttemplateid")
@Param(description = "if Datadisk template, then id of the root disk template this template belongs to")
private String parentTemplateId;

public TemplateResponse() {
tags = new LinkedHashSet<ResourceTagResponse>();
}
Expand Down Expand Up @@ -347,4 +351,8 @@ public String getZoneId() {
return zoneId;
}

public void setParentTemplateId(String parentTemplateId) {
this.parentTemplateId = parentTemplateId;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api.storage;

import org.apache.cloudstack.storage.to.TemplateObjectTO;

import com.cloud.agent.api.Answer;

public class CreateDatadiskTemplateAnswer extends Answer {
private TemplateObjectTO dataDiskTemplate = null;

public CreateDatadiskTemplateAnswer(TemplateObjectTO dataDiskTemplate) {
super(null);
this.dataDiskTemplate = dataDiskTemplate;
}

public TemplateObjectTO getDataDiskTemplate() {
return dataDiskTemplate;
}

public CreateDatadiskTemplateAnswer(String errMsg) {
super(null, false, errMsg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api.storage;

import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataTO;

public final class CreateDatadiskTemplateCommand extends Command {
private DataTO dataDiskTemplate;
private String path;
private long fileSize;
private boolean bootable;

public CreateDatadiskTemplateCommand(DataTO dataDiskTemplate, String path, long fileSize, boolean bootable) {
super();
this.dataDiskTemplate = dataDiskTemplate;
this.path = path;
this.fileSize = fileSize;
this.bootable = bootable;
}

protected CreateDatadiskTemplateCommand() {
super();
}

@Override
public boolean executeInSequence() {
return false;
}

public DataTO getDataDiskTemplate() {
return dataDiskTemplate;
}

public String getPath() {
return path;
}

public long getFileSize() {
return fileSize;
}

public boolean getBootable() {
return bootable;
}
}
Loading