Categorygithub.com/gridscale/gsclient-go/v2
modulepackage
2.2.2
Repository: https://github.com/gridscale/gsclient-go.git
Documentation: pkg.go.dev

# README

The gridscale Go Client

Build Status Go Report Card

This 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.

Preparation for Use

To 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. Then an API-token should be created.

Installation

First the Go programming language will need to be installed. This can be done by using the official Go installation guide or by using the packages provided by your distribution.

Downloading the gridscale Go client can be done with the following go command:

go get github.com/gridscale/gsclient-go/v2

Using the gridscale Client

To 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:

import (
	"github.com/gridscale/gsclient-go"
)

To 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:

//Using default config
config := gsclient.DefaultConfiguration("User-UUID", "API-token")

//OR Custom config
config := gsclient.NewConfiguration(
            "API-URL", 
            "User-UUID", 
            "API-token", 
            false, //Set debug mode
            true, //Set sync mode 
            120, //Timeout (in seconds) of checking requests
            500, //Delay (in milliseconds) between requests
            100, //Maximum number of retries
        )
client := gsclient.NewClient(config)

Make 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.

Using API endpoints

***Note: context has to be passed to all APIs of gsclient-go as the first parameter.

After 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:

ctx := context.Background()
servers := client.GetServerList(ctx)

For 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:

ctx := context.Background()
requestBody := gsclient.IPCreateRequest{
	Name:       "IPTest",
	Family:     gsclient.IPv6Type,
	Failover:   false,
	ReverseDNS: "my-reverse-dns-entry.tld",
	Labels:     []string{"MyLabel"},
}

client.CreateIP(ctx, requestBody)

For updating/scaling server resources you could use:

myServerUuid := "[Server UUID]"
backgroundContext := context.Background()

// No hotplug available for scaling resources down, shutdown server first via ACPI
shutdownErr := client.ShutdownServer(backgroundContext, myServerUuid)
if shutdownErr != nil{
	log.Error("Shutdown server failed", shutdownErr)
	return
}

// Update servers resources
requestBody := gsclient.ServerUpdateRequest{
	Memory:          12,
	Cores:           4,
}

updateErr := client.UpdateServer(backgroundContext, myServerUuid, requestBody)
if updateErr != nil{
	log.Error("Serverupdate failed", updateErr)
	return
}

// Start server again
poweronErr := client.StartServer(backgroundContext, myServerUuid)
if poweronErr != nil{
	log.Error("Start server failed", poweronErr)
	return
}

What options are available for each create and update request can be found in the source code. After installing it should be located in:

~/go/src/github.com/gridscale/gsclient-go

Examples

Examples on how to use each resource can be found in the examples folder:

  • Firewall (firewall.go)
  • IP (ip.go)
  • ISO-image (isoimage.go)
  • Loadbalancer (loadbalancer.go)
  • Network (network.go)
  • Object Storage (objectstorage.go)
  • PaaS service (paas.go)
  • Server (server.go)
  • Storage (storage.go)
  • Storage snapshot (snapshot.go)
  • Storage snapshot schedule (snapshotschedule.go)
  • SSH-key (sshkey.go)
  • Template (template.go)

Implemented API Endpoints

Not 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):

  • Servers
    • Servers Get (GetServerList)
    • Server Get (GetServer)
    • Server Create (CreateServer)
    • Server Patch (UpdateServer)
    • Server Delete (DeleteServer)
    • Server Events Get (GetServerEventList)
    • Server Metrics Get (GetServerMetricList)
    • ACPI Shutdown (ShutdownServer)
    • Server On/Off (StartServer, StopServer)
    • Server's Storages Get (GetServerStorageList)
    • Server's Storage Get (GetServerStorage)
    • Server's Storage Create (CreateServerStorage)
    • Server's Storage Update (UpdateServerStorage)
    • Server's Storage Delete (DeleteServerStorage)
    • Link Storage (LinkStorage)
    • Unlink Storage (UnlinkStorage)
    • Server's Networks Get (GetServerNetworkList)
    • Server's Network Get (GetServerNetwork)
    • Server's Network Create (CreateServerNetwork)
    • Server's Network Update (UpdateServerNetwork)
    • Server's Network Delete (DeleteServerNetwork)
    • Link Network (LinkNetwork)
    • Unlink Network (UnlinkNetwork)
    • Server's IPs Get (GetServerNetworkList)
    • Server's IP Get (GetServerNetwork)
    • Server's IP Create (CreateServerNetwork)
    • Server's IP Update (UpdateServerNetwork)
    • Server's IP Delete (DeleteServerNetwork)
    • Link IP (LinkIP)
    • Unlink IP (UnlinkIP)
    • Server's ISO-Images Get (GetServerIsoImageList)
    • Server's ISO-Image Get (GetServerIsoImage)
    • Server's ISO-Image Create (CreateServerIsoImage)
    • Server's ISO-Image Update (UpdateServerIsoImage)
    • Server's ISO-Image Delete (DeleteServerIsoImage)
    • Link ISO-Image (LinkIsoimage)
    • Unlink ISO-Image (UnlinkIsoimage)
  • Storages
    • Storages Get (GetStorageList)
    • Storage Get (GetStorage)
    • Storage Create (CreateStorage)
    • Storage Patch (UpdateStorage)
    • Storage Delete (DeleteStorage)
    • Storage's events Get (GetStorageEventList)
  • Networks
    • Networks Get (GetNetworkList)
    • Network Get (GetNetwork)
    • Network Create (CreateNetwork)
    • Network Patch (UpdateNetwork)
    • Network Delete (DeleteNetwork)
    • Network Events Get (GetNetworkEventList)
    • (GetNetworkPublic) No official endpoint, but gives the Public Network
  • Loadbalancers
    • LoadBalancers Get (GetLoadBalancerList)
    • LoadBalancer Get (GetLoadBalancer)
    • LoadBalancer Create (CreateLoadBalancer)
    • LoadBalancer Patch (UpdateLoadBalancer)
    • LoadBalancer Delete (DeleteLoadBalancer)
    • LoadBalancerEvents Get (GetLoadBalancerEventList)
  • IPs
    • IPs Get (GetIPList)
    • IP Get (GetIP)
    • IP Create (CreateIP)
    • IP Patch (UpdateIP)
    • IP Delete (DeleteIP)
    • IP Events Get (GetIPEventList)
    • IP Version Get (GetIPVersion)
  • SSH-Keys
    • SSH-Keys Get (GetSshkeyList)
    • SSH-Key Get (GetSshkey)
    • SSH-Key Create (CreateSshkey)
    • SSH-Key Patch (UpdateSshkey)
    • SSH-Key Delete (DeleteSshkey)
    • SSH-Key's events Get (GetSshkeyEventList)
  • Template
    • Templates Get (GetTemplateList)
    • Template Get (GetTemplate)
    • (GetTemplateByName) No official endpoint, but gives a template which matches the exact name given.
    • Template Create (CreateTemplate)
    • Template Update (UpdateTemplate)
    • Template Delete (DeleteTemplate)
    • Template's events Get (GetTemplateEventList)
  • PaaS
    • PaaS services Get (GetPaaSServiceList)
    • PaaS service Get (GetPaaSService)
    • PaaS service Create (CreatePaaSService)
    • PaaS service Update (UpdatePaaSService)
    • PaaS service Delete (DeletePaaSService)
    • PaaS service metrics Get (GetPaaSServiceMetrics)
    • PaaS service templates Get (GetPaaSTemplateList)
    • PaaS service security zones Get (GetPaaSSecurityZoneList)
    • Paas service security zone Get (GetPaaSSecurityZone)
    • PaaS service security zone Create (CreatePaaSSecurityZone)
    • PaaS service security zone Update (UpdatePaaSSecurityZone)
    • PaaS service security zone Delete (DeletePaaSSecurityZone)
  • ISO Image
    • ISO Images Get (GetISOImageList)
    • ISO Image Get (GetISOImage)
    • ISO Image Create (CreateISOImage)
    • ISO Image Update (UpdateISOImage)
    • ISO Image Delete (DeleteISOImage)
    • ISO Image Events Get (GetISOImageEventList)
  • Object Storage
    • Object Storage's Access Keys Get (GetObjectStorageAccessKeyList)
    • Object Storage's Access Key Get (GetObjectStorageAccessKey)
    • Object Storage's Access Key Create (CreateObjectStorageAccessKey)
    • Object Storage's Access Key Delete (DeleteObjectStorageAccessKey)
    • Object Storage's Buckets Get (GetObjectStorageBucketList)
  • Storage Snapshot Scheduler
    • Storage Snapshot Schedules Get (GetStorageSnapshotScheduleList)
    • Storage Snapshot Schedule Get (GetStorageSnapshotSchedule)
    • Storage Snapshot Schedule Create (CreateStorageSnapshotSchedule)
    • Storage Snapshot Schedule Update (UpdateStorageSnapshotSchedule)
    • Storage Snapshot Schedule Delete (DeleteStorageSnapshotSchedule)
  • Storage Snapshot
    • Storage Snapshots Get (GetStorageSnapshotList)
    • Storage Snapshot Get (GetStorageSnapshot)
    • Storage Snapshot Create (CreateStorageSnapshot)
    • Storage Snapshot Update (UpdateStorageSnapshot)
    • Storage Snapshot Delete (DeleteStorageSnapshot)
    • Storage Rollback (RollbackStorage)
    • Storage Snapshot Export to S3 (ExportStorageSnapshotToS3)
  • Firewall
    • Firewalls Get (GetFirewallList)
    • Firewall Get (GetFirewall)
    • Firewall Create (CreateFirewall)
    • Firewall Update (UpdateFirewall)
    • Firewall Delete (DeleteFirewall)
    • Firewall Events Get (GetFirewallEventList)
  • Event
    • Events Get (GetEventList)
  • Label
    • Labels Get (GetLabelList)
  • Location
    • Locations Get (GetLocationList)
    • Location Get (GetLocation)
    • Location IPs Get (GetIPsByLocation)
    • Location ISO Images Get (GetISOImagesByLocation)
    • Location Networks Get (GetNetworksByLocation)
    • Location Servers Get (GetServersByLocation)
    • Location Snapshots Get (GetSnapshotsByLocation)
    • Location Storages Get (GetStoragesByLocation)
    • Location Templates Get (GetTemplatesByLocation)
  • Deleted
    • Deleted IPs Get (GetDeletedIPs)
    • Deleted ISO Images Get (GetDeletedISOImages)
    • Deleted Networks Get (GetDeletedNetworks)
    • Deleted Servers Get (GetDeletedServers)
    • Deleted Snapshots Get (GetDeletedSnapshots)
    • Deleted Storages Get (GetDeletedStorages)
    • Deleted Templates Get (GetDeletedTemplates)
    • Deleted PaaS Services Get (GetDeletedPaaSServices)

Note: The functions in this list can be called with a Client type.

Known Issues

The following issues are known to us:

  • L3security isn't read in the network relation of a server.

# Packages

No description provided by the author

# Functions

DefaultConfiguration creates a default configuration.
NewClient creates new gridscale golang client.
NewConfiguration creates a new config - Parameters: + apiURL string: base URL of API.

# Variables

All available server's hardware types.
All allowed password type's values.
All available server's hardware types.
All allowed storage type's values.
All available server's hardware types.
All allowed storage type's values.
All allowed storage type's values.
Allowed IP address versions.
Allowed IP address versions.
All available server's hardware types.
All available loadbalancer algorithms.
All available loadbalancer algorithms.
All available server's hardware types.
All allowed password type's values.
All available server's hardware types.
All available server's hardware types.
All available server's hardware types.
All available transport protocol.
All available transport protocol.

# Structs

BackendServer is the JSON struct of backend server.
Client struct of a gridscale golang client.
Config config for client.
CreateResponse common struct of a response for creation.
Credential is JSON struct of credential.
DeletedIPList is JSON struct of a list of deleted IPs.
DeletedISOImageList is JSON struct of a list of deleted SO images.
DeletedNetworkList is JSON struct of a list of deleted networks.
DeletedPaaSServices is the JSON struct of a list of deleted PaaS services.
DeletedServerList JSON struct of a list of deleted servers.
DeletedStorageList JSON struct of a list of storages.
DeletedStorageSnapshotList is JSON structure of a list of deleted storage snapshots.
DeletedTemplateList JSON struct of a list of deleted templates.
Event is JSOn struct of a single firewall's event.
EventList is JSON struct of a list of events.
EventProperties is JSON struct of an event properties.
Firewall is JSON structure of a single firewall.
FirewallCreateRequest is JSON struct of a request for creating a firewall.
FirewallCreateResponse is JSON struct of a response for creating a firewall.
FirewallList is JSON structure of a list of firewalls.
FirewallProperties is JSON struct of a firewall's properties.
FirewallRelation is a JSON struct of a list of firewall's relations.
FirewallRuleProperties is JSON struct of a firewall's rule properties.
FirewallRules is JSON struct of a list of firewall's rules.
FirewallUpdateRequest is JSON struct of a request for updating a firewall.
ForwardingRule is the JSON struct of forwarding rule.
GSTime is custom time type of Gridscale.
IP is JSON struct if a single IP.
IPCreateRequest is JSON struct of a request for creating an IP.
IPCreateResponse is JSON struct of a response for creating an IP.
IPList is JSON struct of a list of IPs.
IPLoadbalancer is JSON struct of the relation between an IP and a Load Balancer.
IPProperties is JSON struct of an IP's properties.
IPRelations is JSON struct of a list of an IP's relations.
IPServer is JSON struct of the relation between an IP and a Server.
IPUpdateRequest is JSON struct of a request for updating an IP.
ISOImage is JSON struct of a list an ISO image.
ISOImageCreateRequest is JSON struct of a request for creating an ISO-Image.
ISOImageCreateResponse is JSON struct of a response for creating an ISO-Image.
ISOImageList is JSON struct of a list of ISO images.
ISOImageProperties is JSON struct of properties of an ISO image.
ISOImageRelation is JSON struct of a list of an ISO-Image's relations.
ISOImageUpdateRequest is JSON struct of a request for updating an ISO-Image.
Label JSON struct of a single label.
LabelCreateRequest JSON struct of a request for creating a label.
LabelList JSON struct of a list of labels.
LabelProperties JSON struct of properties of a label.
LoadBalancer is the JSON struct of a loadbalancer.
LoadBalancerCreateRequest is the JSON struct for creating a loadbalancer request.
LoadBalancerCreateResponse is the JSON struct for a loadbalancer response.
LoadBalancerProperties is the properties of a loadbalancer.
LoadBalancers is the JSON struct of a list of loadbalancers.
LoadBalancerUpdateRequest is the JSON struct for updating a loadbalancer request.
Location JSON struct of a single location.
LocationList JSON struct of a list of locations.
LocationProperties JSON struct of properties of a location.
Network is JSON struct of a single network.
NetworkCreateRequest is JSON of a request for creating a network.
NetworkCreateResponse is JSON of a response for creating a network.
NetworkInFirewall is a JSON struct of a firewall's relation.
NetworkList is JSON struct of a list of networks.
No description provided by the author
NetworkProperties is JSON struct of a network's properties.
NetworkRelations is JSON struct of a list of a network's relations.
NetworkServer is JSON struct of a relation between a network and a server.
NetworkUpdateRequest is JSON of a request for updating a network.
NetworkVlan is JSON struct of a relation between a network and a VLAN.
ObjectStorageAccessKey is JSON structure of a single Object Storage Access Key.
ObjectStorageAccessKeyCreateResponse is JSON struct of a response for creating an object storage access key.
ObjectStorageAccessKeyList is JSON structure of a list of Object Storage Access Keys.
ObjectStorageAccessKeyProperties is JSON struct of properties of an object storage access key.
ObjectStorageBucket is JSON struct of a single bucket.
ObjectStorageBucketList is JSON struct of a list of buckets.
ObjectStorageBucketProperties is JSON struct of properties of a bucket.
PaaSMetricProperties JSON of properties of a PaaS metric.
PaaSMetricValue JSON of a metric value.
PaaSRelationService JSON struct of a relation between a PaaS service and a service.
PaaSSecurityZone JSON struct of a single PaaS security zone.
PaaSSecurityZoneCreateRequest JSON struct of a request for creating a PaaS security zone.
PaaSSecurityZoneCreateResponse JSON struct of a response for creating a PaaS security zone.
PaaSSecurityZoneProperties JSOn struct of properties of a PaaS security zone.
PaaSSecurityZones JSON struct of a list of PaaS security zones.
PaaSSecurityZoneUpdateRequest JSON struct of a request for updating a PaaS security zone.
PaaSService is the JSON struct of a single PaaS service.
PaaSServiceCreateRequest is JSON struct of a request for creating a PaaS service.
PaaSServiceCreateResponse is JSON struct of a response for creating a PaaS service.
PaaSServiceMetric JSON of a single PaaS metric.
PaaSServiceMetrics JSON of a list of PaaS metrics.
PaaSServiceProperties is the properties of a single PaaS service.
PaaSServices is the JSON struct of a list of PaaS services.
PaaSServiceUpdateRequest JSON of a request for updating a PaaS service.
PaaSTemplate is JSON struct for a single PaaS Template.
PaaSTemplateProperties is JSOn struct of properties of a PaaS template.
PaaSTemplates is JSON struct of a list of PaaS Templates.
Parameter JSON of a parameter.
RequestError error of a request.
RequestStatusProperties JSON struct of properties of a request's status.
Resource JSON of a resource.
ResourceLimit is JSON struct of resource limit.
S3auth JSON struct of S3 authentication data.
S3data JSON struct of info about snapshot being uploaded.
Server JSON struct of a single server.
ServerCreateRequest JSON struct of a request for creating a server.
ServerCreateRequestIP JSON struct of a relation between a server and an IP address.
ServerCreateRequestIsoimage JSON struct of a relation between a server and an ISO-Image.
ServerCreateRequestNetwork JSON struct of a relation between a server and a network.
ServerCreateRequestRelations JSOn struct of a list of a server's relations.
ServerCreateRequestStorage JSON struct of a relation between a server and a storage.
ServerCreateResponse JSON struct of a response for creating a server.
ServerinISOImage is JSON struct of a relation between an ISO-Image and a Server.
ServerIPRelation JSON struct of a single relation between a server and a IP address.
ServerIPRelationCreateRequest JSON struct of request for creating a relation between a server and a IP address.
ServerIPRelationList JSON struct of a list of relations between a server and IP addresses.
ServerIPRelationProperties JSON struct of properties of a relation between a server and a IP address.
ServerIsoImageRelation JSON struct of a single relation between a server and an ISO-Image.
ServerIsoImageRelationCreateRequest JSON struct of a request for creating a relation between a server and an ISO-Image.
ServerIsoImageRelationList JSON struct of a list of relations between a server and ISO-Images.
ServerIsoImageRelationProperties JSON struct of properties of a relation between a server and an ISO-Image.
ServerIsoImageRelationUpdateRequest JSON struct of a request for updating a relation between a server and an ISO-Image.
ServerList JSON struct of a list of servers.
ServerMetric JSON struct of a single metric of a server.
ServerMetricList JSON struct of a list of a server's metrics.
ServerMetricProperties JSON struct.
ServerNetworkRelation JSON struct of a single relation between a server and a network.
ServerNetworkRelationCreateRequest JSON struct of a request for creating a relation between a server and a network.
ServerNetworkRelationList JSON struct of a list of relations between a server and networks.
ServerNetworkRelationProperties JSON struct of properties of a relation between a server and a network.
ServerNetworkRelationUpdateRequest JSON struct of a request for updating a relation between a server and a network.
ServerPowerUpdateRequest JSON struct of a request for updating server's power state.
ServerProperties JSON struct of properties of a server.
ServerRelations JSON struct of a list of server relations.
ServerStorageRelationCreateRequest JSON struct of a request for creating a relation between a server and a storage.
ServerStorageRelationList JSON struct of a list of relations between a server and storages.
ServerStorageRelationProperties JSON struct of properties of a relation between a server and a storage.
ServerStorageRelationSingle JSON struct of a single relation between a server and a storage.
ServerStorageRelationUpdateRequest JSON struct of a request for updating a relation between a server and a storage.
ServerUpdateRequest JSON of a request for updating a server.
ServiceObject JSON struct of a service object.
Sshkey JSON struct of a single SSH-key.
SshkeyCreateRequest JSON struct of a request for creating a SSH-key.
SshkeyList JSON struct of a list of SSH-keys.
SshkeyProperties JSON struct of properties of a single SSH-key.
SshkeyUpdateRequest JSON struct of a request for updating a SSH-key.
Storage JSON struct of a single storage.
StorageAndSnapshotScheduleRelation JSON struct of a relation between a storage and a snapshot schedule.
StorageCreateRequest JSON struct of a request for creating a storage.
StorageList JSON struct of a list of storages.
StorageProperties JSON struct of properties of a storage.
StorageRelations JSON struct of a list of a storage's relations.
StorageRollbackRequest JSON struct of a request for rolling back.
StorageServerRelation JSON struct of a relation between a storage and a server.
StorageSnapshot is JSON structure of a single storage snapshot.
StorageSnapshotCreateRequest JSON struct of a request for creating a storage snapshot.
StorageSnapshotCreateResponse JSON struct of a response for creating a storage snapshot.
StorageSnapshotExportToS3Request JSON struct of a request for exporting a storage snapshot to S3.
StorageSnapshotList is JSON structure of a list of storage snapshots.
StorageSnapshotProperties JSON struct of properties of a storage snapshot.
StorageSnapshotRelation JSON struct of a relation between a storage and a snapshot.
StorageSnapshotSchedule JSON struct of a single storage snapshot scheduler.
StorageSnapshotScheduleCreateRequest JSON struct of a request for creating a storage snapshot schedule.
StorageSnapshotScheduleCreateResponse JSON struct of a response for creating a storage snapshot schedule.
StorageSnapshotScheduleList JSON of a list of storage snapshot schedules.
StorageSnapshotScheduleProperties JSON struct of properties of a single storage snapshot schedule.
StorageSnapshotScheduleRelation JSON struct of a relation of a storage snapshot schedule.
StorageSnapshotScheduleRelations JSON struct of a list of relations of a storage snapshot schedule.
StorageSnapshotScheduleUpdateRequest JSON struct of a request for updating a storage snapshot schedule.
StorageSnapshotUpdateRequest JSON struct of a request for updating a storage snapshot.
StorageTemplate JSON struct of a storage template.
StorageUpdateRequest JSON struct of a request for updating a storage.
Template JSON struct of a single template.
TemplateCreateRequest JSON struct of a request for creating a template.
TemplateList JSON struct of a list of templates.
TemplateProperties JSOn struct of properties of a template.
TemplateUpdateRequest JSON struct of a request for updating a template.

# Type aliases

RequestStatus status of a request.