This commit is contained in:
Jay 2017-05-26 11:06:15 +08:00
parent 58057bcfa0
commit d702c63eb6
5 changed files with 110 additions and 7 deletions

View File

@ -295,6 +295,68 @@ router
return n(); return n();
}) })
.post('/getbmctl', async(req, res, n) => {
if (!config.permission.server) return n('ERR9000');
try {
let query = "select `uid`,`name` from ??.??";
let param = [config.db.db11, 'bmctl'];
let ctls = await tool.promiseQuery(res, query, param);
res.api_res = {
record: tool.checkArray(ctls.data)
}
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
return n();
})
.post('/runbmctl', async(req, res, n) => {
if (!config.permission.server) return n('ERR9000');
if (!tool.checkPermission(req)) return n('ERR9000');
let arr = req.body;
if (!arr.data) return n('ERR0000');
if (!arr.data.ctlid || !arr.data.ipmuid) return n('ERR0028');
res.api_res = {
record: []
};
try {
let query = "select * from ??.?? where `uid` = ?";
let param = [config.db.db11, 'bmctl', arr.data.ctlid];
let ctl = await tool.promiseQuery(res, query, param);
if (ctl.data.length == 0) return n('ERR8000');
query = "select * from ??.?? where `ipmuid` = ?";
param = [config.db.db11, 'ipmi', arr.data.ipmuid];
let ipmi = await tool.promiseQuery(res, query, param);
if (ipmi.data.length == 0) return n('ERR8000');
let cmd = ctl.data[0].cmd;
cmd = cmd.trim();
if (!cmd) return n('ERR7000');
cmd = cmd.replace(/\@ipmuid/i, ipmi.data[0].ipmuid);
let result = await new Promise((resolve, reject) => {
exec(cmd, (err, stderr, stdout) => {
if (err) return reject(err);
return resolve(stdout || stderr);
});
})
result = result.split(/\n/).filter(e => e).join('');
if (result == 0) return n('ERR7000');
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
return n();
})
.all('*', rt.send); .all('*', rt.send);
module.exports = router; module.exports = router;

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import {Table, Button} from 'semantic-ui-react'; import {Table, Button} from 'semantic-ui-react';
const SetListItem = ({ i18n, data, openModal, delData }) => { const SetListItem = ({ i18n, data, openModal, delData, bmctl, runbmctl }) => {
return ( return (
<Table.Row> <Table.Row>
@ -10,6 +10,13 @@ const SetListItem = ({ i18n, data, openModal, delData }) => {
<Button content="刪除" basic onClick={()=>delData('ipmi', data.ipmuid)} /> <Button content="刪除" basic onClick={()=>delData('ipmi', data.ipmuid)} />
<Button content="ShowInfo" basic onClick={()=>openModal('ipmiinfo', 0, {id: data.ipmuid})} /> <Button content="ShowInfo" basic onClick={()=>openModal('ipmiinfo', 0, {id: data.ipmuid})} />
</Table.Cell> </Table.Cell>
<Table.Cell>
{
bmctl.map((t,idx) => (
<Button key={idx} content={t.name} type="button" onClick={()=>runbmctl(t.uid, data.ipmuid)} />
))
}
</Table.Cell>
<Table.Cell>{data.ip}</Table.Cell> <Table.Cell>{data.ip}</Table.Cell>
<Table.Cell>{data.account}</Table.Cell> <Table.Cell>{data.account}</Table.Cell>
<Table.Cell>{data.mac}</Table.Cell> <Table.Cell>{data.mac}</Table.Cell>

View File

@ -2,7 +2,7 @@ import React from 'react';
import {Container, Segment, Button, Table} from 'semantic-ui-react'; import {Container, Segment, Button, Table} from 'semantic-ui-react';
import SelListItem from './SetListItem'; import SelListItem from './SetListItem';
const IPMIPage = ({i18n, list, openModal, delData}) => { const IPMIPage = ({i18n, list, openModal, delData, bmctl, runbmctl}) => {
return ( return (
<Container> <Container>
<Segment className="clearfix"> <Segment className="clearfix">
@ -17,6 +17,7 @@ const IPMIPage = ({i18n, list, openModal, delData}) => {
<Table.Header> <Table.Header>
<Table.Row> <Table.Row>
<Table.HeaderCell>操作</Table.HeaderCell> <Table.HeaderCell>操作</Table.HeaderCell>
<Table.HeaderCell>設備操作</Table.HeaderCell>
<Table.HeaderCell>IP</Table.HeaderCell> <Table.HeaderCell>IP</Table.HeaderCell>
<Table.HeaderCell>帳號</Table.HeaderCell> <Table.HeaderCell>帳號</Table.HeaderCell>
<Table.HeaderCell>MAC Address</Table.HeaderCell> <Table.HeaderCell>MAC Address</Table.HeaderCell>
@ -30,7 +31,9 @@ const IPMIPage = ({i18n, list, openModal, delData}) => {
i18n={i18n} i18n={i18n}
data={t} data={t}
openModal={openModal} openModal={openModal}
delData={delData} /> delData={delData}
bmctl={bmctl}
runbmctl={runbmctl} />
) )
}) })
} }

View File

@ -72,12 +72,14 @@ const BMCContent = ({group, data}) => {
</Header> </Header>
<List> <List>
{ {
data.map((t2, idx) => ( data.map((t2, idx) => {
if(t2.guid != t.guid) return null;
return (
<List.Item key={idx}> <List.Item key={idx}>
<Label content={t2.name} basic /> <Label content={t2.name} basic />
{t2.value} {t2.value}
</List.Item> </List.Item>
)) )})
} }
</List> </List>
</Segment> </Segment>

View File

@ -9,6 +9,7 @@ import IPMIInfoModal from './Modals/IPMIInfoModal';
const stateDefault = ()=>({ const stateDefault = ()=>({
list: [], list: [],
bmctl: [],
devSel: { devSel: {
id: null, id: null,
type: null, type: null,
@ -42,6 +43,7 @@ class ServerPage extends React.Component {
componentDidMount(){ componentDidMount(){
this.getDevList(); this.getDevList();
this.getBMCtl();
} }
getDevList = () => { getDevList = () => {
@ -58,6 +60,18 @@ class ServerPage extends React.Component {
}) })
} }
getBMCtl = () => {
fetch('/api/server/getbmctl', getRequest())
.then(response=>response.json())
.then(json => {
if(json.status == 1) {
this.setState({
bmctl: json.data.record || []
})
}
})
}
selectDevice = (id, refresh = false) => { selectDevice = (id, refresh = false) => {
if(!id) return ; if(!id) return ;
let {showDialog, toggleLoading} = this.props; let {showDialog, toggleLoading} = this.props;
@ -106,7 +120,9 @@ class ServerPage extends React.Component {
list={this.state.devSel.data.ipmi} list={this.state.devSel.data.ipmi}
openModal={this.openModal} openModal={this.openModal}
closeModal={this.closeModal} closeModal={this.closeModal}
delData={this.delData} /> delData={this.delData}
bmctl={this.state.bmctl}
runbmctl={this.runbmctl} />
default: default:
return null; return null;
@ -246,6 +262,19 @@ class ServerPage extends React.Component {
}) })
} }
runbmctl = (ctlid, ipmuid) => {
if(!ctlid || !ipmuid) return ;
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
toggleLoading(1);
fetch('/api/server/runbmctl', getRequest({ctlid, ipmuid}))
.then(response=>response.json())
.then(json => {
toggleLoading(0);
if(json.status != 1) return showDialog(json.message);
return showDialog('命令執行完成');
})
}
render() { render() {
let {i18n, showDialog, toggleLoading, callConfirm} = this.props; let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
return ( return (