client: more backup namespace support
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
13d6de3787
commit
89ae3c3255
@ -134,11 +134,10 @@ async fn api_datastore_list_snapshots(
|
||||
) -> Result<Value, Error> {
|
||||
let path = format!("api2/json/admin/datastore/{}/snapshots", store);
|
||||
|
||||
let mut args = json!({});
|
||||
if let Some(group) = group {
|
||||
args["backup-type"] = group.ty.to_string().into();
|
||||
args["backup-id"] = group.id.into();
|
||||
}
|
||||
let args = match group {
|
||||
Some(group) => serde_json::to_value(group)?,
|
||||
None => json!({}),
|
||||
};
|
||||
|
||||
let mut result = client.get(&path, Some(args)).await?;
|
||||
|
||||
@ -243,6 +242,10 @@ async fn backup_image<P: AsRef<Path>>(
|
||||
schema: REPO_URL_SCHEMA,
|
||||
optional: true,
|
||||
},
|
||||
"ns": {
|
||||
type: BackupNamespace,
|
||||
optional: true,
|
||||
},
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
optional: true,
|
||||
@ -260,7 +263,13 @@ async fn list_backup_groups(param: Value) -> Result<Value, Error> {
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/groups", repo.store());
|
||||
|
||||
let mut result = client.get(&path, None).await?;
|
||||
let backup_ns: BackupNamespace = match ¶m["ns"] {
|
||||
Value::String(s) => s.parse()?,
|
||||
_ => BackupNamespace::root(),
|
||||
};
|
||||
let mut result = client
|
||||
.get(&path, Some(json!({ "backup-ns": backup_ns })))
|
||||
.await?;
|
||||
|
||||
record_repository(&repo);
|
||||
|
||||
@ -309,6 +318,13 @@ async fn list_backup_groups(param: Value) -> Result<Value, Error> {
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
fn merge_group_into(to: &mut serde_json::Map<String, Value>, group: BackupGroup) {
|
||||
match serde_json::to_value(group).unwrap() {
|
||||
Value::Object(group) => to.extend(group),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
@ -336,8 +352,7 @@ async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Erro
|
||||
|
||||
let group: BackupGroup = group.parse()?;
|
||||
|
||||
param["backup-type"] = group.ty.to_string().into();
|
||||
param["backup-id"] = group.id.into();
|
||||
merge_group_into(param.as_object_mut().unwrap(), group);
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/change-owner", repo.store());
|
||||
client.post(&path, Some(param)).await?;
|
||||
@ -1419,8 +1434,7 @@ async fn prune(
|
||||
if let Some(dry_run) = dry_run {
|
||||
api_param["dry-run"] = dry_run.into();
|
||||
}
|
||||
api_param["backup-type"] = group.ty.to_string().into();
|
||||
api_param["backup-id"] = group.id.into();
|
||||
merge_group_into(api_param.as_object_mut().unwrap(), group);
|
||||
|
||||
let mut result = client.post(&path, Some(api_param)).await?;
|
||||
|
||||
|
@ -122,14 +122,7 @@ async fn list_snapshot_files(param: Value) -> Result<Value, Error> {
|
||||
let path = format!("api2/json/admin/datastore/{}/files", repo.store());
|
||||
|
||||
let mut result = client
|
||||
.get(
|
||||
&path,
|
||||
Some(json!({
|
||||
"backup-type": snapshot.group.ty,
|
||||
"backup-id": snapshot.group.id,
|
||||
"backup-time": snapshot.time,
|
||||
})),
|
||||
)
|
||||
.get(&path, Some(serde_json::to_value(snapshot)?))
|
||||
.await?;
|
||||
|
||||
record_repository(&repo);
|
||||
@ -171,14 +164,7 @@ async fn forget_snapshots(param: Value) -> Result<Value, Error> {
|
||||
let path = format!("api2/json/admin/datastore/{}/snapshots", repo.store());
|
||||
|
||||
let result = client
|
||||
.delete(
|
||||
&path,
|
||||
Some(json!({
|
||||
"backup-type": snapshot.group.ty,
|
||||
"backup-id": snapshot.group.id,
|
||||
"backup-time": snapshot.time,
|
||||
})),
|
||||
)
|
||||
.delete(&path, Some(serde_json::to_value(snapshot)?))
|
||||
.await?;
|
||||
|
||||
record_repository(&repo);
|
||||
@ -290,11 +276,7 @@ async fn show_notes(param: Value) -> Result<Value, Error> {
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/notes", repo.store());
|
||||
|
||||
let args = json!({
|
||||
"backup-type": snapshot.group.ty,
|
||||
"backup-id": snapshot.group.id,
|
||||
"backup-time": snapshot.time,
|
||||
});
|
||||
let args = serde_json::to_value(snapshot)?;
|
||||
|
||||
let output_format = get_output_format(¶m);
|
||||
|
||||
@ -347,12 +329,8 @@ async fn update_notes(param: Value) -> Result<Value, Error> {
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/notes", repo.store());
|
||||
|
||||
let args = json!({
|
||||
"backup-type": snapshot.group.ty,
|
||||
"backup-id": snapshot.group.id,
|
||||
"backup-time": snapshot.time,
|
||||
"notes": notes,
|
||||
});
|
||||
let mut args = serde_json::to_value(snapshot)?;
|
||||
args["notes"] = Value::from(notes);
|
||||
|
||||
client.put(&path, Some(args)).await?;
|
||||
|
||||
@ -387,11 +365,7 @@ async fn show_protection(param: Value) -> Result<(), Error> {
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/protected", repo.store());
|
||||
|
||||
let args = json!({
|
||||
"backup-type": snapshot.group.ty,
|
||||
"backup-id": snapshot.group.id,
|
||||
"backup-time": snapshot.time,
|
||||
});
|
||||
let args = serde_json::to_value(snapshot)?;
|
||||
|
||||
let output_format = get_output_format(¶m);
|
||||
|
||||
@ -443,12 +417,8 @@ async fn update_protection(protected: bool, param: Value) -> Result<(), Error> {
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/protected", repo.store());
|
||||
|
||||
let args = json!({
|
||||
"backup-type": snapshot.group.ty,
|
||||
"backup-id": snapshot.group.id,
|
||||
"backup-time": snapshot.time,
|
||||
"protected": protected,
|
||||
});
|
||||
let mut args = serde_json::to_value(snapshot)?;
|
||||
args["protected"] = Value::from(protected);
|
||||
|
||||
client.put(&path, Some(args)).await?;
|
||||
|
||||
|
@ -147,6 +147,10 @@ fn get_all_snapshot_files(
|
||||
store: {
|
||||
schema: DATASTORE_SCHEMA,
|
||||
},
|
||||
"backup-ns": {
|
||||
type: BackupNamespace,
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
returns: pbs_api_types::ADMIN_DATASTORE_LIST_GROUPS_RETURN_TYPE,
|
||||
@ -160,6 +164,7 @@ fn get_all_snapshot_files(
|
||||
/// List backup groups.
|
||||
pub fn list_groups(
|
||||
store: String,
|
||||
backup_ns: Option<BackupNamespace>,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<Vec<GroupListItem>, Error> {
|
||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
||||
@ -170,7 +175,7 @@ pub fn list_groups(
|
||||
let list_all = (user_privs & PRIV_DATASTORE_AUDIT) != 0;
|
||||
|
||||
datastore
|
||||
.iter_backup_groups(Default::default())? // FIXME: Namespaces and recursion parameters!
|
||||
.iter_backup_groups(backup_ns.unwrap_or_default())? // FIXME: Namespaces and recursion parameters!
|
||||
.try_fold(Vec::new(), |mut group_info, group| {
|
||||
let group = group?;
|
||||
let owner = match datastore.get_owner(group.as_ref()) {
|
||||
|
Loading…
Reference in New Issue
Block a user