From: Oguz Bektas <o.bektas@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] add datastore info api call
Date: Wed, 21 Oct 2020 16:01:59 +0200 [thread overview]
Message-ID: <20201021140159.2250193-1-o.bektas@proxmox.com> (raw)
to be able to copy/paste easily when adding a new PBS datastore remote
in PVE
Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
---
src/api2/admin/datastore.rs | 55 +++++++++++++++++++++++++++++++++++++
src/api2/types/mod.rs | 23 ++++++++++++++++
2 files changed, 78 insertions(+)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 91ca3570..41059f98 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -25,6 +25,7 @@ use pxar::EntryKind;
use crate::api2::types::*;
use crate::api2::node::rrd::create_value_from_rrd;
+use crate::config::network::{self};
use crate::backup::*;
use crate::config::datastore;
use crate::config::cached_user_info::CachedUserInfo;
@@ -36,6 +37,7 @@ use crate::tools::{
AsyncChannelWriter, AsyncReaderStream, WrappedReaderStream,
};
+use crate::tools::cert::CertInfo;
use crate::config::acl::{
PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_MODIFY,
@@ -448,6 +450,54 @@ pub fn status(
crate::tools::disks::disk_usage(&datastore.base_path())
}
+#[api(
+ input: {
+ properties: {
+ store: {
+ schema: DATASTORE_SCHEMA,
+ },
+ },
+ },
+ returns: {
+ type: DataStoreInfo,
+ },
+ access: {
+ permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_READ, true),
+ },
+)]
+/// Get information about the datastore.
+///
+/// Provides PBS node fingerprint, address and datastore name
+pub fn info(
+ store: String,
+ _info: &ApiMethod,
+ _rpcenv: &mut dyn RpcEnvironment,
+) -> Result<DataStoreInfo, Error> {
+ let _datastore = DataStore::lookup_datastore(&store)?;
+ let cert = CertInfo::new()?;
+ let fingerprint = cert.fingerprint()?;
+
+ // get all possible interface IP addresses since there's
+ // no explicit way to tell which is needed
+ let (config, _) = network::config()?;
+ let mut address_list = Vec::new();
+ for (_ , interface) in config.interfaces.iter() {
+ if let Some(cidr) = &interface.cidr {
+ address_list.push(cidr.to_owned());
+ }
+ }
+
+ let result_item = DataStoreInfo {
+ name: store,
+ address_list,
+ fingerprint,
+ };
+
+ Ok(result_item)
+}
+
+
+
#[api(
input: {
properties: {
@@ -1673,6 +1723,11 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&Router::new()
.get(&API_METHOD_LIST_GROUPS)
),
+ (
+ "info",
+ &Router::new()
+ .get(&API_METHOD_INFO)
+ ),
(
"notes",
&Router::new()
diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs
index f97db557..9e61f15c 100644
--- a/src/api2/types/mod.rs
+++ b/src/api2/types/mod.rs
@@ -1070,3 +1070,26 @@ pub struct APTUpdateInfo {
/// URL under which the package's changelog can be retrieved
pub change_log_url: String,
}
+
+#[api(
+ properties: {
+ "address-list": {
+ description: "List of IPs from node",
+ type: Array,
+ items: {
+ description: "CIDR",
+ type: String,
+ },
+ },
+})]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// Necessary information for adding a remote
+pub struct DataStoreInfo {
+ /// Name of the datastore
+ pub name: String,
+ /// Available IP addresses from the node
+ pub address_list: Vec<String>,
+ /// x509 fingerprint of the node
+ pub fingerprint: String,
+}
--
2.20.1
next reply other threads:[~2020-10-21 14:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-21 14:01 Oguz Bektas [this message]
2020-10-22 8:02 ` Fabian Grünbichler
2020-10-22 9:17 ` Oguz Bektas
2020-10-22 10:39 ` Thomas Lamprecht
2020-10-22 11:00 ` Fabian Grünbichler
2020-10-22 11:35 ` Oguz Bektas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201021140159.2250193-1-o.bektas@proxmox.com \
--to=o.bektas@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox