From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
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 UTF8SMTPS id D73B1747C6
 for <pbs-devel@lists.proxmox.com>; Tue, 22 Jun 2021 09:03:52 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with UTF8SMTP id BEC5C22CDA
 for <pbs-devel@lists.proxmox.com>; Tue, 22 Jun 2021 09:03:52 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 UTF8SMTPS id 012C122CC8
 for <pbs-devel@lists.proxmox.com>; Tue, 22 Jun 2021 09:03:50 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with UTF8SMTP id C1A4142EC2
 for <pbs-devel@lists.proxmox.com>; Tue, 22 Jun 2021 09:03:50 +0200 (CEST)
Message-ID: <21d1121b-716e-e7f8-a62b-7bb54153e6d0@proxmox.com>
Date: Tue, 22 Jun 2021 09:03:49 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101
 Thunderbird/90.0
Content-Language: en-US
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
References: <20210608140827.24236-1-d.csapak@proxmox.com>
In-Reply-To: <20210608140827.24236-1-d.csapak@proxmox.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.790 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches 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, proxmox.com]
Subject: Re: [pbs-devel] [PATCH proxmox-backup] proxmox-backup-manager: show
 task log on datastore create
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 22 Jun 2021 07:03:52 -0000

as it turns out, this patch not only improves the visible feedback,
but actually fixes a but where one cannot create
the datastore via cli

seemingly, embedding an async api call into the clihandler that
returns a upid and starts a worker, does not start
in proxmox-backup-proxy, but directly in the cli handler?

which gets cancelled as soon as the upid is  printed?

see https://bugzilla.proxmox.com/show_bug.cgi?id=3486

On 6/8/21 16:08, Dominik Csapak wrote:
> since the output:
> Result: "<UPID>"
> is not really interesting, show instead the task log while
> the datastore is creating, since it is now run in a worker
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>   src/bin/proxmox_backup_manager/datastore.rs | 82 ++++++++++++++++++++-
>   1 file changed, 81 insertions(+), 1 deletion(-)
> 
> diff --git a/src/bin/proxmox_backup_manager/datastore.rs b/src/bin/proxmox_backup_manager/datastore.rs
> index 7e596a1b..7cbd8805 100644
> --- a/src/bin/proxmox_backup_manager/datastore.rs
> +++ b/src/bin/proxmox_backup_manager/datastore.rs
> @@ -5,6 +5,11 @@ use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
>   
>   use proxmox_backup::config;
>   use proxmox_backup::api2::{self, types::* };
> +use proxmox_backup::client::{
> +    connect_to_localhost,
> +    view_task_result,
> +};
> +use proxmox_backup::config::datastore::DIR_NAME_SCHEMA;
>   
>   #[api(
>       input: {
> @@ -67,6 +72,81 @@ fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
>       Ok(Value::Null)
>   }
>   
> +#[api(
> +    protected: true,
> +    input: {
> +        properties: {
> +            name: {
> +                schema: DATASTORE_SCHEMA,
> +            },
> +            path: {
> +                schema: DIR_NAME_SCHEMA,
> +            },
> +            comment: {
> +                optional: true,
> +                schema: SINGLE_LINE_COMMENT_SCHEMA,
> +            },
> +            "notify-user": {
> +                optional: true,
> +                type: Userid,
> +            },
> +            "notify": {
> +                optional: true,
> +                schema: DATASTORE_NOTIFY_STRING_SCHEMA,
> +            },
> +            "gc-schedule": {
> +                optional: true,
> +                schema: GC_SCHEDULE_SCHEMA,
> +            },
> +            "prune-schedule": {
> +                optional: true,
> +                schema: PRUNE_SCHEDULE_SCHEMA,
> +            },
> +            "keep-last": {
> +                optional: true,
> +                schema: PRUNE_SCHEMA_KEEP_LAST,
> +            },
> +            "keep-hourly": {
> +                optional: true,
> +                schema: PRUNE_SCHEMA_KEEP_HOURLY,
> +            },
> +            "keep-daily": {
> +                optional: true,
> +                schema: PRUNE_SCHEMA_KEEP_DAILY,
> +            },
> +            "keep-weekly": {
> +                optional: true,
> +                schema: PRUNE_SCHEMA_KEEP_WEEKLY,
> +            },
> +            "keep-monthly": {
> +                optional: true,
> +                schema: PRUNE_SCHEMA_KEEP_MONTHLY,
> +            },
> +            "keep-yearly": {
> +                optional: true,
> +                schema: PRUNE_SCHEMA_KEEP_YEARLY,
> +            },
> +            "output-format": {
> +                schema: OUTPUT_FORMAT,
> +                optional: true,
> +            },
> +        },
> +    },
> +)]
> +/// Create new datastore config.
> +async fn create_datastore(mut param: Value) -> Result<Value, Error> {
> +
> +    let output_format = extract_output_format(&mut param);
> +
> +    let mut client = connect_to_localhost()?;
> +
> +    let result = client.post(&"api2/json/config/datastore", Some(param)).await?;
> +
> +    view_task_result(&mut client, result, &output_format).await?;
> +
> +    Ok(Value::Null)
> +}
> +
>   pub fn datastore_commands() -> CommandLineInterface {
>   
>       let cmd_def = CliCommandMap::new()
> @@ -77,7 +157,7 @@ pub fn datastore_commands() -> CommandLineInterface {
>                   .completion_cb("name", config::datastore::complete_datastore_name)
>           )
>           .insert("create",
> -                CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE)
> +                CliCommand::new(&API_METHOD_CREATE_DATASTORE)
>                   .arg_param(&["name", "path"])
>           )
>           .insert("update",
>