implement remaining bits of truenas pure api-based driver
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
parent
75abd5e13b
commit
ff659d8004
File diff suppressed because it is too large
Load Diff
|
|
@ -325,6 +325,46 @@ class Api {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalizeProperties(dataset, properties) {
|
||||||
|
let res = {};
|
||||||
|
for (const property of properties) {
|
||||||
|
let p;
|
||||||
|
if (dataset.hasOwnProperty(property)) {
|
||||||
|
p = dataset[property];
|
||||||
|
} else if (
|
||||||
|
dataset.properties &&
|
||||||
|
dataset.properties.hasOwnProperty(property)
|
||||||
|
) {
|
||||||
|
p = dataset.properties[property];
|
||||||
|
} else if (
|
||||||
|
dataset.user_properties &&
|
||||||
|
dataset.user_properties.hasOwnProperty(property)
|
||||||
|
) {
|
||||||
|
p = dataset.user_properties[property];
|
||||||
|
} else {
|
||||||
|
p = {
|
||||||
|
value: "-",
|
||||||
|
rawvalue: "-",
|
||||||
|
source: "-",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof p === "object" && p !== null) {
|
||||||
|
// nothing, leave as is
|
||||||
|
} else {
|
||||||
|
p = {
|
||||||
|
value: p,
|
||||||
|
rawvalue: p,
|
||||||
|
source: "-",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
res[property] = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
async DatasetCreate(datasetName, data) {
|
async DatasetCreate(datasetName, data) {
|
||||||
const httpClient = await this.getHttpClient(false);
|
const httpClient = await this.getHttpClient(false);
|
||||||
let response;
|
let response;
|
||||||
|
|
@ -441,34 +481,7 @@ class Api {
|
||||||
response = await httpClient.get(endpoint);
|
response = await httpClient.get(endpoint);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
let res = {};
|
return this.normalizeProperties(response.body, properties);
|
||||||
for (const property of properties) {
|
|
||||||
let p;
|
|
||||||
if (response.body.hasOwnProperty(property)) {
|
|
||||||
p = response.body[property];
|
|
||||||
} else if (response.body.user_properties.hasOwnProperty(property)) {
|
|
||||||
p = response.body.user_properties[property];
|
|
||||||
} else {
|
|
||||||
p = {
|
|
||||||
value: "-",
|
|
||||||
rawvalue: "-",
|
|
||||||
source: "-",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof p === "object" && p !== null) {
|
|
||||||
// nothing, leave as is
|
|
||||||
} else {
|
|
||||||
p = {
|
|
||||||
value: p,
|
|
||||||
rawvalue: p,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
res[property] = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode == 404) {
|
if (response.statusCode == 404) {
|
||||||
|
|
@ -478,6 +491,26 @@ class Api {
|
||||||
throw new Error(JSON.stringify(response.body));
|
throw new Error(JSON.stringify(response.body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async SnapshotSet(snapshotName, properties) {
|
||||||
|
const httpClient = await this.getHttpClient(false);
|
||||||
|
let response;
|
||||||
|
let endpoint;
|
||||||
|
|
||||||
|
endpoint = `/zfs/snapshot/id/${encodeURIComponent(snapshotName)}`;
|
||||||
|
response = await httpClient.put(endpoint, {
|
||||||
|
//...this.getSystemProperties(properties),
|
||||||
|
user_properties_update: this.getPropertiesKeyValueArray(
|
||||||
|
this.getUserProperties(properties)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(JSON.stringify(response.body));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* zfs get -Hp all tank/k8s/test/PVC-111
|
* zfs get -Hp all tank/k8s/test/PVC-111
|
||||||
|
|
@ -495,34 +528,7 @@ class Api {
|
||||||
response = await httpClient.get(endpoint);
|
response = await httpClient.get(endpoint);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
let res = {};
|
return this.normalizeProperties(response.body, properties);
|
||||||
for (const property of properties) {
|
|
||||||
let p;
|
|
||||||
if (response.body.hasOwnProperty(property)) {
|
|
||||||
p = response.body[property];
|
|
||||||
} else if (response.body.properties.hasOwnProperty(property)) {
|
|
||||||
p = response.body.properties[property];
|
|
||||||
} else {
|
|
||||||
p = {
|
|
||||||
value: "-",
|
|
||||||
rawvalue: "-",
|
|
||||||
source: "-",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof p === "object" && p !== null) {
|
|
||||||
// nothing, leave as is
|
|
||||||
} else {
|
|
||||||
p = {
|
|
||||||
value: p,
|
|
||||||
rawvalue: p,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
res[property] = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode == 404) {
|
if (response.statusCode == 404) {
|
||||||
|
|
@ -621,6 +627,14 @@ class Api {
|
||||||
// https://github.com/truenas/middleware/pull/6934
|
// https://github.com/truenas/middleware/pull/6934
|
||||||
// then use core.bulk to delete all
|
// then use core.bulk to delete all
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* /usr/lib/python3/dist-packages/middlewared/plugins/replication.py
|
||||||
|
* readonly enum=["SET", "REQUIRE", "IGNORE"]
|
||||||
|
*
|
||||||
|
* @param {*} data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
async ReplicationRunOnetime(data) {
|
async ReplicationRunOnetime(data) {
|
||||||
const httpClient = await this.getHttpClient(false);
|
const httpClient = await this.getHttpClient(false);
|
||||||
|
|
||||||
|
|
@ -652,6 +666,8 @@ class Api {
|
||||||
// 200 means the 'job' was accepted only
|
// 200 means the 'job' was accepted only
|
||||||
// must continue to check the status of the job to know when it has finished and if it was successful
|
// must continue to check the status of the job to know when it has finished and if it was successful
|
||||||
// /core/get_jobs [["id", "=", jobidhere]]
|
// /core/get_jobs [["id", "=", jobidhere]]
|
||||||
|
// state = SUCCESS/ABORTED/FAILED means finality has been reached
|
||||||
|
// state = RUNNING
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return response.body;
|
return response.body;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue