46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
import garage_admin_sdk
|
|
from garage_admin_sdk.api import nodes_api, layout_api, key_api
|
|
from garage_admin_sdk.model.node_cluster_info import NodeClusterInfo
|
|
from garage_admin_sdk.model.layout_version import LayoutVersion
|
|
from garage_admin_sdk.model.add_key_request import AddKeyRequest
|
|
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"
|
|
)
|
|
|
|
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)
|
|
|
|
# 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
|
|
))
|
|
|
|
# Create key, allow it to create buckets
|
|
kreq = AddKeyRequest(name="openapi")
|
|
kinfo = keys.add_key(add_key_request=kreq)
|
|
|
|
allow_create = UpdateKeyRequestAllow(create_bucket=True)
|
|
kreq = UpdateKeyRequest(allow=allow_create)
|
|
keys.update_key(kinfo.access_key_id, update_key_request=kreq)
|
|
|
|
# Display key
|
|
print(f"your cluster is ready, your key id: {kinfo.access_key_id}, your secret key: {kinfo.secret_access_key}")
|