1# coding: utf-8 2 3""" 4 API Specification 5 6 # Introduction Welcome to gridscales API documentation. A REST API is a programming interface that allows you to access and send data directly to our systems using HTTPS requests, without the need to use a web GUI. All the functionality you are already familiar with in your control panel is accessible through the API, including expert methods that are only available through the API. Allowing you to script any actions you require, regardless of their complexity. First we will start with a general overview about how the API works, followed by an extensive list of each endpoint, describing them in great detail. ## Requests For security, gridscale requires all API requests are made through the HTTPS protocol so that traffic is encrypted. The following table displays the different type of requests that the interface responds to, depending on the action you require. | Method | Description | | --- | --- | | GET | A simple search of information. The response is a JSON object. Requests using GET are always read-only. | | POST | Adds new objects and object relations. The POST request must contain all the required parameters in the form of a JSON object. | | PATCH | Changes an object or an object relation. The parameters in PATCH requests are usually optional, so only the changed parameters must be specified in a JSON object. | | DELETE | Deletes an object or object relation. The object is deleted if it exists. | | OPTIONS | Get an extensive list of the servers support methods and characteristics. We will not give example OPTION requests on each endpoint, as they are extensive and self-descriptive. | <aside class=\"notice\"> The methods PATCH and DELETE are idempotent - that is, a request with identical parameters can be sent several times, and it doesn't change the result. </aside> ## Status Codes | HTTP Status | `Message` | Description | | --- | --- | --- | | 200 | `OK` | The request has been successfully processed and the result of the request is transmitted in the response. | | 202 | `Accepted` | The request has been accepted, but will run at a later date. Meaning we can not guarantee the success of the request. You should poll the request to be notified once the resource has been provisioned - see the requests endpoint on how to poll. | | 204 | `No Content` | The request was successful, but the answer deliberately contains no data. | | 400 | `Bad Request` | The request message was built incorrectly. | | 401 | `Unauthorised` | The request can not be performed without a valid authentication. X-Auth UserId or X-Auth token HTTP header is not set or the userID / token is invalid. | | 402 | `Payment Required` | Action can not be executed - not provided any or invalid payment methods. | | 403 | `Forbidden` | The request was not carried out due to lack of authorization of the user or because an impossible action was requested. | | 404 | `Not Found` | The requested resource was not found. Will also be used if you do a resource exists, but the user does not have permission for it. | | 405 | `Method Not Allowed` | The request may be made only with other HTTP methods (eg GET rather than POST). | | 409 | `Conflict` | The request was made under false assumptions. For example, a user can not be created twice with the same email. | | 415 | `Unsupported Media Type` | The contents of the request have been submitted with an invalid media type. All POST or PATCH requests must have \"Content-Type : application / json\" as a header, and send a JSON object as a payload. | | 416 | `Requested Range Not Satisfiable` | The request could not be fulfilled. It is possible that a resource limit was reached or an IPv4 address pool is exhausted. | | 424 | `Failed Dependency` | The request could not be performed because the object is in the wrong status. | | 429 | `Too Many Requests` | The request has been rejected because rate limits have been exceeded. | <aside class=\"success\"> Status 200-204 indicates that the request has been accepted and is processed. </aside> <aside class=\"notice\"> Status 400-429 indicates that there was a problem with the request that originated on the client. You will find more information about the problem in the body of 4xx response. </aside> <aside class=\"warning\"> A status 500 means that there was a server-side problem and your request can not be processed now. </aside> ## Request Headers | Header | Description | | --- | --- | | Content-Type | Always \"application/json\". | | X-Auth-userId | The user UUID. This can be found in the panel under \"API\" and will never change ( even after the change of user e-mail). | | X-Auth-Token | Is generated from the API hash and must be sent with all API requests. Both the token and its permissions can be configured in the panel.| ## Response Headers | Header | Description | | --- | --- | | Content-Type | Always \"application/json\". | | X-Time-Provisioning | The time taken to process the request (in ms). | | X-Api-Identity | The currently active Provisioning API version. Useful when reporting bugs to us. | | X-Request-Id | The unique identifier of the request, be sure to include it when referring to a request. | | RateLimit-Limit | The number of requests that can be made per minute. | | RateLimit-Remaining | The number of requests that still remain before you hit your request limit. | | RateLimit-Reset | A [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time) in milliseconds of when the rate limit will reset, or the time at which a request no longer will return 429 - Too Many Requests. | ## Timestamp Format All timestamps follow <a href=\"https://de.wikipedia.org/wiki/ISO_8601\" target=\"_blank_\">ISO 8601</a> and issued in <a href=\"https://www.timeanddate.de/zeitzonen/utc-gmt\" target=\"_blank_\">UTC</a> ## CORS ### Cross Origin Resource Sharing To allow API access from other domains that supports the API CORS (Cross Origin Resource Sharing). See: enable-cors.org/ . This allows direct use the API in the browser running a JavaScript web control panel. All this is done in the background by the browser. The following HTTP headers are set by the API: Header | Parameter | Description --- | --- | --- Access-Control-Allow-Methods | GET, POST, PUT, PATCH, DELETE, OPTIONS | Contains all available methods that may be used for queries. Access-Control-Allow-Credentials | true | Is set to \"true\". Allows the browser to send the authentication data via X-Auth HTTP header. Access-Control-Allow-Headers | Origin, X-Requested-With, Content-Type, Accept, X-Auth-UserId, X-Auth-Token, X-Exec-Time, X-API-Version, X-Api-Client | The HTTP headers available for requests. Access-Control-Allow-Origin | * | The domain sent by the browser as a source of demand. Access-Control-Expose-Headers | X-Exec-Time, X-Api-Version | The HTTP headers that can be used by a browser application. ## Rate Limits The number of requests that can be made through our API is currently limited to 210 requests per 60 seconds. The current state of rate limiting is returned within the response headers of each request. The relevant response headers are - RateLimit-Limit - RateLimit-Remaining - RateLimit-Reset See the Response Headers section for details. As long as the `RateLimit-Remaining` count is above zero, you will be able to make further requests. As soon as the `RateLimit-Remaining` header value is zero, subsequent requests will return the 429 status code. This will stay until the timestamp given in `RateLimit-Reset` has been reached. ### Example rate limiting response ```shell HTTP/1.0 429 TOO MANY REQUESTS Content-Length: 66 Content-Type: application/json; charset=utf-8 Date: Mon, 11 Nov 2019 11:11:33 GMT RateLimit-Limit: 210 RateLimit-Remaining: 0 RateLimit-Reset: 1573468299256 { \"id\": \"too_many_requests\", \"message\": \"API Rate limit exceeded.\" } ``` It is important to understand how rate limits are reset in order to use the API efficiently. Rate limits are reset for all counted requests at once. This means that that once the timestamp `RateLimit-Remaining` has arrived all counted request are reset and you can again start sending requests to the API. This allows for short burst of traffic. The downside is once you have hit the request limit no more requests are allowed until the rate limit duration is reset. ## Object Relations Relationships describe resource objects (storages, networks, IPs, etc.) that are connected to a server. These relationships are treated like objects themselves and can have properties specific to this relation. One example would be, that the MAC address of a private network connected to a server (Server-to-Network relation) can be found as property of the relation itself - the relation is the _network interface_ in the server. Another example is storage, where the SCSI LUN is also part of the Server-to-Storage relation object. This information is especially interesting if some kind of network boot is used on the servers, where the properties of the server need to be known beforehand. ## Deleted Objects Objects that are deleted are no longer visible on their *regular* endpoints. For historical reasons these objects are still available read-only on a special endpoint named /deleted. If objects have been deleted but have not yet been billed in the current period, the yet-to-be-billed price is still shown. <!-- #strip_js --> ## Node.js Library We have a JavaScript library for you to use our API with ease. <a href=\"https://www.npmjs.com/package/@gridscale/api\" target=\"_blank\"><img src=\"https://badge.fury.io/js/%40gridscale%2Fapi.svg\" alt=\"npm badge\"></a> <aside class=\"success\"> We want to make it even easier for you to manage your Infrastructure via our API - so feel free to contact us with any ideas, or languages you would like to see included. </aside> Requests with our Node.js lib return a little differently. Everything is the same except it allows you to add URL parameters to customize your requests. To get started <a href=\"https://www.npmjs.com/package/@gridscale/api\" target=\"_blank\">click here</a> . <!-- #strip_js_end --> <!-- #strip_go --> ## Golang Library We also have a Golang library for Gophers. Requests with our Golang lib return a little differently. Everything is the same except it allows you to add URL parameters to customize your requests. To get started <a href=\"https://github.com/gridscale/gsclient-go\" target=\"_blank\">click here</a> . <!-- #strip_go_end --> <!-- #strip_python --> ## Python Library We have a Python library, that optionally also simplifies handling of asynchronous requests by mimicking synchronous blocking behaviour. To get started <a href=\"https://pypi.org/project/gs-api-client/\" target=\"_blank\">click here</a> . <!-- #strip_python_end --> # Authentication In order to use the API, the User-UUID and an API_Token are required. Both are available via the web GUI which can be found here on <a href=\"https://my.gridscale.io/APIs/\" target=\"_blank\">Your Account</a> <aside class=\"success\"> If you are logged in, your UUID and Token will be pulled dynamically from your account, so you can copy request examples straight into your code. </aside> The User-UUID remains the same, even if the users email address is changed. The API_Token is a randomly generated hash that allows read/write access. ## API_Token <table class=\"security-details\"><tbody><tr><th> Security scheme type: </th><td> API Key </td></tr><tr><th> header parameter name:</th><td> X-Auth-Token </td></tr></tbody></table> ## User_UUID <table class=\"security-details\"><tbody><tr><th> Security scheme type: </th><td> API Key </td></tr><tr><th> header parameter name:</th><td> X-Auth-UserId </td></tr></tbody></table> ## Examples <!-- #strip_js --> > Node.js ``` // to get started // read the docs @ https://www.npmjs.com/package/@gs_js_auth/api var gs_js_auth = require('@gs_js_auth/api').gs_js_auth; var client = new gs_js_auth.Client(\"##API_TOKEN##\",\"##USER_UUID##\"); ``` <!-- #strip_js_end --> <!-- #strip_go --> > Golang ``` // to get started // read the docs @ https://github.com/gridscale/gsclient-go config := gsclient.NewConfiguration( \"https://api.gridscale.io\", \"##USER_UUID##\", \"##API_TOKEN##\", false, //set debug mode ) client := gsclient.NewClient(config) ``` <!-- #strip_go_end --> > Shell Authentication Headers ``` -H \"X-Auth-UserId: ##USER_UUID##\" \\ -H \"X-Auth-Token: ##API_TOKEN##\" \\ ``` > Setting Authentication in your Environment variables ``` export API_TOKEN=\"##API_TOKEN##\" USER_UUID=\"##USER_UUID##\" ``` <aside class=\"notice\"> You must replace <code>USER_UUID</code> and <code>API_Token</code> with your personal UUID and API key respectively. </aside> # noqa: E501 7 8 OpenAPI spec version: 1.0.16 9 10 Generated by: https://github.com/swagger-api/swagger-codegen.git 11""" 12 13 14import pprint 15import re # noqa: F401 16 17import six 18 19 20class Label(object): 21 """NOTE: This class is auto generated by the swagger code generator program. 22 23 Do not edit the class manually. 24 """ 25 26 """ 27 Attributes: 28 swagger_types (dict): The key is attribute name 29 and the value is attribute type. 30 attribute_map (dict): The key is attribute name 31 and the value is json key in definition. 32 """ 33 swagger_types = { 34 'label': 'str', 35 'create_time': 'str', 36 'change_time': 'str', 37 'relations': 'list[object]', 38 'status': 'str' 39 } 40 41 attribute_map = { 42 'label': 'label', 43 'create_time': 'create_time', 44 'change_time': 'change_time', 45 'relations': 'relations', 46 'status': 'status' 47 } 48 49 def __init__(self, label=None, create_time=None, change_time=None, relations=None, status=None): # noqa: E501 50 """Label - a model defined in Swagger""" # noqa: E501 51 52 self._label = None 53 self._create_time = None 54 self._change_time = None 55 self._relations = None 56 self._status = None 57 self.discriminator = None 58 59 if label is not None: 60 self.label = label 61 if create_time is not None: 62 self.create_time = create_time 63 if change_time is not None: 64 self.change_time = change_time 65 if relations is not None: 66 self.relations = relations 67 if status is not None: 68 self.status = status 69 70 @property 71 def label(self): 72 """Gets the label of this Label. # noqa: E501 73 74 75 :return: The label of this Label. # noqa: E501 76 :rtype: str 77 """ 78 return self._label 79 80 @label.setter 81 def label(self, label): 82 """Sets the label of this Label. 83 84 85 :param label: The label of this Label. # noqa: E501 86 :type: str 87 """ 88 89 self._label = label 90 91 @property 92 def create_time(self): 93 """Gets the create_time of this Label. # noqa: E501 94 95 96 :return: The create_time of this Label. # noqa: E501 97 :rtype: str 98 """ 99 return self._create_time 100 101 @create_time.setter 102 def create_time(self, create_time): 103 """Sets the create_time of this Label. 104 105 106 :param create_time: The create_time of this Label. # noqa: E501 107 :type: str 108 """ 109 110 self._create_time = create_time 111 112 @property 113 def change_time(self): 114 """Gets the change_time of this Label. # noqa: E501 115 116 117 :return: The change_time of this Label. # noqa: E501 118 :rtype: str 119 """ 120 return self._change_time 121 122 @change_time.setter 123 def change_time(self, change_time): 124 """Sets the change_time of this Label. 125 126 127 :param change_time: The change_time of this Label. # noqa: E501 128 :type: str 129 """ 130 131 self._change_time = change_time 132 133 @property 134 def relations(self): 135 """Gets the relations of this Label. # noqa: E501 136 137 138 :return: The relations of this Label. # noqa: E501 139 :rtype: list[object] 140 """ 141 return self._relations 142 143 @relations.setter 144 def relations(self, relations): 145 """Sets the relations of this Label. 146 147 148 :param relations: The relations of this Label. # noqa: E501 149 :type: list[object] 150 """ 151 152 self._relations = relations 153 154 @property 155 def status(self): 156 """Gets the status of this Label. # noqa: E501 157 158 159 :return: The status of this Label. # noqa: E501 160 :rtype: str 161 """ 162 return self._status 163 164 @status.setter 165 def status(self, status): 166 """Sets the status of this Label. 167 168 169 :param status: The status of this Label. # noqa: E501 170 :type: str 171 """ 172 173 self._status = status 174 175 def to_dict(self): 176 """Returns the model properties as a dict""" 177 result = {} 178 179 for attr, _ in six.iteritems(self.swagger_types): 180 value = getattr(self, attr) 181 if isinstance(value, list): 182 result[attr] = list(map( 183 lambda x: x.to_dict() if hasattr(x, "to_dict") else x, 184 value 185 )) 186 elif hasattr(value, "to_dict"): 187 result[attr] = value.to_dict() 188 elif isinstance(value, dict): 189 result[attr] = dict(map( 190 lambda item: (item[0], item[1].to_dict()) 191 if hasattr(item[1], "to_dict") else item, 192 value.items() 193 )) 194 else: 195 result[attr] = value 196 if issubclass(Label, dict): 197 for key, value in self.items(): 198 result[key] = value 199 200 return result 201 202 def to_str(self): 203 """Returns the string representation of the model""" 204 return pprint.pformat(self.to_dict()) 205 206 def __repr__(self): 207 """For `print` and `pprint`""" 208 return self.to_str() 209 210 def __eq__(self, other): 211 """Returns true if both objects are equal""" 212 if not isinstance(other, Label): 213 return False 214 215 return self.__dict__ == other.__dict__ 216 217 def __ne__(self, other): 218 """Returns true if both objects are not equal""" 219 return not self == other 220