Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume create function added to Python and JS SDK #263

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/js/pools.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ export default class Pool {
{new_pool_name: newName}
)
}

async createVolume(name, distribute_groups, opts) {
return await Volume.create(this.mgr, this.name, name, distribute_groups, opts);
}
}
12 changes: 12 additions & 0 deletions sdk/js/volumes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ export default class Volume {
this.name = name;
}

static async create(mgr, pool_name, name, distribute_groups, opts) {
return await mgr.httpPost(`/api/v1/pools/${pool_name}/volumes`, {
name: name,
distribute_groups: distribute_groups,
no_start: opts["no_start"] !== undefined ? opts["no_start"] : false,
volume_id: opts["volume_id"] !== undefined ? opts["volume_id"] : "",
auto_create_pool: opts["auto_create_pool"] !== undefined ? opts["auto_create_pool"] : false,
auto_add_nodes: opts["auto_add_nodes"] !== undefined ? opts["auto_add_nodes"] : false,
options: opts["options"] !== undefined ? opts["options"] : {},
})
}

static async list(mgr, pool_name, state=false) {
return await mgr.httpGet(`/api/v1/pools/${pool_name}/volumes?state=${state ? 1 : 0}`)
}
Expand Down
22 changes: 13 additions & 9 deletions sdk/python/kadalu_storage/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def list_volumes(self):
"""
return Volume.list(self.mgr, self.name)

def create_volume(self, volume_name, storage_units, replica=1):
def create_volume(self, volume_name, distribute_groups, options=None):
"""
== Create a Kadalu Storage Volume

Expand All @@ -118,21 +118,25 @@ def create_volume(self, volume_name, storage_units, replica=1):

mgr.pool("DEV").create_volume(
"vol1",
[
"server1.example.com:/exports/vol1/s1/storage",
"server2.example.com:/exports/vol1/s2/storage",
"server3.example.com:/exports/vol1/s3/storage"
],
replica=3
"distribute_groups": [
{
"replica_count": 3,
"storage_units": [
{"node": "server1.example.com", "path": "/exports/vol1/s1/storage"},
{"node": "server2.example.com", "path": "/exports/vol1/s2/storage"},
{"node": "server3.example.com", "path": "/exports/vol1/s3/storage"}
]
}
]
)
----
"""
return Volume.create(
self.mgr,
self.name,
volume_name,
storage_units,
replica=replica
distribute_groups,
options
)

def volume(self, volume_name):
Expand Down
19 changes: 15 additions & 4 deletions sdk/python/kadalu_storage/volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ def list(cls, mgr, pool_name=None, state = False):
return response_object_or_error("Volume", resp, 200)

@classmethod
def create(cls, mgr, pool_name, volume_name, _distribute_groups):
def create(cls, mgr, pool_name, volume_name, distribute_groups, options=None):
# noqa # pylint: disable=missing-function-docstring
# TODO: Implimentation pending
resp = mgr.http_post(f"{mgr.url}/api/v1/pools/{pool_name}/volumes",
{"name": volume_name})
# noqa # pylint: disable=too-many-arguments
options = {} if options is None else options
resp = mgr.http_post(
f"{mgr.url}/api/v1/pools/{pool_name}/volumes",
{
"name": volume_name,
"distribute_groups": distribute_groups,
"no_start": options.get("no_start", False),
"volume_id": options.get("volume_id", ""),
"auto_create_pool": options.get("auto_create_pool", False),
"auto_add_nodes": options.get("auto_add_nodes", False),
"options": options.get("options", {})
}
)
return response_object_or_error("Volume", resp, 201)

def start(self):
Expand Down