Update examples with the new version of the API
This commit is contained in:
parent
2b9d8df0c0
commit
98bae16be0
3 changed files with 67 additions and 63 deletions
62
README.md
62
README.md
|
@ -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
|
||||
|
||||
configuration = garage_admin_sdk.Configuration(
|
||||
host = "http://localhost:3903/v0",
|
||||
access_token = "s3cr3t"
|
||||
host = "http://localhost:3903/v0",
|
||||
access_token = "s3cr3t"
|
||||
)
|
||||
|
||||
with garage_admin_sdk.ApiClient(configuration) as api:
|
||||
# Init APIs
|
||||
nodes = nodes_api.NodesApi(api)
|
||||
layout = layout_api.LayoutApi(api)
|
||||
keys = key_api.KeyApi(api)
|
||||
# Init APIs
|
||||
api = garage_admin_sdk.ApiClient(configuration)
|
||||
nodes = nodes_api.NodesApi(api)
|
||||
layout = layout_api.LayoutApi(api)
|
||||
keys = key_api.KeyApi(api)
|
||||
|
||||
# Display some info on the node
|
||||
status = nodes.get_nodes()
|
||||
print(f"running garage {status.garage_version}, node_id {status.node}")
|
||||
# Display some info on the node
|
||||
status = nodes.get_nodes()
|
||||
print(f"running garage {status.garage_version}, node_id {status.node}")
|
||||
|
||||
# Change layout of this node
|
||||
current = layout.get_layout()
|
||||
layout.add_layout(request_body={
|
||||
f"{status.node}": NodeClusterInfo(
|
||||
zone = "dc1",
|
||||
capacity = 1,
|
||||
tags = [ "dev" ],
|
||||
)
|
||||
})
|
||||
layout.apply_layout(layout_version=LayoutVersion(
|
||||
version = current.version + 1
|
||||
))
|
||||
# Change layout of this node
|
||||
current = layout.get_layout()
|
||||
layout.add_layout({
|
||||
f"{status.node}": NodeClusterInfo(
|
||||
zone = "dc1",
|
||||
capacity = 1,
|
||||
tags = [ "dev" ],
|
||||
)
|
||||
})
|
||||
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)
|
||||
# Create key, allow it to create buckets
|
||||
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)
|
||||
allow_create = UpdateKeyRequestAllow(create_bucket=True)
|
||||
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}")
|
||||
# Display 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.*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
configuration = garage_admin_sdk.Configuration(
|
||||
host = "http://localhost:3903/v0",
|
||||
access_token = "s3cr3t"
|
||||
host = "http://localhost:3903/v0",
|
||||
access_token = "s3cr3t"
|
||||
)
|
||||
|
||||
with garage_admin_sdk.ApiClient(configuration) as api:
|
||||
# Init APIs
|
||||
nodes = nodes_api.NodesApi(api)
|
||||
layout = layout_api.LayoutApi(api)
|
||||
keys = key_api.KeyApi(api)
|
||||
# Init APIs
|
||||
api = garage_admin_sdk.ApiClient(configuration)
|
||||
nodes = nodes_api.NodesApi(api)
|
||||
layout = layout_api.LayoutApi(api)
|
||||
keys = key_api.KeyApi(api)
|
||||
|
||||
# Display some info on the node
|
||||
status = nodes.get_nodes()
|
||||
print(f"running garage {status.garage_version}, node_id {status.node}")
|
||||
# Display some info on the node
|
||||
status = nodes.get_nodes()
|
||||
print(f"running garage {status.garage_version}, node_id {status.node}")
|
||||
|
||||
# Change layout of this node
|
||||
current = layout.get_layout()
|
||||
layout.add_layout(request_body={
|
||||
f"{status.node}": NodeClusterInfo(
|
||||
zone = "dc1",
|
||||
capacity = 1,
|
||||
tags = [ "dev" ],
|
||||
)
|
||||
})
|
||||
layout.apply_layout(layout_version=LayoutVersion(
|
||||
version = current.version + 1
|
||||
))
|
||||
# Change layout of this node
|
||||
current = layout.get_layout()
|
||||
layout.add_layout({
|
||||
f"{status.node}": NodeClusterInfo(
|
||||
zone = "dc1",
|
||||
capacity = 1,
|
||||
tags = [ "dev" ],
|
||||
)
|
||||
})
|
||||
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)
|
||||
# Create key, allow it to create buckets
|
||||
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)
|
||||
allow_create = UpdateKeyRequestAllow(create_bucket=True)
|
||||
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}")
|
||||
# Display key
|
||||
print(f"""
|
||||
cluster ready
|
||||
key id is {kinfo.access_key_id}
|
||||
secret key is {kinfo.secret_access_key}
|
||||
""")
|
||||
|
|
Loading…
Reference in a new issue