Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Disable restart action in VM import status #237

Merged
merged 1 commit into from
Apr 2, 2019
Merged
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
106 changes: 67 additions & 39 deletions frontend/public/kubevirt/components/vm/menu-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
CloneDialog,
getResource,
findVMIMigration,
getVmImporterPods,
getVmStatus,
VM_STATUS_IMPORTING,
} from 'kubevirt-web-ui-components';

import { Kebab, LoadingInline } from '../utils/okdutils';
Expand All @@ -18,6 +21,7 @@ import {
PersistentVolumeClaimModel,
VirtualMachineModel,
DataVolumeModel,
PodModel,
} from '../../models/index';
import { startStopVmModal } from '../modals/start-stop-vm-modal';
import { restartVmModal } from '../modals/restart-vm-modal';
Expand All @@ -28,51 +32,75 @@ import {
import { modalResourceLauncher } from '../utils/modalResourceLauncher';
import { showError } from '../utils/showErrors';

const getStatusForVm = (vm, actionArgs) => {
if (!actionArgs) {
return null;
}

const pods = actionArgs[PodModel.kind];
const importerPods= getVmImporterPods(actionArgs[PodModel.kind], vm);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not have to supply importerPods anymore if you supply all pods. Please see getVmStatus

const migrations = actionArgs[VirtualMachineInstanceMigrationModel.kind];
return getVmStatus(vm, pods, migrations, importerPods);
};

const isImporting = (vm, actionArgs) => {
const status = getStatusForVm(vm, actionArgs);
return status ? status.status === VM_STATUS_IMPORTING : false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorthand? status && status.status === VM_STATUS_IMPORTING

};

const getStartStopActionLabel = (vm) => {
return _.get(vm, 'spec.running', false) ? 'Stop Virtual Machine' : 'Start Virtual Machine';
};

const menuActionStart = (kind, vm) => ({
label: getStartStopActionLabel(vm),
callback: () => startStopVmModal({
kind,
resource: vm,
start: !_.get(vm, 'spec.running', false),
}),
});
const menuActionStart = (kind, vm, actionArgs) => {
return {
hidden: isImporting(vm, actionArgs),
label: getStartStopActionLabel(vm),
callback: () => startStopVmModal({
kind,
resource: vm,
start: !_.get(vm, 'spec.running', false),
}),
};
};

const menuActionRestart = (kind, vm) => ({
hidden: !_.get(vm, 'spec.running', false),
label: 'Restart Virtual Machine',
callback: () => restartVmModal({
kind,
resource: vm,
}),
});
const menuActionRestart = (kind, vm, actionArgs) => {
return {
hidden: !isVmRunning(vm) || isImporting(vm, actionArgs),
label: 'Restart Virtual Machine',
callback: () => restartVmModal({
kind,
resource: vm,
}),
};
};

const menuActionClone = (kind, vm) => ({
label: 'Clone Virtual Machine',
callback: () => {
return modalResourceLauncher(CloneDialog, {
namespaces: {
resource: getResource(NamespaceModel),
required: true,
},
persistentVolumeClaims: {
resource: getResource(PersistentVolumeClaimModel),
required: true,
},
virtualMachines: {
resource: getResource(VirtualMachineModel),
required: true,
},
dataVolumes: {
resource: getResource(DataVolumeModel),
required: true,
},
})({ vm, k8sCreate, k8sPatch, LoadingComponent: LoadingInline });
},
});
const menuActionClone = (kind, vm, actionArgs) => {
return {
hidden: isImporting(vm, actionArgs),
label: 'Clone Virtual Machine',
callback: () => {
return modalResourceLauncher(CloneDialog, {
namespaces: {
resource: getResource(NamespaceModel),
required: true,
},
persistentVolumeClaims: {
resource: getResource(PersistentVolumeClaimModel),
required: true,
},
virtualMachines: {
resource: getResource(VirtualMachineModel),
required: true,
},
dataVolumes: {
resource: getResource(DataVolumeModel),
required: true,
},
})({vm, k8sCreate, k8sPatch, LoadingComponent: LoadingInline});
},
};
};

const menuActionCancelMigration = (kind, vm, actionArgs) => {
const migration = actionArgs && findVMIMigration(actionArgs[VirtualMachineInstanceMigrationModel.kind], actionArgs[VirtualMachineInstanceModel.kind]);
Expand Down
1 change: 1 addition & 0 deletions frontend/public/kubevirt/components/vm/vm-detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const VirtualMachinesDetailsPage = props => {
resources={[
getResource(VirtualMachineInstanceModel, {name, namespace, isList: false}),
getResource(VirtualMachineInstanceMigrationModel, {namespace}),
getResource(PodModel, {namespace, matchLabels: {[CDI_KUBEVIRT_IO]: 'importer'}}),
]}
/>);
};
1 change: 1 addition & 0 deletions frontend/public/kubevirt/components/vm/vm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const VMRow = ({obj: vm}) => {
resources={[
getResource(VirtualMachineInstanceModel, {name, namespace, isList: false}),
migrationResources,
getResource(PodModel, {namespace, matchLabels: {[CDI_KUBEVIRT_IO]: 'importer'}}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to select just pods without the importer labels. Because it might be confusing when somebody gets to use getVmStatus method in menu-actions

]} />
</div>
</ResourceRow>;
Expand Down