Skip to content

Commit 5747a56

Browse files
authored
Merge pull request #13 from k8s-proxmox/feature/get-node-storage
add node service
2 parents 64b579a + 48c6f3d commit 5747a56

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

proxmox/node.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@ import (
44
"context"
55

66
"github.com/k8s-proxmox/proxmox-go/api"
7+
"github.com/k8s-proxmox/proxmox-go/rest"
78
)
89

9-
func (s *Service) Nodes(ctx context.Context) ([]*api.Node, error) {
10+
type Node struct {
11+
service *Service
12+
restclient *rest.RESTClient
13+
Node *api.Node
14+
}
15+
16+
func (s *Service) GetNodes(ctx context.Context) ([]*api.Node, error) {
1017
return s.restclient.GetNodes(ctx)
1118
}
1219

13-
func (s *Service) Node(ctx context.Context, name string) (*api.Node, error) {
20+
func (s *Service) GetNode(ctx context.Context, name string) (*api.Node, error) {
1421
return s.restclient.GetNode(ctx, name)
1522
}
23+
24+
func (s *Service) Node(ctx context.Context, name string) (*Node, error) {
25+
node, err := s.restclient.GetNode(ctx, name)
26+
if err != nil {
27+
return nil, err
28+
}
29+
return &Node{service: s, restclient: s.restclient, Node: node}, nil
30+
}
31+
32+
func (n *Node) GetStorages(ctx context.Context) ([]*api.Storage, error) {
33+
return n.restclient.GetNodeStorages(ctx, n.Node.Node)
34+
}

proxmox/qemu.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525

2626
// VirtualMachines returns all qemus across all proxmox nodes
2727
func (s *Service) VirtualMachines(ctx context.Context) ([]*api.VirtualMachine, error) {
28-
nodes, err := s.Nodes(ctx)
28+
nodes, err := s.GetNodes(ctx)
2929
if err != nil {
3030
return nil, err
3131
}
@@ -41,7 +41,7 @@ func (s *Service) VirtualMachines(ctx context.Context) ([]*api.VirtualMachine, e
4141
}
4242

4343
func (s *Service) VirtualMachine(ctx context.Context, vmid int) (*VirtualMachine, error) {
44-
nodes, err := s.Nodes(ctx)
44+
nodes, err := s.GetNodes(ctx)
4545
if err != nil {
4646
return nil, err
4747
}
@@ -83,7 +83,7 @@ func (s *Service) CloneVirtualMachine(ctx context.Context, node string, vmid int
8383
// VirtualMachineFromUUID attempts to find virtual machine based on SMBIOS UUID. It will ignore any error that prevents
8484
// it from inspecting additional virtual machines (e.g. offline node, vm config not accessible, malformed uuids)
8585
func (s *Service) VirtualMachineFromUUID(ctx context.Context, uuid string) (*VirtualMachine, error) {
86-
nodes, err := s.Nodes(ctx)
86+
nodes, err := s.GetNodes(ctx)
8787
if err != nil {
8888
return nil, err
8989
}
@@ -111,7 +111,7 @@ func (s *Service) VirtualMachineFromUUID(ctx context.Context, uuid string) (*Vir
111111

112112
// return true if there is any vm having specified name
113113
func (s *Service) VirtualMachineExistsWithName(ctx context.Context, name string) (bool, error) {
114-
nodes, err := s.Nodes(ctx)
114+
nodes, err := s.GetNodes(ctx)
115115
if err != nil {
116116
return false, err
117117
}

0 commit comments

Comments
 (0)