@@ -40,12 +40,9 @@ type ParsedFormViewYaml = {
40
40
nmstate : Nmstate ;
41
41
} ;
42
42
43
- const findFirstRealInterface = ( interfaces : NmstateInterface [ ] ) : NmstateInterface | undefined => {
44
- return interfaces . find (
45
- ( currentInterface ) => ! isDummyInterface ( currentInterface . name ) ,
46
- ) as unknown as NmstateInterface | undefined ;
43
+ const findAllRealInterfaces = ( interfaces : NmstateInterface [ ] ) : NmstateInterface [ ] => {
44
+ return interfaces . filter ( ( currentInterface ) => ! isDummyInterface ( currentInterface . name ) ) ;
47
45
} ;
48
-
49
46
const parseYaml = ( yaml : string ) : ParsedFormViewYaml => {
50
47
const lines = yaml . split ( '\n' ) ;
51
48
const lastCommentIdx = findLastIndex ( lines , ( line ) => line . startsWith ( YAML_COMMENT_CHAR ) ) ;
@@ -133,9 +130,26 @@ const getFormViewHost = (
133
130
}
134
131
135
132
const { nmstate } = parseYaml ( infraEnvHost . networkYaml ) ;
136
- const realInterface = findFirstRealInterface ( nmstate . interfaces ) ;
137
133
138
- if ( ! realInterface ) {
134
+ const realInterfaces = findAllRealInterfaces ( nmstate . interfaces ) ;
135
+ const firstInterface = realInterfaces [ 0 ] ;
136
+ const secondInterface = realInterfaces [ 1 ] ; // Puede ser undefined
137
+
138
+ let bondInterface : NmstateInterface | undefined ;
139
+ let nonBondInterface : NmstateInterface | undefined ;
140
+
141
+ if ( firstInterface ) {
142
+ if ( firstInterface . type === NmstateInterfaceType . BOND ) {
143
+ bondInterface = firstInterface ;
144
+ nonBondInterface = secondInterface ;
145
+ } else {
146
+ nonBondInterface = firstInterface ;
147
+ bondInterface =
148
+ secondInterface ?. type === NmstateInterfaceType . BOND ? secondInterface : undefined ;
149
+ }
150
+ }
151
+
152
+ if ( ! realInterfaces ) {
139
153
//handle case 2
140
154
return null ;
141
155
}
@@ -153,16 +167,20 @@ const getFormViewHost = (
153
167
useBond : false ,
154
168
} ;
155
169
156
- if ( realInterface . type === NmstateInterfaceType . BOND ) {
170
+ if ( bondInterface ? .type === NmstateInterfaceType . BOND ) {
157
171
ret . useBond = true ;
158
- ret . bondType = realInterface [ 'link-aggregation' ] . mode ;
172
+ ret . bondType = bondInterface [ 'link-aggregation' ] . mode ;
159
173
ret . bondPrimaryInterface = infraEnvHost . macInterfaceMap [ 0 ] . macAddress ?? '' ;
160
174
ret . bondSecondaryInterface = infraEnvHost . macInterfaceMap [ 1 ] . macAddress ?? '' ;
161
175
}
162
176
163
177
for ( const protocolVersion of getShownProtocolVersions ( protocolType ) ) {
164
- ret . ips [ protocolVersion ] = getIpAddress ( realInterface , protocolVersion ) ;
178
+ const interfaceToUse = nonBondInterface || bondInterface ;
179
+ if ( interfaceToUse ) {
180
+ ret . ips [ protocolVersion ] = getIpAddress ( interfaceToUse , protocolVersion ) ;
181
+ }
165
182
}
183
+
166
184
return ret ;
167
185
} ;
168
186
0 commit comments