Skip to content

Commit

Permalink
machines: Split actions file
Browse files Browse the repository at this point in the history
actions.es6 file contains both provider and store actions.
Let's keep them in seperate files to increase readability
and make it easier for new maintainers to navigate through
the package.

Together with the move the functions were also sorted in
aphabetical order.

Closes #9461
  • Loading branch information
KKoukiou authored and martinpitt committed Jul 26, 2018
1 parent 878c301 commit 24ccf2e
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 279 deletions.
323 changes: 72 additions & 251 deletions pkg/machines/actions.es6 → pkg/machines/actions/provider-actions.es6
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,10 @@
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/
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 {
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';
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,
Expand Down Expand Up @@ -68,107 +48,95 @@ import {
START_VM,
USAGE_START_POLLING,
USAGE_STOP_POLLING,
} from './constants/provider-action-types.es6';
} from '../constants/provider-action-types.es6';

/**
* All actions dispatchable by in the application
*/

// --- Provider actions -----------------------------------------
export function initDataRetrieval() {
return virt(INIT_DATA_RETRIEVAL);
}

/**
/** --- Provider action creators -----------------------------------------
*
* @param connectionName optional - if `undefined` then for all connections
* @param libvirtServiceName
* The naming convention for action creator names is: <verb><Noun>
* with the present tense.
*/
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 attachDisk({ connectionName, diskFileName, target, permanent, hotplug, vmName }) {
return virt(ATTACH_DISK, { connectionName, diskFileName, target, permanent, hotplug, vmName });
}

export function getStoragePools(connectionName) {
return virt(GET_STORAGE_POOLS, { 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 getStorageVolumes(connectionName, poolName) {
return virt(GET_STORAGE_VOLUMES, { connectionName, poolName });
export function checkLibvirtStatus(serviceName) {
return virt(CHECK_LIBVIRT_STATUS, { serviceName });
}

export function shutdownVm(vm) {
return virt(SHUTDOWN_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
export function createVm(vmParams) {
return virt(CREATE_VM, vmParams);
}

export function forceVmOff(vm) {
return virt(FORCEOFF_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 rebootVm(vm) {
return virt(REBOOT_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
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 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 forceVmOff(vm) {
return virt(FORCEOFF_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
}

export function installVm(vm) {
return virt(INSTALL_VM, vm);
/**
*
* @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 createVm(vmParams) {
return virt(CREATE_VM, vmParams);
export function getHypervisorMaxVCPU(connectionName) {
return virt(GET_HYPERVISOR_MAX_VCPU, { connectionName });
}

export function vmDesktopConsole(vm, consoleDetail) {
return virt(CONSOLE_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName, consoleDetail });
export function getOsInfoList() {
return virt(GET_OS_INFO_LIST);
}

export function usageStartPolling(vm) {
return virt(USAGE_START_POLLING, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
export function getStoragePools(connectionName) {
return virt(GET_STORAGE_POOLS, { connectionName });
}

export function usageStopPolling(vm) {
return virt(USAGE_STOP_POLLING, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
export function getStorageVolumes(connectionName, poolName) {
return virt(GET_STORAGE_VOLUMES, { connectionName, poolName });
}

export function sendNMI(vm) {
return virt(SENDNMI_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
export function getVm(connectionName, lookupId) {
return virt(GET_VM, {
lookupId, // provider-specific (i.e. libvirt uses vm_name)
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 initDataRetrieval() {
return virt(INIT_DATA_RETRIEVAL);
}

export function checkLibvirtStatus(serviceName) {
return virt(CHECK_LIBVIRT_STATUS, { serviceName });
export function installVm(vm) {
return virt(INSTALL_VM, vm);
}

export function startLibvirt(serviceName) {
return virt(START_LIBVIRT, { serviceName });
export function rebootVm(vm) {
return virt(REBOOT_VM, { name: vm.name, id: vm.id, connectionName: vm.connectionName });
}

export function enableLibvirt(enable, serviceName) {
return virt(ENABLE_LIBVIRT, { enable, serviceName });
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) {
Expand All @@ -185,16 +153,32 @@ export function setVCPUSettings(vm, max, count, sockets, threads, cores) {
});
}

export function getHypervisorMaxVCPU(connectionName) {
return virt(GET_HYPERVISOR_MAX_VCPU, {connectionName});
export function shutdownVm(vm) {
return virt(SHUTDOWN_VM, { name: vm.name, id: vm.id, connectionName: vm.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 startLibvirt(serviceName) {
return virt(START_LIBVIRT, { serviceName });
}

export function attachDisk({ connectionName, diskFileName, target, permanent, hotplug, vmName }) {
return virt(ATTACH_DISK, { connectionName, diskFileName, target, permanent, hotplug, vmName });
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 });
}

/**
Expand Down Expand Up @@ -227,166 +211,3 @@ export function delayPolling(action, timeout) {
}
};
}

// --- 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,
};
}
Loading

0 comments on commit 24ccf2e

Please sign in to comment.