From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/4] manager: add completion for local sync-jobs
Date: Mon, 13 Feb 2023 16:45:54 +0100 [thread overview]
Message-ID: <20230213154555.49610-4-h.laimer@proxmox.com> (raw)
In-Reply-To: <20230213154555.49610-1-h.laimer@proxmox.com>
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
src/bin/proxmox-backup-manager.rs | 67 +++++++++++++++++++------------
1 file changed, 41 insertions(+), 26 deletions(-)
diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index 740fdc49..1944c468 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -526,35 +526,33 @@ fn get_remote(param: &HashMap<String, String>) -> Option<String> {
param.get("remote").map(|r| r.to_owned()).or_else(|| {
if let Some(id) = param.get("id") {
if let Ok(job) = get_sync_job(id) {
- return Some(job.remote);
+ return job.remote;
}
}
None
})
}
-fn get_remote_store(param: &HashMap<String, String>) -> Option<(String, String)> {
+fn get_remote_store(param: &HashMap<String, String>) -> Option<(Option<String>, String)> {
let mut job: Option<SyncJobConfig> = None;
let remote = param.get("remote").map(|r| r.to_owned()).or_else(|| {
if let Some(id) = param.get("id") {
job = get_sync_job(id).ok();
if let Some(ref job) = job {
- return Some(job.remote.clone());
+ return job.remote.clone();
}
}
None
});
- if let Some(remote) = remote {
- let store = param
- .get("remote-store")
- .map(|r| r.to_owned())
- .or_else(|| job.map(|job| job.remote_store));
+ let store = param
+ .get("remote-store")
+ .map(|r| r.to_owned())
+ .or_else(|| job.map(|job| job.remote_store));
- if let Some(store) = store {
- return Some((remote, store));
- }
+ if let Some(store) = store {
+ return Some((remote, store));
}
None
@@ -575,7 +573,7 @@ fn get_remote_ns(param: &HashMap<String, String>) -> Option<BackupNamespace> {
}
// shell completion helper
-pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
+pub fn complete_remote_datastore_name(arg: &str, param: &HashMap<String, String>) -> Vec<String> {
let mut list = Vec::new();
if let Some(remote) = get_remote(param) {
@@ -586,7 +584,9 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String
list.push(item.store);
}
}
- }
+ } else {
+ list = pbs_config::datastore::complete_datastore_name(arg, param);
+ };
list
}
@@ -598,17 +598,25 @@ pub fn complete_remote_datastore_namespace(
) -> Vec<String> {
let mut list = Vec::new();
- if let Some((remote, remote_store)) = get_remote_store(param) {
- if let Ok(data) = proxmox_async::runtime::block_on(async move {
+ if let Some(data) = match get_remote_store(param) {
+ Some((Some(remote), remote_store)) => proxmox_async::runtime::block_on(async move {
crate::api2::config::remote::scan_remote_namespaces(
remote.clone(),
remote_store.clone(),
)
.await
- }) {
- for item in data {
- list.push(item.ns.name());
- }
+ .ok()
+ }),
+ Some((None, source_store)) => {
+ let mut rpcenv = CliEnvironment::new();
+ rpcenv.set_auth_id(Some(String::from("root@pam")));
+ crate::api2::admin::namespace::list_namespaces(source_store, None, None, &mut rpcenv)
+ .ok()
+ }
+ _ => None,
+ } {
+ for item in data {
+ list.push(item.ns.name());
}
}
@@ -653,19 +661,26 @@ pub fn complete_sync_local_datastore_namespace(
pub fn complete_remote_datastore_group(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
let mut list = Vec::new();
- if let Some((remote, remote_store)) = get_remote_store(param) {
- let ns = get_remote_ns(param);
- if let Ok(data) = proxmox_async::runtime::block_on(async move {
+ let ns = get_remote_ns(param);
+ if let Some(data) = match get_remote_store(param) {
+ Some((Some(remote), remote_store)) => proxmox_async::runtime::block_on(async move {
crate::api2::config::remote::scan_remote_groups(
remote.clone(),
remote_store.clone(),
ns,
)
.await
- }) {
- for item in data {
- list.push(format!("{}/{}", item.backup.ty, item.backup.id));
- }
+ .ok()
+ }),
+ Some((None, source_store)) => {
+ let mut rpcenv = CliEnvironment::new();
+ rpcenv.set_auth_id(Some(String::from("root@pam")));
+ crate::api2::admin::datastore::list_groups(source_store, ns, &mut rpcenv).ok()
+ }
+ _ => None,
+ } {
+ for item in data {
+ list.push(format!("{}/{}", item.backup.ty, item.backup.id));
}
}
--
2.30.2
next prev parent reply other threads:[~2023-02-13 15:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 15:45 [pbs-devel] [PATCH proxmox-backup 0/4] native " Hannes Laimer
2023-02-13 15:45 ` [pbs-devel] [PATCH proxmox-backup 1/4] api2: make remote for sync-jobs optional Hannes Laimer
2023-02-14 14:33 ` Fabian Grünbichler
2023-02-15 11:40 ` Thomas Lamprecht
2023-02-16 8:02 ` Fabian Grünbichler
2023-02-13 15:45 ` [pbs-devel] [PATCH proxmox-backup 2/4] pull: add logic for local pull Hannes Laimer
2023-02-14 14:33 ` Fabian Grünbichler
2023-02-13 15:45 ` Hannes Laimer [this message]
2023-02-13 15:45 ` [pbs-devel] [PATCH proxmox-backup 4/4] ui: add ui support for local sync-jobs Hannes Laimer
2023-02-14 8:02 ` [pbs-devel] [PATCH proxmox-backup 0/4] native " Lukas Wagner
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=20230213154555.49610-4-h.laimer@proxmox.com \
--to=h.laimer@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.