diff --git a/libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx b/libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx index 191f892c5e..38e60c3670 100644 --- a/libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx +++ b/libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx @@ -184,26 +184,25 @@ const emptyValues: AddBmcValues = { bootMACAddress: '', disableCertificateVerification: true, // TODO(mlibra) online: true, - nmState: - 'interfaces:\n\ -- name: \n\ - type: ethernet\n\ - state: up\n\ - ipv4:\n\ - address:\n\ - - ip: \n\ - prefix-length: 24\n\ - enabled: true\n\ -dns-resolver:\n\ - config:\n\ - server:\n\ - - \n\ -routes:\n\ - config:\n\ - - destination: 0.0.0.0/0\n\ - next-hop-address: \n\ - next-hop-interface: \n\ -', + nmState: `interfaces: + - name: + type: ethernet + state: up + ipv4: + address: + - ip: + prefix-length: 24 + enabled: true +dns-resolver: + config: + server: + - +routes: + config: + - destination: 0.0.0.0/0 + next-hop-address: + next-hop-interface: + `, macMapping: [{ macAddress: '', name: '' }], }; @@ -212,9 +211,12 @@ const getInitValues = ( nmState?: NMStateK8sResource, secret?: SecretK8sResource, isEdit?: boolean, + addNMState?: boolean, ): AddBmcValues => { + let values = emptyValues; + if (isEdit) { - return { + values = { name: bmh?.metadata?.name || '', hostname: bmh?.metadata?.annotations?.[BMH_HOSTNAME_ANNOTATION] || '', bmcAddress: bmh?.spec?.bmc?.address || '', @@ -226,9 +228,12 @@ const getInitValues = ( nmState: nmState ? yaml.dump(nmState?.spec?.config) : emptyValues.nmState, macMapping: nmState?.spec?.interfaces || [{ macAddress: '', name: '' }], }; - } else { - return emptyValues; } + + if (!addNMState) { + values.nmState = ''; + } + return values; }; const BMCForm: React.FC = ({ @@ -254,12 +259,16 @@ const BMCForm: React.FC = ({ setError(getErrorMessage(e)); } }; + const { t } = useTranslation(); const { initValues, validationSchema } = React.useMemo(() => { - const initValues = getInitValues(bmh, nmState, secret, isEdit); + const addNmState = + infraEnv.metadata?.labels && infraEnv.metadata?.labels['networkType'] === 'static'; + + const initValues = getInitValues(bmh, nmState, secret, isEdit, addNmState); const validationSchema = getValidationSchema(usedHostnames, initValues.hostname, t); return { initValues, validationSchema }; - }, [usedHostnames, bmh, nmState, secret, isEdit, t]); + }, [infraEnv.metadata?.labels, usedHostnames, bmh, nmState, secret, isEdit, t]); return (