This repository has been archived by the owner on Jan 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
connect.go
3383 lines (3037 loc) · 105 KB
/
connect.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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the libvirt-go project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (c) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
import (
"fmt"
"os"
"reflect"
"sync"
"unsafe"
)
/*
#cgo pkg-config: libvirt
#include <stdlib.h>
#include "connect_wrapper.h"
*/
import "C"
func init() {
C.virInitialize()
}
const (
VERSION_NUMBER = uint32(C.LIBVIR_VERSION_NUMBER)
)
type ConnectCloseReason int
const (
CONNECT_CLOSE_REASON_ERROR = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_ERROR)
CONNECT_CLOSE_REASON_EOF = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_EOF)
CONNECT_CLOSE_REASON_KEEPALIVE = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_KEEPALIVE)
CONNECT_CLOSE_REASON_CLIENT = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_CLIENT)
)
type ConnectListAllDomainsFlags uint
const (
CONNECT_LIST_DOMAINS_ACTIVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_ACTIVE)
CONNECT_LIST_DOMAINS_INACTIVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_INACTIVE)
CONNECT_LIST_DOMAINS_PERSISTENT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_PERSISTENT)
CONNECT_LIST_DOMAINS_TRANSIENT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_TRANSIENT)
CONNECT_LIST_DOMAINS_RUNNING = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_RUNNING)
CONNECT_LIST_DOMAINS_PAUSED = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_PAUSED)
CONNECT_LIST_DOMAINS_SHUTOFF = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_SHUTOFF)
CONNECT_LIST_DOMAINS_OTHER = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_OTHER)
CONNECT_LIST_DOMAINS_MANAGEDSAVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE)
CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)
CONNECT_LIST_DOMAINS_AUTOSTART = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_AUTOSTART)
CONNECT_LIST_DOMAINS_NO_AUTOSTART = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)
CONNECT_LIST_DOMAINS_HAS_SNAPSHOT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT)
CONNECT_LIST_DOMAINS_NO_SNAPSHOT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)
CONNECT_LIST_DOMAINS_HAS_CHECKPOINT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT)
CONNECT_LIST_DOMAINS_NO_CHECKPOINT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT)
)
type ConnectListAllNetworksFlags uint
const (
CONNECT_LIST_NETWORKS_INACTIVE = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_INACTIVE)
CONNECT_LIST_NETWORKS_ACTIVE = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_ACTIVE)
CONNECT_LIST_NETWORKS_PERSISTENT = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_PERSISTENT)
CONNECT_LIST_NETWORKS_TRANSIENT = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_TRANSIENT)
CONNECT_LIST_NETWORKS_AUTOSTART = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_AUTOSTART)
CONNECT_LIST_NETWORKS_NO_AUTOSTART = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)
)
type ConnectListAllStoragePoolsFlags uint
const (
CONNECT_LIST_STORAGE_POOLS_INACTIVE = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)
CONNECT_LIST_STORAGE_POOLS_ACTIVE = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)
CONNECT_LIST_STORAGE_POOLS_PERSISTENT = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT)
CONNECT_LIST_STORAGE_POOLS_TRANSIENT = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT)
CONNECT_LIST_STORAGE_POOLS_AUTOSTART = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART)
CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART)
CONNECT_LIST_STORAGE_POOLS_DIR = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_DIR)
CONNECT_LIST_STORAGE_POOLS_FS = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_FS)
CONNECT_LIST_STORAGE_POOLS_NETFS = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_NETFS)
CONNECT_LIST_STORAGE_POOLS_LOGICAL = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL)
CONNECT_LIST_STORAGE_POOLS_DISK = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_DISK)
CONNECT_LIST_STORAGE_POOLS_ISCSI = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI)
CONNECT_LIST_STORAGE_POOLS_SCSI = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_SCSI)
CONNECT_LIST_STORAGE_POOLS_MPATH = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_MPATH)
CONNECT_LIST_STORAGE_POOLS_RBD = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_RBD)
CONNECT_LIST_STORAGE_POOLS_SHEEPDOG = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG)
CONNECT_LIST_STORAGE_POOLS_GLUSTER = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER)
CONNECT_LIST_STORAGE_POOLS_ZFS = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ZFS)
CONNECT_LIST_STORAGE_POOLS_VSTORAGE = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE)
CONNECT_LIST_STORAGE_POOLS_ISCSI_DIRECT = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI_DIRECT)
)
type ConnectBaselineCPUFlags uint
const (
CONNECT_BASELINE_CPU_EXPAND_FEATURES = ConnectBaselineCPUFlags(C.VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES)
CONNECT_BASELINE_CPU_MIGRATABLE = ConnectBaselineCPUFlags(C.VIR_CONNECT_BASELINE_CPU_MIGRATABLE)
)
type ConnectCompareCPUFlags uint
const (
CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE = ConnectCompareCPUFlags(C.VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE)
CONNECT_COMPARE_CPU_VALIDATE_XML = ConnectCompareCPUFlags(C.VIR_CONNECT_COMPARE_CPU_VALIDATE_XML)
)
type ConnectListAllInterfacesFlags uint
const (
CONNECT_LIST_INTERFACES_INACTIVE = ConnectListAllInterfacesFlags(C.VIR_CONNECT_LIST_INTERFACES_INACTIVE)
CONNECT_LIST_INTERFACES_ACTIVE = ConnectListAllInterfacesFlags(C.VIR_CONNECT_LIST_INTERFACES_ACTIVE)
)
type ConnectListAllNodeDeviceFlags uint
const (
CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM)
CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV)
CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV)
CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE)
CONNECT_LIST_NODE_DEVICES_CAP_NET = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET)
CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST)
CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET)
CONNECT_LIST_NODE_DEVICES_CAP_SCSI = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI)
CONNECT_LIST_NODE_DEVICES_CAP_STORAGE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE)
CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST)
CONNECT_LIST_NODE_DEVICES_CAP_VPORTS = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS)
CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC)
CONNECT_LIST_NODE_DEVICES_CAP_DRM = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM)
CONNECT_LIST_NODE_DEVICES_CAP_MDEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV)
CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES)
CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV)
CONNECT_LIST_NODE_DEVICES_CAP_CSS_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_CSS_DEV)
CONNECT_LIST_NODE_DEVICES_CAP_VDPA = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_VDPA)
CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD)
CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE)
CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX)
CONNECT_LIST_NODE_DEVICES_INACTIVE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE)
CONNECT_LIST_NODE_DEVICES_ACTIVE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE)
)
type ConnectListAllSecretsFlags uint
const (
CONNECT_LIST_SECRETS_EPHEMERAL = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_EPHEMERAL)
CONNECT_LIST_SECRETS_NO_EPHEMERAL = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL)
CONNECT_LIST_SECRETS_PRIVATE = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_PRIVATE)
CONNECT_LIST_SECRETS_NO_PRIVATE = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_NO_PRIVATE)
)
type ConnectGetAllDomainStatsFlags uint
const (
CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE)
CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE)
CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT)
CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT)
CONNECT_GET_ALL_DOMAINS_STATS_RUNNING = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING)
CONNECT_GET_ALL_DOMAINS_STATS_PAUSED = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED)
CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF)
CONNECT_GET_ALL_DOMAINS_STATS_OTHER = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER)
CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT)
CONNECT_GET_ALL_DOMAINS_STATS_BACKING = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING)
CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS)
)
type ConnectFlags uint
const (
CONNECT_RO = ConnectFlags(C.VIR_CONNECT_RO)
CONNECT_NO_ALIASES = ConnectFlags(C.VIR_CONNECT_NO_ALIASES)
)
type ConnectDomainEventAgentLifecycleState int
const (
CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED = ConnectDomainEventAgentLifecycleState(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED)
CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED = ConnectDomainEventAgentLifecycleState(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED)
)
type ConnectDomainEventAgentLifecycleReason int
const (
CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN = ConnectDomainEventAgentLifecycleReason(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN)
CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED = ConnectDomainEventAgentLifecycleReason(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED)
CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL = ConnectDomainEventAgentLifecycleReason(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL)
)
type CPUCompareResult int
const (
CPU_COMPARE_ERROR = CPUCompareResult(C.VIR_CPU_COMPARE_ERROR)
CPU_COMPARE_INCOMPATIBLE = CPUCompareResult(C.VIR_CPU_COMPARE_INCOMPATIBLE)
CPU_COMPARE_IDENTICAL = CPUCompareResult(C.VIR_CPU_COMPARE_IDENTICAL)
CPU_COMPARE_SUPERSET = CPUCompareResult(C.VIR_CPU_COMPARE_SUPERSET)
)
type NodeAllocPagesFlags uint
const (
NODE_ALLOC_PAGES_ADD = NodeAllocPagesFlags(C.VIR_NODE_ALLOC_PAGES_ADD)
NODE_ALLOC_PAGES_SET = NodeAllocPagesFlags(C.VIR_NODE_ALLOC_PAGES_SET)
)
type NodeSuspendTarget int
const (
NODE_SUSPEND_TARGET_MEM = NodeSuspendTarget(C.VIR_NODE_SUSPEND_TARGET_MEM)
NODE_SUSPEND_TARGET_DISK = NodeSuspendTarget(C.VIR_NODE_SUSPEND_TARGET_DISK)
NODE_SUSPEND_TARGET_HYBRID = NodeSuspendTarget(C.VIR_NODE_SUSPEND_TARGET_HYBRID)
)
type NodeGetCPUStatsAllCPUs int
const (
NODE_CPU_STATS_ALL_CPUS = NodeGetCPUStatsAllCPUs(C.VIR_NODE_CPU_STATS_ALL_CPUS)
)
const (
NODE_MEMORY_STATS_ALL_CELLS = int(C.VIR_NODE_MEMORY_STATS_ALL_CELLS)
)
type ConnectCredentialType int
const (
CRED_USERNAME = ConnectCredentialType(C.VIR_CRED_USERNAME)
CRED_AUTHNAME = ConnectCredentialType(C.VIR_CRED_AUTHNAME)
CRED_LANGUAGE = ConnectCredentialType(C.VIR_CRED_LANGUAGE)
CRED_CNONCE = ConnectCredentialType(C.VIR_CRED_CNONCE)
CRED_PASSPHRASE = ConnectCredentialType(C.VIR_CRED_PASSPHRASE)
CRED_ECHOPROMPT = ConnectCredentialType(C.VIR_CRED_ECHOPROMPT)
CRED_NOECHOPROMPT = ConnectCredentialType(C.VIR_CRED_NOECHOPROMPT)
CRED_REALM = ConnectCredentialType(C.VIR_CRED_REALM)
CRED_EXTERNAL = ConnectCredentialType(C.VIR_CRED_EXTERNAL)
)
type Connect struct {
ptr C.virConnectPtr
}
type NodeInfo struct {
Model string
Memory uint64
Cpus uint
MHz uint
Nodes uint32
Sockets uint32
Cores uint32
Threads uint32
}
// Additional data associated to the connection.
type virConnectionData struct {
errCallbackId *int
closeCallbackId *int
}
var connections map[C.virConnectPtr]*virConnectionData
var connectionsLock sync.RWMutex
func init() {
connections = make(map[C.virConnectPtr]*virConnectionData)
}
func saveConnectionData(c *Connect, d *virConnectionData) {
if c.ptr == nil {
return // Or panic?
}
connectionsLock.Lock()
defer connectionsLock.Unlock()
connections[c.ptr] = d
}
func getConnectionData(c *Connect) *virConnectionData {
connectionsLock.RLock()
d := connections[c.ptr]
connectionsLock.RUnlock()
if d != nil {
return d
}
d = &virConnectionData{}
saveConnectionData(c, d)
return d
}
func releaseConnectionData(c *Connect) {
if c.ptr == nil {
return
}
connectionsLock.Lock()
defer connectionsLock.Unlock()
delete(connections, c.ptr)
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virGetVersion
func GetVersion() (uint32, error) {
var version C.ulong
var err C.virError
ret := C.virGetVersionWrapper(&version, nil, nil, &err)
if ret < 0 {
return 0, makeError(&err)
}
return uint32(version), nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen
func NewConnect(uri string) (*Connect, error) {
var cUri *C.char
if uri != "" {
cUri = C.CString(uri)
defer C.free(unsafe.Pointer(cUri))
}
var err C.virError
ptr := C.virConnectOpenWrapper(cUri, &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Connect{ptr: ptr}, nil
}
type ConnectCredential struct {
Type ConnectCredentialType
Prompt string
Challenge string
DefResult string
Result string
ResultLen int
}
type ConnectAuthCallback func(creds []*ConnectCredential)
type ConnectAuth struct {
CredType []ConnectCredentialType
Callback ConnectAuthCallback
}
//export connectAuthCallback
func connectAuthCallback(ccredlist C.virConnectCredentialPtr, ncred C.uint, callbackID C.int) C.int {
cred := make([]*ConnectCredential, int(ncred))
for i := 0; i < int(ncred); i++ {
ccred := (C.virConnectCredentialPtr)(unsafe.Pointer((uintptr)(unsafe.Pointer(ccredlist)) + (unsafe.Sizeof(*ccredlist) * uintptr(i))))
cred[i] = &ConnectCredential{
Type: ConnectCredentialType(ccred._type),
Prompt: C.GoString(ccred.prompt),
Challenge: C.GoString(ccred.challenge),
DefResult: C.GoString(ccred.defresult),
ResultLen: -1,
}
}
callbackEntry := getCallbackId(int(callbackID))
callback, ok := callbackEntry.(ConnectAuthCallback)
if !ok {
panic("Unexpected callback type")
}
callback(cred)
for i := 0; i < int(ncred); i++ {
ccred := (C.virConnectCredentialPtr)(unsafe.Pointer((uintptr)(unsafe.Pointer(ccredlist)) + (unsafe.Sizeof(*ccredlist) * uintptr(i))))
if cred[i].ResultLen >= 0 {
ccred.result = C.CString(cred[i].Result)
ccred.resultlen = C.uint(cred[i].ResultLen)
}
}
return 0
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenAuth
func NewConnectWithAuth(uri string, auth *ConnectAuth, flags ConnectFlags) (*Connect, error) {
var cUri *C.char
ccredtype := make([]C.int, len(auth.CredType))
for i := 0; i < len(auth.CredType); i++ {
ccredtype[i] = C.int(auth.CredType[i])
}
if uri != "" {
cUri = C.CString(uri)
defer C.free(unsafe.Pointer(cUri))
}
callbackID := registerCallbackId(auth.Callback)
var err C.virError
ptr := C.virConnectOpenAuthWrapper(cUri, &ccredtype[0], C.uint(len(auth.CredType)), C.int(callbackID), C.uint(flags), &err)
freeCallbackId(callbackID)
if ptr == nil {
return nil, makeError(&err)
}
return &Connect{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenAuth
func NewConnectWithAuthDefault(uri string, flags ConnectFlags) (*Connect, error) {
var cUri *C.char
if uri != "" {
cUri = C.CString(uri)
defer C.free(unsafe.Pointer(cUri))
}
var err C.virError
ptr := C.virConnectOpenAuthDefaultWrapper(cUri, C.uint(flags), &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Connect{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenReadOnly
func NewConnectReadOnly(uri string) (*Connect, error) {
var cUri *C.char
if uri != "" {
cUri = C.CString(uri)
defer C.free(unsafe.Pointer(cUri))
}
var err C.virError
ptr := C.virConnectOpenReadOnlyWrapper(cUri, &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Connect{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectClose
func (c *Connect) Close() (int, error) {
var err C.virError
result := int(C.virConnectCloseWrapper(c.ptr, &err))
if result == -1 {
return result, makeError(&err)
}
if result == 0 {
// No more reference to this connection, release data.
releaseConnectionData(c)
c.ptr = nil
}
return result, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectRef
func (c *Connect) Ref() error {
var err C.virError
ret := C.virConnectRefWrapper(c.ptr, &err)
if ret == -1 {
return makeError(&err)
}
return nil
}
type CloseCallback func(conn *Connect, reason ConnectCloseReason)
// Register a close callback for the given destination. Only one
// callback per connection is allowed. Setting a callback will remove
// the previous one.
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectRegisterCloseCallback
func (c *Connect) RegisterCloseCallback(callback CloseCallback) error {
c.UnregisterCloseCallback()
goCallbackId := registerCallbackId(callback)
var err C.virError
res := C.virConnectRegisterCloseCallbackWrapper(c.ptr, C.long(goCallbackId), &err)
if res != 0 {
freeCallbackId(goCallbackId)
return makeError(&err)
}
connData := getConnectionData(c)
connData.closeCallbackId = &goCallbackId
return nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectUnregisterCloseCallback
func (c *Connect) UnregisterCloseCallback() error {
connData := getConnectionData(c)
if connData.closeCallbackId == nil {
return nil
}
var err C.virError
res := C.virConnectUnregisterCloseCallbackWrapper(c.ptr, &err)
if res != 0 {
return makeError(&err)
}
connData.closeCallbackId = nil
return nil
}
//export closeCallback
func closeCallback(conn C.virConnectPtr, reason ConnectCloseReason, goCallbackId int) {
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(CloseCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(&Connect{ptr: conn}, reason)
}
type ConnectIdentity struct {
UserNameSet bool
UserName string
UNIXUserIDSet bool
UNIXUserID uint64
GroupNameSet bool
GroupName string
UNIXGroupIDSet bool
UNIXGroupID uint64
ProcessIDSet bool
ProcessID int64
ProcessTimeSet bool
ProcessTime uint64
SASLUserNameSet bool
SASLUserName string
X509DistinguishedNameSet bool
X509DistinguishedName string
SELinuxContextSet bool
SELinuxContext string
}
func getConnectIdentityFieldInfo(params *ConnectIdentity) map[string]typedParamsFieldInfo {
return map[string]typedParamsFieldInfo{
C.VIR_CONNECT_IDENTITY_USER_NAME: typedParamsFieldInfo{
set: ¶ms.UserNameSet,
s: ¶ms.UserName,
},
C.VIR_CONNECT_IDENTITY_UNIX_USER_ID: typedParamsFieldInfo{
set: ¶ms.UNIXUserIDSet,
ul: ¶ms.UNIXUserID,
},
C.VIR_CONNECT_IDENTITY_GROUP_NAME: typedParamsFieldInfo{
set: ¶ms.GroupNameSet,
s: ¶ms.GroupName,
},
C.VIR_CONNECT_IDENTITY_UNIX_GROUP_ID: typedParamsFieldInfo{
set: ¶ms.UNIXGroupIDSet,
ul: ¶ms.UNIXGroupID,
},
C.VIR_CONNECT_IDENTITY_PROCESS_ID: typedParamsFieldInfo{
set: ¶ms.ProcessIDSet,
l: ¶ms.ProcessID,
},
C.VIR_CONNECT_IDENTITY_PROCESS_TIME: typedParamsFieldInfo{
set: ¶ms.ProcessTimeSet,
ul: ¶ms.ProcessTime,
},
C.VIR_CONNECT_IDENTITY_SASL_USER_NAME: typedParamsFieldInfo{
set: ¶ms.SASLUserNameSet,
s: ¶ms.SASLUserName,
},
C.VIR_CONNECT_IDENTITY_X509_DISTINGUISHED_NAME: typedParamsFieldInfo{
set: ¶ms.X509DistinguishedNameSet,
s: ¶ms.X509DistinguishedName,
},
C.VIR_CONNECT_IDENTITY_SELINUX_CONTEXT: typedParamsFieldInfo{
set: ¶ms.SELinuxContextSet,
s: ¶ms.SELinuxContext,
},
}
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectSetIdentity
func (c *Connect) SetIdentity(ident *ConnectIdentity, flags uint32) error {
if C.LIBVIR_VERSION_NUMBER < 5008000 {
return makeNotImplementedError("virConnectSetIdentity")
}
info := getConnectIdentityFieldInfo(ident)
cparams, cnparams, gerr := typedParamsPackNew(info)
if gerr != nil {
return gerr
}
defer C.virTypedParamsFree(cparams, cnparams)
var err C.virError
ret := C.virConnectSetIdentityWrapper(c.ptr, cparams, cnparams, C.uint(flags), &err)
if ret == -1 {
return makeError(&err)
}
return nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetCapabilities
func (c *Connect) GetCapabilities() (string, error) {
var err C.virError
str := C.virConnectGetCapabilitiesWrapper(c.ptr, &err)
if str == nil {
return "", makeError(&err)
}
capabilities := C.GoString(str)
C.free(unsafe.Pointer(str))
return capabilities, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo
func (c *Connect) GetNodeInfo() (*NodeInfo, error) {
var cinfo C.virNodeInfo
var err C.virError
result := C.virNodeGetInfoWrapper(c.ptr, &cinfo, &err)
if result == -1 {
return nil, makeError(&err)
}
return &NodeInfo{
Model: C.GoString((*C.char)(unsafe.Pointer(&cinfo.model[0]))),
Memory: uint64(cinfo.memory),
Cpus: uint(cinfo.cpus),
MHz: uint(cinfo.mhz),
Nodes: uint32(cinfo.nodes),
Sockets: uint32(cinfo.sockets),
Cores: uint32(cinfo.cores),
Threads: uint32(cinfo.threads),
}, nil
}
func (ni *NodeInfo) GetMaxCPUs() uint32 {
return ni.Nodes * ni.Sockets * ni.Cores * ni.Threads
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetHostname
func (c *Connect) GetHostname() (string, error) {
var err C.virError
str := C.virConnectGetHostnameWrapper(c.ptr, &err)
if str == nil {
return "", makeError(&err)
}
hostname := C.GoString(str)
C.free(unsafe.Pointer(str))
return hostname, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetLibVersion
func (c *Connect) GetLibVersion() (uint32, error) {
var version C.ulong
var err C.virError
ret := C.virConnectGetLibVersionWrapper(c.ptr, &version, &err)
if ret < 0 {
return 0, makeError(&err)
}
return uint32(version), nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetType
func (c *Connect) GetType() (string, error) {
var err C.virError
str := C.virConnectGetTypeWrapper(c.ptr, &err)
if str == nil {
return "", makeError(&err)
}
hypDriver := C.GoString(str)
return hypDriver, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsAlive
func (c *Connect) IsAlive() (bool, error) {
var err C.virError
result := C.virConnectIsAliveWrapper(c.ptr, &err)
if result == -1 {
return false, makeError(&err)
}
if result == 1 {
return true, nil
}
return false, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsEncrypted
func (c *Connect) IsEncrypted() (bool, error) {
var err C.virError
result := C.virConnectIsEncryptedWrapper(c.ptr, &err)
if result == -1 {
return false, makeError(&err)
}
if result == 1 {
return true, nil
}
return false, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsSecure
func (c *Connect) IsSecure() (bool, error) {
var err C.virError
result := C.virConnectIsSecureWrapper(c.ptr, &err)
if result == -1 {
return false, makeError(&err)
}
if result == 1 {
return true, nil
}
return false, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListDefinedDomains
func (c *Connect) ListDefinedDomains() ([]string, error) {
var names [1024](*C.char)
namesPtr := unsafe.Pointer(&names)
var err C.virError
numDomains := C.virConnectListDefinedDomainsWrapper(
c.ptr,
(**C.char)(namesPtr),
1024, &err)
if numDomains == -1 {
return nil, makeError(&err)
}
goNames := make([]string, numDomains)
for k := 0; k < int(numDomains); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListDomains
func (c *Connect) ListDomains() ([]uint32, error) {
var cDomainsIds [512](uint32)
cDomainsPointer := unsafe.Pointer(&cDomainsIds)
var err C.virError
numDomains := C.virConnectListDomainsWrapper(c.ptr, (*C.int)(cDomainsPointer), 512, &err)
if numDomains == -1 {
return nil, makeError(&err)
}
return cDomainsIds[:numDomains], nil
}
// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListInterfaces
func (c *Connect) ListInterfaces() ([]string, error) {
const maxIfaces = 1024
var names [maxIfaces](*C.char)
namesPtr := unsafe.Pointer(&names)
var err C.virError
numIfaces := C.virConnectListInterfacesWrapper(
c.ptr,
(**C.char)(namesPtr),
maxIfaces, &err)
if numIfaces == -1 {
return nil, makeError(&err)
}
goNames := make([]string, numIfaces)
for k := 0; k < int(numIfaces); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListNetworks
func (c *Connect) ListNetworks() ([]string, error) {
const maxNets = 1024
var names [maxNets](*C.char)
namesPtr := unsafe.Pointer(&names)
var err C.virError
numNetworks := C.virConnectListNetworksWrapper(
c.ptr,
(**C.char)(namesPtr),
maxNets, &err)
if numNetworks == -1 {
return nil, makeError(&err)
}
goNames := make([]string, numNetworks)
for k := 0; k < int(numNetworks); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListNWFilters
func (c *Connect) ListNWFilters() ([]string, error) {
const maxFilters = 1024
var names [maxFilters](*C.char)
namesPtr := unsafe.Pointer(&names)
var err C.virError
numNWFilters := C.virConnectListNWFiltersWrapper(
c.ptr,
(**C.char)(namesPtr),
maxFilters, &err)
if numNWFilters == -1 {
return nil, makeError(&err)
}
goNames := make([]string, numNWFilters)
for k := 0; k < int(numNWFilters); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListStoragePools
func (c *Connect) ListStoragePools() ([]string, error) {
const maxPools = 1024
var names [maxPools](*C.char)
namesPtr := unsafe.Pointer(&names)
var err C.virError
numStoragePools := C.virConnectListStoragePoolsWrapper(
c.ptr,
(**C.char)(namesPtr),
maxPools, &err)
if numStoragePools == -1 {
return nil, makeError(&err)
}
goNames := make([]string, numStoragePools)
for k := 0; k < int(numStoragePools); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectListSecrets
func (c *Connect) ListSecrets() ([]string, error) {
const maxSecrets = 1024
var uuids [maxSecrets](*C.char)
uuidsPtr := unsafe.Pointer(&uuids)
var err C.virError
numSecrets := C.virConnectListSecretsWrapper(
c.ptr,
(**C.char)(uuidsPtr),
maxSecrets, &err)
if numSecrets == -1 {
return nil, makeError(&err)
}
goUuids := make([]string, numSecrets)
for k := 0; k < int(numSecrets); k++ {
goUuids[k] = C.GoString(uuids[k])
C.free(unsafe.Pointer(uuids[k]))
}
return goUuids, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeListDevices
func (c *Connect) ListDevices(cap string, flags uint32) ([]string, error) {
ccap := C.CString(cap)
defer C.free(unsafe.Pointer(ccap))
const maxNodeDevices = 1024
var uuids [maxNodeDevices](*C.char)
uuidsPtr := unsafe.Pointer(&uuids)
var err C.virError
numNodeDevices := C.virNodeListDevicesWrapper(
c.ptr, ccap,
(**C.char)(uuidsPtr),
maxNodeDevices, C.uint(flags), &err)
if numNodeDevices == -1 {
return nil, makeError(&err)
}
goUuids := make([]string, numNodeDevices)
for k := 0; k < int(numNodeDevices); k++ {
goUuids[k] = C.GoString(uuids[k])
C.free(unsafe.Pointer(uuids[k]))
}
return goUuids, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByID
func (c *Connect) LookupDomainById(id uint32) (*Domain, error) {
var err C.virError
ptr := C.virDomainLookupByIDWrapper(c.ptr, C.int(id), &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByName
func (c *Connect) LookupDomainByName(id string) (*Domain, error) {
cName := C.CString(id)
defer C.free(unsafe.Pointer(cName))
var err C.virError
ptr := C.virDomainLookupByNameWrapper(c.ptr, cName, &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByUUIDString
func (c *Connect) LookupDomainByUUIDString(uuid string) (*Domain, error) {
cUuid := C.CString(uuid)
defer C.free(unsafe.Pointer(cUuid))
var err C.virError
ptr := C.virDomainLookupByUUIDStringWrapper(c.ptr, cUuid, &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByUUID
func (c *Connect) LookupDomainByUUID(uuid []byte) (*Domain, error) {
if len(uuid) != C.VIR_UUID_BUFLEN {
return nil, fmt.Errorf("UUID must be exactly %d bytes in size",
int(C.VIR_UUID_BUFLEN))
}
cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN)
for i := 0; i < C.VIR_UUID_BUFLEN; i++ {
cUuid[i] = C.uchar(uuid[i])
}
var err C.virError
ptr := C.virDomainLookupByUUIDWrapper(c.ptr, &cUuid[0], &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXML
func (c *Connect) DomainCreateXML(xmlConfig string, flags DomainCreateFlags) (*Domain, error) {
cXml := C.CString(string(xmlConfig))
defer C.free(unsafe.Pointer(cXml))
var err C.virError
ptr := C.virDomainCreateXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXMLWithFiles
func (c *Connect) DomainCreateXMLWithFiles(xmlConfig string, files []os.File, flags DomainCreateFlags) (*Domain, error) {
cXml := C.CString(string(xmlConfig))
defer C.free(unsafe.Pointer(cXml))
cfiles := make([]C.int, len(files))
for i := 0; i < len(files); i++ {
cfiles[i] = C.int(files[i].Fd())
}
var err C.virError
ptr := C.virDomainCreateXMLWithFilesWrapper(c.ptr, cXml, C.uint(len(files)), (&cfiles[0]), C.uint(flags), &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDefineXML
func (c *Connect) DomainDefineXML(xmlConfig string) (*Domain, error) {
cXml := C.CString(string(xmlConfig))
defer C.free(unsafe.Pointer(cXml))
var err C.virError
ptr := C.virDomainDefineXMLWrapper(c.ptr, cXml, &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDefineXMLFlags
func (c *Connect) DomainDefineXMLFlags(xmlConfig string, flags DomainDefineFlags) (*Domain, error) {
if C.LIBVIR_VERSION_NUMBER < 1002012 {
return nil, makeNotImplementedError("virDomainDefineXMLFlags")
}
cXml := C.CString(string(xmlConfig))
defer C.free(unsafe.Pointer(cXml))
var err C.virError
ptr := C.virDomainDefineXMLFlagsWrapper(c.ptr, cXml, C.uint(flags), &err)
if ptr == nil {
return nil, makeError(&err)
}
return &Domain{ptr: ptr}, nil
}
// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListDefinedInterfaces
func (c *Connect) ListDefinedInterfaces() ([]string, error) {
const maxIfaces = 1024
var names [maxIfaces](*C.char)
namesPtr := unsafe.Pointer(&names)
var err C.virError
numIfaces := C.virConnectListDefinedInterfacesWrapper(
c.ptr,
(**C.char)(namesPtr),
maxIfaces, &err)
if numIfaces == -1 {
return nil, makeError(&err)
}
goNames := make([]string, numIfaces)
for k := 0; k < int(numIfaces); k++ {
goNames[k] = C.GoString(names[k])