@@ -11,8 +11,6 @@ import (
1111 "github.com/sp-yduck/proxmox-go/proxmox"
1212 "github.com/sp-yduck/proxmox-go/rest"
1313 "sigs.k8s.io/controller-runtime/pkg/log"
14-
15- infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
1614)
1715
1816const (
@@ -72,7 +70,7 @@ func (s *Service) createQEMU(ctx context.Context, nodeName string, vmid *int) (*
7270 s .scope .SetVMID (* vmid )
7371 }
7472
75- vmoption := generateVMOptions ( s . scope . Name (), s . scope . GetStorage (). Name , s . scope . GetNetwork (), s . scope . GetHardware () )
73+ vmoption := s . generateVMOptions ( )
7674 vm , err := s .client .CreateVirtualMachine (ctx , nodeName , * vmid , vmoption )
7775 if err != nil {
7876 log .Error (err , fmt .Sprintf ("failed to create qemu instance %s" , vm .VM .Name ))
@@ -103,24 +101,60 @@ func (s *Service) getRandomNode(ctx context.Context) (*api.Node, error) {
103101 return nodes [r .Intn (len (nodes ))], nil
104102}
105103
106- func generateVMOptions (vmName , storageName string , network infrav1.Network , hardware infrav1.Hardware ) api.VirtualMachineCreateOptions {
104+ func (s * Service ) generateVMOptions () api.VirtualMachineCreateOptions {
105+ vmName := s .scope .Name ()
106+ storageName := s .scope .GetStorage ().Name
107+ network := s .scope .GetNetwork ()
108+ hardware := s .scope .GetHardware ()
109+ options := s .scope .GetOptions ()
110+
107111 vmoptions := api.VirtualMachineCreateOptions {
108- Agent : "enabled=1" ,
109- Cores : hardware .CPU ,
110- Memory : hardware .Memory ,
111- Name : vmName ,
112- NameServer : network .NameServer ,
113- Boot : fmt .Sprintf ("order=%s" , bootDvice ),
114- Ide : api.Ide {Ide2 : fmt .Sprintf ("file=%s:cloudinit,media=cdrom" , storageName )},
115- CiCustom : fmt .Sprintf ("user=%s:%s" , storageName , userSnippetPath (vmName )),
116- IPConfig : api.IPConfig {IPConfig0 : network .IPConfig .String ()},
117- OSType : api .L26 ,
118- Net : api.Net {Net0 : "model=virtio,bridge=vmbr0,firewall=1" },
119- Scsi : api.Scsi {Scsi0 : fmt .Sprintf ("file=%s:8" , storageName )},
120- ScsiHw : api .VirtioScsiPci ,
121- SearchDomain : network .SearchDomain ,
122- Serial : api.Serial {Serial0 : "socket" },
123- VGA : "serial0" ,
112+ ACPI : boolToInt8 (options .ACPI ),
113+ Agent : "enabled=1" ,
114+ Arch : api .Arch (options .Arch ),
115+ Balloon : options .Balloon ,
116+ BIOS : string (hardware .BIOS ),
117+ Boot : fmt .Sprintf ("order=%s" , bootDvice ),
118+ CiCustom : fmt .Sprintf ("user=%s:%s" , storageName , userSnippetPath (vmName )),
119+ Cores : hardware .CPU ,
120+ CpuLimit : hardware .CPULimit ,
121+ Description : options .Description ,
122+ HugePages : options .HugePages .String (),
123+ Ide : api.Ide {Ide2 : fmt .Sprintf ("file=%s:cloudinit,media=cdrom" , storageName )},
124+ IPConfig : api.IPConfig {IPConfig0 : network .IPConfig .String ()},
125+ KeepHugePages : boolToInt8 (options .KeepHugePages ),
126+ KVM : boolToInt8 (options .KVM ),
127+ LocalTime : boolToInt8 (options .LocalTime ),
128+ Lock : string (options .Lock ),
129+ Memory : hardware .Memory ,
130+ Name : vmName ,
131+ NameServer : network .NameServer ,
132+ Net : api.Net {Net0 : "model=virtio,bridge=vmbr0,firewall=1" },
133+ Numa : boolToInt8 (options .NUMA ),
134+ OnBoot : boolToInt8 (options .OnBoot ),
135+ OSType : api .OSType (options .OSType ),
136+ Protection : boolToInt8 (options .Protection ),
137+ Reboot : int (boolToInt8 (options .Reboot )),
138+ Scsi : api.Scsi {Scsi0 : fmt .Sprintf ("file=%s:8" , storageName )},
139+ ScsiHw : api .VirtioScsiPci ,
140+ SearchDomain : network .SearchDomain ,
141+ Serial : api.Serial {Serial0 : "socket" },
142+ Shares : options .Shares ,
143+ Sockets : hardware .Sockets ,
144+ Tablet : boolToInt8 (options .Tablet ),
145+ Tags : options .Tags .String (),
146+ TDF : boolToInt8 (options .TimeDriftFix ),
147+ Template : boolToInt8 (options .Template ),
148+ VCPUs : options .VCPUs ,
149+ VMGenID : options .VMGenerationID ,
150+ VGA : "serial0" ,
124151 }
125152 return vmoptions
126153}
154+
155+ func boolToInt8 (b bool ) int8 {
156+ if b {
157+ return 1
158+ }
159+ return 0
160+ }
0 commit comments