tested real proxmox connection
--> passed
This commit is contained in:
@@ -98,8 +98,9 @@ func NewClient(cluster cluster.Cluster, opts ...Option) (*Client, error) {
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
TLSClientConfig: &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
RootCAs: cfg.rootCAs,
|
||||
MinVersion: tls.VersionTLS12,
|
||||
RootCAs: cfg.rootCAs,
|
||||
InsecureSkipVerify: true,
|
||||
VerifyConnection: func(state tls.ConnectionState) error {
|
||||
return verifyFingerprint(state, fingerprint)
|
||||
},
|
||||
@@ -139,7 +140,7 @@ func (c *Client) GetTaskStatus(ctx context.Context, node string, upid string) (T
|
||||
response, err := c.Get(ctx, fmt.Sprintf(
|
||||
"/nodes/%s/tasks/%s/status",
|
||||
url.PathEscape(node),
|
||||
url.PathEscape(upid),
|
||||
upid,
|
||||
))
|
||||
if err != nil {
|
||||
return TaskStatus{}, err
|
||||
@@ -256,6 +257,66 @@ func (c *Client) CloneVM(ctx context.Context, node string, templateVMID int, new
|
||||
return decodeUPID(response.Body)
|
||||
}
|
||||
|
||||
func (c *Client) ConfigureHardware(ctx context.Context, node string, vmid int, cfg HardwareConfig) (string, error) {
|
||||
requestBody := map[string]any{}
|
||||
if cfg.Cores > 0 {
|
||||
requestBody["cores"] = cfg.Cores
|
||||
}
|
||||
if cfg.Memory > 0 {
|
||||
requestBody["memory"] = cfg.Memory
|
||||
}
|
||||
|
||||
body, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
response, err := c.Post(ctx, fmt.Sprintf(
|
||||
"/nodes/%s/qemu/%d/config",
|
||||
url.PathEscape(node),
|
||||
vmid,
|
||||
), body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode >= http.StatusBadRequest {
|
||||
_, _ = io.Copy(io.Discard, response.Body)
|
||||
return "", fmt.Errorf("proxmox returned %s", response.Status)
|
||||
}
|
||||
|
||||
return decodeUPID(response.Body)
|
||||
}
|
||||
|
||||
func (c *Client) ResizeDisk(ctx context.Context, node string, vmid int, disk string, sizeGB int) (string, error) {
|
||||
requestBody := map[string]any{
|
||||
"disk": disk,
|
||||
"size": fmt.Sprintf("%dG", sizeGB),
|
||||
}
|
||||
body, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
response, err := c.Put(ctx, fmt.Sprintf(
|
||||
"/nodes/%s/qemu/%d/resize",
|
||||
url.PathEscape(node),
|
||||
vmid,
|
||||
), body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode >= http.StatusBadRequest {
|
||||
_, _ = io.Copy(io.Discard, response.Body)
|
||||
return "", fmt.Errorf("proxmox returned %s", response.Status)
|
||||
}
|
||||
|
||||
return decodeUPID(response.Body)
|
||||
}
|
||||
|
||||
func (c *Client) ConfigureCloudInit(ctx context.Context, node string, vmid int, cfg CloudInitConfig) (string, error) {
|
||||
requestBody := map[string]any{
|
||||
"ciuser": cfg.CIUser,
|
||||
@@ -327,6 +388,11 @@ type CloudInitConfig struct {
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
}
|
||||
|
||||
type HardwareConfig struct {
|
||||
Cores int
|
||||
Memory int
|
||||
}
|
||||
|
||||
func decodeUPID(body io.Reader) (string, error) {
|
||||
var response struct {
|
||||
Data string `json:"data"`
|
||||
@@ -364,11 +430,11 @@ func (c *Client) GetVNCTicket(ctx context.Context, node string, vmid int) (VNCIn
|
||||
|
||||
var result struct {
|
||||
Data struct {
|
||||
Port int `json:"port"`
|
||||
Ticket string `json:"ticket"`
|
||||
User string `json:"user"`
|
||||
Cert string `json:"cert"`
|
||||
UPID string `json:"upid"`
|
||||
Port int `json:"port"`
|
||||
Ticket string `json:"ticket"`
|
||||
User string `json:"user"`
|
||||
Cert string `json:"cert"`
|
||||
UPID string `json:"upid"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user