diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-26 15:58:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-26 15:58:21 +0200 |
| commit | 96e19464f98b868bd93b76ac842ec5b32a17cfb6 (patch) | |
| tree | a232cfecd631d49fae8d1402371a284296aeec87 /app/client/system | |
| parent | 28f4bd59314df8162548a1100b280bd256436eaa (diff) | |
means to run remote commands and get output
Diffstat (limited to 'app/client/system')
| -rw-r--r-- | app/client/system/system.actions.js | 7 | ||||
| -rw-r--r-- | app/client/system/system.component.js | 68 | ||||
| -rw-r--r-- | app/client/system/system.reducer.js | 37 |
3 files changed, 112 insertions, 0 deletions
diff --git a/app/client/system/system.actions.js b/app/client/system/system.actions.js new file mode 100644 index 0000000..1732179 --- /dev/null +++ b/app/client/system/system.actions.js @@ -0,0 +1,7 @@ +import * as socket from '../socket' +import types from '../types' + +export const run = (cmd) => { + socket.run_system_command(cmd) + return { type: types.system.running_command, cmd } +} diff --git a/app/client/system/system.component.js b/app/client/system/system.component.js new file mode 100644 index 0000000..0819c2f --- /dev/null +++ b/app/client/system/system.component.js @@ -0,0 +1,68 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import Group from '../common/group.component' +import Slider from '../common/slider.component' +import Select from '../common/select.component' +import Button from '../common/button.component' + +import * as systemActions from './system.actions' + +class System extends Component { + constructor(props){ + super() + } + render(){ + const { site, actions } = this.props + return ( + <div className='dashboard'> + <div className='heading'> + <h2>{site.name} System</h2> + </div> + + <div className='column'> + <Group title="Diagnostics"> + <button onClick={() => actions.run('nvidia-smi')}>nvidia-smi</button> + <button onClick={() => actions.run('ps')}>ps</button> + <button onClick={() => actions.run('w')}>w</button> + </Group> + {this.renderCommandOutput()} + </div> + </div> + ) + } + renderCommandOutput(){ + const { cmd } = this.props + let output + if (cmd.loading) { + output = 'Loading: ' + cmd.name + } + else if (cmd.loaded) { + if (cmd.error) { + output = 'Error: ' + cmd.name + '\n\n' + JSON.stringify(cmd.error, null, 2) + } else { + output = cmd.stdout + if (cmd.stderr) { + output += '\n\n_________________________________\n\n' + output += cmd.stderr + } + } + } + return ( + <div> + <div className='screen'>{output}</div> + </div> + ) + } +} +const mapStateToProps = state => ({ + site: state.system.site, + cmd: state.system.cmd, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(systemActions, dispatch) +}) + +export default connect(mapStateToProps, mapDispatchToProps)(System) diff --git a/app/client/system/system.reducer.js b/app/client/system/system.reducer.js index bc19fd1..e581813 100644 --- a/app/client/system/system.reducer.js +++ b/app/client/system/system.reducer.js @@ -1,3 +1,4 @@ +import types from '../types' import moment from 'moment' let FileSaver = require('file-saver') @@ -8,6 +9,15 @@ const systemInitialState = { site: { name: 'Lens Cortex', }, + cmd: { + loading: false, + loaded: false, + name: null, + error: null, + stdout: null, + stderr: null, + }, + currentTask: { id: 1072, activity: 'train', @@ -29,6 +39,9 @@ const systemInitialState = { { url: 'https://s3.amazonaws.com/i.asdf.us/bucky/data/4282/woodscaled_4_true_20180521_2150.png', }, + { + url: 'https://s3.amazonaws.com/i.asdf.us/bucky/data/4282/woodscaled_4_true_20180521_2146%20(1).png', + }, ], tasks: [ { @@ -98,6 +111,30 @@ const systemInitialState = { const systemReducer = (state = systemInitialState, action) => { switch(action.type) { + case types.system.running_command: + return { + ...state, + cmd: { + loading: true, + loaded: false, + name: action.cmd, + error: null, + stdout: null, + stderr: null, + } + } + case types.system.command_output: + return { + ...state, + cmd: { + loading: false, + loaded: true, + name: action.data.cmd, + error: action.data.error, + stdout: action.data.stdout, + stderr: action.data.stderr, + } + } default: return state } |
