-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmachine.go
148 lines (119 loc) · 5.16 KB
/
machine.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package paperspace
import (
"fmt"
"time"
)
type MachineState string
const (
MachineStateOff MachineState = "off"
MachineStateProvisioning MachineState = "provisioning"
MachineStateRunning MachineState = "running"
)
type Machine struct {
ID string `json:"id"`
Name string `json:"name"`
OS string `json:"os"`
RAM int64 `json:"ram,string"`
CPUs int `json:"cpus"`
GPU string `json:"gpu"`
State MachineState `json:"state"`
Region string `json:"region"`
StorageTotal int64 `json:"storageTotal,string"`
StorageUsed int64 `json:"storageUsed,string"`
UsageRate string `json:"usageRate"`
ShutdownTimeoutInHours int `json:"shutdownTimeoutInHours"`
ShutdownTimeoutForces bool `json:"shutdownTimeoutForces"`
AutoSnapshotFrequency int `json:"autoSnapshotFrequency"`
AutoSnapshotSaveCount int `json:"autoSnapshotSaveCount"`
RestorePointSnapshotID string `json:"restorePointSnapshotId"`
RestorePointFrequency string `json:"restorePointFrequency"`
AgentType string `json:"agentType"`
NetworkID string `json:"networkId"`
PrivateIpAddress string `json:"privateIpAddress"`
PublicIpAddress string `json:"publicIpAddress"`
DtCreated time.Time `json:"dtCreated"`
DtDeleted time.Time `json:"dtDeleted"`
UserID string `json:"userId"`
TeamID string `json:"teamId"`
ScriptID string `json:"scriptId"`
DtLastRun string `json:"dtLastRun"`
IsManaged bool `json:"isManaged"`
MachineType string `json:"machineType"`
}
type MachineCreateParams struct {
RequestParams
Name string `json:"name"`
Region string `json:"region"`
MachineType string `json:"machineType"`
Size int `json:"size"`
BillingType string `json:"billingType"`
TemplateID string `json:"templateId"`
UserID string `json:"userId,omitempty"`
TeamID string `json:"teamId,omitempty"`
ScriptID string `json:"scriptId,omitempty"`
NetworkID string `json:"networkId,omitempty"`
ShutdownTimeoutInHours int `json:"shutdownTimeoutInHours,omitempty"`
AssignPublicIP *bool `json:"assignPublicIP,omitempty"`
IsManaged *bool `json:"isManaged,omitempty"`
StartOnCreate *bool `json:"startOnCreate,omitempty"`
TakeInitialSnapshot *bool `json:"takeInitialSnapshot,omitempty"`
MarkSnapshotAsRestorePoint *bool `json:"markSnapshotAsRestorePoint,omitempty"`
RestorePointFrequency string `json:"restorePointFrequency,omitempty"`
}
type MachineDeleteParams struct {
RequestParams
}
type MachineGetParams struct {
RequestParams
}
type MachineListParams struct {
RequestParams
Filter Filter `json:"filter,omitempty"`
}
type MachineUpdateAttributeParams struct {
RequestParams
Name string `json:"name,omitempty" yaml:"name"`
}
type MachineUpdateParams struct {
RequestParams
ID string `json:"machineId"`
Name string `json:"machineName,omitempty"`
ShutdownTimeoutInHours int `json:"shutdownTimeoutInHours,omitempty"`
ShutdownTimeoutForces *bool `json:"shutdownTimeoutForces,omitempty"`
AutoSnapshotFrequency string `json:"autoSnapshotFrequency,omitempty"`
AutoSnapshotSaveCount int `json:"autoSnapshotSaveCount,omitempty"`
PerformAutoSnapshot *bool `json:"performAutoSnapshot,omitempty"`
DynamicPublicIP *bool `json:"dynamicPublicIp,omitempty"`
}
func NewMachineListParams() MachineListParams {
return MachineListParams{}
}
func (c Client) CreateMachine(params MachineCreateParams) (Machine, error) {
machine := Machine{}
url := fmt.Sprintf("/machines/createSingleMachinePublic")
_, err := c.Request("POST", url, params, &machine, params.RequestParams)
return machine, err
}
func (c Client) GetMachine(id string, params MachineGetParams) (Machine, error) {
machine := Machine{}
url := fmt.Sprintf("/machines/getMachinePublic?machineId=%s", id)
_, err := c.Request("GET", url, nil, &machine, params.RequestParams)
return machine, err
}
func (c Client) GetMachines(params MachineListParams) ([]Machine, error) {
var machines []Machine
url := fmt.Sprintf("/machines/getMachines")
_, err := c.Request("GET", url, params, &machines, params.RequestParams)
return machines, err
}
func (c Client) UpdateMachine(params MachineUpdateParams) (Machine, error) {
machine := Machine{}
url := fmt.Sprintf("/machines/updateMachine")
_, err := c.Request("POST", url, params, &machine, params.RequestParams)
return machine, err
}
func (c Client) DeleteMachine(id string, params MachineDeleteParams) error {
url := fmt.Sprintf("/machines/%s/destroyMachine", id)
_, err := c.Request("POST", url, nil, nil, params.RequestParams)
return err
}