Skip to content

Commit

Permalink
F #6684: Add firmware options fetching (#3198)
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Hansson <[email protected]>
  • Loading branch information
vichansson authored Aug 9, 2024
1 parent 3d527c3 commit 6d60b43
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { string, boolean } from 'yup'

import { useGetHostsQuery } from 'client/features/OneApi/host'
import { useGetVmmConfigQuery } from 'client/features/OneApi/system'
import { getKvmMachines } from 'client/models/Host'
import { Field, arrayToOptions } from 'client/utils'
import {
Expand All @@ -24,7 +25,6 @@ import {
CPU_ARCHITECTURES,
SD_DISK_BUSES,
FIRMWARE_TYPES,
KVM_FIRMWARE_TYPES,
HYPERVISORS,
} from 'client/constants'

Expand Down Expand Up @@ -143,10 +143,14 @@ export const FIRMWARE = {
.default(() => undefined),
dependOf: ['HYPERVISOR', '$general.HYPERVISOR'],
values: ([templateHyperv, hypervisor = templateHyperv] = []) => {
const types =
{
[kvm]: KVM_FIRMWARE_TYPES,
}[hypervisor] ?? FIRMWARE_TYPES
const configurableHypervisors = [kvm]
const { data: { OVMF_UEFIS = '' } = {} } =
configurableHypervisors?.includes(hypervisor) &&
useGetVmmConfigQuery({ hypervisor })

const types = FIRMWARE_TYPES.concat(
OVMF_UEFIS?.replace(/"/g, '')?.split(' ') ?? []
)

return arrayToOptions(types)
},
Expand Down
5 changes: 0 additions & 5 deletions src/fireedge/src/client/constants/vmTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ export const COMMON_RESOLUTIONS = {

export const FIRMWARE_TYPES = ['BIOS', 'EFI']

export const KVM_FIRMWARE_TYPES = FIRMWARE_TYPES.concat([
'/usr/share/OVMF/OVMF_CODE.fd',
'/usr/share/OVMF/OVMF_CODE.secboot.fd',
])

export const PCI_TYPES = { MANUAL: 'pci_manual', AUTOMATIC: 'pci_automatic' }

export const VCENTER_FIRMWARE_TYPES = FIRMWARE_TYPES.concat(['uefi'])
Expand Down
24 changes: 24 additions & 0 deletions src/fireedge/src/client/features/OneApi/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { Actions, Commands } from 'server/utils/constants/commands/system'
import {
Actions as VmmActions,
Commands as VmmCommands,
} from 'server/routes/api/system/routes'
import {
Actions as SunstoneActions,
Commands as SunstoneCommands,
Expand Down Expand Up @@ -117,6 +121,24 @@ const systemApi = oneApi.injectEndpoints({
providesTags: [{ type: SYSTEM, id: 'sunstone-avalaibles-views' }],
keepUnusedDataFor: 600,
}),

getVmmConfig: builder.query({
/**
* Returns the hypervisor VMM_EXEC config.
*
* @param {object} params - Request params
* @returns {object} The set config options
* @throws Fails when response isn't code 200
*/
query: (params) => {
const name = VmmActions.VMM_CONFIG
const command = { name, ...VmmCommands[name] }

return { params, command }
},
providesTags: [{ type: SYSTEM, id: 'vmm_config' }],
keepUnusedDataFor: 600,
}),
}),
})

Expand All @@ -126,6 +148,8 @@ export const {
useLazyGetOneVersionQuery,
useGetOneConfigQuery,
useLazyGetOneConfigQuery,
useGetVmmConfigQuery,
useLazyGetVmmConfigQuery,
useGetSunstoneConfigQuery,
useLazyGetSunstoneConfigQuery,
useGetSunstoneViewsQuery,
Expand Down
2 changes: 1 addition & 1 deletion src/fireedge/src/server/routes/api/logo/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
getAllLogos,
validateLogo,
encodeLogo,
} = require('server/routes/api/logo/utils')
} = require('server/utils/logo')

const { defaults, httpCodes } = require('server/utils/constants')
const { httpResponse } = require('server/utils/server')
Expand Down
149 changes: 0 additions & 149 deletions src/fireedge/src/server/routes/api/logo/utils.js

This file was deleted.

54 changes: 53 additions & 1 deletion src/fireedge/src/server/routes/api/system/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const {
Actions: ActionSystem,
} = require('server/utils/constants/commands/system')
const { createTokenServerAdmin } = require('server/routes/api/auth/utils')
const { getVmmConfig } = require('server/utils/vmm')

const { defaultEmptyFunction, httpMethod } = defaults
const { ok, internalServerError, badRequest } = httpCodes
const { ok, internalServerError, badRequest, notFound } = httpCodes
const { GET } = httpMethod
const { writeInLogger } = require('server/utils/logger')

const ALLOWED_KEYS_ONED_CONF = [
'DEFAULT_COST',
Expand Down Expand Up @@ -112,6 +114,56 @@ const getConfig = (
})
}

/**
*
* @param {object} res - http response
* @param {Function} next - express stepper
* @param {object} params - params of http request
* @param {object} [params.hypervisor="kvm"] - fetch vmm_exec_[hypervisor].conf
* @returns {void}
*/
const getVmmConfigHandler = async (
res = {},
next = defaultEmptyFunction,
params = {}
) => {
try {
const { hypervisor } = params
const vmmConfig = (await getVmmConfig(hypervisor)) ?? {}

if (!vmmConfig) {
res.locals.httpCode = httpResponse(
notFound,
'No vmm_exec config found',
''
)

return next()
}

if (Object.keys(vmmConfig)?.length === 0) {
res.locals.httpCode = httpResponse(
notFound,
'No valid vmm_exec config found',
''
)
} else {
res.locals.httpCode = httpResponse(ok, vmmConfig)
}
} catch (error) {
const httpError = httpResponse(
internalServerError,
'Failed to load vmm_exec config',
''
)
writeInLogger(httpError)
res.locals.httpCode = httpError
}

next()
}

module.exports = {
getConfig,
getVmmConfigHandler,
}
11 changes: 9 additions & 2 deletions src/fireedge/src/server/routes/api/system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
* ------------------------------------------------------------------------- */

const { Actions, Commands } = require('server/routes/api/system/routes')
const { getConfig } = require('server/routes/api/system/functions')
const {
getConfig,
getVmmConfigHandler,
} = require('server/routes/api/system/functions')

const { SYSTEM_CONFIG } = Actions
const { SYSTEM_CONFIG, VMM_CONFIG } = Actions

module.exports = [
{
...Commands[SYSTEM_CONFIG],
action: getConfig,
},
{
...Commands[VMM_CONFIG],
action: getVmmConfigHandler,
},
]
18 changes: 17 additions & 1 deletion src/fireedge/src/server/routes/api/system/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */

const { httpMethod } = require('server/utils/constants/defaults')
const {
from: { query },
httpMethod,
} = require('../../../utils/constants/defaults')

const basepath = '/system'
const { GET } = httpMethod

const SYSTEM_CONFIG = 'system.config'
const VMM_CONFIG = 'vmm.config'
const Actions = {
SYSTEM_CONFIG,
VMM_CONFIG,
}

module.exports = {
Expand All @@ -32,5 +37,16 @@ module.exports = {
httpMethod: GET,
auth: true,
},
[VMM_CONFIG]: {
path: `${basepath}/vmmconfig`,
httpMethod: GET,
params: {
hypervisor: {
from: query,
default: 'kvm',
},
},
auth: true,
},
},
}
Loading

0 comments on commit 6d60b43

Please sign in to comment.