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> {
|
) -> Result<Value, Error> {
|
||||||
let path = format!("api2/json/admin/datastore/{}/snapshots", store);
|
let path = format!("api2/json/admin/datastore/{}/snapshots", store);
|
||||||
|
|
||||||
let mut args = json!({});
|
let args = match group {
|
||||||
if let Some(group) = group {
|
Some(group) => serde_json::to_value(group)?,
|
||||||
args["backup-type"] = group.ty.to_string().into();
|
None => json!({}),
|
||||||
args["backup-id"] = group.id.into();
|
};
|
||||||
}
|
|
||||||
|
|
||||||
let mut result = client.get(&path, Some(args)).await?;
|
let mut result = client.get(&path, Some(args)).await?;
|
||||||
|
|
||||||
|
@ -243,6 +242,10 @@ async fn backup_image<P: AsRef<Path>>(
|
||||||
schema: REPO_URL_SCHEMA,
|
schema: REPO_URL_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
"ns": {
|
||||||
|
type: BackupNamespace,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
"output-format": {
|
"output-format": {
|
||||||
schema: OUTPUT_FORMAT,
|
schema: OUTPUT_FORMAT,
|
||||||
optional: true,
|
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 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);
|
record_repository(&repo);
|
||||||
|
|
||||||
|
@ -309,6 +318,13 @@ async fn list_backup_groups(param: Value) -> Result<Value, Error> {
|
||||||
Ok(Value::Null)
|
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(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -336,8 +352,7 @@ async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Erro
|
||||||
|
|
||||||
let group: BackupGroup = group.parse()?;
|
let group: BackupGroup = group.parse()?;
|
||||||
|
|
||||||
param["backup-type"] = group.ty.to_string().into();
|
merge_group_into(param.as_object_mut().unwrap(), group);
|
||||||
param["backup-id"] = group.id.into();
|
|
||||||
|
|
||||||
let path = format!("api2/json/admin/datastore/{}/change-owner", repo.store());
|
let path = format!("api2/json/admin/datastore/{}/change-owner", repo.store());
|
||||||
client.post(&path, Some(param)).await?;
|
client.post(&path, Some(param)).await?;
|
||||||
|
@ -1419,8 +1434,7 @@ async fn prune(
|
||||||
if let Some(dry_run) = dry_run {
|
if let Some(dry_run) = dry_run {
|
||||||
api_param["dry-run"] = dry_run.into();
|
api_param["dry-run"] = dry_run.into();
|
||||||
}
|
}
|
||||||
api_param["backup-type"] = group.ty.to_string().into();
|
merge_group_into(api_param.as_object_mut().unwrap(), group);
|
||||||
api_param["backup-id"] = group.id.into();
|
|
||||||
|
|
||||||
let mut result = client.post(&path, Some(api_param)).await?;
|
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 path = format!("api2/json/admin/datastore/{}/files", repo.store());
|
||||||
|
|
||||||
let mut result = client
|
let mut result = client
|
||||||
.get(
|
.get(&path, Some(serde_json::to_value(snapshot)?))
|
||||||
&path,
|
|
||||||
Some(json!({
|
|
||||||
"backup-type": snapshot.group.ty,
|
|
||||||
"backup-id": snapshot.group.id,
|
|
||||||
"backup-time": snapshot.time,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
record_repository(&repo);
|
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 path = format!("api2/json/admin/datastore/{}/snapshots", repo.store());
|
||||||
|
|
||||||
let result = client
|
let result = client
|
||||||
.delete(
|
.delete(&path, Some(serde_json::to_value(snapshot)?))
|
||||||
&path,
|
|
||||||
Some(json!({
|
|
||||||
"backup-type": snapshot.group.ty,
|
|
||||||
"backup-id": snapshot.group.id,
|
|
||||||
"backup-time": snapshot.time,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
record_repository(&repo);
|
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 path = format!("api2/json/admin/datastore/{}/notes", repo.store());
|
||||||
|
|
||||||
let args = json!({
|
let args = serde_json::to_value(snapshot)?;
|
||||||
"backup-type": snapshot.group.ty,
|
|
||||||
"backup-id": snapshot.group.id,
|
|
||||||
"backup-time": snapshot.time,
|
|
||||||
});
|
|
||||||
|
|
||||||
let output_format = get_output_format(¶m);
|
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 path = format!("api2/json/admin/datastore/{}/notes", repo.store());
|
||||||
|
|
||||||
let args = json!({
|
let mut args = serde_json::to_value(snapshot)?;
|
||||||
"backup-type": snapshot.group.ty,
|
args["notes"] = Value::from(notes);
|
||||||
"backup-id": snapshot.group.id,
|
|
||||||
"backup-time": snapshot.time,
|
|
||||||
"notes": notes,
|
|
||||||
});
|
|
||||||
|
|
||||||
client.put(&path, Some(args)).await?;
|
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 path = format!("api2/json/admin/datastore/{}/protected", repo.store());
|
||||||
|
|
||||||
let args = json!({
|
let args = serde_json::to_value(snapshot)?;
|
||||||
"backup-type": snapshot.group.ty,
|
|
||||||
"backup-id": snapshot.group.id,
|
|
||||||
"backup-time": snapshot.time,
|
|
||||||
});
|
|
||||||
|
|
||||||
let output_format = get_output_format(¶m);
|
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 path = format!("api2/json/admin/datastore/{}/protected", repo.store());
|
||||||
|
|
||||||
let args = json!({
|
let mut args = serde_json::to_value(snapshot)?;
|
||||||
"backup-type": snapshot.group.ty,
|
args["protected"] = Value::from(protected);
|
||||||
"backup-id": snapshot.group.id,
|
|
||||||
"backup-time": snapshot.time,
|
|
||||||
"protected": protected,
|
|
||||||
});
|
|
||||||
|
|
||||||
client.put(&path, Some(args)).await?;
|
client.put(&path, Some(args)).await?;
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,10 @@ fn get_all_snapshot_files(
|
||||||
store: {
|
store: {
|
||||||
schema: DATASTORE_SCHEMA,
|
schema: DATASTORE_SCHEMA,
|
||||||
},
|
},
|
||||||
|
"backup-ns": {
|
||||||
|
type: BackupNamespace,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
returns: pbs_api_types::ADMIN_DATASTORE_LIST_GROUPS_RETURN_TYPE,
|
returns: pbs_api_types::ADMIN_DATASTORE_LIST_GROUPS_RETURN_TYPE,
|
||||||
|
@ -160,6 +164,7 @@ fn get_all_snapshot_files(
|
||||||
/// List backup groups.
|
/// List backup groups.
|
||||||
pub fn list_groups(
|
pub fn list_groups(
|
||||||
store: String,
|
store: String,
|
||||||
|
backup_ns: Option<BackupNamespace>,
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<Vec<GroupListItem>, Error> {
|
) -> Result<Vec<GroupListItem>, Error> {
|
||||||
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
|
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;
|
let list_all = (user_privs & PRIV_DATASTORE_AUDIT) != 0;
|
||||||
|
|
||||||
datastore
|
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| {
|
.try_fold(Vec::new(), |mut group_info, group| {
|
||||||
let group = group?;
|
let group = group?;
|
||||||
let owner = match datastore.get_owner(group.as_ref()) {
|
let owner = match datastore.get_owner(group.as_ref()) {
|
||||||
|
|
Loading…
Reference in New Issue