diff --git a/pkg/machines/actions.es6 b/pkg/machines/actions.es6 deleted file mode 100644 index 2ceafe66df85..000000000000 --- a/pkg/machines/actions.es6 +++ /dev/null @@ -1,344 +0,0 @@ -/* - * This file is part of Cockpit. - * - * Copyright (C) 2016 Red Hat, Inc. - * - * Cockpit is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * Cockpit is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Cockpit; If not, see . - */ -import cockpit from 'cockpit'; -import { getRefreshInterval } from './selectors.es6'; -import VMS_CONFIG from "./config.es6"; -import { logDebug } from './helpers.es6'; -import { virt } from './provider.es6'; - -/** - * All actions dispatchable by in the application - */ - -// --- Provider actions ----------------------------------------- -export function initDataRetrieval() { - return virt('INIT_DATA_RETRIEVAL'); -} - -/** - * - * @param connectionName optional - if `undefined` then for all connections - * @param libvirtServiceName - */ -export function getAllVms(connectionName, libvirtServiceName) { - return virt('GET_ALL_VMS', { connectionName, libvirtServiceName }); -} - -export function getVm(connectionName, lookupId) { - return virt('GET_VM', { - lookupId, // provider-specific (i.e. libvirt uses vm_name) - connectionName, - }); -} - -export function getOsInfoList() { - return virt('GET_OS_INFO_LIST'); -} - -export function getStoragePools(connectionName) { - return virt('GET_STORAGE_POOLS', { connectionName }); -} - -export function getStorageVolumes(connectionName, poolName) { - return virt('GET_STORAGE_VOLUMES', { connectionName, poolName }); -} - -export function shutdownVm(vm) { - return virt('SHUTDOWN_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function forceVmOff(vm) { - return virt('FORCEOFF_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function rebootVm(vm) { - return virt('REBOOT_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function forceRebootVm(vm) { - return virt('FORCEREBOOT_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function startVm(vm) { - return virt('START_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function deleteVm(vm, options) { - return virt('DELETE_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName, options: options }); -} - -export function installVm(vm) { - return virt('INSTALL_VM', vm); -} - -export function createVm(vmParams) { - return virt('CREATE_VM', vmParams); -} - -export function vmDesktopConsole(vm, consoleDetail) { - return virt('CONSOLE_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName, consoleDetail }); -} - -export function usageStartPolling(vm) { - return virt('USAGE_START_POLLING', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function usageStopPolling(vm) { - return virt('USAGE_STOP_POLLING', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function sendNMI(vm) { - return virt('SENDNMI_VM', { name: vm.name, id: vm.id, connectionName: vm.connectionName }); -} - -export function changeNetworkState(vm, networkMac, state) { - return virt('CHANGE_NETWORK_STATE', { name: vm.name, id: vm.id, networkMac, state, connectionName: vm.connectionName }); -} - -export function checkLibvirtStatus(serviceName) { - return virt('CHECK_LIBVIRT_STATUS', { serviceName }); -} - -export function startLibvirt(serviceName) { - return virt('START_LIBVIRT', { serviceName }); -} - -export function enableLibvirt(enable, serviceName) { - return virt('ENABLE_LIBVIRT', { enable, serviceName }); -} - -export function setVCPUSettings(vm, max, count, sockets, threads, cores) { - return virt('SET_VCPU_SETTINGS', { - id: vm.id, - name: vm.name, - connectionName: vm.connectionName, - max, - count, - sockets, - threads, - cores, - isRunning: vm.state == 'running' - }); -} - -export function getHypervisorMaxVCPU(connectionName) { - return virt('GET_HYPERVISOR_MAX_VCPU', {connectionName}); -} - -export function volumeCreateAndAttach({ connectionName, poolName, volumeName, size, format, target, permanent, hotplug, vmName }) { - return virt('CREATE_AND_ATTACH_VOLUME', { connectionName, poolName, volumeName, size, format, target, permanent, hotplug, vmName }); -} - -export function attachDisk({ connectionName, diskFileName, target, permanent, hotplug, vmName }) { - return virt('ATTACH_DISK', { connectionName, diskFileName, target, permanent, hotplug, vmName }); -} - -/** - * Delay call of polling action. - * - * To avoid execution overlap, the setTimeout() is used instead of setInterval(). - * - * The delayPolling() function is called after previous execution is finished so - * the refresh interval starts counting since that moment. - * - * If the application is not visible, the polling action execution is skipped - * and scheduled on later. - * - * @param action I.e. getAllVms() - * @param timeout Non-default timeout - */ -export function delayPolling(action, timeout) { - return (dispatch, getState) => { - timeout = timeout || getRefreshInterval(getState()); - - if (timeout > 0 && !cockpit.hidden) { - logDebug(`Scheduling ${timeout} ms delayed action`); - window.setTimeout(() => { - logDebug('Executing delayed action'); - dispatch(action); - }, timeout); - } else { - // logDebug(`Skipping delayed action since refreshing is switched off`); - window.setTimeout(() => dispatch(delayPolling(action, timeout)), VMS_CONFIG.DefaultRefreshInterval); - } - }; -} - -// --- Store actions -------------------------------------------- -export function setProvider(provider) { - return { - type: 'SET_PROVIDER', - provider, - }; -} - -export function setRefreshInterval(refreshInterval) { - return { - type: 'SET_REFRESH_INTERVAL', - refreshInterval, - }; -} - -export function updateOrAddVm(props) { - return { - type: 'UPDATE_ADD_VM', - vm: props, - }; -} - -export function updateVm(props) { - return { - type: 'UPDATE_VM', - vm: props, - }; -} - -export function updateStoragePools({ connectionName, pools }) { - return { - type: 'UPDATE_STORAGE_POOLS', - payload: { - connectionName, - pools, - } - }; -} - -export function updateStorageVolumes({ connectionName, poolName, volumes }) { - return { - type: 'UPDATE_STORAGE_VOLUMES', - payload: { - connectionName, - poolName, - volumes, - }, - }; -} - -export function updateOsInfoList(osInfoList) { - return { - type: 'UPDATE_OS_INFO_LIST', - osInfoList, - }; -} - -export function addUiVm(vm) { - return { - type: 'ADD_UI_VM', - vm, - }; -} - -export function updateUiVm(vm) { - return { - type: 'UPDATE_UI_VM', - vm, - }; -} - -export function deleteUiVm(vm) { - return { - type: 'DELETE_UI_VM', - vm, - }; -} - -export function addErrorNotification(notification) { - if (typeof notification === 'string') { - notification = { message: notification }; - } - notification.type = 'error'; - - return { - type: 'ADD_NOTIFICATION', - notification, - }; -} - -export function addNotification(notification) { - return { - type: 'ADD_NOTIFICATION', - notification, - }; -} - -export function clearNotification(id) { - return { - type: 'CLEAR_NOTIFICATION', - id, - - }; -} - -export function clearNotifications() { - return { - type: 'CLEAR_NOTIFICATIONS', - }; -} - -export function updateLibvirtState(state) { - return { - type: 'UPDATE_LIBVIRT_STATE', - state, - }; -} - -export function setHypervisorMaxVCPU({ count, connectionName }) { - return { - type: 'SET_HYPERVISOR_MAX_VCPU', - payload: { - count, - connectionName, - } - }; -} - -export function vmActionFailed({ name, connectionName, message, detail, extraPayload }) { - return { - type: 'VM_ACTION_FAILED', - payload: { - name, - connectionName, - message, - detail, - extraPayload, - }, - }; -} - -export function deleteVmMessage({ name, connectionName }) { - // recently there's just the last error message kept so we can reuse the code - return vmActionFailed({ name, connectionName, message: null, detail: null, extraPayload: null }); -} - -export function undefineVm(connectionName, name, transientOnly) { - return { - type: 'UNDEFINE_VM', - name, - connectionName, - transientOnly, - }; -} - -export function deleteUnlistedVMs(connectionName, vmNames) { - return { - type: 'DELETE_UNLISTED_VMS', - vmNames, - connectionName, - }; -} diff --git a/pkg/machines/actions/provider-actions.es6 b/pkg/machines/actions/provider-actions.es6 new file mode 100644 index 000000000000..093e5b57cdeb --- /dev/null +++ b/pkg/machines/actions/provider-actions.es6 @@ -0,0 +1,213 @@ +/* + * This file is part of Cockpit. + * + * Copyright (C) 2016 Red Hat, Inc. + * + * Cockpit is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * Cockpit is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Cockpit; If not, see . + */ +import cockpit from 'cockpit'; +import { getRefreshInterval } from '../selectors.es6'; +import VMS_CONFIG from "../config.es6"; +import { logDebug } from '../helpers.es6'; +import { virt } from '../provider.es6'; +import { + ATTACH_DISK, + CHANGE_NETWORK_STATE, + CHECK_LIBVIRT_STATUS, + CONSOLE_VM, + CREATE_AND_ATTACH_VOLUME, + CREATE_VM, + DELETE_VM, + ENABLE_LIBVIRT, + FORCEOFF_VM, + FORCEREBOOT_VM, + GET_ALL_VMS, + GET_HYPERVISOR_MAX_VCPU, + GET_OS_INFO_LIST, + GET_STORAGE_POOLS, + GET_STORAGE_VOLUMES, + GET_VM, + INIT_DATA_RETRIEVAL, + INSTALL_VM, + REBOOT_VM, + SENDNMI_VM, + SET_VCPU_SETTINGS, + SHUTDOWN_VM, + START_LIBVIRT, + START_VM, + USAGE_START_POLLING, + USAGE_STOP_POLLING, +} from '../constants/provider-action-types.es6'; + +/** + * All actions dispatchable by in the application + */ + +/** --- Provider action creators ----------------------------------------- + * + * The naming convention for action creator names is: + * with the present tense. + */ +export function attachDisk({ connectionName, diskFileName, target, permanent, hotplug, vmName }) { + return virt(ATTACH_DISK, { connectionName, diskFileName, target, permanent, hotplug, vmName }); +} + +export function changeNetworkState(vm, networkMac, state) { + return virt(CHANGE_NETWORK_STATE, { name: vm.name, id: vm.id, networkMac, state, connectionName: vm.connectionName }); +} + +export function checkLibvirtStatus(serviceName) { + return virt(CHECK_LIBVIRT_STATUS, { serviceName }); +} + +export function createVm(vmParams) { + return virt(CREATE_VM, vmParams); +} + +export function deleteVm(vm, options) { + return virt(DELETE_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName, options: options }); +} + +export function enableLibvirt(enable, serviceName) { + return virt(ENABLE_LIBVIRT, { enable, serviceName }); +} + +export function forceRebootVm(vm) { + return virt(FORCEREBOOT_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function forceVmOff(vm) { + return virt(FORCEOFF_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +/** + * + * @param connectionName optional - if `undefined` then for all connections + * @param libvirtServiceName + */ +export function getAllVms(connectionName, libvirtServiceName) { + return virt(GET_ALL_VMS, { connectionName, libvirtServiceName }); +} + +export function getHypervisorMaxVCPU(connectionName) { + return virt(GET_HYPERVISOR_MAX_VCPU, { connectionName }); +} + +export function getOsInfoList() { + return virt(GET_OS_INFO_LIST); +} + +export function getStoragePools(connectionName) { + return virt(GET_STORAGE_POOLS, { connectionName }); +} + +export function getStorageVolumes(connectionName, poolName) { + return virt(GET_STORAGE_VOLUMES, { connectionName, poolName }); +} + +export function getVm(connectionName, lookupId) { + return virt(GET_VM, { + lookupId, // provider-specific (i.e. libvirt uses vm_name) + connectionName, + }); +} + +export function initDataRetrieval() { + return virt(INIT_DATA_RETRIEVAL); +} + +export function installVm(vm) { + return virt(INSTALL_VM, vm); +} + +export function rebootVm(vm) { + return virt(REBOOT_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function sendNMI(vm) { + return virt(SENDNMI_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function setVCPUSettings(vm, max, count, sockets, threads, cores) { + return virt(SET_VCPU_SETTINGS, { + id: vm.id, + name: vm.name, + connectionName: vm.connectionName, + max, + count, + sockets, + threads, + cores, + isRunning: vm.state == 'running' + }); +} + +export function shutdownVm(vm) { + return virt(SHUTDOWN_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function startLibvirt(serviceName) { + return virt(START_LIBVIRT, { serviceName }); +} + +export function startVm(vm) { + return virt(START_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function usageStartPolling(vm) { + return virt(USAGE_START_POLLING, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function usageStopPolling(vm) { + return virt(USAGE_STOP_POLLING, { name: vm.name, id: vm.id, connectionName: vm.connectionName }); +} + +export function vmDesktopConsole(vm, consoleDetail) { + return virt(CONSOLE_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName, consoleDetail }); +} + +export function volumeCreateAndAttach({ connectionName, poolName, volumeName, size, format, target, permanent, hotplug, vmName }) { + return virt(CREATE_AND_ATTACH_VOLUME, { connectionName, poolName, volumeName, size, format, target, permanent, hotplug, vmName }); +} + +/** + * Delay call of polling action. + * + * To avoid execution overlap, the setTimeout() is used instead of setInterval(). + * + * The delayPolling() function is called after previous execution is finished so + * the refresh interval starts counting since that moment. + * + * If the application is not visible, the polling action execution is skipped + * and scheduled on later. + * + * @param action I.e. getAllVms() + * @param timeout Non-default timeout + */ +export function delayPolling(action, timeout) { + return (dispatch, getState) => { + timeout = timeout || getRefreshInterval(getState()); + + if (timeout > 0 && !cockpit.hidden) { + logDebug(`Scheduling ${timeout} ms delayed action`); + window.setTimeout(() => { + logDebug('Executing delayed action'); + dispatch(action); + }, timeout); + } else { + // logDebug(`Skipping delayed action since refreshing is switched off`); + window.setTimeout(() => dispatch(delayPolling(action, timeout)), VMS_CONFIG.DefaultRefreshInterval); + } + }; +} diff --git a/pkg/machines/actions/store-actions.es6 b/pkg/machines/actions/store-actions.es6 new file mode 100644 index 000000000000..94079195d8c9 --- /dev/null +++ b/pkg/machines/actions/store-actions.es6 @@ -0,0 +1,210 @@ +/* + * This file is part of Cockpit. + * + * Copyright (C) 2016 Red Hat, Inc. + * + * Cockpit is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * Cockpit is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Cockpit; If not, see . + */ +import { + ADD_NOTIFICATION, + ADD_UI_VM, + CLEAR_NOTIFICATION, + CLEAR_NOTIFICATIONS, + DELETE_UI_VM, + DELETE_UNLISTED_VMS, + SET_HYPERVISOR_MAX_VCPU, + SET_PROVIDER, + SET_REFRESH_INTERVAL, + UNDEFINE_VM, + UPDATE_ADD_VM, + UPDATE_LIBVIRT_STATE, + UPDATE_OS_INFO_LIST, + UPDATE_STORAGE_POOLS, + UPDATE_STORAGE_VOLUMES, + UPDATE_UI_VM, + UPDATE_VM, + VM_ACTION_FAILED, +} from '../constants/store-action-types.es6'; + +/** + * All actions dispatchable by in the application + */ + +/** --- Store action creators ----------------------------------------- + * + * The naming convention for action creator names is: + * with the present tense. + */ + +export function addErrorNotification(notification) { + if (typeof notification === 'string') { + notification = { message: notification }; + } + notification.type = 'error'; + + return { + type: ADD_NOTIFICATION, + notification, + }; +} + +export function addNotification(notification) { + return { + type: ADD_NOTIFICATION, + notification, + }; +} + +export function addUiVm(vm) { + return { + type: ADD_UI_VM, + vm, + }; +} + +export function clearNotification(id) { + return { + type: CLEAR_NOTIFICATION, + id, + + }; +} + +export function clearNotifications() { + return { + type: CLEAR_NOTIFICATIONS, + }; +} + +export function deleteUiVm(vm) { + return { + type: DELETE_UI_VM, + vm, + }; +} + +export function deleteUnlistedVMs(connectionName, vmNames) { + return { + type: DELETE_UNLISTED_VMS, + vmNames, + connectionName, + }; +} + +export function deleteVmMessage({ name, connectionName }) { + // recently there's just the last error message kept so we can reuse the code + return vmActionFailed({ name, connectionName, message: null, detail: null, extraPayload: null }); +} + +export function setHypervisorMaxVCPU({ count, connectionName }) { + return { + type: SET_HYPERVISOR_MAX_VCPU, + payload: { + count, + connectionName, + } + }; +} + +export function setProvider(provider) { + return { + type: SET_PROVIDER, + provider, + }; +} + +export function setRefreshInterval(refreshInterval) { + return { + type: SET_REFRESH_INTERVAL, + refreshInterval, + }; +} + +export function undefineVm(connectionName, name, transientOnly) { + return { + type: UNDEFINE_VM, + name, + connectionName, + transientOnly, + }; +} + +export function updateLibvirtState(state) { + return { + type: UPDATE_LIBVIRT_STATE, + state, + }; +} + +export function updateOrAddVm(props) { + return { + type: UPDATE_ADD_VM, + vm: props, + }; +} + +export function updateOsInfoList(osInfoList) { + return { + type: UPDATE_OS_INFO_LIST, + osInfoList, + }; +} + +export function updateStoragePools({ connectionName, pools }) { + return { + type: UPDATE_STORAGE_POOLS, + payload: { + connectionName, + pools, + } + }; +} + +export function updateStorageVolumes({ connectionName, poolName, volumes }) { + return { + type: UPDATE_STORAGE_VOLUMES, + payload: { + connectionName, + poolName, + volumes, + }, + }; +} + +export function updateUiVm(vm) { + return { + type: UPDATE_UI_VM, + vm, + }; +} + +export function updateVm(props) { + return { + type: UPDATE_VM, + vm: props, + }; +} + +export function vmActionFailed({ name, connectionName, message, detail, extraPayload }) { + return { + type: VM_ACTION_FAILED, + payload: { + name, + connectionName, + message, + detail, + extraPayload, + }, + }; +} diff --git a/pkg/machines/components/consoles.jsx b/pkg/machines/components/consoles.jsx index a6f760c7a89f..f6d27831d803 100644 --- a/pkg/machines/components/consoles.jsx +++ b/pkg/machines/components/consoles.jsx @@ -25,7 +25,7 @@ import Vnc, { VncActions } from './vnc.jsx'; import DesktopConsole from './desktopConsole.jsx'; import { logDebug } from '../helpers.es6'; -import { vmDesktopConsole } from '../actions.es6'; +import { vmDesktopConsole } from '../actions/provider-actions.es6'; import './consoles.css'; diff --git a/pkg/machines/components/create-vm-dialog/createVmDialog.jsx b/pkg/machines/components/create-vm-dialog/createVmDialog.jsx index 46d31d44d043..6a26d02ee9a6 100644 --- a/pkg/machines/components/create-vm-dialog/createVmDialog.jsx +++ b/pkg/machines/components/create-vm-dialog/createVmDialog.jsx @@ -22,7 +22,8 @@ import React, { PropTypes } from "react"; import DialogPattern from 'cockpit-components-dialog.jsx'; import Select from "cockpit-components-select.jsx"; import FileAutoComplete from "cockpit-components-file-autocomplete.jsx"; -import { createVm, addErrorNotification } from '../../actions.es6'; +import { createVm } from '../../actions/provider-actions.es6'; +import { addErrorNotification } from '../../actions/store-actions.es6'; import { isEmpty, convertToUnit, diff --git a/pkg/machines/components/create-vm-dialog/uiState.es6 b/pkg/machines/components/create-vm-dialog/uiState.es6 index da87600c1ddf..00c4346f4c7b 100644 --- a/pkg/machines/components/create-vm-dialog/uiState.es6 +++ b/pkg/machines/components/create-vm-dialog/uiState.es6 @@ -21,7 +21,7 @@ import { addUiVm, updateUiVm, deleteUiVm, -} from '../../actions.es6'; +} from '../../actions/store-actions.es6'; import VMS_CONFIG from "../../config.es6"; diff --git a/pkg/machines/components/deleteDialog.jsx b/pkg/machines/components/deleteDialog.jsx index 66c2250b0888..2d69f91c1137 100644 --- a/pkg/machines/components/deleteDialog.jsx +++ b/pkg/machines/components/deleteDialog.jsx @@ -20,7 +20,7 @@ import cockpit from 'cockpit'; import React from 'react'; import { show_modal_dialog } from 'cockpit-components-dialog.jsx'; -import { deleteVm } from '../actions.es6'; +import { deleteVm } from '../actions/provider-actions.es6'; import './deleteDialog.css'; diff --git a/pkg/machines/components/diskAdd.jsx b/pkg/machines/components/diskAdd.jsx index 34066264b192..e6783a3de6ab 100644 --- a/pkg/machines/components/diskAdd.jsx +++ b/pkg/machines/components/diskAdd.jsx @@ -23,7 +23,7 @@ import DialogPattern from 'cockpit-components-dialog.jsx'; import Select from "cockpit-components-select.jsx"; import { mouseClick, units, convertToUnit, digitFilter, toFixedPrecision } from '../helpers.es6'; -import { volumeCreateAndAttach, attachDisk, getVm, getStoragePools } from '../actions.es6'; +import { volumeCreateAndAttach, attachDisk, getVm, getStoragePools } from '../actions/provider-actions.es6'; import './diskAdd.css'; diff --git a/pkg/machines/components/libvirtSlate.jsx b/pkg/machines/components/libvirtSlate.jsx index b22fe1754df0..5d34bf444225 100644 --- a/pkg/machines/components/libvirtSlate.jsx +++ b/pkg/machines/components/libvirtSlate.jsx @@ -22,7 +22,7 @@ import { mouseClick } from "../helpers.es6"; import { startLibvirt, enableLibvirt, -} from "../actions.es6"; +} from "../actions/provider-actions.es6"; import './libvirtSlate.css'; diff --git a/pkg/machines/components/vcpuModal.jsx b/pkg/machines/components/vcpuModal.jsx index 4bf594601dfb..0cc17e9444e1 100644 --- a/pkg/machines/components/vcpuModal.jsx +++ b/pkg/machines/components/vcpuModal.jsx @@ -5,7 +5,7 @@ import { show_modal_dialog } from 'cockpit-components-dialog.jsx'; import SelectComponent from 'cockpit-components-select.jsx'; import InfoRecord from './infoRecord.jsx'; import { Alert } from './notification/inlineNotification.jsx'; -import { setVCPUSettings } from "../actions.es6"; +import { setVCPUSettings } from "../actions/provider-actions.es6"; const _ = cockpit.gettext; diff --git a/pkg/machines/components/vmLastMessage.jsx b/pkg/machines/components/vmLastMessage.jsx index 8b71e2e20187..4049bbed2447 100644 --- a/pkg/machines/components/vmLastMessage.jsx +++ b/pkg/machines/components/vmLastMessage.jsx @@ -18,7 +18,7 @@ */ import React from "react"; import { vmId } from '../helpers.es6'; -import { deleteVmMessage } from '../actions.es6'; +import { deleteVmMessage } from '../actions/store-actions.es6'; import { Alert } from './notification/inlineNotification.jsx'; const VmLastMessage = ({ vm, dispatch }) => { diff --git a/pkg/machines/constants/provider-action-types.es6 b/pkg/machines/constants/provider-action-types.es6 new file mode 100644 index 000000000000..a31f6bd0599e --- /dev/null +++ b/pkg/machines/constants/provider-action-types.es6 @@ -0,0 +1,46 @@ +/* + * This file is part of Cockpit. + * + * Copyright (C) 2018 Red Hat, Inc. + * + * Cockpit is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * Cockpit is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Cockpit; If not, see . + */ + +// --- Provider actions ----------------------------------------- +export const ATTACH_DISK = "ATTACH_DISK"; +export const CHANGE_NETWORK_STATE = "CHANGE_NETWORK_STATE"; +export const CHECK_LIBVIRT_STATUS = "CHECK_LIBVIRT_STATUS"; +export const CONSOLE_VM = "CONSOLE_VM"; +export const CREATE_AND_ATTACH_VOLUME = "CREATE_AND_ATTACH_VOLUME"; +export const CREATE_VM = "CREATE_VM"; +export const DELETE_VM = "DELETE_VM"; +export const ENABLE_LIBVIRT = "ENABLE_LIBVIRT"; +export const FORCEOFF_VM = "FORCEOFF_VM"; +export const FORCEREBOOT_VM = "FORCEREBOOT_VM"; +export const GET_ALL_VMS = "GET_ALL_VMS"; +export const GET_HYPERVISOR_MAX_VCPU = "GET_HYPERVISOR_MAX_VCPU"; +export const GET_OS_INFO_LIST = "GET_OS_INFO_LIST"; +export const GET_STORAGE_POOLS = "GET_STORAGE_POOLS" +export const GET_STORAGE_VOLUMES = "GET_STORAGE_VOLUMES"; +export const GET_VM = "GET_VM"; +export const INIT_DATA_RETRIEVAL = "INIT_DATA_RETRIEVAL"; +export const INSTALL_VM = "INSTALL_VM"; +export const REBOOT_VM = "REBOOT_VM"; +export const SENDNMI_VM = "SENDNMI_VM"; +export const SET_VCPU_SETTINGS = "SET_VCPU_SETTINGS"; +export const SHUTDOWN_VM = "SHUTDOWN_VM"; +export const START_LIBVIRT = "START_LIBVIRT"; +export const START_VM = "START_VM"; +export const USAGE_START_POLLING = "USAGE_START_POLLING"; +export const USAGE_STOP_POLLING = "USAGE_STOP_POLLING"; diff --git a/pkg/machines/constants/store-action-types.es6 b/pkg/machines/constants/store-action-types.es6 new file mode 100644 index 000000000000..92beb5249fb1 --- /dev/null +++ b/pkg/machines/constants/store-action-types.es6 @@ -0,0 +1,38 @@ +/* + * This file is part of Cockpit. + * + * Copyright (C) 2018 Red Hat, Inc. + * + * Cockpit is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * Cockpit is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Cockpit; If not, see . + */ + +// --- Store actions -------------------------------------------- +export const ADD_NOTIFICATION = "ADD_NOTIFICATION"; +export const ADD_UI_VM = "ADD_UI_VM"; +export const CLEAR_NOTIFICATION = "CLEAR_NOTIFICATION"; +export const CLEAR_NOTIFICATIONS = "CLEAR_NOTIFICATIONS"; +export const DELETE_UI_VM = "DELETE_UI_VM"; +export const DELETE_UNLISTED_VMS = "DELETE_UNLISTED_VMS"; +export const SET_HYPERVISOR_MAX_VCPU = "SET_HYPERVISOR_MAX_VCPU"; +export const SET_PROVIDER = "SET_PROVIDER"; +export const SET_REFRESH_INTERVAL = "SET_REFRESH_INTERVAL"; +export const UNDEFINE_VM = "UNDEFINE_VM"; +export const UPDATE_ADD_VM = "UPDATE_ADD_VM"; +export const UPDATE_LIBVIRT_STATE = "UPDATE_LIBVIRT_STATE"; +export const UPDATE_OS_INFO_LIST = "UPDATE_OS_INFO_LIST"; +export const UPDATE_STORAGE_POOLS = "UPDATE_STORAGE_POOLS"; +export const UPDATE_STORAGE_VOLUMES = "UPDATE STORAGE_VOLUMES"; +export const UPDATE_UI_VM = "UPDATE_UI_VM"; +export const UPDATE_VM = "UPDATE_VM"; +export const VM_ACTION_FAILED = "VM_ACTION_FAILED"; diff --git a/pkg/machines/hostvmslist.jsx b/pkg/machines/hostvmslist.jsx index 74de51ca2cf7..c409c382fa25 100644 --- a/pkg/machines/hostvmslist.jsx +++ b/pkg/machines/hostvmslist.jsx @@ -29,8 +29,10 @@ import { installVm, usageStartPolling, usageStopPolling, +} from "./actions/provider-actions.es6"; +import { clearNotification, -} from "./actions.es6"; +} from "./actions/store-actions.es6"; import { vmId } from "./helpers.es6"; diff --git a/pkg/machines/index.es6 b/pkg/machines/index.es6 index 01c414b87afd..f93fd19ab3cd 100644 --- a/pkg/machines/index.es6 +++ b/pkg/machines/index.es6 @@ -21,7 +21,7 @@ import '../lib/polyfills.js'; // once per application import React from 'react'; import store from './store.es6'; import App from './app.jsx'; -import { initDataRetrieval } from './actions.es6'; +import { initDataRetrieval } from './actions/provider-actions.es6'; import { logDebug } from './helpers.es6'; import Libvirt from './libvirt.es6'; diff --git a/pkg/machines/libvirt-common.es6 b/pkg/machines/libvirt-common.es6 index 9c522420e2cc..6198ef236439 100644 --- a/pkg/machines/libvirt-common.es6 +++ b/pkg/machines/libvirt-common.es6 @@ -7,15 +7,18 @@ import getOSListScript from 'raw!./scripts/get_os_list.sh'; import getLibvirtServiceNameScript from 'raw!./scripts/get_libvirt_service_name.sh'; import { - checkLibvirtStatus, - getAllVms, - getHypervisorMaxVCPU, - getOsInfoList, vmActionFailed, updateLibvirtState, updateOrAddVm, updateOsInfoList, -} from './actions.es6'; +} from './actions/store-actions.es6'; + +import { + checkLibvirtStatus, + getAllVms, + getHypervisorMaxVCPU, + getOsInfoList +} from './actions/provider-actions.es6'; import { convertToUnit, diff --git a/pkg/machines/libvirt.es6 b/pkg/machines/libvirt.es6 index 29c15a4aa1c2..e353120955ee 100644 --- a/pkg/machines/libvirt.es6 +++ b/pkg/machines/libvirt.es6 @@ -24,20 +24,23 @@ import cockpit from 'cockpit'; import { updateVm, - getVm, - getAllVms, - delayPolling, undefineVm, deleteUnlistedVMs, - checkLibvirtStatus, + updateStoragePools, + updateStorageVolumes, setHypervisorMaxVCPU, +} from './actions/store-actions.es6'; + +import { + attachDisk, + checkLibvirtStatus, + delayPolling, + getAllVms, getHypervisorMaxVCPU, getStoragePools, getStorageVolumes, - updateStoragePools, - updateStorageVolumes, - attachDisk, -} from './actions.es6'; + getVm, +} from './actions/provider-actions.es6' import { usagePollingEnabled } from './selectors.es6'; import { spawnScript, spawnProcess } from './services.es6'; diff --git a/pkg/machines/provider.es6 b/pkg/machines/provider.es6 index 021cdd2cf625..044ed697c64b 100644 --- a/pkg/machines/provider.es6 +++ b/pkg/machines/provider.es6 @@ -20,7 +20,7 @@ import cockpit from 'cockpit'; import { logDebug } from './helpers.es6'; -import { setProvider } from './actions.es6'; +import { setProvider } from './actions/store-actions.es6'; var provider = null; diff --git a/pkg/machines/reducers.es6 b/pkg/machines/reducers.es6 index 59d185bcbd88..2bcdc9e4f606 100644 --- a/pkg/machines/reducers.es6 +++ b/pkg/machines/reducers.es6 @@ -19,6 +19,25 @@ import { combineReducers } from 'redux/dist/redux'; import VMS_CONFIG from "./config.es6"; import { logDebug } from './helpers.es6'; +import { + ADD_NOTIFICATION, + ADD_UI_VM, + CLEAR_NOTIFICATION, + CLEAR_NOTIFICATIONS, + DELETE_UI_VM, + DELETE_UNLISTED_VMS, + SET_PROVIDER, + SET_REFRESH_INTERVAL, + UNDEFINE_VM, + UPDATE_ADD_VM, + UPDATE_LIBVIRT_STATE, + UPDATE_OS_INFO_LIST, + UPDATE_STORAGE_POOLS, + UPDATE_STORAGE_VOLUMES, + UPDATE_UI_VM, + UPDATE_VM, + VM_ACTION_FAILED, +} from './constants/store-action-types.es6'; // --- helpers ------------------- function getFirstIndexOfVm(state, field, value, connectionName) { @@ -36,9 +55,9 @@ function config(state, action) { }; switch (action.type) { - case 'SET_PROVIDER': + case SET_PROVIDER: return Object.assign({}, state, { provider: action.provider }); - case 'SET_REFRESH_INTERVAL': { + case SET_REFRESH_INTERVAL: { const newState = Object.assign({}, state); newState.refreshInterval = action.refreshInterval; return newState; @@ -98,7 +117,7 @@ function vms(state, action) { } switch (action.type) { - case 'UPDATE_ADD_VM': { + case UPDATE_ADD_VM: { const connectionName = action.vm.connectionName; const index = action.vm.id ? getFirstIndexOfVm(state, 'id', action.vm.id, connectionName) : getFirstIndexOfVm(state, 'name', action.vm.name, connectionName); @@ -109,7 +128,7 @@ function vms(state, action) { const updatedVm = Object.assign({}, state[index], action.vm); return replaceVm({ state, updatedVm, index }); } - case 'UPDATE_VM': { + case UPDATE_VM: { const indexedVm = findVmToUpdate(state, action.vm); if (!indexedVm) { return state; @@ -128,7 +147,7 @@ function vms(state, action) { // replace whole object return replaceVm({ state, updatedVm, index: indexedVm.index }); } - case 'VM_ACTION_FAILED': { + case VM_ACTION_FAILED: { const indexedVm = findVmToUpdate(state, action.payload); if (!indexedVm) { // already logged return state; @@ -140,12 +159,12 @@ function vms(state, action) { return replaceVm({ state, updatedVm, index: indexedVm.index }); } - case 'UNDEFINE_VM': { + case UNDEFINE_VM: { return state .filter(vm => (action.connectionName !== vm.connectionName || action.name != vm.name || (action.transientOnly && vm.persistent))); } - case 'DELETE_UNLISTED_VMS': { + case DELETE_UNLISTED_VMS: { return state .filter(vm => (action.connectionName !== vm.connectionName || action.vmNames.indexOf(vm.name) >= 0)); } @@ -165,13 +184,13 @@ function systemInfo(state, action) { }; switch (action.type) { - case 'UPDATE_OS_INFO_LIST': { + case UPDATE_OS_INFO_LIST: { if (action.osInfoList instanceof Array) { state.osInfoList = [...action.osInfoList]; } return state; } - case 'UPDATE_LIBVIRT_STATE': { + case UPDATE_LIBVIRT_STATE: { state.libvirtService = Object.assign({}, state.libvirtService, action.state); return state; } @@ -194,7 +213,7 @@ function storagePools(state, action) { } */ switch (action.type) { - case 'UPDATE_STORAGE_POOLS': { + case UPDATE_STORAGE_POOLS: { const { connectionName, pools } = action.payload; const newState = Object.assign({}, state); @@ -207,7 +226,7 @@ function storagePools(state, action) { return newState; } - case 'UPDATE_STORAGE_VOLUMES': { + case UPDATE_STORAGE_VOLUMES: { const { connectionName, poolName, volumes } = action.payload; const newState = Object.assign({}, state); @@ -236,20 +255,20 @@ function ui(state, action) { }; switch (action.type) { - case 'ADD_UI_VM': { + case ADD_UI_VM: { addVm(); return state; } - case 'UPDATE_UI_VM': { + case UPDATE_UI_VM: { if (state.vms[action.vm.name]) { addVm(); } return state; } - case 'DELETE_UI_VM': + case DELETE_UI_VM: delete state.vms[action.vm.name]; return state; - case 'ADD_NOTIFICATION': { + case ADD_NOTIFICATION: { const notification = typeof action.notification === 'string' ? { message: action.notification } : action.notification; const notifs = state.notifications; notification.id = notifs.length > 0 ? notifs[notifs.length - 1].id + 1 : 1; @@ -261,11 +280,11 @@ function ui(state, action) { state.notifications = [...notifs, notification]; return state; } - case 'CLEAR_NOTIFICATION': { + case CLEAR_NOTIFICATION: { state.notifications = state.notifications.filter(error => error.id !== action.id); return state; } - case 'CLEAR_NOTIFICATIONS': { + case CLEAR_NOTIFICATIONS: { state.notifications = []; return state; } diff --git a/pkg/machines/vmnetworktab.jsx b/pkg/machines/vmnetworktab.jsx index 8e5194087f69..b3e806fe0be1 100644 --- a/pkg/machines/vmnetworktab.jsx +++ b/pkg/machines/vmnetworktab.jsx @@ -18,7 +18,7 @@ */ import React from 'react'; import cockpit from 'cockpit'; -import { changeNetworkState } from "./actions.es6"; +import { changeNetworkState } from "./actions/provider-actions.es6"; import { rephraseUI, vmId } from "./helpers.es6"; import { Listing, ListingRow } from 'cockpit-components-listing.jsx'; diff --git a/pkg/ovirt/components/vcpuModal.jsx b/pkg/ovirt/components/vcpuModal.jsx index ea645842f0b1..353da6a325ea 100644 --- a/pkg/ovirt/components/vcpuModal.jsx +++ b/pkg/ovirt/components/vcpuModal.jsx @@ -2,7 +2,7 @@ import React from 'react'; import cockpit from 'cockpit'; import { show_modal_dialog } from 'cockpit-components-dialog.jsx'; -import { setVCPUSettings } from "../../machines/actions.es6"; +import { setVCPUSettings } from "../../machines/actions/provider-actions.es6"; import InfoRecord from '../../machines/components/infoRecord.jsx'; const _ = cockpit.gettext; diff --git a/pkg/ovirt/index.es6 b/pkg/ovirt/index.es6 index bafee8c0b9c6..6d702658e8f8 100644 --- a/pkg/ovirt/index.es6 +++ b/pkg/ovirt/index.es6 @@ -20,7 +20,7 @@ import '../lib/polyfills.js'; // once per application import React from 'react'; import store from './store.es6'; -import { initDataRetrieval } from '../machines/actions.es6'; +import { initDataRetrieval } from '../machines/actions/provider-actions.es6'; import { logDebug } from '../machines/helpers.es6'; import Provider from './provider.es6'; diff --git a/pkg/ovirt/provider.es6 b/pkg/ovirt/provider.es6 index 65a36ec2fde4..57f7364861f2 100644 --- a/pkg/ovirt/provider.es6 +++ b/pkg/ovirt/provider.es6 @@ -28,7 +28,7 @@ import { pollOvirt, forceNextOvirtPoll } from './ovirt.es6'; import { oVirtIconToInternal } from './ovirtConverters.es6'; import { updateIcon, downloadIcon } from './actions.es6'; -import { getHypervisorMaxVCPU } from '../machines/actions.es6'; +import { getHypervisorMaxVCPU } from '../machines/actions/provider-actions.es6'; import { getAllIcons, isVmManagedByOvirt } from './selectors.es6'; import { ovirtReducer } from './reducers.es6';