Skip to content

Commit b139d37

Browse files
committed
handle restore for VMs deployed from ISO
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 6af5094 commit b139d37

5 files changed

Lines changed: 36 additions & 30 deletions

File tree

engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
*/
6060
public interface VirtualMachineManager extends Manager {
6161

62+
String KVM_BLANK_VM_TEMPLATE_NAME = "kvm-blank-vm-template";
63+
6264
ConfigKey<Boolean> ExecuteInSequence = new ConfigKey<>("Advanced", Boolean.class, "execute.in.sequence.hypervisor.commands", "false",
6365
"If set to true, start, stop, reboot, copy and migrate commands will be serialized on the agent side. If set to false the commands are executed in parallel. Default value is false.", false);
6466

@@ -312,4 +314,8 @@ void checkDeploymentPlan(VirtualMachine virtualMachine, VirtualMachineTemplate t
312314
ServiceOffering serviceOffering, Account systemAccount, DeploymentPlan plan)
313315
throws InsufficientServerCapacityException;
314316

317+
boolean isBlankInstanceDefaultTemplate(VirtualMachineTemplate template);
318+
319+
boolean isBlankInstance(VirtualMachineTemplate template);
320+
315321
}

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public void allocate(final String vmInstanceName, final VirtualMachineTemplate t
575575

576576
logger.debug("Allocating disks for {}", persistedVm);
577577

578-
if (_userVmMgr.isBlankInstance(template)) {
578+
if (isBlankInstance(template)) {
579579
logger.debug("Template is a dummy template for hypervisor {}, skipping volume allocation", hyperType);
580580
return;
581581
} else {
@@ -6702,4 +6702,18 @@ public void checkDeploymentPlan(VirtualMachine virtualMachine, VirtualMachineTem
67026702
vmProfile), DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile));
67036703
}
67046704
}
6705+
6706+
@Override
6707+
public boolean isBlankInstanceDefaultTemplate(VirtualMachineTemplate template) {
6708+
return KVM_BLANK_VM_TEMPLATE_NAME.equals(template.getUniqueName());
6709+
}
6710+
6711+
@Override
6712+
public boolean isBlankInstance(VirtualMachineTemplate template) {
6713+
if (isBlankInstanceDefaultTemplate(template)) {
6714+
return true;
6715+
}
6716+
return Boolean.TRUE.equals(
6717+
MapUtils.getBoolean(CallContext.current().getContextParameters(), ApiConstants.BLANK_INSTANCE));
6718+
}
67056719
}

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.cloudstack.engine.orchestration;
2020

2121
import com.cloud.storage.Snapshot;
22+
import com.cloud.storage.VMTemplateVO;
2223
import com.cloud.storage.Volume;
2324
import com.cloud.template.VirtualMachineTemplate;
2425
import java.net.URL;
@@ -292,9 +293,11 @@ public VirtualMachineEntity createVirtualMachineFromScratch(String id, String ow
292293

293294
ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
294295

296+
VMTemplateVO iso = _templateDao.findByIdIncludingRemoved(Long.valueOf(isoId));
297+
295298
DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
296299

297-
if (diskOfferingId == null) {
300+
if (diskOfferingId == null && !_itMgr.isBlankInstance(iso)) {
298301
throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
299302
}
300303
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
@@ -345,7 +348,7 @@ public VirtualMachineEntity createVirtualMachineFromScratch(String id, String ow
345348

346349
HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
347350

348-
_itMgr.allocate(vm.getInstanceName(), _templateDao.findByIdIncludingRemoved(new Long(isoId)), computeOffering, rootDiskOfferingInfo, dataDiskOfferings, dataDiskDeviceIds,
351+
_itMgr.allocate(vm.getInstanceName(), iso, computeOffering, rootDiskOfferingInfo, dataDiskOfferings, dataDiskDeviceIds,
349352
networkIpMap, plan, hypervisorType, extraDhcpOptionMap, null, volume, snapshot);
350353

351354
return vmEntity;

server/src/main/java/com/cloud/vm/UserVmManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,4 @@ static Set<String> getStrictHostTags() {
206206
* @return true if the VM is part of a CKS cluster, false otherwise.
207207
*/
208208
boolean isVMPartOfAnyCKSCluster(VMInstanceVO vm);
209-
210-
boolean isBlankInstance(VirtualMachineTemplate template);
211209
}

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
426426

427427
private static final long GiB_TO_BYTES = 1024 * 1024 * 1024;
428428

429-
private static final String KVM_BLANK_VM_TEMPLATE_NAME = "kvm-blank-vm-template";
430-
431429

432430
@Inject
433431
private EntityManager _entityMgr;
@@ -3939,7 +3937,7 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service
39393937
_accountMgr.checkAccess(owner, _diskOfferingDao.findById(diskOfferingId), zone);
39403938

39413939
// If no network is specified, find system security group enabled network
3942-
if (isBlankInstance(template)) {
3940+
if (_itMgr.isBlankInstance(template)) {
39433941
logger.debug("Blank instance for {} hypervisor, skipping network allocation in an advanced security group enabled zone", hypervisor);
39443942
} else if (networkIdList == null || networkIdList.isEmpty()) {
39453943
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(owner, zone.getId());
@@ -4054,7 +4052,7 @@ public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serv
40544052
_accountMgr.checkAccess(owner, diskOffering, zone);
40554053

40564054
List<HypervisorType> vpcSupportedHTypes = _vpcMgr.getSupportedVpcHypervisors();
4057-
if (isBlankInstance(template)) {
4055+
if (_itMgr.isBlankInstance(template)) {
40584056
logger.debug("Template is a dummy template for hypervisor {}, skipping network allocation in an advanced zone", hypervisor);
40594057
} else if (networkIdList == null || networkIdList.isEmpty()) {
40604058
NetworkVO defaultNetwork = getDefaultNetwork(zone, owner, false);
@@ -4290,7 +4288,7 @@ private UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOffe
42904288
if (isIso) {
42914289
if (diskOfferingId == null) {
42924290
DiskOfferingVO diskOffering = _diskOfferingDao.findById(rootDiskOfferingId);
4293-
if (diskOffering.isComputeOnly()) {
4291+
if (diskOffering.isComputeOnly() && !_itMgr.isBlankInstance(template)) {
42944292
throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
42954293
}
42964294
} else {
@@ -4488,7 +4486,7 @@ private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, Stri
44884486
}
44894487

44904488
if (TemplateType.SYSTEM.equals(template.getTemplateType()) && !CKS_NODE.equals(vmType) &&
4491-
!SHAREDFSVM.equals(vmType) && !isBlankInstanceDefaultTemplate(template)) {
4489+
!SHAREDFSVM.equals(vmType) && !_itMgr.isBlankInstanceDefaultTemplate(template)) {
44924490
throw new InvalidParameterValueException(String.format("Unable to use system template %s to deploy a user vm", template));
44934491
}
44944492

@@ -4501,7 +4499,7 @@ private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, Stri
45014499
if (CollectionUtils.isEmpty(snapshotsOnZone)) {
45024500
throw new InvalidParameterValueException("The snapshot does not exist on zone " + zone.getId());
45034501
}
4504-
} else if (!isBlankInstanceDefaultTemplate(template)) {
4502+
} else if (!_itMgr.isBlankInstanceDefaultTemplate(template)) {
45054503
List<VMTemplateZoneVO> listZoneTemplate = _templateZoneDao.listByZoneTemplate(zone.getId(), template.getId());
45064504
if (listZoneTemplate == null || listZoneTemplate.isEmpty()) {
45074505
throw new InvalidParameterValueException("The template " + template.getId() + " is not available for use");
@@ -4616,7 +4614,7 @@ private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, Stri
46164614
// by Agent Manager in order to configure default
46174615
// gateway for the vm
46184616
if (defaultNetworkNumber == 0) {
4619-
if (isBlankInstance(template)) {
4617+
if (_itMgr.isBlankInstance(template)) {
46204618
logger.debug("Template is a dummy template for hypervisor {}, vm can be created without a default network", hypervisorType);
46214619
} else {
46224620
throw new InvalidParameterValueException("At least 1 default network has to be specified for the vm");
@@ -6658,7 +6656,7 @@ private UserVm createVirtualMachine(BaseDeployVMCmd cmd, DataCenter zone, Accoun
66586656
applyLeaseOnCreateInstance(vm, cmd.getLeaseDuration(), cmd.getLeaseExpiryAction(), svcOffering);
66596657
}
66606658

6661-
if (isBlankInstance(template) && cmd instanceof DeployVMCmd && ((DeployVMCmd) cmd).isBlankInstance()) {
6659+
if (_itMgr.isBlankInstance(template) && cmd instanceof DeployVMCmd && ((DeployVMCmd) cmd).isBlankInstance()) {
66626660
logger.info("Revoking launch permission for Dummy template");
66636661
launchPermissionDao.removePermissions(template.getId(), Collections.singletonList(owner.getId()));
66646662
}
@@ -10104,26 +10102,13 @@ private void setVncPasswordForKvmIfAvailable(Map<String, String> customParameter
1010410102
}
1010510103
}
1010610104

10107-
protected boolean isBlankInstanceDefaultTemplate(VirtualMachineTemplate template) {
10108-
return KVM_BLANK_VM_TEMPLATE_NAME.equals(template.getUniqueName());
10109-
}
10110-
10111-
@Override
10112-
public boolean isBlankInstance(VirtualMachineTemplate template) {
10113-
if (isBlankInstanceDefaultTemplate(template)) {
10114-
return true;
10115-
}
10116-
return Boolean.TRUE.equals(
10117-
MapUtils.getBoolean(CallContext.current().getContextParameters(), ApiConstants.BLANK_INSTANCE));
10118-
}
10119-
10120-
VMTemplateVO getBlankInstanceTemplate() {
10121-
VMTemplateVO template = _templateDao.findByName(KVM_BLANK_VM_TEMPLATE_NAME);
10105+
protected VMTemplateVO getBlankInstanceTemplate() {
10106+
VMTemplateVO template = _templateDao.findByName(VirtualMachineManager.KVM_BLANK_VM_TEMPLATE_NAME);
1012210107
if (template != null) {
1012310108
return template;
1012410109
}
1012510110
template = VMTemplateVO.createSystemIso(_templateDao.getNextInSequence(Long.class, "id"),
10126-
KVM_BLANK_VM_TEMPLATE_NAME, KVM_BLANK_VM_TEMPLATE_NAME, true,
10111+
VirtualMachineManager.KVM_BLANK_VM_TEMPLATE_NAME, VirtualMachineManager.KVM_BLANK_VM_TEMPLATE_NAME, true,
1012710112
"", true, 64, Account.ACCOUNT_ID_SYSTEM, "",
1012810113
"Blank Template for KVM VM", false, 1);
1012910114
template.setState(VirtualMachineTemplate.State.Active);

0 commit comments

Comments
 (0)