mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Guard OS type update for iso/template with existing vms (#11215)
* Guard OS type update for iso/template with existing vms * fix identation * rename vm -> instance * force update iso/template as true by default via api * add missing message.success.update.iso label
This commit is contained in:
parent
6ad9296412
commit
e7172161dd
@ -223,6 +223,7 @@ public class ApiConstants {
|
|||||||
public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage";
|
public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage";
|
||||||
public static final String FORCE_DELETE_HOST = "forcedeletehost";
|
public static final String FORCE_DELETE_HOST = "forcedeletehost";
|
||||||
public static final String FORCE_MS_TO_IMPORT_VM_FILES = "forcemstoimportvmfiles";
|
public static final String FORCE_MS_TO_IMPORT_VM_FILES = "forcemstoimportvmfiles";
|
||||||
|
public static final String FORCE_UPDATE_OS_TYPE = "forceupdateostype";
|
||||||
public static final String FORMAT = "format";
|
public static final String FORMAT = "format";
|
||||||
public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork";
|
public static final String FOR_VIRTUAL_NETWORK = "forvirtualnetwork";
|
||||||
public static final String FOR_SYSTEM_VMS = "forsystemvms";
|
public static final String FOR_SYSTEM_VMS = "forsystemvms";
|
||||||
|
|||||||
@ -51,6 +51,10 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd {
|
|||||||
description = "the ID of the OS type that best represents the OS of this image.")
|
description = "the ID of the OS type that best represents the OS of this image.")
|
||||||
private Long osTypeId;
|
private Long osTypeId;
|
||||||
|
|
||||||
|
@Parameter(name = ApiConstants.FORCE_UPDATE_OS_TYPE, type = CommandType.BOOLEAN, since = "4.21", description = "Force OS type update. Warning: Updating OS type will " +
|
||||||
|
"update the guest OS configuration for all the existing Instances deployed with this template/iso, which may affect their behavior.")
|
||||||
|
private Boolean forceUpdateOsType;
|
||||||
|
|
||||||
@Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, description = "the format for the image")
|
@Parameter(name = ApiConstants.FORMAT, type = CommandType.STRING, description = "the format for the image")
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
@ -112,6 +116,10 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd {
|
|||||||
return osTypeId;
|
return osTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getForceUpdateOsType() {
|
||||||
|
return forceUpdateOsType;
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean getPasswordEnabled() {
|
public Boolean getPasswordEnabled() {
|
||||||
return passwordEnabled;
|
return passwordEnabled;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2238,6 +2238,12 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
sc.addAnd("state", SearchCriteria.Op.NEQ, State.Expunging);
|
sc.addAnd("state", SearchCriteria.Op.NEQ, State.Expunging);
|
||||||
List<VMInstanceVO> vms = _vmInstanceDao.search(sc, null);
|
List<VMInstanceVO> vms = _vmInstanceDao.search(sc, null);
|
||||||
if (vms != null && !vms.isEmpty()) {
|
if (vms != null && !vms.isEmpty()) {
|
||||||
|
if (Boolean.FALSE.equals(cmd.getForceUpdateOsType())) {
|
||||||
|
String message = String.format("Updating OS type will update the guest OS configuration " +
|
||||||
|
"for all of the %d Instance(s) deployed with this Template/ISO, which may affect their behavior. " +
|
||||||
|
"To proceed, please set the 'forceupdateostype' parameter to true.", vms.size());
|
||||||
|
throw new InvalidParameterValueException(message);
|
||||||
|
}
|
||||||
for (VMInstanceVO vm: vms) {
|
for (VMInstanceVO vm: vms) {
|
||||||
vm.setGuestOSId(guestOSId);
|
vm.setGuestOSId(guestOSId);
|
||||||
_vmInstanceDao.update(vm.getId(), vm);
|
_vmInstanceDao.update(vm.getId(), vm);
|
||||||
|
|||||||
@ -1039,6 +1039,7 @@
|
|||||||
"label.forbidden": "Forbidden",
|
"label.forbidden": "Forbidden",
|
||||||
"label.forced": "Force",
|
"label.forced": "Force",
|
||||||
"label.force.ms.to.import.vm.files": "Enable to force OVF Download via Management Server. Disable to use KVM Host ovftool (if installed)",
|
"label.force.ms.to.import.vm.files": "Enable to force OVF Download via Management Server. Disable to use KVM Host ovftool (if installed)",
|
||||||
|
"label.force.update.os.type": "Force update OS type",
|
||||||
"label.force.stop": "Force stop",
|
"label.force.stop": "Force stop",
|
||||||
"label.force.reboot": "Force reboot",
|
"label.force.reboot": "Force reboot",
|
||||||
"label.forceencap": "Force UDP encapsulation of ESP packets",
|
"label.forceencap": "Force UDP encapsulation of ESP packets",
|
||||||
@ -3693,6 +3694,7 @@
|
|||||||
"message.success.update.ipaddress": "Successfully updated IP address",
|
"message.success.update.ipaddress": "Successfully updated IP address",
|
||||||
"message.success.update.iprange": "Successfully updated IP range",
|
"message.success.update.iprange": "Successfully updated IP range",
|
||||||
"message.success.update.ipv4.subnet": "Successfully updated IPv4 subnet",
|
"message.success.update.ipv4.subnet": "Successfully updated IPv4 subnet",
|
||||||
|
"message.success.update.iso": "Successfully updated ISO",
|
||||||
"message.success.update.kubeversion": "Successfully updated Kubernetes supported version",
|
"message.success.update.kubeversion": "Successfully updated Kubernetes supported version",
|
||||||
"message.success.update.network": "Successfully updated Network",
|
"message.success.update.network": "Successfully updated Network",
|
||||||
"message.success.update.template": "Successfully updated Template",
|
"message.success.update.template": "Successfully updated Template",
|
||||||
|
|||||||
@ -67,6 +67,13 @@
|
|||||||
</a-select-option>
|
</a-select-option>
|
||||||
</a-select>
|
</a-select>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
<a-form-item name="forceupdateostype" ref="forceupdateostype" v-if="hasOstypeidChanged()">
|
||||||
|
<template #label>
|
||||||
|
<tooltip-label :title="$t('label.force.update.os.type')" :tooltip="apiParams.forceupdateostype.description"/>
|
||||||
|
</template>
|
||||||
|
<a-switch v-model:checked="form.forceupdateostype" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item name="isdynamicallyscalable" ref="isdynamicallyscalable">
|
<a-form-item name="isdynamicallyscalable" ref="isdynamicallyscalable">
|
||||||
<template #label>
|
<template #label>
|
||||||
<tooltip-label :title="$t('label.isdynamicallyscalable')" :tooltip="apiParams.isdynamicallyscalable.description"/>
|
<tooltip-label :title="$t('label.isdynamicallyscalable')" :tooltip="apiParams.isdynamicallyscalable.description"/>
|
||||||
@ -172,7 +179,8 @@ export default {
|
|||||||
userdataid: null,
|
userdataid: null,
|
||||||
userdatapolicy: null,
|
userdatapolicy: null,
|
||||||
userdatapolicylist: {},
|
userdatapolicylist: {},
|
||||||
architectureTypes: {}
|
architectureTypes: {},
|
||||||
|
originalOstypeid: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
@ -195,7 +203,7 @@ export default {
|
|||||||
displaytext: [{ required: true, message: this.$t('message.error.required.input') }],
|
displaytext: [{ required: true, message: this.$t('message.error.required.input') }],
|
||||||
ostypeid: [{ required: true, message: this.$t('message.error.select') }]
|
ostypeid: [{ required: true, message: this.$t('message.error.select') }]
|
||||||
})
|
})
|
||||||
const resourceFields = ['name', 'displaytext', 'passwordenabled', 'isdynamicallyscalable', 'ostypeid', 'userdataid', 'userdatapolicy']
|
const resourceFields = ['name', 'displaytext', 'passwordenabled', 'isdynamicallyscalable', 'ostypeid', 'forceupdateostype', 'userdataid', 'userdatapolicy']
|
||||||
|
|
||||||
for (var field of resourceFields) {
|
for (var field of resourceFields) {
|
||||||
var fieldValue = this.resource[field]
|
var fieldValue = this.resource[field]
|
||||||
@ -207,6 +215,10 @@ export default {
|
|||||||
case 'userdatapolicy':
|
case 'userdatapolicy':
|
||||||
this.userdatapolicy = fieldValue
|
this.userdatapolicy = fieldValue
|
||||||
break
|
break
|
||||||
|
case 'ostypeid':
|
||||||
|
this.form[field] = fieldValue
|
||||||
|
this.originalOstypeid = fieldValue
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
this.form[field] = fieldValue
|
this.form[field] = fieldValue
|
||||||
break
|
break
|
||||||
@ -214,6 +226,9 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
hasOstypeidChanged () {
|
||||||
|
return this.form.ostypeid !== this.originalOstypeid
|
||||||
|
},
|
||||||
fetchData () {
|
fetchData () {
|
||||||
this.fetchOsTypes()
|
this.fetchOsTypes()
|
||||||
this.architectureTypes.opts = this.$fetchCpuArchitectureTypes()
|
this.architectureTypes.opts = this.$fetchCpuArchitectureTypes()
|
||||||
@ -295,6 +310,7 @@ export default {
|
|||||||
if (!this.isValidValueForKey(values, key)) continue
|
if (!this.isValidValueForKey(values, key)) continue
|
||||||
params[key] = values[key]
|
params[key] = values[key]
|
||||||
}
|
}
|
||||||
|
params.forceupdateostype = this.form.forceupdateostype || false
|
||||||
postAPI('updateIso', params).then(json => {
|
postAPI('updateIso', params).then(json => {
|
||||||
if (this.userdataid !== null) {
|
if (this.userdataid !== null) {
|
||||||
this.linkUserdataToTemplate(this.userdataid, json.updateisoresponse.iso.id, this.userdatapolicy)
|
this.linkUserdataToTemplate(this.userdataid, json.updateisoresponse.iso.id, this.userdatapolicy)
|
||||||
|
|||||||
@ -103,6 +103,14 @@
|
|||||||
</a-select>
|
</a-select>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
<a-col :md="24" :lg="24" v-if="hasOstypeidChanged()">
|
||||||
|
<a-form-item name="forceupdateostype" ref="forceupdateostype">
|
||||||
|
<template #label>
|
||||||
|
<tooltip-label :title="$t('label.force.update.os.type')" :tooltip="apiParams.forceupdateostype.description"/>
|
||||||
|
</template>
|
||||||
|
<a-switch v-model:checked="form.forceupdateostype" />
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
<a-row :gutter="12">
|
<a-row :gutter="12">
|
||||||
<a-col :md="24" :lg="12">
|
<a-col :md="24" :lg="12">
|
||||||
@ -251,7 +259,8 @@ export default {
|
|||||||
userdataid: null,
|
userdataid: null,
|
||||||
userdatapolicy: null,
|
userdatapolicy: null,
|
||||||
userdatapolicylist: {},
|
userdatapolicylist: {},
|
||||||
architectureTypes: {}
|
architectureTypes: {},
|
||||||
|
originalOstypeid: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
@ -295,6 +304,10 @@ export default {
|
|||||||
case 'userdatapolicy':
|
case 'userdatapolicy':
|
||||||
this.userdatapolicy = fieldValue
|
this.userdatapolicy = fieldValue
|
||||||
break
|
break
|
||||||
|
case 'ostypeid':
|
||||||
|
this.form[field] = fieldValue
|
||||||
|
this.originalOstypeid = fieldValue
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
this.form[field] = fieldValue
|
this.form[field] = fieldValue
|
||||||
break
|
break
|
||||||
@ -510,6 +523,7 @@ export default {
|
|||||||
}
|
}
|
||||||
params[key] = values[key]
|
params[key] = values[key]
|
||||||
}
|
}
|
||||||
|
params.forceupdateostype = this.form.forceupdateostype || false
|
||||||
postAPI('updateTemplate', params).then(json => {
|
postAPI('updateTemplate', params).then(json => {
|
||||||
if (this.userdataid !== null) {
|
if (this.userdataid !== null) {
|
||||||
this.linkUserdataToTemplate(this.userdataid, json.updatetemplateresponse.template.id, this.userdatapolicy)
|
this.linkUserdataToTemplate(this.userdataid, json.updatetemplateresponse.template.id, this.userdatapolicy)
|
||||||
@ -546,6 +560,9 @@ export default {
|
|||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
hasOstypeidChanged () {
|
||||||
|
return this.form.ostypeid !== this.originalOstypeid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user