Merge pull request #106 from huntermm18/next

Added support for cloning
This commit is contained in:
Travis Glenn Hansen 2021-08-05 22:34:11 -06:00 committed by GitHub
commit c240af2891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 10 deletions

View File

@ -174,6 +174,23 @@ class SynologyHttpClient {
} }
} }
async GetLunByID(lun_id) {
const lun_list = {
api: "SYNO.Core.ISCSI.LUN",
version: "1",
method: "list",
};
let response = await this.do_request("GET", "entry.cgi", lun_list);
let lun = response.body.data.luns.find((i) => {
return i.lun_id == lun_id;
});
if (lun) {
return lun;
}
}
async GetLunByName(name) { async GetLunByName(name) {
const lun_list = { const lun_list = {
api: "SYNO.Core.ISCSI.LUN", api: "SYNO.Core.ISCSI.LUN",
@ -464,6 +481,36 @@ class SynologyHttpClient {
Object.assign({}, iscsi_lun_extend, { uuid: uuid, new_size: size }) Object.assign({}, iscsi_lun_extend, { uuid: uuid, new_size: size })
); );
} }
async CreateClonedVolume(src_lun_uuid, dst_lun_name) {
const create_cloned_volume = {
api: "SYNO.Core.ISCSI.LUN",
version: 1,
method: "clone",
src_lun_uuid: JSON.stringify(src_lun_uuid), // src lun uuid
dst_lun_name: dst_lun_name, // dst lun name
is_same_pool: true, // always true? string?
clone_type: "democratic-csi", // check
}
return await this.do_request("GET", "entry.cgi", create_cloned_volume);
}
async CreateVolumeFromSnapshot(src_lun_uuid, snapshot_uuid, cloned_lun_name) {
const create_volume_from_snapshot = {
api: "SYNO.Core.ISCSI.LUN",
version: 1,
method: "clone_snapshot",
src_lun_uuid: src_lun_uuid, // src lun uuid, snapshot id?
snapshot_uuid: JSON.stringify(snapshot_uuid), // shaptop uuid
cloned_lun_name: cloned_lun_name, // cloned lun name
clone_type: "democratic-csi", // check
}
return await this.do_request("GET", "entry.cgi", create_volume_from_snapshot);
}
} }
module.exports.SynologyHttpClient = SynologyHttpClient; module.exports.SynologyHttpClient = SynologyHttpClient;

View File

@ -280,14 +280,63 @@ class ControllerSynologyDriver extends CsiBaseDriver {
let data; let data;
let target; let target;
let lun_mapping; let lun_mapping;
let lun_uuid;
let existingLun;
// create lun if (volume_content_source) {
data = Object.assign({}, driver.options.iscsi.lunAttributes, { let src_lun_uuid;
name: iscsiName, let src_lun_id;
location: driver.options.synology.volume, switch (volume_content_source.type) {
size: capacity_bytes, case "snapshot":
}); let parts = volume_content_source.snapshot.snapshot_id.split("/");
let lun_uuid = await httpClient.CreateLun(data); src_lun_id = parts[2];
let snapshot_uuid = parts[3];
let src_lun = await httpClient.GetLunByID(src_lun_id);
src_lun_uuid = src_lun.uuid;
existingLun = await httpClient.GetLunByName(iscsiName);
if (!existingLun) {
await httpClient.CreateVolumeFromSnapshot(
src_lun_uuid,
snapshot_uuid,
iscsiName
);
}
break;
case "volume":
let srcLunName = driver.buildIscsiName(
volume_content_source.volume.volume_id
);
src_lun_uuid = await httpClient.GetLunUUIDByName(srcLunName);
existingLun = httpClient.GetLunByName(iscsiName);
if (!existingLun) {
await httpClient.CreateClonedVolume(src_lun_uuid, iscsiName);
}
break;
default:
throw new GrpcError(
grpc.status.INVALID_ARGUMENT,
`invalid volume_content_source type: ${volume_content_source.type}`
);
break;
}
// resize to requested amount
let lun = await httpClient.GetLunByName(iscsiName);
lun_uuid = lun.uuid;
if (lun.size < capacity_bytes) {
await httpClient.ExpandISCSILun(lun_uuid, capacity_bytes);
}
} else {
// create lun
data = Object.assign({}, driver.options.iscsi.lunAttributes, {
name: iscsiName,
location: driver.options.synology.volume,
size: capacity_bytes,
});
lun_uuid = await httpClient.CreateLun(data);
}
// create target // create target
let iqn = driver.options.iscsi.baseiqn + iscsiName; let iqn = driver.options.iscsi.baseiqn + iscsiName;
@ -437,16 +486,16 @@ class ControllerSynologyDriver extends CsiBaseDriver {
driver.options.api.lunDelete.settleMaxRetries || 6; driver.options.api.lunDelete.settleMaxRetries || 6;
let settleSeconds = driver.options.api.lunDelete.settleSeconds || 5; let settleSeconds = driver.options.api.lunDelete.settleSeconds || 5;
let waitTimeBetweenChecks = settleSeconds * 1000; let waitTimeBetweenChecks = settleSeconds * 1000;
await sleep(waitTimeBetweenChecks); await sleep(waitTimeBetweenChecks);
lun_uuid = await httpClient.GetLunUUIDByName(iscsiName); lun_uuid = await httpClient.GetLunUUIDByName(iscsiName);
while (currentCheck <= settleMaxRetries && lun_uuid) { while (currentCheck <= settleMaxRetries && lun_uuid) {
currentCheck++; currentCheck++;
await sleep(waitTimeBetweenChecks); await sleep(waitTimeBetweenChecks);
lun_uuid = await httpClient.GetLunUUIDByName(iscsiName); lun_uuid = await httpClient.GetLunUUIDByName(iscsiName);
} }
if (lun_uuid) { if (lun_uuid) {
throw new GrpcError( throw new GrpcError(
grpc.status.UNKNOWN, grpc.status.UNKNOWN,