Skip to content

Commit f7d6d31

Browse files
committed
Add some examples
1 parent a842d38 commit f7d6d31

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ After the documentation has been created, click on `Usage` section
3939

4040
Or open `docs/usage.rst`
4141

42+
You can find some examples under `examples/`.
43+
4244

4345
Style Guide
4446
-------------

examples/__init__.py

Whitespace-only changes.

examples/create_server.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from hcloud import HcloudClient
2+
from hcloud.images.domain import Image
3+
4+
client = HcloudClient(token="{YOUR_API_TOKEN}") # Please paste your API token here between the quotes
5+
response = client.servers.create(name="my-server", server_type="cx11", image=Image(name="ubuntu-18.04"))
6+
server = response.server
7+
print("Server was created!\n")
8+
print('\tServer ID: {server_id}\n'.format(server_id=server.id))
9+
print('\tServer Name: ' + server.name + '\n')
10+
print('\tServer IPv4: ' + server.public_net["ipv4"]["ip"] + '\n')
11+
print('\tRoot password: ' + response.root_password + '\n')
12+
13+
print("Now we delete the server\n")
14+
server.delete()

examples/list_servers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from hcloud import HcloudClient
2+
3+
client = HcloudClient(token="{YOUR_API_TOKEN}") # Please paste your API token here between the quotes
4+
servers = client.servers.get_all()
5+
print('In this project are {servers_count} Servers\n'.format(servers_count=len(servers)))
6+
for idx, server in enumerate(servers):
7+
print("Server {index} :\n".format(index=(idx + 1)))
8+
print('\tServer ID: {server_id}\n'.format(server_id=server.id))
9+
print('\tServer Name: ' + server.name + '\n')
10+
print('\tServer IPv4: ' + server.public_net["ipv4"]["ip"] + '\n')

0 commit comments

Comments
 (0)