Skip to content

Commit 6f83f03

Browse files
committed
remove proxmox pkg
1 parent 5693bcf commit 6f83f03

File tree

7 files changed

+63
-67
lines changed

7 files changed

+63
-67
lines changed

api/v1beta1/type.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/sp-yduck/proxmox/pkg/service/node/vm"
7+
"github.com/sp-yduck/proxmox-go/api"
88
)
99

1010
// ServerRef is used for configuring Proxmox client
@@ -127,7 +127,7 @@ type Storage struct {
127127
type InstanceStatus string
128128

129129
var (
130-
InstanceStatusPaused = InstanceStatus(vm.ProcessStatusPaused)
131-
InstanceStatusRunning = InstanceStatus(vm.ProcessStatusRunning)
132-
InstanceStatusStopped = InstanceStatus(vm.ProcessStatusStopped)
130+
InstanceStatusPaused = InstanceStatus(api.ProcessStatusPaused)
131+
InstanceStatusRunning = InstanceStatus(api.ProcessStatusRunning)
132+
InstanceStatusStopped = InstanceStatus(api.ProcessStatusStopped)
133133
)

cloud/services/compute/instance/image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"strings"
88

99
"github.com/pkg/errors"
10-
"github.com/sp-yduck/proxmox/pkg/service/node/vm"
10+
"github.com/sp-yduck/proxmox-go/api"
1111
"sigs.k8s.io/controller-runtime/pkg/log"
1212

1313
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
1414
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
1515
)
1616

1717
// reconcileBootDevice
18-
func (s *Service) reconcileBootDevice(ctx context.Context, vm *vm.VirtualMachine) error {
18+
func (s *Service) reconcileBootDevice(ctx context.Context, vm *api.VirtualMachine) error {
1919
vmid := s.scope.GetVMID()
2020
storage := s.scope.GetStorage()
2121
image := s.scope.GetImage()

cloud/services/compute/instance/qemu.go

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9594
func (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

cloud/services/compute/instance/reconcile.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"strings"
88

99
"github.com/pkg/errors"
10-
"github.com/sp-yduck/proxmox/pkg/api"
11-
"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"
1212
"k8s.io/utils/pointer"
1313
"sigs.k8s.io/controller-runtime/pkg/log"
1414

@@ -72,7 +72,7 @@ func (s *Service) Delete(ctx context.Context) error {
7272
return instance.Delete()
7373
}
7474

75-
func (s *Service) createOrGetInstance(ctx context.Context) (*vm.VirtualMachine, error) {
75+
func (s *Service) createOrGetInstance(ctx context.Context) (*api.VirtualMachine, error) {
7676
log := log.FromContext(ctx)
7777

7878
log.Info("Getting bootstrap data for machine")
@@ -100,25 +100,25 @@ func (s *Service) createOrGetInstance(ctx context.Context) (*vm.VirtualMachine,
100100
return instance, nil
101101
}
102102

103-
func (s *Service) GetInstance(ctx context.Context) (*vm.VirtualMachine, error) {
103+
func (s *Service) GetInstance(ctx context.Context) (*api.VirtualMachine, error) {
104104
log := log.FromContext(ctx)
105105
biosUUID := s.scope.GetBiosUUID()
106106
if biosUUID == nil {
107-
return nil, api.ErrNotFound
107+
return nil, rest.ErrNotFound
108108
}
109109
vm, err := s.getInstanceFromBiosUUID(*biosUUID)
110110
if err != nil {
111-
if api.IsNotFound(err) {
111+
if rest.IsNotFound(err) {
112112
log.Info("instance wasn't found")
113-
return nil, api.ErrNotFound
113+
return nil, rest.ErrNotFound
114114
}
115115
log.Error(err, "failed to get instance from bios UUID")
116116
return nil, err
117117
}
118118
return vm, nil
119119
}
120120

121-
func getBiosUUID(vm *vm.VirtualMachine) (*string, error) {
121+
func getBiosUUID(vm *api.VirtualMachine) (*string, error) {
122122
config, err := vm.Config()
123123
if err != nil {
124124
return nil, err
@@ -141,7 +141,7 @@ func convertSMBiosToUUID(smbios string) (string, error) {
141141
return strings.Split(match, "=")[1], nil
142142
}
143143

144-
func (s *Service) getInstanceFromBiosUUID(uuid string) (*vm.VirtualMachine, error) {
144+
func (s *Service) getInstanceFromBiosUUID(uuid string) (*api.VirtualMachine, error) {
145145
nodes, err := s.client.Nodes()
146146
if err != nil {
147147
return nil, err
@@ -170,7 +170,7 @@ func (s *Service) getInstanceFromBiosUUID(uuid string) (*vm.VirtualMachine, erro
170170
}
171171
}
172172
}
173-
return nil, api.ErrNotFound
173+
return nil, rest.ErrNotFound
174174
}
175175

176176
func (s *Service) CreateInstance(ctx context.Context, bootstrap string) (*vm.VirtualMachine, error) {
@@ -202,20 +202,20 @@ func (s *Service) CreateInstance(ctx context.Context, bootstrap string) (*vm.Vir
202202
}
203203

204204
func IsNotFound(err error) bool {
205-
return api.IsNotFound(err)
205+
return rest.IsNotFound(err)
206206
}
207207

208-
func EnsureRunning(instance vm.VirtualMachine) error {
208+
func EnsureRunning(instance api.VirtualMachine) error {
209209
// ensure instance is running
210210
switch instance.Status {
211-
case vm.ProcessStatusRunning:
211+
case api.ProcessStatusRunning:
212212
return nil
213-
case vm.ProcessStatusStopped:
214-
if err := instance.Start(vm.StartOption{}); err != nil {
213+
case api.ProcessStatusStopped:
214+
if err := instance.Start(api.StartOption{}); err != nil {
215215
return err
216216
}
217-
case vm.ProcessStatusPaused:
218-
if err := instance.Resume(vm.ResumeOption{}); err != nil {
217+
case api.ProcessStatusPaused:
218+
if err := instance.Resume(api.ResumeOption{}); err != nil {
219219
return err
220220
}
221221
default:
@@ -224,15 +224,15 @@ func EnsureRunning(instance vm.VirtualMachine) error {
224224
return nil
225225
}
226226

227-
func EnsureStoppedOrPaused(instance vm.VirtualMachine) error {
227+
func EnsureStoppedOrPaused(instance api.VirtualMachine) error {
228228
switch instance.Status {
229-
case vm.ProcessStatusRunning:
229+
case api.ProcessStatusRunning:
230230
if err := instance.Stop(); err != nil {
231231
return err
232232
}
233-
case vm.ProcessStatusPaused:
233+
case api.ProcessStatusPaused:
234234
return nil
235-
case vm.ProcessStatusStopped:
235+
case api.ProcessStatusStopped:
236236
return nil
237237
default:
238238
return errors.Errorf("unexpected status : %s", instance.Status)

cloud/services/compute/storage/reconcile.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"errors"
66
"fmt"
77

8-
"github.com/sp-yduck/proxmox/pkg/api"
9-
"github.com/sp-yduck/proxmox/pkg/service/node/storage"
8+
"github.com/sp-yduck/proxmox-go/api"
9+
"github.com/sp-yduck/proxmox-go/rest"
1010
"sigs.k8s.io/controller-runtime/pkg/log"
1111

1212
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
@@ -36,7 +36,7 @@ func (s *Service) Delete(ctx context.Context) error {
3636
func (s *Service) createOrGetStorage(ctx context.Context) error {
3737
opts := generateVMStorageOptions(s.scope)
3838
if err := s.getStorage(opts.Storage); err != nil {
39-
if api.IsNotFound(err) {
39+
if rest.IsNotFound(err) {
4040
if err := s.createStorage(opts); err != nil {
4141
return err
4242
}
@@ -55,7 +55,7 @@ func (s *Service) getStorage(name string) error {
5555
return nil
5656
}
5757

58-
func (s *Service) createStorage(options storage.StorageCreateOptions) error {
58+
func (s *Service) createStorage(options api.StorageCreateOptions) error {
5959
if _, err := s.client.CreateStorage(options.Storage, options.StorageType, options); err != nil {
6060
return err
6161
}
@@ -64,7 +64,7 @@ func (s *Service) createStorage(options storage.StorageCreateOptions) error {
6464

6565
func (s *Service) deleteStorage(ctx context.Context) error {
6666
log := log.FromContext(ctx)
67-
nodes, err := s.client.Nodes()
67+
nodes, err := s.client.Nodes(ctx)
6868
if err != nil {
6969
return err
7070
}
@@ -93,9 +93,9 @@ func (s *Service) deleteStorage(ctx context.Context) error {
9393
return nil
9494
}
9595

96-
func generateVMStorageOptions(scope Scope) storage.StorageCreateOptions {
96+
func generateVMStorageOptions(scope Scope) api.StorageCreateOptions {
9797
storageSpec := scope.Storage()
98-
options := storage.StorageCreateOptions{
98+
options := api.StorageCreateOptions{
9999
Storage: storageSpec.Name,
100100
StorageType: "dir",
101101
Content: "images,snippets",

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/onsi/ginkgo/v2 v2.11.0
88
github.com/onsi/gomega v1.27.8
99
github.com/pkg/errors v0.9.1
10-
github.com/sp-yduck/proxmox v0.0.0-20230702124708-d086ca37fd8f
1110
github.com/sp-yduck/proxmox-go v0.0.0-alpha4
1211
golang.org/x/crypto v0.11.0
1312
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g
288288
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
289289
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
290290
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
291-
github.com/sp-yduck/proxmox v0.0.0-20230702124708-d086ca37fd8f h1:n32eSWqWLtjk+jb4B1Ok+W5KoAxuYuouEkXjumqySXI=
292-
github.com/sp-yduck/proxmox v0.0.0-20230702124708-d086ca37fd8f/go.mod h1:VIKtGZXlx0nO9Y+K2vJ4z3rJLkZ3v0OvTnKbO22EnL4=
293291
github.com/sp-yduck/proxmox-go v0.0.0-alpha4 h1:z4S3zc/mGBvthz4gjP9Dj4SEzXnEgyDz9dPNimfB8vs=
294292
github.com/sp-yduck/proxmox-go v0.0.0-alpha4/go.mod h1:hrQc1bUUCN71yn+in+LkfdpJstaaMv2nrn3+GeKFbkA=
295293
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=

0 commit comments

Comments
 (0)