@@ -7,48 +7,47 @@ import (
77 "time"
88
99 "github.com/pkg/errors"
10- "github.com/sp-yduck/proxmox/pkg/api"
11- "github.com/sp-yduck/proxmox/pkg/service/node"
12- "github.com/sp-yduck/proxmox/pkg/service/node/vm"
10+ "github.com/sp-yduck/proxmox-go/api"
11+ "github.com/sp-yduck/proxmox-go/rest"
1312 "sigs.k8s.io/controller-runtime/pkg/log"
1413
1514 infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
1615)
1716
18- func (s * Service ) reconcileQEMU (ctx context.Context ) (* vm .VirtualMachine , error ) {
17+ func (s * Service ) reconcileQEMU (ctx context.Context ) (* api .VirtualMachine , error ) {
1918 log := log .FromContext (ctx )
2019 log .Info ("Reconciling QEMU" )
2120
2221 nodeName := s .scope .NodeName ()
2322 vmid := s .scope .GetVMID ()
24- vm , err := s .getQEMU (nodeName , vmid )
25- if err == nil { // if vm is found, return it
26- return vm , nil
23+ api , err := s .getQEMU (nodeName , vmid )
24+ if err == nil { // if api is found, return it
25+ return api , nil
2726 }
2827 if ! IsNotFound (err ) {
29- log .Error (err , fmt .Sprintf ("failed to get vm : node=%s,vmid=%d" , nodeName , * vmid ))
28+ log .Error (err , fmt .Sprintf ("failed to get api : node=%s,vmid=%d" , nodeName , * vmid ))
3029 return nil , err
3130 }
3231
33- // no vm found, create new one
32+ // no api found, create new one
3433 return s .createQEMU (ctx , nodeName , vmid )
3534}
3635
37- func (s * Service ) getQEMU (nodeName string , vmid * int ) (* vm .VirtualMachine , error ) {
36+ func (s * Service ) getQEMU (nodeName string , vmid * int ) (* api .VirtualMachine , error ) {
3837 if vmid != nil && nodeName != "" {
3938 node , err := s .GetNode (nodeName )
4039 if err != nil {
4140 return nil , err
4241 }
4342 return node .VirtualMachine (* vmid )
4443 }
45- return nil , api .ErrNotFound
44+ return nil , rest .ErrNotFound
4645}
4746
48- func (s * Service ) createQEMU (ctx context.Context , nodeName string , vmid * int ) (* vm .VirtualMachine , error ) {
47+ func (s * Service ) createQEMU (ctx context.Context , nodeName string , vmid * int ) (* api .VirtualMachine , error ) {
4948 log := log .FromContext (ctx )
5049
51- var node * node .Node
50+ var node * api .Node
5251 var err error
5352
5453 // get node
@@ -81,31 +80,31 @@ func (s *Service) createQEMU(ctx context.Context, nodeName string, vmid *int) (*
8180 vmid = & nextid
8281 }
8382
84- // create vm
83+ // create api
8584 vmoption := generateVMOptions (s .scope .Name (), s .scope .GetStorage ().Name , s .scope .GetNetwork (), s .scope .GetHardware ())
86- vm , err := node .CreateVirtualMachine (* vmid , vmoption )
85+ api , err := node .CreateVirtualMachine (* vmid , vmoption )
8786 if err != nil {
8887 log .Error (err , "failed to create virtual machine" )
8988 return nil , err
9089 }
9190 s .scope .SetVMID (* vmid )
92- return vm , nil
91+ return api , nil
9392}
9493
9594func (s * Service ) GetNextID () (int , error ) {
96- return s .client .NextID ( )
95+ return s .client .RESTClient (). GetNextID ( context . TODO () )
9796}
9897
99- func (s * Service ) GetNodes () ([]* node .Node , error ) {
100- return s .client .Nodes ()
98+ func (s * Service ) GetNodes () ([]* api .Node , error ) {
99+ return s .client .Nodes (context . TODO () )
101100}
102101
103- func (s * Service ) GetNode (name string ) (* node .Node , error ) {
102+ func (s * Service ) GetNode (name string ) (* api .Node , error ) {
104103 return s .client .Node (name )
105104}
106105
107106// GetRandomNode returns a node chosen randomly
108- func (s * Service ) GetRandomNode () (* node .Node , error ) {
107+ func (s * Service ) GetRandomNode () (* api .Node , error ) {
109108 nodes , err := s .GetNodes ()
110109 if err != nil {
111110 return nil , err
@@ -118,23 +117,23 @@ func (s *Service) GetRandomNode() (*node.Node, error) {
118117 return nodes [r .Intn (len (nodes ))], nil
119118}
120119
121- func generateVMOptions (vmName , storageName string , network infrav1.Network , hardware infrav1.Hardware ) vm .VirtualMachineCreateOptions {
122- vmoptions := vm .VirtualMachineCreateOptions {
120+ func generateVMOptions (vmName , storageName string , network infrav1.Network , hardware infrav1.Hardware ) api .VirtualMachineCreateOptions {
121+ vmoptions := api .VirtualMachineCreateOptions {
123122 Agent : "enabled=1" ,
124123 Cores : hardware .CPU ,
125124 Memory : hardware .Memory ,
126125 Name : vmName ,
127126 NameServer : network .NameServer ,
128127 Boot : "order=scsi0" ,
129- Ide : vm .Ide {Ide2 : fmt .Sprintf ("file=%s:cloudinit,media=cdrom" , storageName )},
128+ Ide : api .Ide {Ide2 : fmt .Sprintf ("file=%s:cloudinit,media=cdrom" , storageName )},
130129 CiCustom : fmt .Sprintf ("user=%s:%s" , storageName , userSnippetPath (vmName )),
131- IPConfig : vm .IPConfig {IPConfig0 : network .IPConfig .String ()},
132- OSType : vm .L26 ,
133- Net : vm .Net {Net0 : "model=virtio,bridge=vmbr0,firewall=1" },
134- Scsi : vm .Scsi {Scsi0 : fmt .Sprintf ("file=%s:8" , storageName )},
135- ScsiHw : vm .VirtioScsiPci ,
130+ IPConfig : api .IPConfig {IPConfig0 : network .IPConfig .String ()},
131+ OSType : api .L26 ,
132+ Net : api .Net {Net0 : "model=virtio,bridge=vmbr0,firewall=1" },
133+ Scsi : api .Scsi {Scsi0 : fmt .Sprintf ("file=%s:8" , storageName )},
134+ ScsiHw : api .VirtioScsiPci ,
136135 SearchDomain : network .SearchDomain ,
137- Serial : vm .Serial {Serial0 : "socket" },
136+ Serial : api .Serial {Serial0 : "socket" },
138137 VGA : "serial0" ,
139138 }
140139 return vmoptions
0 commit comments