From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 83FA161842 for ; Wed, 21 Oct 2020 16:02:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7368218B3F for ; Wed, 21 Oct 2020 16:02:04 +0200 (CEST) Received: from gaia.proxmox.com (212-186-127-178.static.upcbusiness.at [212.186.127.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 2FD3918B35 for ; Wed, 21 Oct 2020 16:02:03 +0200 (CEST) Received: from gaia.proxmox.com (localhost.localdomain [127.0.0.1]) by gaia.proxmox.com (8.15.2/8.15.2/Debian-14~deb10u1) with ESMTP id 09LE22rU2250434; Wed, 21 Oct 2020 16:02:02 +0200 Received: (from oguz@localhost) by gaia.proxmox.com (8.15.2/8.15.2/Submit) id 09LE22PS2250433; Wed, 21 Oct 2020 16:02:02 +0200 From: Oguz Bektas To: pbs-devel@lists.proxmox.com Date: Wed, 21 Oct 2020 16:01:59 +0200 Message-Id: <20201021140159.2250193-1-o.bektas@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.592 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods KHOP_HELO_FCRDNS 0.399 Relay HELO differs from its IP's reverse DNS NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [datastore.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup] add datastore info api call X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Oct 2020 14:02:34 -0000 to be able to copy/paste easily when adding a new PBS datastore remote in PVE Signed-off-by: Oguz Bektas --- 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 { + 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, + /// x509 fingerprint of the node + pub fingerprint: String, +} -- 2.20.1