cisco/sdk/instance.go -rw-r--r-- 5.1 KiB View raw
                                                                                
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package cisco

import (
	"encoding/json"
	"time"
)

type Instance struct {
	Uuid         string    `json:"uuid"`
	Name         string    `json:"name"`
	Status       string    `json:"status"`
	Ipv4         string    `json:"ipv4"`
	Ipv4Private  string    `json:"ipv4_private"`
	Ipv6         string    `json:"ipv6"`
	Ipv6Mask     string    `json:"ipv6_mask"`
	Size         uint      `json:"size"`
	OS           string    `json:"os"`
	Architecture string    `json:"architecture"`
	Type         string    `json:"type"`
	Created      time.Time `json:"created"`
}

type InstanceType struct {
	Name         string `json:"name"`
	Architecture string `json:"architecture"`
	CPU          int    `json:"cpu"`
	Memory       int    `json:"memory"`
	Type         string `json:"type"`
	Enabled      bool   `json:"enabled"`
}

func ListInstance() ([]Instance, error) {
	var result []Instance

	data, err := SendRequest(InstanceListRoute, Request{})

	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

func ShowInstance(name string) (Instance, error) {
	var result Instance

	data, err := SendRequest(InstanceShowRoute, Request{
		Arg: name,
	})

	if err != nil {
		return result, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

type InstanceNew struct {
	Name string `json:"name"`
	OS   string `json:"os"`
	Type string `json:"type"`
	Size uint   `json:"size"`
}

func NewInstance(instance InstanceNew) error {
	_, err := SendRequest(InstanceNewRoute, Request{
		Data: instance,
	})

	return err
}

func StartInstance(name string) error {
	_, err := SendRequest(InstanceStartRoute, Request{
		Arg: name,
	})

	return err
}

func StopInstance(name string) error {
	_, err := SendRequest(InstanceStopRoute, Request{
		Arg: name,
	})

	return err
}

func DeleteInstance(name string) error {
	_, err := SendRequest(InstanceDeleteRoute, Request{
		Arg: name,
	})

	return err
}

func CreateInstanceType(name string) error {
	_, err := SendRequest(AdminInstanceTypeCreateRoute, Request{
		Arg: name,
	})

	return err
}

func DeleteInstanceType(name string) error {
	_, err := SendRequest(AdminInstanceTypeDeleteRoute, Request{
		Arg: name,
	})

	return err
}

func ListInstanceType() ([]InstanceType, error) {
	var result []InstanceType

	data, err := SendRequest(AdminInstanceTypeListRoute, Request{})

	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

func GetInstanceType(name string) (InstanceType, error) {
	var result InstanceType

	data, err := SendRequest(AdminInstanceTypeGetRoute, Request{
		Arg: name,
	})

	if err != nil {
		return result, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

type InstanceTypeArchUpdate struct {
	Arch string `json:"arch"`
}

func UpdateInstanceTypeArch(name string, architecture string) error {
	_, err := SendRequest(AdminInstanceTypeUpdateArchRoute, Request{
		Arg: name,
		Data: &InstanceTypeArchUpdate{
			Arch: architecture,
		},
	})

	return err
}

type InstanceTypeCPUUpdate struct {
	CPU int `json:"cpu"`
}

func UpdateInstanceTypeCPU(name string, cpu int) error {
	_, err := SendRequest(AdminInstanceTypeUpdateCPURoute, Request{
		Arg: name,
		Data: &InstanceTypeCPUUpdate{
			CPU: cpu,
		},
	})

	return err
}

type InstanceTypeMemoryUpdate struct {
	Memory int `json:"cpu"`
}

func UpdateInstanceTypeMemory(name string, memory int) error {
	_, err := SendRequest(AdminInstanceTypeUpdateMemoryRoute, Request{
		Arg: name,
		Data: &InstanceTypeMemoryUpdate{
			Memory: memory,
		},
	})

	return err
}

type InstanceTypeTypeUpdate struct {
	Type string `json:"string"`
}

func UpdateInstanceTypeType(name string, instanceType string) error {
	_, err := SendRequest(AdminInstanceTypeUpdateTypeRoute, Request{
		Arg: name,
		Data: &InstanceTypeTypeUpdate{
			Type: instanceType,
		},
	})

	return err
}

type InstanceTypeEnableUpdate struct {
	Enable bool `json:"enable"`
}

func UpdateInstanceTypeEnable(name string, enable bool) error {
	_, err := SendRequest(AdminInstanceTypeUpdateEnableRoute, Request{
		Arg: name,
		Data: &InstanceTypeEnableUpdate{
			Enable: enable,
		},
	})

	return err
}

func ListInstanceTypes() ([]InstanceType, error) {
	var result []InstanceType

	data, err := SendRequest(InstanceTypesRoute, Request{})

	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

type InstanceSizeUpdate struct {
	Size uint `json:"size"`
}

func ResizeInstance(name string, size uint) error {
	_, err := SendRequest(InstanceResizeRoute, Request{
		Arg: name,
		Data: &InstanceSizeUpdate{
			Size: size,
		},
	})

	return err
}

type InstanceTypeUpdate struct {
	Type string `json:"type"`
}

func SetTypeInstance(name string, Itype string) error {
	_, err := SendRequest(InstanceTypeRoute, Request{
		Arg: name,
		Data: &InstanceTypeUpdate{
			Type: Itype,
		},
	})

	return err
}

type InstanceNameUpdate struct {
	Name string `json:"name"`
}

func SetNameInstance(name string, newName string) error {
	_, err := SendRequest(InstanceSetNameRoute, Request{
		Arg: name,
		Data: &InstanceNameUpdate{
			Name: newName,
		},
	})

	return err
}