Skip to content

Commit 22302ca

Browse files
committed
devide pkg into api/rest
1 parent 0f1c739 commit 22302ca

28 files changed

+582
-404
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Proxmox VE REST API Client
2+
3+
Go client for the Proxmox VE REST API (https://pve.proxmox.com/wiki/Proxmox_VE_API)
4+
5+
## Overview
6+
A Go package containing a client for [Proxmox VE](https://www.proxmox.com/). The client implements [/api2/json](https://pve.proxmox.com/pve-docs/api-viewer/index.html) and aims to provide better sdk solution for especially [cluster-api-provider-proxmox](https://github.com/sp-yduck/cluster-api-provider-proxmox) and [cloud-provider-proxmox](https://github.com/sp-yduck/cloud-provider-proxmox) project.
7+
8+
## Developing
9+
10+
### Unit Testing
11+
```sh
12+
go test ./... -v -skip ^TestSuiteIntegration
13+
```
14+
15+
### Integration Testing
16+
```sh
17+
export PROXMOX_URL="http://localhost:8006/api2/json"
18+
export PROXMOX_USERNAME="root@pam"
19+
export PROXMOX_PASSWORD="password"
20+
21+
go test ./... -v -run ^TestSuiteIntegration
22+
```
Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
1-
package proxmox
2-
3-
type Node struct {
4-
Cpu float32 `json:"cpu"`
5-
Disk int `json:"disk"`
6-
ID string `json:"id"`
7-
Level string `json:"level"`
8-
MaxCpu int `json:"maxcpu"`
9-
MaxDisk int `json:"maxdisk"`
10-
MaxMem int `json:"maxmem"`
11-
Mem int `json:"mem"`
12-
Node string `json:"node"`
13-
SSLFingerprint string `json:"ssl_fingerprint"`
14-
Stauts string `json:"status"`
15-
Type string `json:"type"`
16-
UpTime int `json:"uptime"`
17-
}
18-
19-
func (c *RESTClient) GetNodes() ([]*Node, error) {
20-
var nodes []*Node
21-
if err := c.Get("/nodes", &nodes); err != nil {
22-
return nil, err
23-
}
24-
return nodes, nil
25-
}
26-
27-
func (c *RESTClient) GetNode(name string) (*Node, error) {
28-
nodes, err := c.GetNodes()
29-
if err != nil {
30-
return nil, err
31-
}
32-
for _, n := range nodes {
33-
if n.Node == name {
34-
return n, nil
35-
}
36-
}
37-
return nil, NotFoundErr
38-
}
1+
package api
2+
3+
type Node struct {
4+
Cpu float32 `json:"cpu"`
5+
Disk int `json:"disk"`
6+
ID string `json:"id"`
7+
Level string `json:"level"`
8+
MaxCpu int `json:"maxcpu"`
9+
MaxDisk int `json:"maxdisk"`
10+
MaxMem int `json:"maxmem"`
11+
Mem int `json:"mem"`
12+
Node string `json:"node"`
13+
SSLFingerprint string `json:"ssl_fingerprint"`
14+
Stauts string `json:"status"`
15+
Type string `json:"type"`
16+
UpTime int `json:"uptime"`
17+
}

proxmox/qemu_type.go renamed to api/qemu_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package proxmox
1+
package api
22

33
type VirtualMachine struct {
44
Cpu float32 `json:",omitempty"`

api/session_type.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package api
2+
3+
type Session struct {
4+
Username string `json:"username"`
5+
CSRFPreventionToken string `json:"CSRFPreventionToken,omitempty"`
6+
ClusterName string `json:"clustername,omitempty"`
7+
Ticket string `json:"ticket,omitempty"`
8+
}

api/storage_type.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package api
2+
3+
type Storage struct {
4+
Active int
5+
Avail int
6+
Content string
7+
Enabled int
8+
Shared int
9+
Storage string
10+
Total int
11+
Type string
12+
Used int
13+
UsedFraction float64 `json:"used_fraction"`
14+
}
15+
16+
// wip
17+
// https://pve.proxmox.com/pve-docs/api-viewer/#/storage
18+
type StorageCreateOptions struct {
19+
Storage string `json:"storage,omitempty"`
20+
StorageType string `json:"type,omitempty"`
21+
// allowed cotent types
22+
// NOTE: the value 'rootdir' is used for Containers, and value 'images' for VMs
23+
Content string `json:"content,omitempty"`
24+
ContentDirs string `json:"content-dirs,omitempty"`
25+
Format string `json:"format,omitempty"`
26+
Mkdir bool `json:"mkdir,omitempty"`
27+
Path string `json:"path,omitempty"`
28+
}

api/task_type.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package api
2+
3+
type Task struct {
4+
Endtime int `json:"endtime"`
5+
// Id string `json:"id,omitempty"`
6+
Node string `json:"node"`
7+
PID int `json:"pid"`
8+
PStart int `json:"pstart"`
9+
StartTime int `json:"starttime"`
10+
Status string `json:"status"`
11+
Type string `json:"type"`
12+
UPID string `json:"upid"`
13+
User string `json:"user"`
14+
}
15+
16+
type TaskStatus struct {
17+
Exitstatus string `json:"exitstatus"`
18+
Id string `json:"id"`
19+
}

api/version_type.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package api
2+
3+
type Version struct {
4+
Release string `json:"release"`
5+
RepoID string `json:"repoid"`
6+
Version string `json:"version"`
7+
Console Console `json:"console"`
8+
}
9+
10+
type Console string

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,13 @@ module github.com/sp-yduck/proxmox-go
22

33
go 1.20
44

5-
require github.com/pkg/errors v0.9.1
5+
require (
6+
github.com/pkg/errors v0.9.1
7+
github.com/stretchr/testify v1.8.4
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v3 v3.0.1 // indirect
14+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
24
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
8+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)