-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
virtual_environment_client_types.go
79 lines (64 loc) · 1.94 KB
/
virtual_environment_client_types.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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package proxmox
import (
"io"
"net/http"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster"
"github.com/bpg/terraform-provider-proxmox/proxmox/container"
"github.com/bpg/terraform-provider-proxmox/proxmox/vm"
)
const (
basePathJSONAPI = "api2/json"
)
// VirtualEnvironmentClient implements an API client for the Proxmox Virtual Environment API.
type VirtualEnvironmentClient struct {
Endpoint string
Insecure bool
OTP *string
Password string
Username string
SSHUsername string
SSHPassword string
SSHAgent bool
SSHAgentSocket string
authenticationData *VirtualEnvironmentAuthenticationResponseData
httpClient *http.Client
}
// VirtualEnvironmentErrorResponseBody contains the body of an error response.
type VirtualEnvironmentErrorResponseBody struct {
Data *string
Errors *map[string]string
}
// VirtualEnvironmentMultiPartData enables multipart uploads in DoRequest.
type VirtualEnvironmentMultiPartData struct {
Boundary string
Reader io.Reader
Size *int64
}
type API interface {
Cluster() *cluster.Client
VM(nodeName string, vmID int) *vm.Client
Container(nodeName string, vmID int) *container.Client
}
func (c *VirtualEnvironmentClient) API() API {
return &client{c}
}
func (c *VirtualEnvironmentClient) ExpandPath(path string) string {
return path
}
type client struct {
c *VirtualEnvironmentClient
}
func (c *client) Cluster() *cluster.Client {
return &cluster.Client{Client: c.c}
}
func (c *client) VM(nodeName string, vmID int) *vm.Client {
return &vm.Client{Client: c.c, NodeName: nodeName, VMID: vmID}
}
func (c *client) Container(nodeName string, vmID int) *container.Client {
return &container.Client{Client: c.c, NodeName: nodeName, VMID: vmID}
}