-
Notifications
You must be signed in to change notification settings - Fork 3
/
host.go
493 lines (455 loc) · 17.8 KB
/
host.go
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
// Copyright (C) 2017 Battelle Memorial Institute
// All rights reserved.
//
// This software may be modified and distributed under the terms
// of the BSD-2 license. See the LICENSE file for details.
package ovirtapi
import (
"encoding/json"
"fmt"
)
// TransparentHugePages Type representing a transparent huge pages (THP) support
type TransparentHugePages struct {
Enabled string `json:"enabled,omitempty"`
}
// VMSummary Type containing information related to virtual machines on a particular host.
type VMSummary struct {
// The number of virtual machines active on the host.
Active int `json:"active,omitempty,string"`
// The number of virtual machines migrating to or from the host.
Migrating int `json:"migrating,omitempty,string"`
// The number of virtual machines present on the host.
Total int `json:"total,omitempty,string"`
}
// User Represents a user in the system.
type User struct {
//Free text containing comments about this object.
Comment string `json:"comment,omitempty"`
Department string `json:"department,omitempty"`
//A human-readable description in plain text.
Description string `json:"description,omitempty"`
DomainEntryID string `json:"domain_entry_id,omitempty"`
Email string `json:"email,omitempty"`
//A unique identifier.
ID string `json:"id,omitempty"`
LastName string `json:"last_name,omitempty"`
LoggedIn string `json:"logged_in,omitempty"`
//A human-readable name in plain text.
Name string `json:"name,omitempty"`
//Namespace where the user resides.
Namespace string `json:"namespace,omitempty"`
Password string `json:"password,omitempty"`
//Similar to user_name.
Principal string `json:"principal,omitempty"`
//The user's username.
UserName string `json:"user_name,omitempty"`
}
type SSH struct {
AuthenticationMethod string `json:"authentication_method,omitempty"`
// Free text containing comments about this object.
Comment string `json:"comment,omitempty"`
// A human-readable description in plain text.
Description string `json:"description,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
// A unique identifier.
ID string `json:"id,omitempty"`
// A human-readable name in plain text.
Name string `json:"name,omitempty"`
Port int `json:"port,omitempty,string"`
User User `json:"user,omitempty"`
}
type SPM struct {
Priority int `json:"priority,omitempty,string"`
Status string `json:"status,omitempty"`
}
// SELinux Represents SELinux in the system.
type SELinux struct {
Mode string `json:"mode,omitempty"`
}
type PMProxy struct {
Type string `json:"type,omitempty"`
}
// Option ...
type Option struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
}
// Agent Type representing a fence agent.
type Agent struct {
// Fence agent address.
Address string `json:"address,omitempty"`
// Free text containing comments about this object.
Comment string `json:"comment,omitempty"`
// Specifies whether the agent should be used concurrently or sequentially.
Concurrent string `json:"concurrent,omitempty"`
// A human-readable description in plain text.
Description string `json:"description,omitempty"`
// Specifies whether the options should be encrypted.
EncryptOptions string `json:"encrypt_options,omitempty"`
// A unique identifier.
ID string `json:"id,omitempty"`
// A human-readable name in plain text.
Name string `json:"name,omitempty"`
// Fence agent options (comma-delimited list of key-value pairs).
Options []Option `json:"options,omitempty"`
// The order of this agent if used with other agents.
Order int `json:"order,omitempty,string"`
// Fence agent password.
Password string `json:"password,omitempty"`
// Fence agent port.
Port int `json:"port,omitempty,string"`
// Fence agent type.
Type string `json:"type,omitempty"`
// Fence agent user name.
Username string `json:"username,omitempty"`
}
// PowerManagement ...
type PowerManagement struct {
// The host name or IP address of the host.
Address string `json:"address,omitempty"`
// Specifies fence agent options when multiple fences are used.
Agents []Agent `json:"agents,omitempty"`
// Toggles the automated power control of the host in order to save energy.
AutomaticPMEnabled string `json:"automatic_pm_enabled,omitempty"`
// Indicates whether power management configuration is enabled or disabled.
Enabled string `json:"enabled,omitempty"`
// Toggles whether to determine if kdump is running on the host before it is shut down.
KdumpDetection string `json:"kdump_detection,omitempty"`
// Fencing options for the selected type= specified with the option name="" and value="" strings.
Options []Option `json:"options,omitempty"`
// A valid, robust password for power management.
Password string `json:"password,omitempty"`
// Determines the power management proxy.
PMProxies PMProxy `json:"pm_proxies,omitempty"`
// Determines the power status of the host.
Status string `json:"status,omitempty"`
// Fencing device code.
Type string `json:"type,omitempty"`
// A valid user name for power management.
Username string `json:"username,omitempty"`
}
// KSM ...
type KSM struct {
Enabled string `json:"enabled,omitempty"`
MergeAcrossNodes string `json:"merge_across_nodes,omitempty"`
}
// HostDevicePassthrough ...
type HostDevicePassthrough struct {
Enabled string `json:"enabled,omitempty"`
}
// ISCSIDetails ...
type ISCSIDetails struct {
Address string `json:"address,omitempty"`
DiskID string `json:"disk_id,omitempty"`
Initiator string `json:"initiator,omitempty"`
LunMapping int `json:"lun_mapping,omitempty,string"`
Password string `json:"password,omitempty"`
Paths int `json:"paths,omitempty,string"`
Port int `json:"port,omitempty,string"`
Portal string `json:"portal,omitempty"`
ProductID string `json:"product_id,omitempty"`
Serial string `json:"serial,omitempty"`
Size int `json:"size,omitempty,string"`
Status string `json:"status,omitempty"`
StorageDomainID string `json:"storage_domain_id,omitempty"`
Target string `json:"target,omitempty"`
Username string `json:"username,omitempty"`
VendorID string `json:"vendor_id,omitempty"`
VolumeGroupID string `json:"volume_group_id,omitempty"`
}
// HostedEngine ...
type HostedEngine struct {
Active string `json:"active,omitempty"`
Configured string `json:"configured,omitempty"`
GlobalMaintenance string `json:"global_maintenance,omitempty"`
LocalMaintenance string `json:"local_maintenance,omitempty"`
Score int `json:"score,omitempty,string"`
}
// HardwareInformation Represents hardware information of host.
type HardwareInformation struct {
// Type of host's CPU.
Family string `json:"family,omitempty"`
// Manufacturer of the host's machine and hardware vendor.
Manufacturer string `json:"manufacturer,omitempty"`
// Host's product name (for example RHEV Hypervisor).
ProductName string `json:"product_name,omitempty"`
// Unique ID for host's chassis.
SerialNumber string `json:"serial_number,omitempty"`
// Supported sources of random number generator.
SupportedRngSources []string `json:"supported_rng_sources>supported_rng_source,omitempty"`
// Unique ID for each host.
UUID string `json:"uuid,omitempty"`
// Unique name for each of the manufacturer.
Version string `json:"version,omitempty"`
}
// Host Type representing a host.
type Host struct {
OvirtObject
// The host address (FQDN/IP).
Address string `json:"address,omitempty"`
// The host auto non uniform memory access (NUMA) status.
AutoNumaStatus string `json:"auto_numa_status,omitempty"`
// The host certificate.
Certificate *Certificate `json:"certificate,omitempty"`
// Free text containing comments about this object.
Comment string `json:"comment,omitempty"`
// The CPU type of this host.
CPU *CPU `json:"cpu,omitempty"`
// A human-readable description in plain text.
Description string `json:"description,omitempty"`
// Specifies whether host device passthrough is enabled on this host.
DevicePassthrough *HostDevicePassthrough `json:"device_passthrough,omitempty"`
// Optionally specify the display address of this host explicitly.
Display *Display `json:"display,omitempty"`
// The host external status.
ExternalStatus string `json:"external_status,omitempty"`
// The host hardware information.
HardwareInformation *HardwareInformation `json:"hardware_information,omitempty"`
// The self-hosted engine status of this host.
HostedEngine *HostedEngine `json:"hosted_engine,omitempty"`
// A unique identifier.
ID string `json:"id,omitempty"`
// The host iSCSI details.
ISCSI *ISCSIDetails `json:"iscsi,omitempty"`
// The host KDUMP status.
KdumpStatus string `json:"kdump_status,omitempty"`
// Kernel SamePage Merging (KSM) reduces references to memory pages from multiple identical pages to a single page reference.
KSM KSM `json:"ksm,omitempty"`
// The host libvirt version.
LibvirtVersion *Version `json:"libvirt_version,omitempty"`
// The max scheduling memory on this host in bytes.
MaxSchedulingMemory int `json:"max_scheduling_memory,omitempty"`
// The amount of physical memory on this host in bytes.
Memory int `json:"memory,omitempty"`
// A human-readable name in plain text.
Name string `json:"name,omitempty"`
// Specifies whether non uniform memory access (NUMA) is supported on this host.
NumaSupported string `json:"numa_supported,omitempty"`
// The operating system on this host.
OS *OperatingSystem `json:"os,omitempty"`
// Specifies whether we should override firewall definitions.
OverrideIptables string `json:"override_iptables,omitempty"`
// The host port.
Port int `json:"port,omitempty,string"`
// The host power management definitions.
PowerManagement *PowerManagement `json:"power_management,omitempty"`
// The protocol that the engine uses to communicate with the host.
Protocol string `json:"protocol,omitempty"`
// When creating a new host, a root password is required if the password authentication method is chosen, but this is not subsequently included in the representation.
RootPassword string `json:"root_password,omitempty"`
// The host SElinux status.
SELinux *SELinux `json:"se_linux,omitempty"`
// The host storage pool manager (SPM) status and definition.
SPM *SPM `json:"spm,omitempty"`
// The SSH definitions.
SSH *SSH `json:"ssh,omitempty"`
// The host status.
Status string `json:"status,omitempty"`
// The host status details.
StatusDetail string `json:"status_detail,omitempty"`
// The virtual machine summary - how many are active, migrating and total.
Summary *VMSummary `json:"summary,omitempty"`
// Transparent huge page support expands the size of memory pages beyond the standard 4 KiB limit.
TransparentHugePages *TransparentHugePages `json:"transparent_huge_pages,omitempty"`
// Indicates if the host contains a full installation of the operating system or a scaled-down version intended only to host virtual machines.
Type string `json:"type,omitempty"`
// Specifies whether there is an oVirt-related update on this host.
UpdateAvailable string `json:"update_available,omitempty"`
// The version of VDSM.
Version *Version `json:"version,omitempty"`
}
// Activate the host for use, such as running virtual machines.
func (host *Host) Activate(async string) error {
return host.DoAction("activate", Action {
Async: async,
})
}
// Approve a pre-installed Hypervisor host for usage in the virtualization environment.
// This action also accepts an optional cluster element to define the target cluster for this host.
func (host *Host) Approve(async string, cluster *Cluster, newHost *Host) error {
return host.DoAction("Approve", Action {
Async: async,
Cluster: cluster,
Host: newHost,
})
}
// CommitNetConfig Marks the network configuration as good and persists it inside the host.
// An API user commits the network configuration to persist a host network interface attachment or detachment, or persist the creation and deletion of a bonded interface.
func (host *Host) CommitNetConfig(async string) error {
return host.DoAction("commitnetconfig", Action {
Async: async,
})
}
// Deactivate the host to perform maintenance tasks.
func (host *Host) Deactivate(async, reason, stopGlusterService string) error {
return host.DoAction("deactivate", Action {
Async: async,
Reason: reason,
StopGlusterService: stopGlusterService,
})
}
// EnrollCertificate Enroll certificate of the host. Useful in case you get a warning that it is about to, or already expired.
func (host *Host) EnrollCertificate(async string) error {
return host.DoAction("enrolcertificate", Action {
Async: async,
})
}
// Fence Controls host's power management device.
func (host *Host) Fence(async, fenceType string) error {
return host.DoAction("fence", Action {
Async: async,
})
}
// ForceSelectSPM Manually set a host as the storage pool manager (SPM).
func (host *Host) ForceSelectSPM(async string) error {
return host.DoAction("fence", Action {
Async: async,
})
}
// Install VDSM and related software on the host. The host type defines additional parameters for the action.
func (host *Host) Install(async, deployHostedEngine, undeployHostedEngine, image, rootPassword string, additionalParameters *Host, ssh *SSH) error {
return host.DoAction("install", Action {
Async: async,
DeployHostedEngine: deployHostedEngine,
Host: additionalParameters,
Image: image,
RootPassword: rootPassword,
SSH: ssh,
UnDeployHostedEngine: undeployHostedEngine,
})
}
// ISCSIDiscover Discover iSCSI targets on the host, using the initiator details.
func (host *Host) ISCSIDiscover(async string, iscsi *ISCSIDetails) error {
return host.DoAction("iscsidiscover", Action {
Async: async,
ISCSI: iscsi,
})
}
// ISCSILogin Login to iSCSI targets on the host, using the target details.
func (host *Host) ISCSILogin(async string, iscsi *ISCSIDetails) error {
return host.DoAction("iscsilogin", Action {
Async: async,
ISCSI: iscsi,
})
}
// Refresh the host devices and capabilities.
func (host *Host) Refresh(async string) error {
return host.DoAction("refresh", Action {
Async: async,
})
}
// // SetupNetwork This method is used to change the configuration of the network interfaces of a host.
// func (host *Host) SetupNetwork(async, checkConnectivity string, connectivityTimeout int, modifiedBonds []HostNic, modifiedLabels []NetworkLabels, modifiedNetworkAttachments []NetworkAttachments, removedBonds []HostNIC, removedLabels []NetworkLabel, removedNetworkAttachments []NetworkAttachment, synchronizedNetworkAttachments []NetworkAttachments) error {
// return host.DoAction("refresh", Action {
// Async: async,
// CheckConnectivity: checkConnectivity,
// ConnectivityTimeout: connectivityTimeout,
// ModifiedBonds: modifiedBonds,
// ModifiedLabels: modifiedLabels,
// ModifiedNetworkAttachments: modifiedNetworkAttachments,
// RemovedBonds: removedBonds,
// RemovedLabels: removedLabels,
// RemovedNetworkAttachments: removedNetworkAttachments,
// SynchronizedNetworkAttachments: synchronizedNetworkAttachments,
// })
// }
// UnregisteredStorageDomainsDiscover ...
func (host *Host) UnregisteredStorageDomainsDiscover(async string, iscsi *ISCSIDetails) error {
return host.DoAction("unregisteredstoragedomainsdiscover", Action {
Async: async,
ISCSI: iscsi,
})
}
// Upgrade VDSM and selected software on the host.
func (host *Host) Upgrade(async string) error {
return host.DoAction("upgrade", Action {
Async: async,
})
}
// UpgradeCheck Check if there are upgrades available for the host. If there are upgrades available an icon will be displayed next to host status icon in the webadmin. Audit log messages are also added to indicate the availability of upgrades. The upgrade can be started from the webadmin or by using the upgrade host action.
func (host *Host) UpgradeCheck() error {
return host.DoAction("upgradecheck", Action{})
}
// GetHost retrieve a host from the server
func (con *Connection) GetHost(id string) (*Host, error) {
body, err := con.GetLinkBody("hosts", id)
if err != nil {
return nil, err
}
host := con.NewHost()
err = json.Unmarshal(body, host)
if err != nil {
return nil, err
}
return host, err
}
// Update Synchronize the local Host with a copy from the server
func (host *Host) Update() error {
if host.Href == "" {
return fmt.Errorf("host has not been saved to the server")
}
body, err := host.Con.Request("GET", host.Con.ResolveLink(host.Href), nil)
if err != nil {
return err
}
tempHost := Host{OvirtObject: OvirtObject{Con: host.Con}}
err = json.Unmarshal(body, &tempHost)
if err != nil {
return err
}
*host = tempHost
return nil
}
// GetAllHosts Retrieve all the hosts from the server
func (con *Connection) GetAllHosts() ([]*Host, error) {
body, err := con.GetLinkBody("hosts", "")
if err != nil {
return nil, err
}
hosts := []*Host{}
err = json.Unmarshal(body, &struct {
Host *[]*Host
}{&hosts})
if err != nil {
return nil, err
}
for _, host := range hosts {
host.Con = con
}
return hosts, err
}
// NewHost Create a new host structure
func (con *Connection) NewHost() *Host {
return &Host{OvirtObject: OvirtObject{Con: con}}
}
// Save Updates the server with the local copy of the host
func (host *Host) Save() error {
body, err := json.MarshalIndent(host, "", " ")
if err != nil {
return err
}
// If there is a link, it is an already saved host, we need to update it
if host.Href != "" {
body, err = host.Con.Request("PUT", host.Con.ResolveLink(host.Href), body)
if err != nil {
return err
}
} else {
link, err := host.Con.GetLink("hosts")
if err != nil {
return err
}
body, err = host.Con.Request("POST", link, body)
if err != nil {
return err
}
}
tempHost := Host{OvirtObject: OvirtObject{Con: host.Con}}
err = json.Unmarshal(body, &tempHost)
if err != nil {
return err
}
*host = tempHost
return nil
}