Update examples with the new version of the API

This commit is contained in:
Quentin 2022-09-14 16:01:59 +02:00
parent 2b9d8df0c0
commit 98bae16be0
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 67 additions and 63 deletions

View file

@ -25,43 +25,45 @@ from garage_admin_sdk.model.update_key_request import UpdateKeyRequest
from garage_admin_sdk.model.update_key_request_allow import UpdateKeyRequestAllow from garage_admin_sdk.model.update_key_request_allow import UpdateKeyRequestAllow
configuration = garage_admin_sdk.Configuration( configuration = garage_admin_sdk.Configuration(
host = "http://localhost:3903/v0", host = "http://localhost:3903/v0",
access_token = "s3cr3t" access_token = "s3cr3t"
) )
with garage_admin_sdk.ApiClient(configuration) as api: # Init APIs
# Init APIs api = garage_admin_sdk.ApiClient(configuration)
nodes = nodes_api.NodesApi(api) nodes = nodes_api.NodesApi(api)
layout = layout_api.LayoutApi(api) layout = layout_api.LayoutApi(api)
keys = key_api.KeyApi(api) keys = key_api.KeyApi(api)
# Display some info on the node # Display some info on the node
status = nodes.get_nodes() status = nodes.get_nodes()
print(f"running garage {status.garage_version}, node_id {status.node}") print(f"running garage {status.garage_version}, node_id {status.node}")
# Change layout of this node # Change layout of this node
current = layout.get_layout() current = layout.get_layout()
layout.add_layout(request_body={ layout.add_layout({
f"{status.node}": NodeClusterInfo( f"{status.node}": NodeClusterInfo(
zone = "dc1", zone = "dc1",
capacity = 1, capacity = 1,
tags = [ "dev" ], tags = [ "dev" ],
) )
}) })
layout.apply_layout(layout_version=LayoutVersion( layout.apply_layout(LayoutVersion(
version = current.version + 1 version = current.version + 1
)) ))
# Create key, allow it to create buckets # Create key, allow it to create buckets
kreq = AddKeyRequest(name="openapi") kinfo = keys.add_key(AddKeyRequest(name="openapi"))
kinfo = keys.add_key(add_key_request=kreq)
allow_create = UpdateKeyRequestAllow(create_bucket=True) allow_create = UpdateKeyRequestAllow(create_bucket=True)
kreq = UpdateKeyRequest(allow=allow_create) keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create))
keys.update_key(kinfo.access_key_id, update_key_request=kreq)
# Display key # Display key
print(f"your cluster is ready, your key id: {kinfo.access_key_id}, your secret key: {kinfo.secret_access_key}") print(f"""
cluster ready
key id is {kinfo.access_key_id}
secret key is {kinfo.secret_access_key}
""")
``` ```
*This example is named `short.py` in the example folder. Other python examples are also available.* *This example is named `short.py` in the example folder. Other python examples are also available.*

View file

@ -29,7 +29,7 @@ with garage_admin_sdk.ApiClient(configuration) as api_client:
exit(1) exit(1)
print("it seems to be a fresh node, continuing the configuration") print("it seems to be a fresh node, continuing the configuration")
layout.add_layout(request_body={ layout.add_layout({
f"{status.node}": NodeClusterInfo( f"{status.node}": NodeClusterInfo(
zone = "dc1", zone = "dc1",
capacity = 1, capacity = 1,
@ -54,7 +54,7 @@ with garage_admin_sdk.ApiClient(configuration) as api_client:
# --- CREATE KEY --- # --- CREATE KEY ---
keys = key_api.KeyApi(api_client) keys = key_api.KeyApi(api_client)
kreq = AddKeyRequest(name="openapi") kreq = AddKeyRequest(name="openapi")
kinfo = keys.add_key(add_key_request=kreq) kinfo = keys.add_key(kreq)
print(f"key {kinfo.name} added.") print(f"key {kinfo.name} added.")
# --- UPDATE KEY --- # --- UPDATE KEY ---
@ -63,7 +63,7 @@ with garage_admin_sdk.ApiClient(configuration) as api_client:
allow_create = UpdateKeyRequestAllow(create_bucket=True) allow_create = UpdateKeyRequestAllow(create_bucket=True)
kreq = UpdateKeyRequest(allow=allow_create) kreq = UpdateKeyRequest(allow=allow_create)
keys.update_key(kinfo.access_key_id, update_key_request=kreq) keys.update_key(kinfo.access_key_id, kreq)
print(f"key {kinfo.access_key_id} can now create buckets") print(f"key {kinfo.access_key_id} can now create buckets")
# update key info # update key info

View file

@ -7,40 +7,42 @@ from garage_admin_sdk.model.update_key_request import UpdateKeyRequest
from garage_admin_sdk.model.update_key_request_allow import UpdateKeyRequestAllow from garage_admin_sdk.model.update_key_request_allow import UpdateKeyRequestAllow
configuration = garage_admin_sdk.Configuration( configuration = garage_admin_sdk.Configuration(
host = "http://localhost:3903/v0", host = "http://localhost:3903/v0",
access_token = "s3cr3t" access_token = "s3cr3t"
) )
with garage_admin_sdk.ApiClient(configuration) as api: # Init APIs
# Init APIs api = garage_admin_sdk.ApiClient(configuration)
nodes = nodes_api.NodesApi(api) nodes = nodes_api.NodesApi(api)
layout = layout_api.LayoutApi(api) layout = layout_api.LayoutApi(api)
keys = key_api.KeyApi(api) keys = key_api.KeyApi(api)
# Display some info on the node # Display some info on the node
status = nodes.get_nodes() status = nodes.get_nodes()
print(f"running garage {status.garage_version}, node_id {status.node}") print(f"running garage {status.garage_version}, node_id {status.node}")
# Change layout of this node # Change layout of this node
current = layout.get_layout() current = layout.get_layout()
layout.add_layout(request_body={ layout.add_layout({
f"{status.node}": NodeClusterInfo( f"{status.node}": NodeClusterInfo(
zone = "dc1", zone = "dc1",
capacity = 1, capacity = 1,
tags = [ "dev" ], tags = [ "dev" ],
) )
}) })
layout.apply_layout(layout_version=LayoutVersion( layout.apply_layout(LayoutVersion(
version = current.version + 1 version = current.version + 1
)) ))
# Create key, allow it to create buckets # Create key, allow it to create buckets
kreq = AddKeyRequest(name="openapi") kinfo = keys.add_key(AddKeyRequest(name="openapi"))
kinfo = keys.add_key(add_key_request=kreq)
allow_create = UpdateKeyRequestAllow(create_bucket=True) allow_create = UpdateKeyRequestAllow(create_bucket=True)
kreq = UpdateKeyRequest(allow=allow_create) keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create))
keys.update_key(kinfo.access_key_id, update_key_request=kreq)
# Display key # Display key
print(f"your cluster is ready, your key id: {kinfo.access_key_id}, your secret key: {kinfo.secret_access_key}") print(f"""
cluster ready
key id is {kinfo.access_key_id}
secret key is {kinfo.secret_access_key}
""")