From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 04/11] api: admin/datastore: simplify prune api call
Date: Fri, 16 Jul 2021 10:53:21 +0200 [thread overview]
Message-ID: <20210716085328.3731574-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210716085328.3731574-1-d.csapak@proxmox.com>
by using the api macro and reusing the PruneOptions from pbs-datastore
this means we can now drop the 'add_common_prune_prameters' macro
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/api2/admin/datastore.rs | 135 ++++++++++++------------------------
1 file changed, 45 insertions(+), 90 deletions(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 184def5a..0bf6a86b 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -16,7 +16,7 @@ use proxmox::api::{
api, ApiResponseFuture, ApiHandler, ApiMethod, Router,
RpcEnvironment, RpcEnvironmentType, Permission
};
-use proxmox::api::router::{ReturnType, SubdirMap};
+use proxmox::api::router::SubdirMap;
use proxmox::api::schema::*;
use proxmox::tools::fs::{
file_read_firstline, file_read_optional_string, replace_file, CreateOptions,
@@ -797,106 +797,61 @@ pub fn verify(
Ok(json!(upid_str))
}
-#[macro_export]
-macro_rules! add_common_prune_prameters {
- ( [ $( $list1:tt )* ] ) => {
- add_common_prune_prameters!([$( $list1 )* ] , [])
- };
- ( [ $( $list1:tt )* ] , [ $( $list2:tt )* ] ) => {
- [
- $( $list1 )*
- (
- "keep-daily",
- true,
- &PRUNE_SCHEMA_KEEP_DAILY,
- ),
- (
- "keep-hourly",
- true,
- &PRUNE_SCHEMA_KEEP_HOURLY,
- ),
- (
- "keep-last",
- true,
- &PRUNE_SCHEMA_KEEP_LAST,
- ),
- (
- "keep-monthly",
- true,
- &PRUNE_SCHEMA_KEEP_MONTHLY,
- ),
- (
- "keep-weekly",
- true,
- &PRUNE_SCHEMA_KEEP_WEEKLY,
- ),
- (
- "keep-yearly",
- true,
- &PRUNE_SCHEMA_KEEP_YEARLY,
- ),
- $( $list2 )*
- ]
- }
-}
-
-pub const API_RETURN_SCHEMA_PRUNE: Schema = ArraySchema::new(
- "Returns the list of snapshots and a flag indicating if there are kept or removed.",
- &PruneListItem::API_SCHEMA
-).schema();
-
-pub const API_METHOD_PRUNE: ApiMethod = ApiMethod::new(
- &ApiHandler::Sync(&prune),
- &ObjectSchema::new(
- "Prune the datastore.",
- &add_common_prune_prameters!([
- ("backup-id", false, &BACKUP_ID_SCHEMA),
- ("backup-type", false, &BACKUP_TYPE_SCHEMA),
- ("dry-run", true, &BooleanSchema::new(
- "Just show what prune would do, but do not delete anything.")
- .schema()
- ),
- ],[
- ("store", false, &DATASTORE_SCHEMA),
- ])
- ))
- .returns(ReturnType::new(false, &API_RETURN_SCHEMA_PRUNE))
- .access(None, &Permission::Privilege(
- &["datastore", "{store}"],
- PRIV_DATASTORE_MODIFY | PRIV_DATASTORE_PRUNE,
- true)
-);
-
+#[api(
+ input: {
+ properties: {
+ "backup-id": {
+ schema: BACKUP_ID_SCHEMA,
+ },
+ "backup-type": {
+ schema: BACKUP_TYPE_SCHEMA,
+ },
+ "dry-run": {
+ optional: true,
+ type: bool,
+ default: false,
+ description: "Just show what prune would do, but do not delete anything.",
+ },
+ "prune-options": {
+ type: PruneOptions,
+ flatten: true,
+ },
+ store: {
+ schema: DATASTORE_SCHEMA,
+ },
+ },
+ },
+ returns: {
+ type: Array,
+ description: "Returns the list of snapshots and a flag indicating if there are kept or removed.",
+ items: {
+ type: PruneListItem,
+ },
+ },
+ access: {
+ permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY | PRIV_DATASTORE_PRUNE, true),
+ },
+)]
+/// Prune the datastore
pub fn prune(
- param: Value,
- _info: &ApiMethod,
+ backup_id: String,
+ backup_type: String,
+ dry_run: bool,
+ prune_options: PruneOptions,
+ store: String,
+ _param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
- let store = tools::required_string_param(¶m, "store")?;
- let backup_type = tools::required_string_param(¶m, "backup-type")?;
- let backup_id = tools::required_string_param(¶m, "backup-id")?;
-
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
- let dry_run = param["dry-run"].as_bool().unwrap_or(false);
-
- let group = BackupGroup::new(backup_type, backup_id);
+ let group = BackupGroup::new(&backup_type, &backup_id);
let datastore = DataStore::lookup_datastore(&store)?;
check_priv_or_backup_owner(&datastore, &group, &auth_id, PRIV_DATASTORE_MODIFY)?;
- let prune_options = PruneOptions {
- keep_last: param["keep-last"].as_u64(),
- keep_hourly: param["keep-hourly"].as_u64(),
- keep_daily: param["keep-daily"].as_u64(),
- keep_weekly: param["keep-weekly"].as_u64(),
- keep_monthly: param["keep-monthly"].as_u64(),
- keep_yearly: param["keep-yearly"].as_u64(),
- };
-
- let worker_id = format!("{}:{}/{}", store, backup_type, backup_id);
+ let worker_id = format!("{}:{}/{}", store, &backup_type, &backup_id);
let mut prune_result = Vec::new();
--
2.30.2
next prev parent reply other threads:[~2021-07-16 8:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-16 8:53 [pbs-devel] [PATCH proxmox-backup 00/11] add 'prune all' button to datastore content Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 01/11] api-types: move PRUNE_SCHEMA_KEEP_* to pbs-api-types Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 02/11] pbs-datastore/prune: make PruneOptions an api type Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 03/11] client: simplify prune api method Dominik Csapak
2021-07-16 8:53 ` Dominik Csapak [this message]
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 05/11] backup/datastore: refactor check_backup_owner there Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 06/11] server/prune_job: factor out 'prune_datastore' Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 07/11] server/prune_job: add 'keep_all' logic to 'prune_datastore' Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 08/11] server/prune_job: add proper permission checks " Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 09/11] api: admin/datastore: add new 'prune-datastore' api call Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 10/11] ui: datastore/Content: add 'Prune All' button Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 11/11] ui: datastore/Prune: improve title of group prune window Dominik Csapak
2021-07-16 9:48 ` [pbs-devel] applied: [PATCH proxmox-backup 00/11] add 'prune all' button to datastore content Dietmar Maurer
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=20210716085328.3731574-5-d.csapak@proxmox.com \
--to=d.csapak@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal