-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples.py
73 lines (58 loc) · 2.22 KB
/
examples.py
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
import sys
from pprint import pprint
from uuid import uuid4
from index_by.key import index_by_key
from gs_api_client import SyncGridscaleApiClient, GridscaleApiClient, models
from gs_api_client import Configuration
if __name__ == '__main__':
# run `pip3 install index_by` before executing this file
api_config = Configuration()
# api_config.debug = True
api_config.host = 'https://api.gridscale.io'
#TODO: Insert your API token and User ID
api_config.api_key['X-Auth-Token'] = "AUTH_TOKEN"
api_config.api_key['X-Auth-UserId'] = "USER_UUID"
# api_config.debug = True
print('-' * 80)
client = SyncGridscaleApiClient(configuration=api_config, http_info=False)
# get locations
get_locations_response = client.get_locations()
locations = get_locations_response['locations'].values()
location_by_name = index_by_key(locations, 'name')
location = location_by_name['de/fra']
# get templates
get_templates_response = client.get_templates()
templates = get_templates_response['templates'].values()
template_by_name = index_by_key(templates, 'name')
template = template_by_name['Debian 11']
# create storage
create_storage_response = client.create_storage({
'name': 'my storage',
'capacity': 10,
'location_uuid': location['object_uuid'],
'storage_type': 'storage_insane',
'template': {
'template_uuid': template['object_uuid'],
'hostname': 'myserver',
'password': 'secret_pass123!#.,'
}
})
storage = create_storage_response['storage']
# create server
create_server_response = client.create_server({
'name': 'my server',
'cores': 1,
'memory': 2,
'location_uuid': location['object_uuid']})
server = create_server_response['server']
# link storage to server
client.link_storage_to_server(
server['object_uuid'],
{'bootdevice': True, 'object_uuid': storage['object_uuid']})
# start server
client.update_server_power(
server['object_uuid'],
{'power': True})
# get updated server
get_server_response = client.get_server(server['object_uuid'])
updated_server = get_server_response['server']