1package vps
2
3import (
4	"github.com/transip/gotransip/v6/ipaddress"
5	"github.com/transip/gotransip/v6/product"
6	"github.com/transip/gotransip/v6/rest"
7	"net"
8)
9
10// BackupStatus is one of the following strings
11// 'active', 'creating', 'reverting', 'deleting', 'pendingDeletion', 'syncing', 'moving'
12type BackupStatus string
13
14// Definition of all of the possible backup statuses
15const (
16	// BackupStatusActive is the status field for a ready to use backup
17	BackupStatusActive BackupStatus = "active"
18	// BackupStatusCreating is the status field for a backup that is still in creation
19	BackupStatusCreating BackupStatus = "creating"
20	// BackupStatusReverting is the status field for a currently used backup for a revert
21	BackupStatusReverting BackupStatus = "reverting"
22	// BackupStatusDeleting is the status field for a backup that is about to be deleted
23	BackupStatusDeleting BackupStatus = "deleting"
24	// BackupStatusPendingDeletion is the status field for a backup that has a pending deletion
25	BackupStatusPendingDeletion BackupStatus = "pendingDeletion"
26	// BackupStatusSyncing is the status field for a backup that is still syncing
27	BackupStatusSyncing BackupStatus = "syncing"
28	// BackupStatusMoving is the status field for a moving backup, this means that the backup is under migration
29	BackupStatusMoving BackupStatus = "moving"
30)
31
32// SnapshotStatus is one of the following strings
33// 'active', 'creating', 'reverting', 'deleting', 'pendingDeletion', 'syncing', 'moving'
34type SnapshotStatus string
35
36// Definition of all of the possible snapshot statuses
37const (
38	// SnapshotStatusActive is the status field for an active snapshot, ready to use
39	SnapshotStatusActive SnapshotStatus = "active"
40	// SnapshotStatusCreating is the status field for a snapshot that is going to be created
41	SnapshotStatusCreating SnapshotStatus = "creating"
42	// SnapshotStatusReverting is the status field for snapshot that is being reverted
43	SnapshotStatusReverting SnapshotStatus = "reverting"
44	// SnapshotStatusDeleting is the status field for snapshot that is going to be deleted
45	SnapshotStatusDeleting SnapshotStatus = "deleting"
46	// SnapshotStatusPendingDeletion is the status field for snapshot that is going to be deleted in the near future
47	SnapshotStatusPendingDeletion SnapshotStatus = "pendingDeletion"
48	// SnapshotStatusSyncing is the status field for a snapshot that is still under creation
49	SnapshotStatusSyncing SnapshotStatus = "syncing"
50	// SnapshotStatusMoving is the status field for a snapshot that is moving to another location,
51	// this means that the snapshot is under migration
52	SnapshotStatusMoving SnapshotStatus = "moving"
53)
54
55// Status is one of the following strings
56// 'created', 'installing', 'running', 'stopped', 'paused'
57type Status string
58
59// Definition of all of the possible vps statuses
60const (
61	// VpsStatusCreated is the status field for a vps that is created but not yet used
62	VpsStatusCreated Status = "created"
63	// VpsStatusInstalling is the status field for a vps that is going to be installed
64	VpsStatusInstalling Status = "installing"
65	// VpsStatusRunning is the status field for a vps that is currently turned on
66	VpsStatusRunning Status = "running"
67	// VpsStatusStopped is the status field for a vps that is in stopped state
68	VpsStatusStopped Status = "stopped"
69	// VpsStatusPaused is the status field for a vps that is in paused state
70	VpsStatusPaused Status = "paused"
71)
72
73// UsageType can be one of the following strings
74// 'cpu', 'disk', 'network'
75type UsageType string
76
77const (
78	// UsageTypeCPU is used to request the cpu usage data of a VPS
79	UsageTypeCPU UsageType = "cpu"
80	// UsageTypeDisk is used to request the disk usage data of a VPS
81	UsageTypeDisk UsageType = "disk"
82	// UsageTypeNetwork is used to request the network usage data of a VPS
83	UsageTypeNetwork UsageType = "network"
84)
85
86// InstallFlavour can be one of the following strings
87// 'installer', 'preinstallable', 'cloudinit'
88type InstallFlavour string
89
90const (
91	// InstallFlavourInstaller is used to explicitly specify that the
92	// operating system will be provided through the standard installer
93	InstallFlavourInstaller InstallFlavour = "installer"
94	// InstallFlavourPreinstallable is used to explicitly specify that the
95	// operating system will be provided by a preinstalled image
96	InstallFlavourPreinstallable InstallFlavour = "preinstallable"
97	// InstallFlavourCloudInit is used to explicitly specify that the
98	// operating system will be provided by a cloudinit-enabled image
99	InstallFlavourCloudInit InstallFlavour = "cloudinit"
100)
101
102// vpsWrapper struct contains a Vps in it,
103// this is solely used for unmarshalling/marshalling
104type vpsWrapper struct {
105	Vps Vps `json:"vps"`
106}
107
108// vpssWrapper struct contains a list of Vpses in it,
109// this is solely used for unmarshalling/marshalling
110type vpssWrapper struct {
111	Vpss []Vps `json:"vpss"`
112}
113
114// vpssOrderWrapper struct contains a list of VpsOrders in it,
115// this is solely used for marshalling
116type vpssOrderWrapper struct {
117	Orders []Order `json:"vpss"`
118}
119
120// cloneRequest is solely used for marshalling a vpsName and an availabilityZone
121type cloneRequest struct {
122	VpsName          string `json:"vpsName"`
123	AvailabilityZone string `json:"availabilityZone,omitempty"`
124}
125
126// actionWrapper struct contains an action in it,
127// this is solely used for marshalling
128type actionWrapper struct {
129	Action string `json:"action"`
130}
131
132// handoverRequest is used to request a handover, this is solely used for marshalling
133type handoverRequest struct {
134	Action             string `json:"action"`
135	TargetCustomerName string `json:"targetCustomerName"`
136}
137
138// convertBackupRequest is used to request a backup conversion to snapshot,
139// this is solely used for marshalling
140type convertBackupRequest struct {
141	Action              string `json:"action"`
142	SnapshotDescription string `json:"description"`
143}
144
145// usageWrapper struct contains Usage in it,
146// this is solely used for unmarshalling
147type usageWrapper struct {
148	Usage Usage `json:"usage"`
149}
150
151// vncDataWrapper struct contains VncData in it,
152// this is solely used for unmarshalling
153type vncDataWrapper struct {
154	VncData VncData `json:"vncData"`
155}
156
157// addonsWrapper struct contains a list with Addons in it,
158// this is solely used for unmarshalling
159type addonsWrapper struct {
160	Addons Addons `json:"addons"`
161}
162
163// addonOrderRequest struct contains a list with Addons in it,
164// this is solely used for marshalling
165type addonOrderRequest struct {
166	Addons []string `json:"addons"`
167}
168
169// upgradeRequest struct contains a Product Name in it,
170// this is solely used for marshalling
171type upgradeRequest struct {
172	ProductName string `json:"productName"`
173}
174
175// upgradesWrapper struct contains a list with Products in it,
176// this is solely used for marshalling
177type upgradesWrapper struct {
178	Upgrades []product.Product `json:"upgrades"`
179}
180
181// operatingSystemsWrapper struct contains a list with OperatingSystems in it,
182// this is solely used for marshalling
183type operatingSystemsWrapper struct {
184	OperatingSystems []OperatingSystem `json:"operatingSystems"`
185}
186
187// ipAddressWrapper struct contains an IPAddress in it,
188// this is solely used for unmarshalling
189type ipAddressWrapper struct {
190	IPAddress ipaddress.IPAddress `json:"ipAddress"`
191}
192
193// snapshotWrapper struct contains a Snapshot in it,
194// this is solely used for unmarshalling
195type snapshotWrapper struct {
196	Snapshot Snapshot `json:"snapshot"`
197}
198
199// snapshotWrapper struct contains a list of Snapshots in it,
200// this is solely used for unmarshalling
201type snapshotsWrapper struct {
202	Snapshots []Snapshot `json:"snapshots"`
203}
204
205// backupsWrapper struct contains a list of Backups in it,
206// this is solely used for unmarshalling
207type backupsWrapper struct {
208	Backups []Backup `json:"backups"`
209}
210
211// firewallWrapper struct contains a Firewall in it,
212// this is solely used for marshalling/unmarshalling
213type firewallWrapper struct {
214	Firewall Firewall `json:"vpsFirewall"`
215}
216
217// privateNetworkWrapper struct contains a PrivateNetwork in it,
218// this is solely used for marshalling/unmarshalling
219type privateNetworkWrapper struct {
220	PrivateNetwork PrivateNetwork `json:"privateNetwork"`
221}
222
223// privateNetworksWrapper struct contains a PrivateNetwork in it,
224// this is solely used for unmarshalling
225type privateNetworksWrapper struct {
226	PrivateNetworks []PrivateNetwork `json:"privateNetworks"`
227}
228
229// privateNetworkActionWrapper struct is used to attach/detach a vps with a private network,
230// this is solely used for marshalling
231type privateNetworkActionwrapper struct {
232	Action  string `json:"action"`
233	VpsName string `json:"vpsName"`
234}
235
236// privateNetworkOrderRequest struct contains a description in it,
237// this is solely used for ordering a private network and encapsulating the description
238type privateNetworkOrderRequest struct {
239	Description string `json:"description"`
240}
241
242// addIPRequest struct contains an IPAddress in it,
243// this is solely used for marshalling
244type addIPRequest struct {
245	IPAddress net.IP `json:"ipAddress"`
246}
247
248// createSnapshotRequest is used to marshal a request for creating a snapshot on a vps
249// this is solely used for marshalling
250type createSnapshotRequest struct {
251	Description    string `json:"description"`
252	ShouldStartVps bool   `json:"shouldStartVps"`
253}
254
255// revertSnapshotRequest is used to marshal a request for reverting a snapshot to a vps
256// this is solely used for marshalling
257type revertSnapshotRequest struct {
258	DestinationVpsName string `json:"destinationVpsName"`
259}
260
261// installRequest struct contains a list with OperatingSystems in it,
262// this is used for marshalling and aliased by InstallOptions
263type installRequest struct {
264	// The name of the operating system to install
265	OperatingSystemName string `json:"operatingSystemName"`
266	// Install flavour to use for providing the operating system (optional)
267	// If the field is left empty, the default install flavour for the operating system will be used
268	InstallFlavour InstallFlavour `json:"installFlavour,omitempty"`
269	// The name for the host, only needed for the preinstallable and cloudinit install flavours
270	Hostname string `json:"hostname,omitempty"`
271	// Username used for account creating during cloudinit installation (max 32 chars)
272	Username string `json:"username,omitempty"`
273	// Array of public SSH keys to use for account creating during installation
274	// (currently only supported with the cloudinit flavour)
275	SSHKeys []string `json:"sshKeys,omitempty"`
276	// Base64 encoded preseed / kickstart / cloudinit instructions, when installing unattended
277	Base64InstallText string `json:"base64InstallText,omitempty"`
278}
279
280// InstallOptions can be used to provide options to
281// the InstallOperatingSystemWithOptions method
282type InstallOptions installRequest
283
284// bigStorageWrapper struct contains a BigStorage in it,
285// this is solely used for marshalling/unmarshalling
286type bigStorageWrapper struct {
287	BigStorage BigStorage `json:"bigStorage"`
288}
289
290// bigStoragesWrapper struct contains a list of BigStorages in it,
291// this is solely used for unmarshalling
292type bigStoragesWrapper struct {
293	BigStorages []BigStorage `json:"bigStorages"`
294}
295
296// bigStorageUpgradeRequest struct is used upon when upgrading a bigstorage
297// this struct is used for marshalling the request
298type bigStorageUpgradeRequest struct {
299	BigStorageName string `json:"bigStorageName"`
300	Size           int    `json:"size"`
301	OffsiteBackups bool   `json:"offsiteBackups"`
302}
303
304// bigStorageBackupsWrapper struct contains a list of BigStorageBackups in it,
305// this is solely used for unmarshalling
306type bigStorageBackupsWrapper struct {
307	BigStorageBackups []BigStorageBackup `json:"backups"`
308}
309
310// usageDataDiskWrapper struct contains UsageDataDisk struct in it
311type usageDataDiskWrapper struct {
312	Usage []UsageDataDisk `json:"usage"`
313}
314
315// tcpMonitorsWrapper struct is used for unmarshalling a []TCPMonitor list
316type tcpMonitorsWrapper struct {
317	TCPMonitors []TCPMonitor `json:"tcpMonitors"`
318}
319
320// tcpMonitorWrapper struct is used for marshalling/unmarshalling the TCPMonitor struct
321type tcpMonitorWrapper struct {
322	TCPMonitor TCPMonitor `json:"tcpMonitor"`
323}
324
325// contactsWrapper struct is used for unmarshalling a []MonitoringContact list
326type contactsWrapper struct {
327	Contacts []MonitoringContact `json:"contacts"`
328}
329
330// contactWrapper struct is used for marshalling/unmarshalling a MonitoringContact
331type contactWrapper struct {
332	Contact MonitoringContact `json:"contact"`
333}
334
335// Vps struct for a Vps
336type Vps struct {
337	// The unique VPS name
338	Name string `json:"name"`
339	// The unique identifier for the VPS
340	UUID string `json:"uuid"`
341	// The name that can be set by customer
342	Description string `json:"description"`
343	// The product name
344	ProductName string `json:"productName,omitempty"`
345	// The VPS OperatingSystem
346	OperatingSystem string `json:"operatingSystem,omitempty"`
347	// The VPS disk size in kB
348	DiskSize int64 `json:"diskSize,omitempty"`
349	// The VPS memory size in kB
350	MemorySize int64 `json:"memorySize,omitempty"`
351	// The VPS cpu count
352	CPUs int `json:"cpus,omitempty"`
353	// The VPS status, either 'created', 'installing', 'running', 'stopped' or 'paused'
354	Status Status `json:"status,omitempty"`
355	// The VPS main ipAddress
356	IPAddress string `json:"ipAddress,omitempty"`
357	// The VPS macaddress
358	MacAddress string `json:"macAddress,omitempty"`
359	// The amount of snapshots that is used on this VPS
360	CurrentSnapshots int `json:"currentSnapshots,omitempty"`
361	// The maximum amount of snapshots for this VPS
362	MaxSnapshots int `json:"maxSnapshots,omitempty"`
363	// Whether or not another process is already doing stuff with this VPS
364	IsLocked bool `json:"isLocked,omitempty"`
365	// If the VPS is administratively blocked
366	IsBlocked bool `json:"isBlocked,omitempty"`
367	// If this VPS is locked by the customer
368	IsCustomerLocked bool `json:"isCustomerLocked"`
369	// The name of the availability zone the VPS is in
370	AvailabilityZone string `json:"availabilityZone,omitempty"`
371	// The custom tags added to this VPS
372	Tags []string `json:"tags,omitempty"`
373}
374
375// VncData struct for the vps vnc data
376type VncData struct {
377	// Location of the VNC Proxy
378	Host string `json:"host,omitempty"`
379	// Password to setup up the VNC connection (changes dynamically)
380	Password string `json:"password,omitempty"`
381	// Websocket path including the token
382	Path string `json:"path,omitempty"`
383	// token to identify the VPS to connect to (changes dynamically)
384	Token string `json:"token,omitempty"`
385	// Complete websocket URL
386	URL string `json:"url,omitempty"`
387}
388
389// UsageDataNetwork struct for UsageDataNetwork
390type UsageDataNetwork struct {
391	// Date of the entry, by default in UNIX timestamp format
392	Date float32 `json:"date"`
393	// The amount of inbound traffic in Mbps for this usage entry
394	MbitIn float32 `json:"mbitIn"`
395	// The amount of outbound traffic in Mbps for this usage entry
396	MbitOut float32 `json:"mbitOut"`
397}
398
399// UsagePeriod is struct that can be used to query usage statistics for a certain period
400type UsagePeriod struct {
401	// TimeStart contains a unix timestamp for the start of the period
402	TimeStart int64 `json:"dateTimeStart"`
403	// TimeEnd contains a unix timestamp for the end of the period
404	TimeEnd int64 `json:"dateTimeEnd"`
405}
406
407// UsageDataDisk struct contains disk usage for a certain date
408type UsageDataDisk struct {
409	// Date of the entry, by default in UNIX timestamp format
410	Date int64 `json:"date"`
411	// The read IOPS for this entry
412	IopsRead float32 `json:"iopsRead"`
413	// The write IOPS for this entry
414	IopsWrite float32 `json:"iopsWrite"`
415}
416
417// UsageDataCPU struct contains cpu usage percentage for a certain date
418type UsageDataCPU struct {
419	// Date of the entry, by default in UNIX timestamp format
420	Date int64 `json:"date"`
421	// The percentage of CPU usage for this entry
422	Percentage float32 `json:"percentage"`
423}
424
425// Order struct can be used to order a new VPS
426type Order struct {
427	// Name of the product
428	ProductName string `json:"productName"`
429	// The name of the operating system to install
430	OperatingSystem string `json:"operatingSystem"`
431	// The name of the availability zone where the vps should be created
432	AvailabilityZone string `json:"availabilityZone,omitempty"`
433	// The description of the VPS
434	Description string `json:"description,omitempty"`
435	// Array with additional addons
436	Addons []string `json:"addons,omitempty"`
437	// Install flavour to use for providing the operating system (optional)
438	// If the field is left empty, the default install flavour for the operating system will be used
439	InstallFlavour InstallFlavour `json:"installFlavour,omitempty"`
440	// The name for the host, only needed for the preinstallable and cloudinit install flavours
441	Hostname string `json:"hostname,omitempty"`
442	// Username used for account creating during cloudinit installation (max 32 chars)
443	Username string `json:"username,omitempty"`
444	// Array of public SSH keys to use for account creating during installation
445	// (currently only supported with the cloudinit flavour)
446	SSHKeys []string `json:"sshKeys,omitempty"`
447	// Base64 encoded preseed / kickstart / cloudinit instructions, when installing unattended
448	Base64InstallText string `json:"base64InstallText,omitempty"`
449}
450
451// Addons struct for an Addons
452type Addons struct {
453	// A list of all active addons
454	Active []product.Product `json:"active,omitempty"`
455	// A list of available addons that you can order
456	Available []product.Product `json:"available,omitempty"`
457	// A list of addons that you can cancel
458	Cancellable []product.Product `json:"cancellable,omitempty"`
459}
460
461// Backup struct for a Backup
462type Backup struct {
463	// The backup id
464	ID int64 `json:"id"`
465	// Status of the backup ('active', 'creating', 'reverting', 'deleting', 'pendingDeletion', 'syncing', 'moving')
466	Status BackupStatus `json:"status"`
467	// The backup creation date
468	DateTimeCreate rest.Time `json:"dateTimeCreate"`
469	// The backup disk size in kB
470	DiskSize int64 `json:"diskSize"`
471	// The backup operatingSystem
472	OperatingSystem string `json:"operatingSystem"`
473	// The name of the availability zone the backup is in
474	AvailabilityZone string `json:"availabilityZone"`
475}
476
477// Snapshot struct for a Snapshot
478type Snapshot struct {
479	// The snapshot creation date
480	DateTimeCreate string `json:"dateTimeCreate,omitempty"`
481	// The snapshot description
482	Description string `json:"description,omitempty"`
483	// The size of the snapshot in kB
484	DiskSize int64 `json:"diskSize,omitempty"`
485	// The snapshot name
486	Name string `json:"name,omitempty"`
487	// The snapshot OperatingSystem
488	OperatingSystem string `json:"operatingSystem,omitempty"`
489	// The snapshot status ('active', 'creating', 'reverting', 'deleting', 'pendingDeletion', 'syncing', 'moving')
490	Status SnapshotStatus `json:"status,omitempty"`
491}
492
493// OperatingSystem struct for an OperatingSystem
494type OperatingSystem struct {
495	// Description
496	Description string `json:"description,omitempty"`
497	// Is a preinstallable image
498	// Deprecated: Use the InstallFlavours field to determine this instead
499	IsPreinstallableImage bool `json:"isPreinstallableImage,omitempty"`
500	// List of supported install flavours for this operating system
501	InstallFlavours []InstallFlavour `json:"installFlavours"`
502	// The operating system name
503	Name string `json:"name"`
504	// The monthly price of the operating system in cents
505	Price int `json:"price,omitempty"`
506	// The version of the operating system
507	Version string `json:"version,omitempty"`
508	// available licenses for this operating system
509	Licenses []LicenseProduct `json:"licenses,omitempty"`
510}
511
512// Usage struct for an Usage
513type Usage struct {
514	CPU     []UsageDataCPU     `json:"cpu"`
515	Disk    []UsageDataDisk    `json:"disk"`
516	Network []UsageDataNetwork `json:"network"`
517}
518