forked from osbuild/image-builder-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetEnvironment.tsx
More file actions
460 lines (434 loc) · 15.9 KB
/
TargetEnvironment.tsx
File metadata and controls
460 lines (434 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
import React, { useEffect, useMemo } from 'react';
import {
Alert,
Checkbox,
Content,
EmptyState,
FormGroup,
Spinner,
} from '@patternfly/react-core';
import { provisioningApi, rhsmApi } from '@/store/api';
import { ImageTypes, useGetArchitecturesQuery } from '@/store/api/backend';
import { useCustomizationRestrictions } from '@/store/api/distributions';
import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { selectIsOnPremise } from '@/store/slices';
import {
addImageType,
changeRegistrationType,
reinitializeAws,
reinitializeAzure,
reinitializeGcp,
removeImageType,
selectArchitecture,
selectDistribution,
selectImageTypes,
} from '@/store/slices/wizard';
import Aws from './Aws';
import Azure from './Azure';
import Gcp from './Gcp';
const TEXT_WRAP_WIDTH = '54rem';
const PRIVATE_CLOUD_TYPES = new Set<string>(['vsphere', 'vsphere-ova']);
const PUBLIC_CLOUD_TYPES = new Set<string>(['aws', 'azure', 'gcp', 'oci']);
const EMPTY_ENVIRONMENTS: string[] = [];
const TargetEnvironment = () => {
const arch = useAppSelector(selectArchitecture);
const environments = useAppSelector(selectImageTypes);
const distribution = useAppSelector(selectDistribution);
const { restrictions } = useCustomizationRestrictions({
selectedImageTypes: environments,
});
const {
isError,
isFetching,
environments: supportedEnvironments,
} = useGetArchitecturesQuery(
{
distribution,
},
{
selectFromResult: ({ data, isFetching, isError }) => ({
isError,
isFetching,
environments:
data?.find((elem) => elem.arch === arch)?.image_types ??
// this is defined as a const for referential stability
EMPTY_ENVIRONMENTS,
}),
},
);
const dispatch = useAppDispatch();
const isOnPremise = useAppSelector(selectIsOnPremise);
const prefetchSources = provisioningApi.usePrefetch('getSourceList');
const prefetchActivationKeys = rhsmApi.usePrefetch('listActivationKeys');
useEffect(() => {
prefetchActivationKeys();
// This useEffect hook should run *only* on mount and therefore has an empty
// dependency array. eslint's exhaustive-deps rule does not support this use.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const registrationType = restrictions.registration.shouldHide
? 'register-later'
: 'register-now-rhc';
dispatch(changeRegistrationType(registrationType));
}, [restrictions.registration.shouldHide, dispatch]);
useEffect(() => {
prefetchSources({ provider: 'aws' });
}, [prefetchSources]);
const isOnlyNetworkInstallerSelected =
environments.length === 1 && environments.includes('network-installer');
const isOtherEnvironmentSelected =
environments.length >= 1 && !environments.includes('network-installer');
const privateClouds = useMemo(
() =>
supportedEnvironments.filter((env): env is ImageTypes =>
PRIVATE_CLOUD_TYPES.has(env),
),
[supportedEnvironments],
);
const publicClouds = useMemo(
() =>
supportedEnvironments.filter((env): env is ImageTypes =>
PUBLIC_CLOUD_TYPES.has(env),
),
[supportedEnvironments],
);
const miscFormats = useMemo(
() =>
supportedEnvironments.filter(
// Technically unknown values that aren't private or public clouds would get
// incorrectly narrowed here, but this is fine since we only render known
// values with the checkboxes and anything else gets discarded
(env): env is ImageTypes =>
!PRIVATE_CLOUD_TYPES.has(env) && !PUBLIC_CLOUD_TYPES.has(env),
),
[supportedEnvironments],
);
useEffect(() => {
if (isOnPremise) return;
publicClouds
.filter((env): env is 'aws' | 'azure' | 'gcp' => env !== 'oci')
.forEach((provider) => prefetchSources({ provider }));
}, [isOnPremise, publicClouds, prefetchSources]);
const handleToggleEnvironment = (environment: ImageTypes) => {
if (environments.includes(environment)) {
switch (environment) {
case 'aws':
dispatch(reinitializeAws());
break;
case 'azure':
dispatch(reinitializeAzure());
break;
case 'gcp':
dispatch(reinitializeGcp());
}
dispatch(removeImageType(environment));
} else {
dispatch(addImageType(environment));
}
};
if (isFetching) {
return (
<EmptyState
titleText='Loading target environments'
headingLevel='h6'
icon={Spinner}
/>
);
}
if (isError) {
return (
<Alert
title="Couldn't fetch target environments"
variant='danger'
isInline
>
Target environments couldn't be loaded, please refresh the page or
try again later.
</Alert>
);
}
return (
<FormGroup
isRequired={true}
role='group'
label={<span className='pf-v6-u-font-size-md'>Target environments</span>}
fieldId='target-environments'
>
<Content component='p'>
Select one or more target environments for this image.
</Content>
{publicClouds.length > 0 && (
<FormGroup
label='Public cloud'
className='pf-v6-u-mt-md'
role='group'
aria-label='Public cloud'
fieldId='public-cloud-group'
>
{publicClouds.includes('aws') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-aws'
name='Amazon Web Services'
label='Amazon Web Services'
aria-label='Amazon Web Services checkbox'
isChecked={environments.includes('aws')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => handleToggleEnvironment('aws')}
body={environments.includes('aws') ? <Aws /> : undefined}
/>
)}
{publicClouds.includes('gcp') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-gcp'
name='Google Cloud Platform'
label='Google Cloud Platform'
aria-label='Google Cloud checkbox'
isChecked={environments.includes('gcp')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => handleToggleEnvironment('gcp')}
body={environments.includes('gcp') ? <Gcp /> : undefined}
/>
)}
{publicClouds.includes('azure') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-azure'
name='Microsoft Azure'
label='Microsoft Azure'
aria-label='Microsoft Azure checkbox'
isChecked={environments.includes('azure')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => handleToggleEnvironment('azure')}
body={environments.includes('azure') ? <Azure /> : undefined}
/>
)}
{publicClouds.includes('oci') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-oci'
name='Oracle Cloud Infrastructure'
label='Oracle Cloud Infrastructure'
aria-label='Oracle Cloud Infrastructure checkbox'
isChecked={environments.includes('oci')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => handleToggleEnvironment('oci')}
/>
)}
</FormGroup>
)}
{privateClouds.length > 0 && (
<FormGroup
label='Private cloud'
className='pf-v6-u-mt-md'
role='group'
aria-label='Private cloud'
fieldId='private-cloud-group'
>
{privateClouds.includes('vsphere-ova') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='vsphere-checkbox-ova'
isLabelWrapped
name='vsphere-checkbox-ova'
label='VMware vSphere - Open virtualization format (.ova)'
aria-label='VMware vSphere checkbox OVA'
description={
<Content
component='small'
style={{ maxWidth: TEXT_WRAP_WIDTH }}
>
An OVA file is a virtual appliance used by virtualization
platforms such as VMware vSphere. It is a package that
contains files used to describe a virtual machine, which
includes a VMDK image, OVF descriptor file and a manifest
file.
</Content>
}
isChecked={environments.includes('vsphere-ova')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => {
handleToggleEnvironment('vsphere-ova');
}}
/>
)}
{privateClouds.includes('vsphere') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='vsphere-checkbox-vmdk'
isLabelWrapped
name='vsphere-checkbox-vmdk'
label='VMware vSphere - Virtual disk (.vmdk)'
aria-label='VMware vSphere checkbox VMDK'
description={
<Content
component='small'
style={{ maxWidth: TEXT_WRAP_WIDTH }}
>
A VMDK file is a virtual disk that stores the contents of a
virtual machine. This disk has to be imported into vSphere
using govc import.vmdk, use the OVA version when using the
vSphere UI.
</Content>
}
isChecked={environments.includes('vsphere')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => {
handleToggleEnvironment('vsphere');
}}
/>
)}
</FormGroup>
)}
<FormGroup
label={
privateClouds.length > 0 || publicClouds.length > 0
? 'Miscellaneous formats'
: undefined
}
className='pf-v6-u-mt-md'
role='group'
aria-label='Miscellaneous formats'
fieldId='misc-formats-group'
>
{miscFormats.includes('guest-image') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-guest-image'
isLabelWrapped
name='Virtualization guest image'
label='Virtualization - Guest image (.qcow2)'
aria-label='Virtualization guest image checkbox'
description={
<Content component='small' style={{ maxWidth: TEXT_WRAP_WIDTH }}>
A deployment-ready virtual disk format used by virtualization
software like QEMU and KVM. It allows for efficient storage
usage by only writing the changes made to the disk image rather
than the entire image, ensuring the file only consumes physical
storage as data is written.
</Content>
}
isChecked={environments.includes('guest-image')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => {
handleToggleEnvironment('guest-image');
}}
/>
)}
{miscFormats.includes('image-installer') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-image-installer'
isLabelWrapped
name='Bare metal installer'
label='Bare metal - Installer (.iso)'
aria-label='Bare metal installer checkbox'
description={
<Content component='small' style={{ maxWidth: TEXT_WRAP_WIDTH }}>
This is a standard bootable image used to install RHEL directly
onto physical hardware or “bare metal” servers. It
contains the necessary installer and kernel to initialize a
system from scratch, ensuring the OS is configured correctly for
your specific hardware environment.
</Content>
}
isChecked={environments.includes('image-installer')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => {
handleToggleEnvironment('image-installer');
}}
/>
)}
{miscFormats.includes('network-installer') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-network-installer'
isLabelWrapped
name='Network - Installer'
label='Network - Installer (.iso)'
aria-label='Network installer checkbox'
description={
<Content component='small' style={{ maxWidth: TEXT_WRAP_WIDTH }}>
This is a lightweight image that differs from a standard
"full" ISO by requiring an active network connection
to pull the latest software directly from package repositories,
as no OS packages are stored locally on the image.
</Content>
}
isChecked={environments.includes('network-installer')}
isDisabled={isOtherEnvironmentSelected}
onChange={() => {
handleToggleEnvironment('network-installer');
}}
/>
)}
{miscFormats.includes('pxe-tar-xz') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-pxe-boot'
isLabelWrapped
name='PXE boot image'
label='Network - PXE boot (.tar.xz)'
aria-label='PXE boot image checkbox'
description={
<Content component='small' style={{ maxWidth: TEXT_WRAP_WIDTH }}>
A PXE boot image is a compressed archive containing the kernel,
initramfs, and root filesystem needed to boot a system over the
network using the Preboot Execution Environment (PXE) protocol.
</Content>
}
isChecked={environments.includes('pxe-tar-xz')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => {
handleToggleEnvironment('pxe-tar-xz');
}}
/>
)}
{miscFormats.includes('wsl') && (
<Checkbox
className='pf-v6-u-mb-sm pf-v6-u-ml-lg'
id='checkbox-wsl'
isLabelWrapped
name='WSL'
label='WSL - Windows Subsystem for Linux (.wsl)'
aria-label='Windows Subsystem for Linux checkbox'
description={
<Content component='small' style={{ maxWidth: TEXT_WRAP_WIDTH }}>
You can use RHEL on Microsoft's Windows Subsystem for Linux
(WSL) for development and learning use cases. Red Hat supports
WSL under the Validated Software Pattern and Third Party
Component Support Policy, which does not include production use
cases.
</Content>
}
isChecked={environments.includes('wsl')}
isDisabled={isOnlyNetworkInstallerSelected}
onChange={() => {
handleToggleEnvironment('wsl');
}}
/>
)}
</FormGroup>
{isOnlyNetworkInstallerSelected && (
<Alert
variant='info'
className='pf-v6-u-mt-lg'
style={{ maxWidth: TEXT_WRAP_WIDTH }}
isInline
title='Network installer image selection'
>
<Content>
This image type requires specific, minimal configuration for remote
installation, so most customization options are restricted.
</Content>
<Content>
To select a different target, first deselect network installer.
</Content>
</Alert>
)}
</FormGroup>
);
};
export default TargetEnvironment;