2022-09-13 15:54:05 +00:00
|
|
|
import garage_admin_sdk
|
2022-11-12 21:48:50 +00:00
|
|
|
from garage_admin_sdk.apis import *
|
|
|
|
from garage_admin_sdk.models import *
|
2022-09-13 15:54:05 +00:00
|
|
|
|
|
|
|
configuration = garage_admin_sdk.Configuration(
|
2023-11-22 17:49:08 +00:00
|
|
|
host = "http://localhost:3903/v1",
|
2022-09-14 14:01:59 +00:00
|
|
|
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)
|
2022-11-12 22:12:52 +00:00
|
|
|
nodes, layout, keys, buckets = NodesApi(api), LayoutApi(api), KeyApi(api), BucketApi(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()
|
2023-11-22 17:49:08 +00:00
|
|
|
layout.add_layout([
|
|
|
|
NodeRoleChange(
|
|
|
|
id = status.node,
|
2022-09-14 14:01:59 +00:00
|
|
|
zone = "dc1",
|
2023-11-22 17:49:08 +00:00
|
|
|
capacity = 1000000000,
|
2022-09-14 14:01:59 +00:00
|
|
|
tags = [ "dev" ],
|
|
|
|
)
|
2023-11-22 17:49:08 +00:00
|
|
|
])
|
2022-09-14 14:01:59 +00:00
|
|
|
layout.apply_layout(LayoutVersion(
|
|
|
|
version = current.version + 1
|
|
|
|
))
|
2022-11-12 22:16:11 +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-11-12 22:12:52 +00:00
|
|
|
# Create a bucket, allow key, set quotas
|
2022-11-12 22:16:11 +00:00
|
|
|
binfo = buckets.create_bucket(CreateBucketRequest(global_alias="documentation"))
|
|
|
|
binfo = buckets.allow_bucket_key(AllowBucketKeyRequest(
|
|
|
|
bucket_id=binfo.id,
|
2022-11-12 22:12:52 +00:00
|
|
|
access_key_id=kinfo.access_key_id,
|
|
|
|
permissions=AllowBucketKeyRequestPermissions(read=True, write=True, owner=True),
|
|
|
|
))
|
2022-11-12 22:16:11 +00:00
|
|
|
binfo = buckets.update_bucket(binfo.id, UpdateBucketRequest(
|
2022-11-12 22:12:52 +00:00
|
|
|
quotas=UpdateBucketRequestQuotas(max_size=19029801,max_objects=1500)))
|
|
|
|
|
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}
|
2022-11-12 22:16:11 +00:00
|
|
|
bucket {binfo.global_aliases[0]} contains {binfo.objects}/{binfo.quotas.max_objects} objects
|
2022-09-14 14:01:59 +00:00
|
|
|
""")
|