-
Notifications
You must be signed in to change notification settings - Fork 592
/
vm-nics.tsx
150 lines (142 loc) · 4.52 KB
/
vm-nics.tsx
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
import * as React from 'react';
import { Table, RowFunction } from '@console/internal/components/factory';
import { sortable } from '@patternfly/react-table';
import { useSafetyFirst } from '@console/internal/components/safety-first';
import { createBasicLookup, dimensifyHeader } from '@console/shared';
import { EmptyBox } from '@console/internal/components/utils';
import { Button, ButtonVariant } from '@patternfly/react-core';
import { VMGenericLikeEntityKind } from '../../types/vmLike';
import { isVMI } from '../../selectors/check-type';
import { VMLikeEntityTabProps } from '../vms/types';
import { NetworkInterfaceWrapper } from '../../k8s/wrapper/vm/network-interface-wrapper';
import { nicModalEnhanced } from '../modals/nic-modal/nic-modal-enhanced';
import { getSimpleName } from '../../selectors/utils';
import { NetworkWrapper } from '../../k8s/wrapper/vm/network-wrapper';
import { wrapWithProgress } from '../../utils/utils';
import { NicRow } from './nic-row';
import { NetworkBundle } from './types';
import { nicTableColumnClasses } from './utils';
import { asVMILikeWrapper } from '../../k8s/wrapper/utils/convert';
import { ADD_NETWORK_INTERFACE } from '../../utils/strings';
const getNicsData = (vmLikeEntity: VMGenericLikeEntityKind): NetworkBundle[] => {
const vmiLikeWrapper = asVMILikeWrapper(vmLikeEntity);
const networks = vmiLikeWrapper?.getNetworks() || [];
const interfaces = vmiLikeWrapper?.getNetworkInterfaces() || [];
const networkLookup = createBasicLookup(networks, getSimpleName);
return interfaces.map((nic) => {
const network = networkLookup[nic.name];
const interfaceWrapper = new NetworkInterfaceWrapper(nic);
const networkWrapper = new NetworkWrapper(network);
return {
nic,
network,
// for sorting
name: interfaceWrapper.getName(),
model: interfaceWrapper.getReadableModel(),
networkName: networkWrapper.getReadableName(),
interfaceType: interfaceWrapper.getTypeValue(),
macAddress: interfaceWrapper.getMACAddress(),
};
});
};
export type VMNicsTableProps = {
data?: any[];
customData?: object;
row: RowFunction;
columnClasses: string[];
};
const NoDataEmptyMsg = () => <EmptyBox label="Network Interfaces" />;
export const VMNicsTable: React.FC<VMNicsTableProps> = ({
data,
customData,
row: Row,
columnClasses,
}) => {
return (
<Table
aria-label="VM Nics List"
data={data}
NoDataEmptyMsg={NoDataEmptyMsg}
Header={() =>
dimensifyHeader(
[
{
title: 'Name',
sortField: 'name',
transforms: [sortable],
},
{
title: 'Model',
sortField: 'model',
transforms: [sortable],
},
{
title: 'Network',
sortField: 'networkName',
transforms: [sortable],
},
{
title: 'Type',
sortField: 'interfaceType',
transforms: [sortable],
},
{
title: 'MAC Address',
sortField: 'macAddress',
transforms: [sortable],
},
{
title: '',
},
],
columnClasses,
)
}
Row={Row}
customData={{ ...customData, columnClasses }}
virtualize
loaded
/>
);
};
export const VMNics: React.FC<VMLikeEntityTabProps> = ({ obj: vmLikeEntity }) => {
const [isLocked, setIsLocked] = useSafetyFirst(false);
const withProgress = wrapWithProgress(setIsLocked);
return (
<div className="co-m-list">
{!isVMI(vmLikeEntity) && (
<div className="co-m-pane__filter-bar">
<div className="co-m-pane__filter-bar-group">
<Button
variant={ButtonVariant.primary}
id="add-nic"
onClick={() =>
withProgress(
nicModalEnhanced({
blocking: true,
vmLikeEntity,
}).result,
)
}
isDisabled={isLocked}
>
{ADD_NETWORK_INTERFACE}
</Button>
</div>
</div>
)}
<div className="co-m-pane__body">
<VMNicsTable
data={getNicsData(vmLikeEntity)}
customData={{
vmLikeEntity,
withProgress,
isDisabled: isLocked,
}}
row={NicRow}
columnClasses={nicTableColumnClasses}
/>
</div>
</div>
);
};