private void validate(APISetVmBootOrderMsg msg) { if (msg.getBootOrder() != null) { for (String o : msg.getBootOrder()) { try { VmBootDevice.valueOf(o); } catch (IllegalArgumentException e) { throw new ApiMessageInterceptionException(argerr("invalid boot device[%s] in boot order%s", o, msg.getBootOrder())); } } } }
private List<String> toKvmBootDev(List<String> order) { List<String> ret = new ArrayList<String>(); for (String o : order) { if (VmBootDevice.HardDisk.toString().equals(o)) { ret.add(BootDev.hd.toString()); } else if (VmBootDevice.CdRom.toString().equals(o)) { ret.add(BootDev.cdrom.toString()); } else { throw new CloudRuntimeException(String.format("unknown boot device[%s]", o)); } } return ret; }
private void handle(APIGetVmBootOrderMsg msg) { APIGetVmBootOrderReply reply = new APIGetVmBootOrderReply(); String order = VmSystemTags.BOOT_ORDER.getTokenByResourceUuid(self.getUuid(), VmSystemTags.BOOT_ORDER_TOKEN); if (order != null) { reply.setOrder(list(order.split(","))); } else if (order == null && !IsoOperator.isIsoAttachedToVm(msg.getUuid())) { reply.setOrder(list(VmBootDevice.HardDisk.toString())); } else { reply.setOrder(list(VmBootDevice.HardDisk.toString(), VmBootDevice.CdRom.toString())); } bus.reply(msg, reply); }
protected void selectBootOrder(VmInstanceSpec spec) { if (spec.getCurrentVmOperation() == null) { throw new CloudRuntimeException("selectBootOrder must be called after VmOperation is set"); } List<CdRomSpec> cdRomSpecs = spec.getCdRomSpecs().stream() .filter(cdRom -> cdRom.getImageUuid() != null) .collect(Collectors.toList()); if (spec.getCurrentVmOperation() == VmOperation.NewCreate && !cdRomSpecs.isEmpty()) { ImageVO imageVO = dbf.findByUuid(spec.getVmInventory().getImageUuid(), ImageVO.class); assert imageVO != null; if(imageVO.getMediaType() == ImageMediaType.ISO) { spec.setBootOrders(list(VmBootDevice.CdRom.toString())); } else { spec.setBootOrders(list(VmBootDevice.HardDisk.toString())); } } else { String order = VmSystemTags.BOOT_ORDER.getTokenByResourceUuid(self.getUuid(), VmSystemTags.BOOT_ORDER_TOKEN); if (order == null) { spec.setBootOrders(list(VmBootDevice.HardDisk.toString())); } else { spec.setBootOrders(list(order.split(","))); // set vm to boot from cdrom once only if (VmSystemTags.CDROM_BOOT_ONCE.hasTag(self.getUuid(), VmInstanceVO.class)) { VmSystemTags.BOOT_ORDER.deleteInherentTag(self.getUuid()); VmSystemTags.CDROM_BOOT_ONCE.deleteInherentTag(self.getUuid()); } } } }
spec.setCurrentVmOperation(VmInstanceConstant.VmOperation.NewCreate); spec.putExtensionData(ApplianceVmConstant.Params.applianceVmSubType.toString(), getSelf().getApplianceVmType()); spec.setBootOrders(list(VmBootDevice.HardDisk.toString()));