-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
schema.go
1024 lines (856 loc) · 29 KB
/
schema.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 KubeVirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2017,2018 Red Hat, Inc.
*
*/
//go:generate deepcopy-gen -i . --go-header-file ../../../../hack/boilerplate/boilerplate.go.txt
package api
import (
"encoding/json"
"encoding/xml"
"fmt"
"strings"
kubev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
v1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/client-go/precond"
)
// For versioning of the virt-handler and -launcher communication,
// you need to increase the Version const when making changes,
// and make necessary changes in the cmd and notify rpc implementation!
const (
DomainVersion = "v1"
)
type LifeCycle string
type StateChangeReason string
const (
NoState LifeCycle = "NoState"
Running LifeCycle = "Running"
Blocked LifeCycle = "Blocked"
Paused LifeCycle = "Paused"
Shutdown LifeCycle = "ShuttingDown"
Shutoff LifeCycle = "Shutoff"
Crashed LifeCycle = "Crashed"
PMSuspended LifeCycle = "PMSuspended"
// Common reasons
ReasonUnknown StateChangeReason = "Unknown"
// ShuttingDown reasons
ReasonUser StateChangeReason = "User"
// Shutoff reasons
ReasonShutdown StateChangeReason = "Shutdown"
ReasonDestroyed StateChangeReason = "Destroyed"
ReasonMigrated StateChangeReason = "Migrated"
ReasonCrashed StateChangeReason = "Crashed"
ReasonPanicked StateChangeReason = "Panicked"
ReasonSaved StateChangeReason = "Saved"
ReasonFailed StateChangeReason = "Failed"
ReasonFromSnapshot StateChangeReason = "FromSnapshot"
// NoState reasons
ReasonNonExistent StateChangeReason = "NonExistent"
// Pause reasons
ReasonPausedUnknown StateChangeReason = "Unknown"
ReasonPausedUser StateChangeReason = "User"
ReasonPausedMigration StateChangeReason = "Migration"
ReasonPausedSave StateChangeReason = "Save"
ReasonPausedDump StateChangeReason = "Dump"
ReasonPausedIOError StateChangeReason = "IOError"
ReasonPausedWatchdog StateChangeReason = "Watchdog"
ReasonPausedFromSnapshot StateChangeReason = "FromSnapshot"
ReasonPausedShuttingDown StateChangeReason = "ShuttingDown"
ReasonPausedSnapshot StateChangeReason = "Snapshot"
ReasonPausedCrashed StateChangeReason = "Crashed"
ReasonPausedStartingUp StateChangeReason = "StartingUp"
ReasonPausedPostcopy StateChangeReason = "Postcopy"
ReasonPausedPostcopyFailed StateChangeReason = "PostcopyFailed"
UserAliasPrefix = "ua-"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Domain struct {
metav1.TypeMeta
ObjectMeta metav1.ObjectMeta
Spec DomainSpec
Status DomainStatus
}
type DomainStatus struct {
Status LifeCycle
Reason StateChangeReason
Interfaces []InterfaceStatus
OSInfo GuestOSInfo
}
type DomainSysInfo struct {
Hostname string
OSInfo GuestOSInfo
Timezone Timezone
}
type GuestOSInfo struct {
Name string
KernelRelease string
Version string
PrettyName string
VersionId string
KernelVersion string
Machine string
Id string
}
type InterfaceStatus struct {
Name string
Mac string
Ip string
IPs []string
InterfaceName string
}
type Timezone struct {
Zone string
Offset int
}
type Filesystem struct {
Name string
Mountpoint string
Type string
UsedBytes int
TotalBytes int
}
type User struct {
Name string
Domain string
LoginTime float64
}
// DomainGuestInfo represent guest agent info for specific domain
type DomainGuestInfo struct {
Interfaces []InterfaceStatus
OSInfo *GuestOSInfo
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type DomainList struct {
metav1.TypeMeta
ListMeta metav1.ListMeta
Items []Domain
}
// DomainSpec represents the actual conversion to libvirt XML. The fields must be
// tagged, and they must correspond to the libvirt domain as described in
// https://libvirt.org/formatdomain.html.
type DomainSpec struct {
XMLName xml.Name `xml:"domain"`
Type string `xml:"type,attr"`
XmlNS string `xml:"xmlns:qemu,attr,omitempty"`
Name string `xml:"name"`
UUID string `xml:"uuid,omitempty"`
Memory Memory `xml:"memory"`
MemoryBacking *MemoryBacking `xml:"memoryBacking,omitempty"`
OS OS `xml:"os"`
SysInfo *SysInfo `xml:"sysinfo,omitempty"`
Devices Devices `xml:"devices"`
Clock *Clock `xml:"clock,omitempty"`
Resource *Resource `xml:"resource,omitempty"`
QEMUCmd *Commandline `xml:"qemu:commandline,omitempty"`
Metadata Metadata `xml:"metadata,omitempty"`
Features *Features `xml:"features,omitempty"`
CPU CPU `xml:"cpu"`
VCPU *VCPU `xml:"vcpu"`
CPUTune *CPUTune `xml:"cputune"`
IOThreads *IOThreads `xml:"iothreads,omitempty"`
}
type CPUTune struct {
VCPUPin []CPUTuneVCPUPin `xml:"vcpupin"`
IOThreadPin []CPUTuneIOThreadPin `xml:"iothreadpin,omitempty"`
EmulatorPin *CPUEmulatorPin `xml:"emulatorpin"`
}
type CPUTuneVCPUPin struct {
VCPU uint `xml:"vcpu,attr"`
CPUSet string `xml:"cpuset,attr"`
}
type CPUTuneIOThreadPin struct {
IOThread uint `xml:"iothread,attr"`
CPUSet string `xml:"cpuset,attr"`
}
type CPUEmulatorPin struct {
CPUSet string `xml:"cpuset,attr"`
}
type VCPU struct {
Placement string `xml:"placement,attr"`
CPUs uint32 `xml:",chardata"`
}
type CPU struct {
Mode string `xml:"mode,attr,omitempty"`
Model string `xml:"model,omitempty"`
Features []CPUFeature `xml:"feature"`
Topology *CPUTopology `xml:"topology"`
NUMA *NUMA `xml:"numa,omitempty"`
}
type NUMA struct {
Cells []NUMACell `xml:"cell"`
}
type NUMACell struct {
ID string `xml:"id,attr"`
CPUs string `xml:"cpus,attr"`
Memory string `xml:"memory,attr,omitempty"`
Unit string `xml:"unit,attr,omitempty"`
MemoryAccess string `xml:"memAccess,attr,omitempty"`
}
type CPUFeature struct {
Name string `xml:"name,attr"`
Policy string `xml:"policy,attr,omitempty"`
}
type CPUTopology struct {
Sockets uint32 `xml:"sockets,attr,omitempty"`
Cores uint32 `xml:"cores,attr,omitempty"`
Threads uint32 `xml:"threads,attr,omitempty"`
}
type Features struct {
ACPI *FeatureEnabled `xml:"acpi,omitempty"`
APIC *FeatureEnabled `xml:"apic,omitempty"`
Hyperv *FeatureHyperv `xml:"hyperv,omitempty"`
SMM *FeatureEnabled `xml:"smm,omitempty"`
KVM *FeatureKVM `xml:"kvm,omitempty"`
PVSpinlock *FeaturePVSpinlock `xml:"pvspinlock,omitempty"`
}
type FeatureHyperv struct {
Relaxed *FeatureState `xml:"relaxed,omitempty"`
VAPIC *FeatureState `xml:"vapic,omitempty"`
Spinlocks *FeatureSpinlocks `xml:"spinlocks,omitempty"`
VPIndex *FeatureState `xml:"vpindex,omitempty"`
Runtime *FeatureState `xml:"runtime,omitempty"`
SyNIC *FeatureState `xml:"synic,omitempty"`
SyNICTimer *FeatureState `xml:"stimer,omitempty"`
Reset *FeatureState `xml:"reset,omitempty"`
VendorID *FeatureVendorID `xml:"vendor_id,omitempty"`
Frequencies *FeatureState `xml:"frequencies,omitempty"`
Reenlightenment *FeatureState `xml:"reenlightenment,omitempty"`
TLBFlush *FeatureState `xml:"tlbflush,omitempty"`
IPI *FeatureState `xml:"ipi,omitempty"`
EVMCS *FeatureState `xml:"evmcs,omitempty"`
}
type FeatureSpinlocks struct {
State string `xml:"state,attr,omitempty"`
Retries *uint32 `xml:"retries,attr,omitempty"`
}
type FeaturePVSpinlock struct {
State string `xml:"state,attr,omitempty"`
}
type FeatureVendorID struct {
State string `xml:"state,attr,omitempty"`
Value string `xml:"value,attr,omitempty"`
}
type FeatureEnabled struct {
}
type FeatureState struct {
State string `xml:"state,attr,omitempty"`
}
type FeatureKVM struct {
Hidden *FeatureState `xml:"hidden,omitempty"`
}
type Metadata struct {
// KubeVirt contains kubevirt related metadata
// Note: Libvirt only accept one element at metadata root with a specific namespace
KubeVirt KubeVirtMetadata `xml:"http://kubevirt.io kubevirt"`
}
type KubeVirtMetadata struct {
UID types.UID `xml:"uid"`
GracePeriod *GracePeriodMetadata `xml:"graceperiod,omitempty"`
Migration *MigrationMetadata `xml:"migration,omitempty"`
AccessCredential *AccessCredentialMetadata `xml:"accessCredential,omitempty"`
}
type AccessCredentialMetadata struct {
Succeeded bool `xml:"succeeded,omitempty"`
Message string `xml:"message,omitempty"`
}
type MigrationMetadata struct {
UID types.UID `xml:"uid,omitempty"`
StartTimestamp *metav1.Time `xml:"startTimestamp,omitempty"`
EndTimestamp *metav1.Time `xml:"endTimestamp,omitempty"`
Completed bool `xml:"completed,omitempty"`
Failed bool `xml:"failed,omitempty"`
FailureReason string `xml:"failureReason,omitempty"`
AbortStatus string `xml:"abortStatus,omitempty"`
Mode v1.MigrationMode `xml:"mode,omitempty"`
}
type GracePeriodMetadata struct {
DeletionGracePeriodSeconds int64 `xml:"deletionGracePeriodSeconds"`
DeletionTimestamp *metav1.Time `xml:"deletionTimestamp,omitempty"`
MarkedForGracefulShutdown *bool `xml:"markedForGracefulShutdown,omitempty"`
}
type Commandline struct {
QEMUEnv []Env `xml:"qemu:env,omitempty"`
QEMUArg []Arg `xml:"qemu:arg,omitempty"`
}
type Env struct {
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
type Arg struct {
Value string `xml:"value,attr"`
}
type Resource struct {
Partition string `xml:"partition"`
}
type Memory struct {
Value uint64 `xml:",chardata"`
Unit string `xml:"unit,attr"`
}
// MemoryBacking mirroring libvirt XML under https://libvirt.org/formatdomain.html#elementsMemoryBacking
type MemoryBacking struct {
HugePages *HugePages `xml:"hugepages,omitempty"`
Source *MemoryBackingSource `xml:"source,omitempty"`
Access *MemoryBackingAccess `xml:"access,omitempty"`
}
type MemoryBackingSource struct {
Type string `xml:"type,attr"`
}
// HugePages mirroring libvirt XML under memoryBacking
type HugePages struct {
HugePage []HugePage `xml:"page,omitempty"`
}
// HugePage mirroring libvirt XML under hugepages
type HugePage struct {
Size string `xml:"size,attr"`
Unit string `xml:"unit,attr"`
}
type MemoryBackingAccess struct {
Mode string `xml:"mode,attr"`
}
type Devices struct {
Emulator string `xml:"emulator,omitempty"`
Interfaces []Interface `xml:"interface"`
Channels []Channel `xml:"channel"`
HostDevices []HostDevice `xml:"hostdev,omitempty"`
Controllers []Controller `xml:"controller,omitempty"`
Video []Video `xml:"video"`
Graphics []Graphics `xml:"graphics"`
Ballooning *MemBalloon `xml:"memballoon,omitempty"`
Disks []Disk `xml:"disk"`
Inputs []Input `xml:"input"`
Serials []Serial `xml:"serial"`
Consoles []Console `xml:"console"`
Watchdog *Watchdog `xml:"watchdog,omitempty"`
Rng *Rng `xml:"rng,omitempty"`
Filesystems []FilesystemDevice `xml:"filesystem,omitempty"`
}
type FilesystemDevice struct {
Type string `xml:"type,attr"`
AccessMode string `xml:"accessMode,attr"`
Source *FilesystemSource `xml:"source,omitempty"`
Target *FilesystemTarget `xml:"target,omitempty"`
Driver *FilesystemDriver `xml:"driver,omitempty"`
Binary *FilesystemBinary `xml:"binary,omitempty"`
}
type FilesystemTarget struct {
Dir string `xml:"dir,attr,omitempty"`
}
type FilesystemSource struct {
Dir string `xml:"dir,attr"`
}
type FilesystemDriver struct {
Type string `xml:"type,attr"`
Queue string `xml:"queue,attr,omitempty"`
}
type FilesystemBinary struct {
Path string `xml:"path,attr,omitempty"`
Xattr string `xml:"xattr,attr,omitempty"`
Cache *FilesystemBinaryCache `xml:"cache,omitempty"`
Lock *FilesystemBinaryLock `xml:"lock,omitempty"`
}
type FilesystemBinaryCache struct {
Mode string `xml:"mode,attr,omitempty"`
}
type FilesystemBinaryLock struct {
Posix string `xml:"posix,attr,omitempty"`
Flock string `xml:"flock,attr,omitempty"`
}
// Input represents input device, e.g. tablet
type Input struct {
Type string `xml:"type,attr"`
Bus string `xml:"bus,attr"`
Alias *Alias `xml:"alias,omitempty"`
Address *Address `xml:"address,emitempty"`
Model string `xml:"model,attr,omitempty"`
}
// BEGIN HostDevice -----------------------------
type HostDevice struct {
Source HostDeviceSource `xml:"source"`
Type string `xml:"type,attr"`
BootOrder *BootOrder `xml:"boot,omitempty"`
Managed string `xml:"managed,attr"`
Mode string `xml:"mode,attr,omitempty"`
Model string `xml:"model,attr,omitempty"`
Address *Address `xml:"address,emitempty"`
Alias *Alias `xml:"alias,omitempty"`
}
type HostDeviceSource struct {
Address *Address `xml:"address,omitempty"`
}
// END HostDevice -----------------------------
// BEGIN Controller -----------------------------
// Controller represens libvirt controller element https://libvirt.org/formatdomain.html#elementsControllers
type Controller struct {
Type string `xml:"type,attr"`
Index string `xml:"index,attr"`
Model string `xml:"model,attr,omitempty"`
Driver *ControllerDriver `xml:"driver,omitempty"`
Alias *Alias `xml:"alias,omitempty"`
Address *Address `xml:"address,emitempty"`
}
// END Controller -----------------------------
// BEGIN ControllerDriver
type ControllerDriver struct {
IOThread *uint `xml:"iothread,attr,omitempty"`
}
// END ControllerDriver
// BEGIN Disk -----------------------------
type Disk struct {
Device string `xml:"device,attr"`
Snapshot string `xml:"snapshot,attr,omitempty"`
Type string `xml:"type,attr"`
Source DiskSource `xml:"source"`
Target DiskTarget `xml:"target"`
Serial string `xml:"serial,omitempty"`
Driver *DiskDriver `xml:"driver,omitempty"`
ReadOnly *ReadOnly `xml:"readonly,omitempty"`
Auth *DiskAuth `xml:"auth,omitempty"`
Alias *Alias `xml:"alias,omitempty"`
BackingStore *BackingStore `xml:"backingStore,omitempty"`
BootOrder *BootOrder `xml:"boot,omitempty"`
Address *Address `xml:"address,omitempty"`
Model string `xml:"model,attr,omitempty"`
}
type DiskAuth struct {
Username string `xml:"username,attr"`
Secret *DiskSecret `xml:"secret,omitempty"`
}
type DiskSecret struct {
Type string `xml:"type,attr"`
Usage string `xml:"usage,attr,omitempty"`
UUID string `xml:"uuid,attr,omitempty"`
}
type ReadOnly struct{}
type DiskSource struct {
Dev string `xml:"dev,attr,omitempty"`
File string `xml:"file,attr,omitempty"`
StartupPolicy string `xml:"startupPolicy,attr,omitempty"`
Protocol string `xml:"protocol,attr,omitempty"`
Name string `xml:"name,attr,omitempty"`
Host *DiskSourceHost `xml:"host,omitempty"`
}
type DiskTarget struct {
Bus string `xml:"bus,attr,omitempty"`
Device string `xml:"dev,attr,omitempty"`
Tray string `xml:"tray,attr,omitempty"`
}
type DiskDriver struct {
Cache string `xml:"cache,attr,omitempty"`
ErrorPolicy string `xml:"error_policy,attr,omitempty"`
IO string `xml:"io,attr,omitempty"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
IOThread *uint `xml:"iothread,attr,omitempty"`
Queues *uint `xml:"queues,attr,omitempty"`
}
type DiskSourceHost struct {
Name string `xml:"name,attr"`
Port string `xml:"port,attr,omitempty"`
}
type BackingStore struct {
Type string `xml:"type,attr,omitempty"`
Format *BackingStoreFormat `xml:"format,omitempty"`
Source *DiskSource `xml:"source,omitempty"`
}
type BackingStoreFormat struct {
Type string `xml:"type,attr"`
}
// END Disk -----------------------------
// BEGIN Serial -----------------------------
type Serial struct {
Type string `xml:"type,attr"`
Target *SerialTarget `xml:"target,omitempty"`
Source *SerialSource `xml:"source,omitempty"`
Alias *Alias `xml:"alias,omitempty"`
}
type SerialTarget struct {
Port *uint `xml:"port,attr,omitempty"`
}
type SerialSource struct {
Mode string `xml:"mode,attr,omitempty"`
Path string `xml:"path,attr,omitempty"`
}
// END Serial -----------------------------
// BEGIN Console -----------------------------
type Console struct {
Type string `xml:"type,attr"`
Target *ConsoleTarget `xml:"target,omitempty"`
Source *ConsoleSource `xml:"source,omitempty"`
Alias *Alias `xml:"alias,omitempty"`
}
type ConsoleTarget struct {
Type *string `xml:"type,attr,omitempty"`
Port *uint `xml:"port,attr,omitempty"`
}
type ConsoleSource struct {
Mode string `xml:"mode,attr,omitempty"`
Path string `xml:"path,attr,omitempty"`
}
// END Serial -----------------------------
// BEGIN Inteface -----------------------------
type Interface struct {
Address *Address `xml:"address,omitempty"`
Type string `xml:"type,attr"`
TrustGuestRxFilters string `xml:"trustGuestRxFilters,attr,omitempty"`
Source InterfaceSource `xml:"source"`
Target *InterfaceTarget `xml:"target,omitempty"`
Model *Model `xml:"model,omitempty"`
MAC *MAC `xml:"mac,omitempty"`
MTU *MTU `xml:"mtu,omitempty"`
BandWidth *BandWidth `xml:"bandwidth,omitempty"`
BootOrder *BootOrder `xml:"boot,omitempty"`
LinkState *LinkState `xml:"link,omitempty"`
FilterRef *FilterRef `xml:"filterref,omitempty"`
Alias *Alias `xml:"alias,omitempty"`
Driver *InterfaceDriver `xml:"driver,omitempty"`
Rom *Rom `xml:"rom,omitempty"`
}
type InterfaceDriver struct {
Name string `xml:"name,attr"`
Queues *uint `xml:"queues,attr,omitempty"`
}
type LinkState struct {
State string `xml:"state,attr"`
}
type BandWidth struct {
}
type BootOrder struct {
Order uint `xml:"order,attr"`
}
type MAC struct {
MAC string `xml:"address,attr"`
}
type MTU struct {
Size string `xml:"size,attr"`
}
type FilterRef struct {
Filter string `xml:"filter,attr"`
}
type InterfaceSource struct {
Network string `xml:"network,attr,omitempty"`
Device string `xml:"dev,attr,omitempty"`
Bridge string `xml:"bridge,attr,omitempty"`
Mode string `xml:"mode,attr,omitempty"`
Address *Address `xml:"address,omitempty"`
}
type Model struct {
Type string `xml:"type,attr"`
}
type InterfaceTarget struct {
Device string `xml:"dev,attr"`
Managed string `xml:"managed,attr,omitempty"`
}
type Alias struct {
name string
userDefined bool
}
// Package private, responsible to interact with xml and json marshal/unmarshal
type userAliasMarshal struct {
Name string `xml:"name,attr"`
UserDefined bool `xml:"-"`
}
type Rom struct {
Enabled string `xml:"enabled,attr"`
}
func NewUserDefinedAlias(aliasName string) *Alias {
return &Alias{name: aliasName, userDefined: true}
}
func (alias Alias) GetName() string {
return alias.name
}
func (alias Alias) IsUserDefined() bool {
return alias.userDefined
}
func (alias Alias) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
userAlias := userAliasMarshal{Name: alias.name}
if alias.userDefined {
userAlias.Name = UserAliasPrefix + userAlias.Name
}
return e.EncodeElement(userAlias, start)
}
func (alias *Alias) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var userAlias userAliasMarshal
err := d.DecodeElement(&userAlias, &start)
if err != nil {
return err
}
*alias = Alias{name: userAlias.Name}
if strings.HasPrefix(alias.name, UserAliasPrefix) {
alias.userDefined = true
alias.name = alias.name[len(UserAliasPrefix):]
}
return nil
}
func (alias Alias) MarshalJSON() ([]byte, error) {
userAlias := userAliasMarshal{Name: alias.name, UserDefined: alias.userDefined}
return json.Marshal(&userAlias)
}
func (alias *Alias) UnmarshalJSON(data []byte) error {
var userAlias userAliasMarshal
if err := json.Unmarshal(data, &userAlias); err != nil {
return err
}
*alias = Alias{name: userAlias.Name, userDefined: userAlias.UserDefined}
return nil
}
// END Inteface -----------------------------
//BEGIN OS --------------------
type OS struct {
Type OSType `xml:"type"`
SMBios *SMBios `xml:"smbios,omitempty"`
BootOrder []Boot `xml:"boot"`
BootMenu *BootMenu `xml:"bootmenu,omitempty"`
BIOS *BIOS `xml:"bios,omitempty"`
BootLoader *Loader `xml:"loader,omitempty"`
NVRam *NVRam `xml:"nvram,omitempty"`
Kernel string `xml:"kernel,omitempty"`
Initrd string `xml:"initrd,omitempty"`
KernelArgs string `xml:"cmdline,omitempty"`
}
type OSType struct {
OS string `xml:",chardata"`
Arch string `xml:"arch,attr,omitempty"`
Machine string `xml:"machine,attr,omitempty"`
}
type SMBios struct {
Mode string `xml:"mode,attr"`
}
type NVRam struct {
Template string `xml:"template,attr,omitempty"`
NVRam string `xml:",chardata"`
}
type Boot struct {
Dev string `xml:"dev,attr"`
}
type BootMenu struct {
Enabled bool `xml:"enabled,attr"`
Timeout *uint `xml:"timeout,attr,omitempty"`
}
type Loader struct {
ReadOnly string `xml:"readonly,attr,omitempty"`
Secure string `xml:"secure,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Path string `xml:",chardata"`
}
// TODO <bios rebootTimeout='0'/>
type BIOS struct {
UseSerial string `xml:"useserial,attr,omitempty"`
}
type SysInfo struct {
Type string `xml:"type,attr"`
System []Entry `xml:"system>entry"`
BIOS []Entry `xml:"bios>entry"`
BaseBoard []Entry `xml:"baseBoard>entry"`
Chassis []Entry `xml:"chassis>entry"`
}
type Entry struct {
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
}
//END OS --------------------
//BEGIN Clock --------------------
type Clock struct {
Offset string `xml:"offset,attr,omitempty"`
Timezone string `xml:"timezone,attr,omitempty"`
Adjustment string `xml:"adjustment,attr,omitempty"`
Timer []Timer `xml:"timer,omitempty"`
}
type Timer struct {
Name string `xml:"name,attr"`
TickPolicy string `xml:"tickpolicy,attr,omitempty"`
Present string `xml:"present,attr,omitempty"`
Track string `xml:"track,attr,omitempty"`
}
//END Clock --------------------
//BEGIN Channel --------------------
type Channel struct {
Type string `xml:"type,attr"`
Source *ChannelSource `xml:"source,omitempty"`
Target *ChannelTarget `xml:"target,omitempty"`
}
type ChannelTarget struct {
Name string `xml:"name,attr,omitempty"`
Type string `xml:"type,attr"`
Address string `xml:"address,attr,omitempty"`
Port uint `xml:"port,attr,omitempty"`
State string `xml:"state,attr,omitempty"`
}
type ChannelSource struct {
Mode string `xml:"mode,attr"`
Path string `xml:"path,attr"`
}
//END Channel --------------------
//BEGIN Video -------------------
/*
<graphics autoport="yes" defaultMode="secure" listen="0" passwd="*****" passwdValidTo="1970-01-01T00:00:01" port="-1" tlsPort="-1" type="spice" />
*/
type Video struct {
Model VideoModel `xml:"model"`
}
type VideoModel struct {
Type string `xml:"type,attr"`
Heads *uint `xml:"heads,attr,omitempty"`
Ram *uint `xml:"ram,attr,omitempty"`
VRam *uint `xml:"vram,attr,omitempty"`
VGAMem *uint `xml:"vgamem,attr,omitempty"`
}
type Graphics struct {
AutoPort string `xml:"autoPort,attr,omitempty"`
DefaultMode string `xml:"defaultMode,attr,omitempty"`
Listen *GraphicsListen `xml:"listen,omitempty"`
PasswdValidTo string `xml:"passwdValidTo,attr,omitempty"`
Port int32 `xml:"port,attr,omitempty"`
TLSPort int `xml:"tlsPort,attr,omitempty"`
Type string `xml:"type,attr"`
}
type GraphicsListen struct {
Type string `xml:"type,attr"`
Address string `xml:"address,attr,omitempty"`
Network string `xml:"newtork,attr,omitempty"`
Socket string `xml:"socket,attr,omitempty"`
}
type Address struct {
Type string `xml:"type,attr"`
Domain string `xml:"domain,attr,omitempty"`
Bus string `xml:"bus,attr"`
Slot string `xml:"slot,attr,omitempty"`
Function string `xml:"function,attr,omitempty"`
Controller string `xml:"controller,attr,omitempty"`
Target string `xml:"target,attr,omitempty"`
Unit string `xml:"unit,attr,omitempty"`
UUID string `xml:"uuid,attr,omitempty"`
}
//END Video -------------------
type Stats struct {
Period uint `xml:"period,attr"`
}
type MemBalloon struct {
Model string `xml:"model,attr"`
Stats *Stats `xml:"stats,omitempty"`
Address *Address `xml:"address,emitempty"`
}
type Watchdog struct {
Model string `xml:"model,attr"`
Action string `xml:"action,attr"`
Alias *Alias `xml:"alias,omitempty"`
Address *Address `xml:"address,emitempty"`
}
// Rng represents the source of entropy from host to VM
type Rng struct {
// Model attribute specifies what type of RNG device is provided
Model string `xml:"model,attr"`
// Backend specifies the source of entropy to be used
Backend *RngBackend `xml:"backend,omitempty"`
Address *Address `xml:"address,emitempty"`
}
// RngRate sets the limiting factor how to read from entropy source
type RngRate struct {
// Period define how long is the read period
Period uint32 `xml:"period,attr"`
// Bytes define how many bytes can guest read from entropy source
Bytes uint32 `xml:"bytes,attr"`
}
// RngBackend is the backend device used
type RngBackend struct {
// Model is source model
Model string `xml:"model,attr"`
// specifies the source of entropy to be used
Source string `xml:",chardata"`
}
type IOThreads struct {
IOThreads uint `xml:",chardata"`
}
// TODO ballooning, rng, cpu ...
type SecretUsage struct {
Type string `xml:"type,attr"`
Target string `xml:"target,omitempty"`
}
type SecretSpec struct {
XMLName xml.Name `xml:"secret"`
Ephemeral string `xml:"ephemeral,attr"`
Private string `xml:"private,attr"`
Description string `xml:"description,omitempty"`
Usage SecretUsage `xml:"usage,omitempty"`
}
func NewMinimalDomainSpec(vmiName string) *DomainSpec {
precond.MustNotBeEmpty(vmiName)
domain := &DomainSpec{}
domain.Name = vmiName
domain.Memory = Memory{Unit: "MB", Value: 9}
domain.Devices = Devices{}
return domain
}
func NewMinimalDomain(name string) *Domain {
return NewMinimalDomainWithNS(kubev1.NamespaceDefault, name)
}
func NewMinimalDomainWithUUID(name string, uuid types.UID) *Domain {
domain := NewMinimalDomainWithNS(kubev1.NamespaceDefault, name)
domain.Spec.Metadata = Metadata{
KubeVirt: KubeVirtMetadata{
UID: uuid,
},
}
return domain
}
func NewMinimalDomainWithNS(namespace string, name string) *Domain {
domain := NewDomainReferenceFromName(namespace, name)
domain.Spec = *NewMinimalDomainSpec(namespace + "_" + name)
return domain
}
func NewDomainReferenceFromName(namespace string, name string) *Domain {
return &Domain{
Spec: DomainSpec{},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Status: DomainStatus{},
TypeMeta: metav1.TypeMeta{
APIVersion: "1.2.2",
Kind: "Domain",
},
}
}
func (d *Domain) SetState(state LifeCycle, reason StateChangeReason) {
d.Status.Status = state
d.Status.Reason = reason
}
// Required to satisfy Object interface
func (d *Domain) GetObjectKind() schema.ObjectKind {