mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-01 03:36:04 +08:00
Latest changes from Harvester master - a537c1ae38eb7030542ac371f24ae3336cd9d422
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import HarvesterResource from './harvester';
|
||||
import { get } from '@shell/utils/object';
|
||||
import { findBy } from '@shell/utils/array';
|
||||
import { colorForState, stateDisplay, STATES } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { _CREATE } from '@shell/config/query-params';
|
||||
import { ucFirst, escapeHtml } from '@shell/utils/string';
|
||||
|
||||
export default class ScheduleVmBackup extends HarvesterResource {
|
||||
detailPageHeaderActionOverride(realMode) {
|
||||
if (realMode === _CREATE) {
|
||||
return this.t('harvester.schedule.createTitle');
|
||||
}
|
||||
}
|
||||
|
||||
get _availableActions() {
|
||||
const toFilter = ['goToClone'];
|
||||
|
||||
const out = super._availableActions.filter((action) => {
|
||||
if (!toFilter.includes(action.action)) {
|
||||
return action;
|
||||
}
|
||||
});
|
||||
|
||||
return [
|
||||
{
|
||||
action: 'resumeSchedule',
|
||||
enabled: ucFirst(this.state) === STATES.suspended.label,
|
||||
icon: 'icons icon-play',
|
||||
label: this.t('harvester.action.resumeSchedule'),
|
||||
},
|
||||
{
|
||||
action: 'suspendSchedule',
|
||||
enabled: ucFirst(this.state) === STATES.active.label,
|
||||
icon: 'icons icon-pause',
|
||||
label: this.t('harvester.action.suspendSchedule'),
|
||||
},
|
||||
...out
|
||||
];
|
||||
}
|
||||
|
||||
async suspendSchedule() {
|
||||
try {
|
||||
this.spec.suspend = true; // suspend schedule
|
||||
await this.save();
|
||||
} catch (err) {
|
||||
this.spec.suspend = false;
|
||||
|
||||
this.$dispatch('growl/fromError', {
|
||||
title: this.t('generic.notification.title.error', { name: escapeHtml(this.metadata.name) }),
|
||||
err,
|
||||
}, { root: true });
|
||||
}
|
||||
}
|
||||
|
||||
async resumeSchedule() {
|
||||
try {
|
||||
this.spec.suspend = false; // resume schedule
|
||||
await this.save();
|
||||
} catch (err) {
|
||||
this.spec.suspend = true;
|
||||
|
||||
this.$dispatch('growl/fromError', {
|
||||
title: this.t('generic.notification.title.error', { name: escapeHtml(this.metadata.name) }),
|
||||
err,
|
||||
}, { root: true });
|
||||
}
|
||||
}
|
||||
|
||||
get state() {
|
||||
const conditions = get(this, 'status.conditions');
|
||||
const isSuspended = findBy(conditions, 'type', 'BackupSuspend')?.status === 'True';
|
||||
|
||||
if (isSuspended) {
|
||||
return STATES.suspended.label;
|
||||
}
|
||||
|
||||
return this.metadata.state.name;
|
||||
}
|
||||
|
||||
get stateDescription() {
|
||||
const suspendedCondition = (this.status?.conditions || []).find(c => c.type === 'BackupSuspend');
|
||||
|
||||
return ucFirst(suspendedCondition?.message) || super.stateDescription;
|
||||
}
|
||||
|
||||
get stateBackground() {
|
||||
return colorForState(this.stateDisplay).replace('text-', 'bg-');
|
||||
}
|
||||
|
||||
get stateColor() {
|
||||
return colorForState(this.state);
|
||||
}
|
||||
|
||||
get stateDisplay() {
|
||||
return stateDisplay(this.state);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { get, clone } from '@shell/utils/object';
|
||||
import { findBy } from '@shell/utils/array';
|
||||
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
||||
import { _CREATE } from '@shell/config/query-params';
|
||||
import { HCI } from '../types';
|
||||
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
|
||||
@@ -18,9 +19,8 @@ export default class HciVmBackup extends HarvesterResource {
|
||||
|
||||
get detailLocation() {
|
||||
const detailLocation = clone(this._detailLocation);
|
||||
const route = this.currentRoute();
|
||||
|
||||
detailLocation.params.resource = route.params.resource;
|
||||
detailLocation.params.resource = HCI.BACKUP;
|
||||
|
||||
return detailLocation;
|
||||
}
|
||||
@@ -81,24 +81,30 @@ export default class HciVmBackup extends HarvesterResource {
|
||||
}
|
||||
|
||||
restoreExistingVM(resource = this) {
|
||||
const route = this.currentRoute();
|
||||
const router = this.currentRouter();
|
||||
const targetResource = resource.spec.type === BACKUP_TYPE.BACKUP ? HCI.BACKUP : HCI.VM_SNAPSHOT;
|
||||
|
||||
router.push({
|
||||
name: `${ HARVESTER_PRODUCT }-c-cluster-resource-create`,
|
||||
params: { resource: route.params.resource },
|
||||
query: { restoreMode: 'existing', resourceName: resource.name }
|
||||
params: { resource: targetResource },
|
||||
query: {
|
||||
restoreMode: 'existing',
|
||||
resourceName: resource.name,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
restoreNewVM(resource = this) {
|
||||
const route = this.currentRoute();
|
||||
const router = this.currentRouter();
|
||||
const targetResource = resource.spec.type === BACKUP_TYPE.BACKUP ? HCI.BACKUP : HCI.VM_SNAPSHOT;
|
||||
|
||||
router.push({
|
||||
name: `${ HARVESTER_PRODUCT }-c-cluster-resource-create`,
|
||||
params: { resource: route.params.resource },
|
||||
query: { restoreMode: 'new', resourceName: resource.name }
|
||||
params: { resource: targetResource },
|
||||
query: {
|
||||
restoreMode: 'new',
|
||||
resourceName: resource.name,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -125,6 +131,10 @@ export default class HciVmBackup extends HarvesterResource {
|
||||
return colorForState(state);
|
||||
}
|
||||
|
||||
get sourceSchedule() {
|
||||
return this.metadata?.annotations[HCI_ANNOTATIONS.SVM_BACKUP_ID];
|
||||
}
|
||||
|
||||
get attachVM() {
|
||||
return this.spec.source.name;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { load } from 'js-yaml';
|
||||
import { omitBy, pickBy } from 'lodash';
|
||||
|
||||
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
|
||||
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { POD, NODE, PVC } from '@shell/config/types';
|
||||
import { findBy } from '@shell/utils/array';
|
||||
@@ -161,6 +161,12 @@ export default class VirtVm extends HarvesterResource {
|
||||
icon: 'icon icon-storage',
|
||||
label: this.t('harvester.action.editVMQuota')
|
||||
},
|
||||
{
|
||||
action: 'createSchedule',
|
||||
enabled: true,
|
||||
icon: 'icon icon-history',
|
||||
label: this.t('harvester.action.createSchedule')
|
||||
},
|
||||
{
|
||||
action: 'restoreVM',
|
||||
enabled: !!this.actions?.restore,
|
||||
@@ -323,6 +329,16 @@ export default class VirtVm extends HarvesterResource {
|
||||
);
|
||||
}
|
||||
|
||||
createSchedule(resources = this) {
|
||||
const router = this.currentRouter();
|
||||
|
||||
router.push({
|
||||
name: `${ HARVESTER_PRODUCT }-c-cluster-resource-create`,
|
||||
params: { resource: HCI.SCHEDULE_VM_BACKUP },
|
||||
query: { vmNamespace: this.metadata.namespace, vmName: this.metadata.name }
|
||||
});
|
||||
}
|
||||
|
||||
backupVM(resources = this) {
|
||||
this.$dispatch('promptModal', {
|
||||
resources,
|
||||
|
||||
Reference in New Issue
Block a user