[pbs-devel] [PATCH proxmox-backup v3 3/6] manager: add completion for opt. Remote in SyncJob
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Aug 24 11:24:32 CEST 2023
On Tue, Aug 08, 2023 at 02:13:41PM +0200, Hannes Laimer wrote:
> Signed-off-by: Hannes Laimer <h.laimer at 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 b4cb6cb3..eadfe547 100644
> --- a/src/bin/proxmox-backup-manager.rs
> +++ b/src/bin/proxmox-backup-manager.rs
> @@ -535,35 +535,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;
^ belongs in patch 1
> }
> }
> 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();
^ belongs in patch 1
> }
> }
> 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
> @@ -584,7 +582,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) {
> @@ -595,7 +593,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
> }
> @@ -607,17 +607,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)) => {
Something about "remote store" vs "source store" just bugs me here...
Pull jobs should altogether just have a 'source' instead of a 'remote'
:-/
> + let mut rpcenv = CliEnvironment::new();
> + rpcenv.set_auth_id(Some(String::from("root at pam")));
> + crate::api2::admin::namespace::list_namespaces(source_store, None, None, &mut rpcenv)
> + .ok()
> + }
> + _ => None,
> + } {
> + for item in data {
> + list.push(item.ns.name());
> }
> }
>
> @@ -662,19 +670,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 at 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.39.2
More information about the pbs-devel
mailing list