fix targetCli when using nameTemplate
This commit is contained in:
parent
c4979712bd
commit
fbdc592fba
|
|
@ -3,6 +3,8 @@ const { GrpcError, grpc } = require("../../utils/grpc");
|
||||||
|
|
||||||
const Handlebars = require("handlebars");
|
const Handlebars = require("handlebars");
|
||||||
|
|
||||||
|
const ISCSI_ASSETS_NAME_PROPERTY_NAME = "democratic-csi:iscsi_assets_name";
|
||||||
|
|
||||||
class ControllerZfsGenericDriver extends ControllerZfsSshBaseDriver {
|
class ControllerZfsGenericDriver extends ControllerZfsSshBaseDriver {
|
||||||
/**
|
/**
|
||||||
* cannot make this a storage class parameter as storage class/etc context is *not* sent
|
* cannot make this a storage class parameter as storage class/etc context is *not* sent
|
||||||
|
|
@ -159,6 +161,11 @@ create /backstores/block/${iscsiName}
|
||||||
let iqn = basename + ":" + iscsiName;
|
let iqn = basename + ":" + iscsiName;
|
||||||
this.ctx.logger.info("iqn: " + iqn);
|
this.ctx.logger.info("iqn: " + iqn);
|
||||||
|
|
||||||
|
// store this off to make delete process more bullet proof
|
||||||
|
await zb.zfs.set(datasetName, {
|
||||||
|
[ISCSI_ASSETS_NAME_PROPERTY_NAME]: iscsiName,
|
||||||
|
});
|
||||||
|
|
||||||
volume_context = {
|
volume_context = {
|
||||||
node_attach_driver: "iscsi",
|
node_attach_driver: "iscsi",
|
||||||
portal: this.options.iscsi.targetPortal,
|
portal: this.options.iscsi.targetPortal,
|
||||||
|
|
@ -182,6 +189,7 @@ create /backstores/block/${iscsiName}
|
||||||
const sshClient = this.getSshClient();
|
const sshClient = this.getSshClient();
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
|
let properties;
|
||||||
|
|
||||||
switch (this.options.driver) {
|
switch (this.options.driver) {
|
||||||
case "zfs-generic-nfs":
|
case "zfs-generic-nfs":
|
||||||
|
|
@ -200,14 +208,27 @@ create /backstores/block/${iscsiName}
|
||||||
let basename;
|
let basename;
|
||||||
let iscsiName;
|
let iscsiName;
|
||||||
|
|
||||||
if (this.options.iscsi.nameTemplate) {
|
// Delete iscsi assets
|
||||||
iscsiName = Handlebars.compile(this.options.iscsi.nameTemplate)({
|
try {
|
||||||
name: call.request.name,
|
properties = await zb.zfs.get(datasetName, [
|
||||||
parameters: call.request.parameters,
|
ISCSI_ASSETS_NAME_PROPERTY_NAME,
|
||||||
});
|
]);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.toString().includes("dataset does not exist")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
properties = properties[datasetName];
|
||||||
|
this.ctx.logger.debug("zfs props data: %j", properties);
|
||||||
|
|
||||||
|
iscsiName = properties[ISCSI_ASSETS_NAME_PROPERTY_NAME].value;
|
||||||
|
|
||||||
|
if (zb.helpers.isPropertyValueSet(iscsiName)) {
|
||||||
|
//do nothing
|
||||||
} else {
|
} else {
|
||||||
iscsiName = zb.helpers.extractLeafName(datasetName);
|
iscsiName = zb.helpers.extractLeafName(datasetName);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.iscsi.namePrefix) {
|
if (this.options.iscsi.namePrefix) {
|
||||||
iscsiName = this.options.iscsi.namePrefix + iscsiName;
|
iscsiName = this.options.iscsi.namePrefix + iscsiName;
|
||||||
|
|
@ -216,6 +237,7 @@ create /backstores/block/${iscsiName}
|
||||||
if (this.options.iscsi.nameSuffix) {
|
if (this.options.iscsi.nameSuffix) {
|
||||||
iscsiName += this.options.iscsi.nameSuffix;
|
iscsiName += this.options.iscsi.nameSuffix;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
iscsiName = iscsiName.toLowerCase();
|
iscsiName = iscsiName.toLowerCase();
|
||||||
switch (this.options.iscsi.shareStrategy) {
|
switch (this.options.iscsi.shareStrategy) {
|
||||||
|
|
@ -223,9 +245,11 @@ create /backstores/block/${iscsiName}
|
||||||
basename = this.options.iscsi.shareStrategyTargetCli.basename;
|
basename = this.options.iscsi.shareStrategyTargetCli.basename;
|
||||||
response = await this.targetCliCommand(
|
response = await this.targetCliCommand(
|
||||||
`
|
`
|
||||||
|
# delete target
|
||||||
cd /iscsi
|
cd /iscsi
|
||||||
delete ${basename}:${iscsiName}
|
delete ${basename}:${iscsiName}
|
||||||
|
|
||||||
|
# delete extent
|
||||||
cd /backstores/block
|
cd /backstores/block
|
||||||
delete ${iscsiName}
|
delete ${iscsiName}
|
||||||
`
|
`
|
||||||
|
|
@ -268,6 +292,8 @@ delete ${iscsiName}
|
||||||
|
|
||||||
async targetCliCommand(data) {
|
async targetCliCommand(data) {
|
||||||
const sshClient = this.getSshClient();
|
const sshClient = this.getSshClient();
|
||||||
|
const driver = this;
|
||||||
|
|
||||||
data = data.trim();
|
data = data.trim();
|
||||||
|
|
||||||
let command = "sh";
|
let command = "sh";
|
||||||
|
|
@ -284,7 +310,28 @@ delete ${iscsiName}
|
||||||
|
|
||||||
args.push("'" + taregetCliCommand.join(" ") + "'");
|
args.push("'" + taregetCliCommand.join(" ") + "'");
|
||||||
|
|
||||||
return sshClient.exec(sshClient.buildCommand(command, args));
|
let logCommandTmp = command + " " + args.join(" ");
|
||||||
|
let logCommand = "";
|
||||||
|
|
||||||
|
logCommandTmp.split("\n").forEach((line) => {
|
||||||
|
if (line.startsWith("set auth password=")) {
|
||||||
|
logCommand += "set auth password=<redacted>";
|
||||||
|
} else if (line.startsWith("set auth mutual_password=")) {
|
||||||
|
logCommand += "set auth mutual_password=<redacted>";
|
||||||
|
} else {
|
||||||
|
logCommand += line;
|
||||||
|
}
|
||||||
|
|
||||||
|
logCommand += "\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
driver.ctx.logger.verbose("TargetCLI command: " + logCommand);
|
||||||
|
|
||||||
|
let response = await sshClient.exec(sshClient.buildCommand(command, args));
|
||||||
|
driver.ctx.logger.verbose(
|
||||||
|
"TargetCLI response: " + JSON.stringify(response)
|
||||||
|
);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue