-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
88 lines (69 loc) · 2.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"github.com/dragse/proxmox-api-go/client"
"github.com/dragse/proxmox-api-go/proxmox"
"github.com/dragse/proxmox-api-go/proxmox/builder"
"github.com/dragse/proxmox-api-go/static/disk"
"github.com/dragse/proxmox-api-go/util"
"log"
)
func main() {
session := client.ProxmoxSession{
Hostname: "192.168.1.205:8006",
Username: "prox-api@pve!test-token",
Token: "1fedfb41-b8f3-40a7-8707-6f40fe617d19",
VerifySSL: false,
}
proxClient := client.NewProxmoxClient()
err := proxClient.AddSession(&session)
if err != nil {
log.Fatal(err)
}
proxCluster := proxmox.NewProxmoxCluster(proxClient)
err = proxCluster.InitInformation()
if err != nil {
log.Fatal(err)
}
//m, err := proxClient.Get(endpoints.Pools_Pool_.FormatValues("test"))
/*builder := builder.NewVmBuilder().
SetID("434").
SetName("testvm").
SetCPUType("host").
SetSocket(1).
SetCoresPerSocket(3).
SetMemory(util.NewBytesFromGigaBytes(4)).
SetIso("local", "debian-11.0.0-amd64-netinst.iso").
SetOSType(operation_system.L24).
AddNetwork("vmbr0").
AddStorage("local-lvm", "5").
SetPool("test")
m, err := proxCluster.GetNode("pve").CreateVM(builder)*/
//m, err := proxCluster.GetPool("test").GetDetail()
_, err = proxCluster.GetNode("pve").GetVM(105).Clone(builder.NewVmCopyBuilder().SetFullCopy(true).SetPool("test").SetName("copy").SetTargetNode("pve").SetNewID(999))
if err != nil {
log.Fatal(err)
}
copyBuilder := builder.NewVmBuilder().
SetName("cloudCoyp").
SetCoresPerSocket(4).
SetMemory(util.NewBytesFromGigaBytes(16)).
SetCloudInitDrive("local-lvm").
SetCloudInit(builder.NewCloudInitBuilder().
SetNameservers("1.1.1.1").
SetUser("hans").
AddIPConfig("10.0.0.10/24", "10.0.0.1", "", ""))
vals := copyBuilder.BuildToValues()
for k, v := range vals {
log.Println(k, " => ", v)
}
err = proxCluster.GetNode("pve").GetVM(999).UpdateConfigASync(copyBuilder)
if err != nil {
log.Fatal(err)
}
err = proxCluster.GetNode("pve").GetVM(999).Resize(disk.Scsi0, util.NewBytesFromGigaBytes(20))
if err != nil {
log.Fatal(err)
}
//test, _ := json.Marshal(m)
//log.Println(string(test))
}