fix(striker-ui-api): include IPMI info in host list

main
Tsu-ba-me 9 months ago
parent 47d0d63a54
commit 1d08f747c6
  1. 60
      striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts
  2. 17
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  3. 12
      striker-ui-api/src/types/ApiHost.d.ts

@ -48,7 +48,9 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
const query = ` const query = `
SELECT SELECT
a.host_ipmi,
a.host_name, a.host_name,
a.host_status,
a.host_type, a.host_type,
a.host_uuid, a.host_uuid,
b.variable_name, b.variable_name,
@ -84,32 +86,35 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
if (output.length === 0) return {}; if (output.length === 0) return {};
const { const {
0: [hostName, hostType, hostUUID], 0: [hostIpmi, hostName, hostStatus, hostType, hostUUID],
} = output; } = output;
const shortHostName = getShortHostName(hostName); const shortHostName = getShortHostName(hostName);
return output.reduce< /**
{ * Assumes:
hostName: string; * - ip is not quoted
hostType: string; * - password is quoted, and it's the last switch in the string
hostUUID: string; * - username has no space, and it's not quoted
shortHostName: string; *
} & Tree * TODO: replace with a package to handle parsing such command strings
>( */
( const ipmi: HostIpmi = {
previous, command: hostIpmi,
[ ip: hostIpmi.replace(/^.*--ip\s+([^\s'"]+).*$/, '$1'),
, password: hostIpmi.replace(/^.*--password\s+"(.*)"$/, '$1'),
, username: hostIpmi.replace(/^.*--username\s+(\w+).*$/, '$1'),
, };
variableName,
variableValue, return output.reduce<HostDetail>(
, (previous, row) => {
networkType, const {
networkLink, 5: variableName,
networkInterfaceUuid, 6: variableValue,
], 8: networkType,
) => { 9: networkLink,
10: networkInterfaceUuid,
} = row;
if (!variableName) return previous; if (!variableName) return previous;
const [variablePrefix, ...restVariableParts] = const [variablePrefix, ...restVariableParts] =
@ -130,7 +135,14 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
return previous; return previous;
}, },
{ hostName, hostType, hostUUID, shortHostName }, {
hostName,
hostStatus,
hostType,
hostUUID,
ipmi,
shortHostName,
},
); );
}); });

@ -14,7 +14,7 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
const { after: typeCondition } = buildUnknownIDCondition( const { after: typeCondition } = buildUnknownIDCondition(
hostTypes, hostTypes,
'hos.host_type', 'a.host_type',
); );
let condition = ''; let condition = '';
@ -25,19 +25,22 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
let query = ` let query = `
SELECT SELECT
hos.host_name, a.host_name,
hos.host_type, a.host_status,
hos.host_uuid a.host_type,
FROM hosts AS hos a.host_uuid
FROM hosts AS a
${condition} ${condition}
ORDER BY hos.host_name ASC;`; ORDER BY a.host_name ASC;`;
let afterQueryReturn: QueryResultModifierFunction | undefined = let afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>( buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>(
(previous, [hostName, hostType, hostUUID]) => { (previous, [hostName, hostStatus, hostType, hostUUID]) => {
const key = toLocal(hostUUID, localHostUUID); const key = toLocal(hostUUID, localHostUUID);
previous[key] = { previous[key] = {
hostName, hostName,
hostStatus,
hostType, hostType,
hostUUID, hostUUID,
shortHostName: getShortHostName(hostName), shortHostName: getShortHostName(hostName),

@ -40,13 +40,25 @@ type HostConnectionOverview = {
}; };
}; };
type HostIpmi = {
command: string;
ip: string;
password: string;
username: string;
};
type HostOverview = { type HostOverview = {
hostName: string; hostName: string;
hostStatus: string;
hostType: string; hostType: string;
hostUUID: string; hostUUID: string;
shortHostName: string; shortHostName: string;
}; };
type HostDetail = HostOverview & {
ipmi: HostIpmi;
} & Tree<string>;
type InitializeStrikerNetworkForm = { type InitializeStrikerNetworkForm = {
createBridge?: StringBoolean; createBridge?: StringBoolean;
interfaces: Array<NetworkInterfaceOverview | null | undefined>; interfaces: Array<NetworkInterfaceOverview | null | undefined>;

Loading…
Cancel
Save