From 048bf777997bdbf599240645fc66612c98abf3c2 Mon Sep 17 00:00:00 2001 From: vincent van beek Date: Fri, 27 Mar 2026 16:49:40 +0100 Subject: Add import topology (#393) * add a the posibility to import and export topogies in JSON format * fix web-runner integration, there were several bugs and mismatches between new implementations in OpenDC and the UI --- .../main/webui/redux/reducers/topology/index.js | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology') diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js index 2c849387..18d6cde4 100644 --- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js +++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js @@ -21,18 +21,36 @@ */ import { CPU_UNITS, GPU_UNITS, MEMORY_UNITS, STORAGE_UNITS } from '../../../util/unit-specifications' +import { STORE_TOPOLOGY } from '../../actions/topology' +import { ADD_RACK_TO_TILE } from '../../actions/topology/room' import machine from './machine' import rack from './rack' import room from './room' import tile from './tile' import topology from './topology' +function unitReducer(defaultUnits, entityType) { + return (state = defaultUnits, action) => { + if (action.type === STORE_TOPOLOGY) { + return { ...defaultUnits, ...((action.entities && action.entities[entityType]) || {}) } + } else if (action.type === ADD_RACK_TO_TILE) { + return { ...state, ...((action.entities && action.entities[entityType]) || {}) } + } + return state + } +} + +const cpus = unitReducer(CPU_UNITS, 'cpus') +const gpus = unitReducer(GPU_UNITS, 'gpus') +const memories = unitReducer(MEMORY_UNITS, 'memories') +const storages = unitReducer(STORAGE_UNITS, 'storages') + function objects(state = {}, action) { return { - cpus: CPU_UNITS, - gpus: GPU_UNITS, - memories: MEMORY_UNITS, - storages: STORAGE_UNITS, + cpus: cpus(state.cpus, action), + gpus: gpus(state.gpus, action), + memories: memories(state.memories, action), + storages: storages(state.storages, action), machines: machine(state.machines, action, state), racks: rack(state.racks, action, state), tiles: tile(state.tiles, action), -- cgit v1.2.3