2022-09-13 15:54:05 +00:00
|
|
|
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(
|
2022-09-14 14:01:59 +00:00
|
|
|
host = "http://localhost:3903/v0",
|
|
|
|
access_token = "s3cr3t"
|
2022-09-13 15:54:05 +00:00
|
|
|
)
|
|
|
|
|
2022-09-14 14:01:59 +00:00
|
|
|
# Init APIs
|
|
|
|
api = garage_admin_sdk.ApiClient(configuration)
|
|
|
|
nodes = nodes_api.NodesApi(api)
|
|
|
|
layout = layout_api.LayoutApi(api)
|
|
|
|
keys = key_api.KeyApi(api)
|
2022-09-13 15:54:05 +00:00
|
|
|
|
2022-09-14 14:01:59 +00:00
|
|
|
# Display some info on the node
|
|
|
|
status = nodes.get_nodes()
|
|
|
|
print(f"running garage {status.garage_version}, node_id {status.node}")
|
2022-09-13 15:54:05 +00:00
|
|
|
|
2022-09-14 14:01:59 +00:00
|
|
|
# Change layout of this node
|
|
|
|
current = layout.get_layout()
|
|
|
|
layout.add_layout({
|
2022-09-28 18:26:01 +00:00
|
|
|
status.node: NodeClusterInfo(
|
2022-09-14 14:01:59 +00:00
|
|
|
zone = "dc1",
|
|
|
|
capacity = 1,
|
|
|
|
tags = [ "dev" ],
|
|
|
|
)
|
|
|
|
})
|
|
|
|
layout.apply_layout(LayoutVersion(
|
|
|
|
version = current.version + 1
|
|
|
|
))
|
2022-09-13 15:54:05 +00:00
|
|
|
|
2022-09-14 14:01:59 +00:00
|
|
|
# Create key, allow it to create buckets
|
|
|
|
kinfo = keys.add_key(AddKeyRequest(name="openapi"))
|
2022-09-13 15:54:05 +00:00
|
|
|
|
2022-09-14 14:01:59 +00:00
|
|
|
allow_create = UpdateKeyRequestAllow(create_bucket=True)
|
|
|
|
keys.update_key(kinfo.access_key_id, UpdateKeyRequest(allow=allow_create))
|
2022-09-13 15:54:05 +00:00
|
|
|
|
2022-09-14 14:01:59 +00:00
|
|
|
# Display key
|
|
|
|
print(f"""
|
|
|
|
cluster ready
|
|
|
|
key id is {kinfo.access_key_id}
|
|
|
|
secret key is {kinfo.secret_access_key}
|
|
|
|
""")
|