/
buttons.js
195 lines (165 loc) · 5.36 KB
/
buttons.js
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
import { entityTypes, vmUpStates } from '_/constants'
import getPluginApi from '_/plugin-api'
import config from '_/plugin-config'
import { msg } from '_/intl-messages'
import { showVmCpuPinningModal, showHostCpuPinningModal } from './showCpuPinning'
import { showVmManageGpuModal } from './showVmManageGpu'
import { showVmMigrateModal } from './showVmMigrate'
import { showClusterUpgradeWizard } from './showClusterUpgrade'
import { showVmExportModal } from './showVmExport'
import { showHostCopyNetworksModal } from './showHostCopyNetworks'
import { showStorageConnectionsModal } from './showStorageConnectionsModal'
function isVmUp (vm) {
return vmUpStates.includes(vm.status)
}
// for the time being the vGPU dialog will be available on both, vm devices tab and host devices tab
function addVmManageGpuButton () {
getPluginApi().addDetailPlaceActionButton(entityTypes.vm, entityTypes.hostDevices, msg.vmManageGpuButton(), {
onClick: function (_selectedItems, parent) {
showVmManageGpuModal(parent)
},
index: 2,
id: 'VmManageGpu',
})
getPluginApi().addDetailPlaceActionButton(entityTypes.vm, entityTypes.vmDevices, msg.vmManageGpuButton(), {
onClick: function (_selectedItems, parent) {
showVmManageGpuModal(parent)
},
id: 'VmManageGpuVmDevicesView',
})
}
function addVmCpuPinningButton () {
getPluginApi().addDetailPlaceActionButton(entityTypes.vm, entityTypes.hostDevices, msg.cpuPinningModalButton(), {
onClick: function (_selectedItems, parent) {
showVmCpuPinningModal(parent)
},
index: 3,
id: 'VmCpuPinning',
})
}
/**
* "Migrate" button to VMs List. Enabled when at least 1 running VM is selected.
*/
function addVmMigrateButton () {
let selectedUpVms = []
getPluginApi().addMenuPlaceActionButton(entityTypes.vm, msg.migrateVmButton(), {
onClick: function () {
showVmMigrateModal(selectedUpVms)
},
isEnabled: function (selectedVms) {
selectedUpVms = selectedVms.filter(isVmUp)
return selectedUpVms.length > 0 || config.useFakeData
},
index: 8,
id: 'VmMigrate',
})
}
/**
* "Migrate" button to Host Detail / VMs List. Enabled when at least 1 running VM is selected.
*/
function addHostVmMigrateButton () {
let selectedUpVms = []
getPluginApi().addDetailPlaceActionButton(entityTypes.host, entityTypes.vm, msg.migrateVmButton(), {
onClick: function () {
showVmMigrateModal(selectedUpVms)
},
isEnabled: function (selectedVms) {
selectedUpVms = selectedVms.filter(isVmUp)
return selectedUpVms.length > 0 || config.useFakeData
},
index: 5,
id: 'HostVmMigrate',
})
}
/**
* "Export" button to VMs List. Enabled when 1 down VM is selected.
*/
function addVmExportButton () {
getPluginApi().addMenuPlaceActionButton(entityTypes.vm, msg.exportVmButton(), {
onClick: function ([selectedDownVm]) {
showVmExportModal(selectedDownVm)
},
isEnabled: function (selectedVms) {
return (
selectedVms.length === 1 &&
selectedVms[0] &&
selectedVms[0].status === 'Down' &&
selectedVms[0].managed
)
},
index: 13,
id: 'VmExport',
moreMenu: true,
})
}
/**
* "Upgrade" button to Cluster List. Enabled when exactly 1 cluster is selected.
*/
function addClusterUpgradeButton () {
getPluginApi().addMenuPlaceActionButton(entityTypes.cluster, msg.clusterUpgradeButton(), {
onClick: function ([selectedCluster]) {
if (selectedCluster.id && selectedCluster.name) {
showClusterUpgradeWizard(selectedCluster)
}
},
isEnabled: function (selectedClusters) {
return selectedClusters.length === 1 && selectedClusters[0].managed
},
index: 3,
id: 'ClusterUpgrade',
})
}
/**
* "Copy Host Networks" button in Host List. Enabled when exactly 1 host is selected.
*/
function addHostCopyNetworksButton () {
getPluginApi().addMenuPlaceActionButton(entityTypes.host, msg.hostCopyNetworksButton(), {
onClick: function ([selectedHost]) {
if (selectedHost.id && selectedHost.name) {
showHostCopyNetworksModal(selectedHost)
}
},
isEnabled: function (selectedHosts) {
return selectedHosts.length === 1 && selectedHosts[0].managed
},
index: 9,
id: 'HostCopyNetworksButton',
})
}
function addHostCpuPinningButton () {
getPluginApi().addDetailPlaceActionButton(entityTypes.host, entityTypes.hostDevices, msg.cpuPinningModalButton(), {
onClick: function (_selectedItems, parent) {
showHostCpuPinningModal(parent)
},
id: 'HostCpuPinning',
})
}
/**
* "Connections" button in the Storage Domains list. Enabled when exactly 1 iSCSI domain is selected
*/
function addManageStorageConnectionsButton () {
getPluginApi().addMenuPlaceActionButton(entityTypes.storage, msg.storageConnectionsManageButton(), {
onClick: function ([selectedDomain]) {
showStorageConnectionsModal(selectedDomain)
},
isEnabled: function (selectedDomains) {
return (
selectedDomains.length === 1 &&
selectedDomains[0]?.type?.toLowerCase() === 'iscsi'
)
},
index: 4,
id: 'StorageConnectionsButton',
})
}
export function addButtons () {
addVmManageGpuButton()
addVmCpuPinningButton()
addVmMigrateButton()
addHostVmMigrateButton()
addVmExportButton()
addClusterUpgradeButton()
addHostCopyNetworksButton()
addHostCpuPinningButton()
addManageStorageConnectionsButton()
}