• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..07-Jul-2020-

.gitignoreH A D07-Jul-20206 21

.travis.ymlH A D07-Jul-2020162 127

CHANGELOG.mdH A D07-Jul-20203.6 KiB13094

CONTRIBUTING.mdH A D07-Jul-2020710 2113

CONTRIBUTORS.mdH A D07-Jul-2020118 43

LICENSE.mdH A D07-Jul-20201.1 KiB2217

README.mdH A D07-Jul-202011.5 KiB295259

RELEASECHECKLIST.mdH A D07-Jul-2020540 1212

client.goH A D07-Jul-20202.7 KiB11487

common.goH A D07-Jul-20201.3 KiB5946

config.goH A D07-Jul-20202.6 KiB8967

event.goH A D07-Jul-20201.6 KiB6736

firewall.goH A D07-Jul-20208.5 KiB265145

go.modH A D07-Jul-2020220 118

go.sumH A D07-Jul-20202.6 KiB3029

ip.goH A D07-Jul-20209.8 KiB334189

isoimage.goH A D07-Jul-20208.6 KiB273164

label.goH A D07-Jul-20201.4 KiB6135

loadbalancer.goH A D07-Jul-20209.7 KiB289155

location.goH A D07-Jul-20202.1 KiB7748

network.goH A D07-Jul-202010.5 KiB330193

objectstorage.goH A D07-Jul-20205 KiB15599

paas.goH A D07-Jul-202019.5 KiB602333

request.goH A D07-Jul-20208 KiB262182

server.goH A D07-Jul-202017.9 KiB560332

serverip.goH A D07-Jul-20204 KiB12480

serverisoimage.goH A D07-Jul-20205.3 KiB14394

servernetwork.goH A D07-Jul-20208.7 KiB218118

serverstorage.goH A D07-Jul-20207.5 KiB183105

snapshot.goH A D07-Jul-202010 KiB300180

snapshotscheduler.goH A D07-Jul-20208 KiB213118

sshkey.goH A D07-Jul-20205 KiB173108

storage.goH A D07-Jul-202013.8 KiB407219

template.goH A D07-Jul-20208.1 KiB268170

testcommon.goH A D07-Jul-20201.3 KiB6352

types.goH A D07-Jul-20201.9 KiB9465

README.md

1# The gridscale Go Client
2
3[![Build Status](https://travis-ci.com/gridscale/gsclient-go.svg?branch=master)](https://travis-ci.com/gridscale/gsclient-go) [![Go Report Card](https://goreportcard.com/badge/github.com/gridscale/gsclient-go)](https://goreportcard.com/report/github.com/gridscale/gsclient-go)
4[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/gridscale/gsclient-go?label=release)](https://github.com/gridscale/gsclient-go/releases)
5
6This is a client for the gridscale API. It can be used to make an application interact with the gridscale cloud platform to create and manage resources.
7
8## Preparation for Use
9
10To be able to use this client a number of steps need to be taken. First a gridscale account will be required, which can be created [here](https://my.gridscale.io/signup/). Then an API-token [should be created](https://my.gridscale.io/APIs/).
11
12## Installation
13
14First the Go programming language will need to be installed. This can be done by using [the official Go installation guide](https://golang.org/doc/install) or by using the packages provided by your distribution.
15
16Downloading the gridscale Go client can be done with the following go command:
17
18    $ go get github.com/gridscale/gsclient-go/v3
19
20## Using the gridscale Client
21
22To be able to use the gridscale Go client in an application it can be imported in a go file. This can be done with the following code:
23
24```go
25import (
26	"github.com/gridscale/gsclient-go/v3"
27)
28```
29
30To get access to the functions of the Go client, a Client type needs to be created. This requires a Config type. Both of these can be created with the following code:
31
32```go
33//Using default config
34config := gsclient.DefaultConfiguration("User-UUID", "API-token")
35
36//OR Custom config
37config := gsclient.NewConfiguration(
38            "API-URL",
39            "User-UUID",
40            "API-token",
41            false, //Set debug mode
42            true, //Set sync mode
43            500, //Delay (in milliseconds) between requests
44            100, //Maximum number of retries
45        )
46client := gsclient.NewClient(config)
47```
48
49Make sure to replace the user-UUID and API-token strings with valid credentials or variables containing valid credentials. It is recommended to use environment variables for them.
50
51## Using API endpoints
52
53***Note: `context` has to be passed to all APIs of `gsclient-go` as the first parameter. In case you want to set timeout for a specific operation, you can pass a context with timeout (via `context.WithTimeout` or `context.WithDeadline`)
54
55After having created a Client type, as shown above, it will be possible to interact with the API. An example would be the [Servers Get endpoint](https://gridscale.io/en/api-documentation/index.html#servers-get):
56
57```go
58ctx := context.Background()
59servers := client.GetServerList(ctx)
60```
61
62For creating and updating/patching objects in gridscale, it will be required to use the respective CreateRequest and UpdateRequest types. For creating an IP that would be IPCreateRequest and IPUpdateRequest. Here an example:
63
64```go
65ctx := context.Background()
66requestBody := gsclient.IPCreateRequest{
67	Name:       "IPTest",
68	Family:     gsclient.IPv6Type,
69	Failover:   false,
70	ReverseDNS: "my-reverse-dns-entry.tld",
71	Labels:     []string{"MyLabel"},
72}
73
74client.CreateIP(ctx, requestBody)
75```
76
77For updating/scaling server resources you could use:
78
79```go
80myServerUuid := "[Server UUID]"
81backgroundContext := context.Background()
82
83// No hotplug available for scaling resources down, shutdown server first via ACPI
84shutdownErr := client.ShutdownServer(backgroundContext, myServerUuid)
85if shutdownErr != nil{
86	log.Error("Shutdown server failed", shutdownErr)
87	return
88}
89
90// Update servers resources
91requestBody := gsclient.ServerUpdateRequest{
92	Memory:          12,
93	Cores:           4,
94}
95
96updateErr := client.UpdateServer(backgroundContext, myServerUuid, requestBody)
97if updateErr != nil{
98	log.Error("Serverupdate failed", updateErr)
99	return
100}
101
102// Start server again
103poweronErr := client.StartServer(backgroundContext, myServerUuid)
104if poweronErr != nil{
105	log.Error("Start server failed", poweronErr)
106	return
107}
108```
109
110What options are available for each create and update request can be found in the source code. After installing it should be located in:
111```
112~/go/src/github.com/gridscale/gsclient-go
113```
114## Examples
115Examples on how to use each resource can be found in the examples folder:
116* Firewall (firewall.go)
117* IP (ip.go)
118* ISO-image (isoimage.go)
119* Loadbalancer (loadbalancer.go)
120* Network (network.go)
121* Object Storage (objectstorage.go)
122* PaaS service (paas.go)
123* Server (server.go)
124* Storage (storage.go)
125* Storage snapshot (snapshot.go)
126* Storage snapshot schedule (snapshotschedule.go)
127* SSH-key (sshkey.go)
128* Template (template.go)
129
130## Implemented API Endpoints
131
132Not all endpoints have been implemented in this client, but new ones will be added in the future. Here is the current list of implemented endpoints and their respective function written like endpoint (function):
133
134* Servers
135    * Servers Get (GetServerList)
136    * Server Get (GetServer)
137    * Server Create (CreateServer)
138    * Server Patch (UpdateServer)
139    * Server Delete (DeleteServer)
140    * Server Events Get (GetServerEventList)
141    * Server Metrics Get (GetServerMetricList)
142    * ACPI Shutdown (ShutdownServer) *NOTE: ShutdownServer() will not run StopServer() when it fails to shutdown a server*
143    * Server On/Off (StartServer, StopServer)
144    * Server's Storages Get (GetServerStorageList)
145    * Server's Storage Get (GetServerStorage)
146    * Server's Storage Create (CreateServerStorage)
147    * Server's Storage Update (UpdateServerStorage)
148    * Server's Storage Delete (DeleteServerStorage)
149    * Link Storage (LinkStorage)
150    * Unlink Storage (UnlinkStorage)
151    * Server's Networks Get (GetServerNetworkList)
152    * Server's Network Get (GetServerNetwork)
153    * Server's Network Create (CreateServerNetwork)
154    * Server's Network Update (UpdateServerNetwork)
155    * Server's Network Delete (DeleteServerNetwork)
156    * Link Network (LinkNetwork)
157    * Unlink Network (UnlinkNetwork)
158    * Server's IPs Get (GetServerNetworkList)
159    * Server's IP Get (GetServerNetwork)
160    * Server's IP Create (CreateServerNetwork)
161    * Server's IP Update (UpdateServerNetwork)
162    * Server's IP Delete (DeleteServerNetwork)
163    * Link IP (LinkIP)
164    * Unlink IP (UnlinkIP)
165    * Server's ISO-Images Get (GetServerIsoImageList)
166    * Server's ISO-Image Get (GetServerIsoImage)
167    * Server's ISO-Image Create (CreateServerIsoImage)
168    * Server's ISO-Image Update (UpdateServerIsoImage)
169    * Server's ISO-Image Delete (DeleteServerIsoImage)
170    * Link ISO-Image (LinkIsoimage)
171    * Unlink ISO-Image (UnlinkIsoimage)
172* Storages
173    * Storages Get (GetStorageList)
174    * Storage Get (GetStorage)
175    * Storage Create (CreateStorage)
176    * Storage Clone (CloneStorage)
177    * Storage Patch (UpdateStorage)
178    * Storage Delete (DeleteStorage)
179    * Storage's events Get (GetStorageEventList)
180* Networks
181    * Networks Get (GetNetworkList)
182    * Network Get (GetNetwork)
183    * Network Create (CreateNetwork)
184    * Network Patch (UpdateNetwork)
185    * Network Delete (DeleteNetwork)
186    * Network Events Get (GetNetworkEventList)
187    * (GetNetworkPublic) No official endpoint, but gives the Public Network
188* Loadbalancers
189    * LoadBalancers Get (GetLoadBalancerList)
190    * LoadBalancer Get (GetLoadBalancer)
191    * LoadBalancer Create (CreateLoadBalancer)
192    * LoadBalancer Patch (UpdateLoadBalancer)
193    * LoadBalancer Delete (DeleteLoadBalancer)
194    * LoadBalancerEvents Get (GetLoadBalancerEventList)
195* IPs
196    * IPs Get (GetIPList)
197    * IP Get (GetIP)
198    * IP Create (CreateIP)
199    * IP Patch (UpdateIP)
200    * IP Delete (DeleteIP)
201    * IP Events Get (GetIPEventList)
202    * IP Version Get (GetIPVersion)
203* SSH-Keys
204    * SSH-Keys Get (GetSshkeyList)
205    * SSH-Key Get (GetSshkey)
206    * SSH-Key Create (CreateSshkey)
207    * SSH-Key Patch (UpdateSshkey)
208    * SSH-Key Delete (DeleteSshkey)
209    * SSH-Key's events Get (GetSshkeyEventList)
210* Template
211    * Templates Get (GetTemplateList)
212    * Template Get (GetTemplate)
213    * (GetTemplateByName) No official endpoint, but gives a template which matches the exact name given.
214    * Template Create (CreateTemplate)
215    * Template Update (UpdateTemplate)
216    * Template Delete (DeleteTemplate)
217    * Template's events Get (GetTemplateEventList)
218* PaaS
219    * PaaS services Get (GetPaaSServiceList)
220    * PaaS service Get (GetPaaSService)
221    * PaaS service Create (CreatePaaSService)
222    * PaaS service Update (UpdatePaaSService)
223    * PaaS service Delete (DeletePaaSService)
224    * PaaS service metrics Get (GetPaaSServiceMetrics)
225    * PaaS service templates Get (GetPaaSTemplateList)
226    * PaaS service security zones Get (GetPaaSSecurityZoneList)
227    * Paas service security zone Get (GetPaaSSecurityZone)
228    * PaaS service security zone Create (CreatePaaSSecurityZone)
229    * PaaS service security zone Update (UpdatePaaSSecurityZone)
230    * PaaS service security zone Delete (DeletePaaSSecurityZone)
231* ISO Image
232    * ISO Images Get (GetISOImageList)
233    * ISO Image Get (GetISOImage)
234    * ISO Image Create (CreateISOImage)
235    * ISO Image Update (UpdateISOImage)
236    * ISO Image Delete (DeleteISOImage)
237    * ISO Image Events Get (GetISOImageEventList)
238* Object Storage
239    * Object Storage's Access Keys Get (GetObjectStorageAccessKeyList)
240    * Object Storage's Access Key Get (GetObjectStorageAccessKey)
241    * Object Storage's Access Key Create (CreateObjectStorageAccessKey)
242    * Object Storage's Access Key Delete (DeleteObjectStorageAccessKey)
243    * Object Storage's Buckets Get (GetObjectStorageBucketList)
244* Storage Snapshot Scheduler
245    * Storage Snapshot Schedules Get (GetStorageSnapshotScheduleList)
246    * Storage Snapshot Schedule Get (GetStorageSnapshotSchedule)
247    * Storage Snapshot Schedule Create (CreateStorageSnapshotSchedule)
248    * Storage Snapshot Schedule Update (UpdateStorageSnapshotSchedule)
249    * Storage Snapshot Schedule Delete (DeleteStorageSnapshotSchedule)
250* Storage Snapshot
251    * Storage Snapshots Get (GetStorageSnapshotList)
252    * Storage Snapshot Get (GetStorageSnapshot)
253    * Storage Snapshot Create (CreateStorageSnapshot)
254    * Storage Snapshot Update (UpdateStorageSnapshot)
255    * Storage Snapshot Delete (DeleteStorageSnapshot)
256    * Storage Rollback (RollbackStorage)
257    * Storage Snapshot Export to S3 (ExportStorageSnapshotToS3)
258* Firewall
259    * Firewalls Get (GetFirewallList)
260    * Firewall Get (GetFirewall)
261    * Firewall Create (CreateFirewall)
262    * Firewall Update (UpdateFirewall)
263    * Firewall Delete (DeleteFirewall)
264    * Firewall Events Get (GetFirewallEventList)
265* Event
266    * Events Get (GetEventList)
267* Label
268    * Labels Get (GetLabelList)
269* Location
270    * Locations Get (GetLocationList)
271    * Location Get (GetLocation)
272    * Location IPs Get (GetIPsByLocation)
273    * Location ISO Images Get (GetISOImagesByLocation)
274    * Location Networks Get (GetNetworksByLocation)
275    * Location Servers Get (GetServersByLocation)
276    * Location Snapshots Get (GetSnapshotsByLocation)
277    * Location Storages Get (GetStoragesByLocation)
278    * Location Templates Get (GetTemplatesByLocation)
279* Deleted
280    * Deleted IPs Get (GetDeletedIPs)
281    * Deleted ISO Images Get (GetDeletedISOImages)
282    * Deleted Networks Get (GetDeletedNetworks)
283    * Deleted Servers Get (GetDeletedServers)
284    * Deleted Snapshots Get (GetDeletedSnapshots)
285    * Deleted Storages Get (GetDeletedStorages)
286    * Deleted Templates Get (GetDeletedTemplates)
287    * Deleted PaaS Services Get (GetDeletedPaaSServices)
288
289Note: The functions in this list can be called with a Client type.
290
291## Known Issues
292The following issues are known to us:
293
294* L3security isn't read in the network relation of a server.
295