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

@ -29,8 +29,8 @@ configuration = garage_admin_sdk.Configuration(
access_token = "s3cr3t"
)
with garage_admin_sdk.ApiClient(configuration) as api:
# Init APIs
api = garage_admin_sdk.ApiClient(configuration)
nodes = nodes_api.NodesApi(api)
layout = layout_api.LayoutApi(api)
keys = key_api.KeyApi(api)
@ -41,27 +41,29 @@ with garage_admin_sdk.ApiClient(configuration) as api:
# Change layout of this node
current = layout.get_layout()
layout.add_layout(request_body={
layout.add_layout({
f"{status.node}": NodeClusterInfo(
zone = "dc1",
capacity = 1,
tags = [ "dev" ],
)
})
layout.apply_layout(layout_version=LayoutVersion(
layout.apply_layout(LayoutVersion(
version = current.version + 1
))
# Create key, allow it to create buckets
kreq = AddKeyRequest(name="openapi")
kinfo = keys.add_key(add_key_request=kreq)
kinfo = keys.add_key(AddKeyRequest(name="openapi"))
allow_create = UpdateKeyRequestAllow(create_bucket=True)
kreq = UpdateKeyRequest(allow=allow_create)
keys.update_key(kinfo.access_key_id, update_key_request=kreq)
keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create))
# 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.*

View file

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

View file

@ -11,8 +11,8 @@ configuration = garage_admin_sdk.Configuration(
access_token = "s3cr3t"
)
with garage_admin_sdk.ApiClient(configuration) as api:
# Init APIs
api = garage_admin_sdk.ApiClient(configuration)
nodes = nodes_api.NodesApi(api)
layout = layout_api.LayoutApi(api)
keys = key_api.KeyApi(api)
@ -23,24 +23,26 @@ with garage_admin_sdk.ApiClient(configuration) as api:
# Change layout of this node
current = layout.get_layout()
layout.add_layout(request_body={
layout.add_layout({
f"{status.node}": NodeClusterInfo(
zone = "dc1",
capacity = 1,
tags = [ "dev" ],
)
})
layout.apply_layout(layout_version=LayoutVersion(
layout.apply_layout(LayoutVersion(
version = current.version + 1
))
# Create key, allow it to create buckets
kreq = AddKeyRequest(name="openapi")
kinfo = keys.add_key(add_key_request=kreq)
kinfo = keys.add_key(AddKeyRequest(name="openapi"))
allow_create = UpdateKeyRequestAllow(create_bucket=True)
kreq = UpdateKeyRequest(allow=allow_create)
keys.update_key(kinfo.access_key_id, update_key_request=kreq)
keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create))
# 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}
""")