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 = `
SELECT
a.host_ipmi,
a.host_name,
a.host_status,
a.host_type,
a.host_uuid,
b.variable_name,
@ -84,32 +86,35 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
if (output.length === 0) return {};
const {
0: [hostName, hostType, hostUUID],
0: [hostIpmi, hostName, hostStatus, hostType, hostUUID],
} = output;
const shortHostName = getShortHostName(hostName);
return output.reduce<
{
hostName: string;
hostType: string;
hostUUID: string;
shortHostName: string;
} & Tree
>(
(
previous,
[
,
,
,
variableName,
variableValue,
,
networkType,
networkLink,
networkInterfaceUuid,
],
) => {
/**
* Assumes:
* - ip is not quoted
* - password is quoted, and it's the last switch in the string
* - username has no space, and it's not quoted
*
* TODO: replace with a package to handle parsing such command strings
*/
const ipmi: HostIpmi = {
command: hostIpmi,
ip: hostIpmi.replace(/^.*--ip\s+([^\s'"]+).*$/, '$1'),
password: hostIpmi.replace(/^.*--password\s+"(.*)"$/, '$1'),
username: hostIpmi.replace(/^.*--username\s+(\w+).*$/, '$1'),
};
return output.reduce<HostDetail>(
(previous, row) => {
const {
5: variableName,
6: variableValue,
8: networkType,
9: networkLink,
10: networkInterfaceUuid,
} = row;
if (!variableName) return previous;
const [variablePrefix, ...restVariableParts] =
@ -130,7 +135,14 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
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(
hostTypes,
'hos.host_type',
'a.host_type',
);
let condition = '';
@ -25,19 +25,22 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
let query = `
SELECT
hos.host_name,
hos.host_type,
hos.host_uuid
FROM hosts AS hos
a.host_name,
a.host_status,
a.host_type,
a.host_uuid
FROM hosts AS a
${condition}
ORDER BY hos.host_name ASC;`;
ORDER BY a.host_name ASC;`;
let afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>(
(previous, [hostName, hostType, hostUUID]) => {
(previous, [hostName, hostStatus, hostType, hostUUID]) => {
const key = toLocal(hostUUID, localHostUUID);
previous[key] = {
hostName,
hostStatus,
hostType,
hostUUID,
shortHostName: getShortHostName(hostName),

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

Loading…
Cancel
Save