mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-04-30 12:34:21 +00:00
api: node: allow creation of removable datastore through directory endpoint
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
parent
f0e1cb86d6
commit
94a068e316
@ -123,6 +123,11 @@ pub fn list_datastore_mounts() -> Result<Vec<DatastoreMountInfo>, Error> {
|
|||||||
description: "Configure a datastore using the directory.",
|
description: "Configure a datastore using the directory.",
|
||||||
type: bool,
|
type: bool,
|
||||||
optional: true,
|
optional: true,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
"removable-datastore": {
|
||||||
|
description: "The added datastore is removable.",
|
||||||
|
type: bool,
|
||||||
},
|
},
|
||||||
filesystem: {
|
filesystem: {
|
||||||
type: FileSystemType,
|
type: FileSystemType,
|
||||||
@ -141,7 +146,8 @@ pub fn list_datastore_mounts() -> Result<Vec<DatastoreMountInfo>, Error> {
|
|||||||
pub fn create_datastore_disk(
|
pub fn create_datastore_disk(
|
||||||
name: String,
|
name: String,
|
||||||
disk: String,
|
disk: String,
|
||||||
add_datastore: Option<bool>,
|
add_datastore: bool,
|
||||||
|
removable_datastore: bool,
|
||||||
filesystem: Option<FileSystemType>,
|
filesystem: Option<FileSystemType>,
|
||||||
rpcenv: &mut dyn RpcEnvironment,
|
rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<String, Error> {
|
) -> Result<String, Error> {
|
||||||
@ -156,7 +162,6 @@ pub fn create_datastore_disk(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mount_point = format!("{}{}", BASE_MOUNT_DIR, &name);
|
let mount_point = format!("{}{}", BASE_MOUNT_DIR, &name);
|
||||||
|
|
||||||
// check if the default path exists already.
|
// check if the default path exists already.
|
||||||
// bail if it is not empty or another filesystem mounted on top
|
// bail if it is not empty or another filesystem mounted on top
|
||||||
let default_path = std::path::PathBuf::from(&mount_point);
|
let default_path = std::path::PathBuf::from(&mount_point);
|
||||||
@ -183,7 +188,6 @@ pub fn create_datastore_disk(
|
|||||||
move |_worker| {
|
move |_worker| {
|
||||||
info!("create datastore '{name}' on disk {disk}");
|
info!("create datastore '{name}' on disk {disk}");
|
||||||
|
|
||||||
let add_datastore = add_datastore.unwrap_or(false);
|
|
||||||
let filesystem = filesystem.unwrap_or(FileSystemType::Ext4);
|
let filesystem = filesystem.unwrap_or(FileSystemType::Ext4);
|
||||||
|
|
||||||
let manager = DiskManage::new();
|
let manager = DiskManage::new();
|
||||||
@ -196,18 +200,24 @@ pub fn create_datastore_disk(
|
|||||||
let uuid = get_fs_uuid(&partition)?;
|
let uuid = get_fs_uuid(&partition)?;
|
||||||
let uuid_path = format!("/dev/disk/by-uuid/{}", uuid);
|
let uuid_path = format!("/dev/disk/by-uuid/{}", uuid);
|
||||||
|
|
||||||
|
if !removable_datastore {
|
||||||
let mount_unit_name =
|
let mount_unit_name =
|
||||||
create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?;
|
create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?;
|
||||||
|
|
||||||
crate::tools::systemd::reload_daemon()?;
|
crate::tools::systemd::reload_daemon()?;
|
||||||
crate::tools::systemd::enable_unit(&mount_unit_name)?;
|
crate::tools::systemd::enable_unit(&mount_unit_name)?;
|
||||||
crate::tools::systemd::start_unit(&mount_unit_name)?;
|
crate::tools::systemd::start_unit(&mount_unit_name)?;
|
||||||
|
}
|
||||||
|
|
||||||
if add_datastore {
|
if add_datastore {
|
||||||
let lock = pbs_config::datastore::lock_config()?;
|
let lock = pbs_config::datastore::lock_config()?;
|
||||||
let datastore: DataStoreConfig =
|
let datastore: DataStoreConfig = if removable_datastore {
|
||||||
serde_json::from_value(json!({ "name": name, "path": mount_point }))?;
|
serde_json::from_value(
|
||||||
|
json!({ "name": name, "path": format!("/{name}"), "backing-device": uuid }),
|
||||||
|
)?
|
||||||
|
} else {
|
||||||
|
serde_json::from_value(json!({ "name": name, "path": mount_point }))?
|
||||||
|
};
|
||||||
let (config, _digest) = pbs_config::datastore::config()?;
|
let (config, _digest) = pbs_config::datastore::config()?;
|
||||||
|
|
||||||
if config.sections.contains_key(&datastore.name) {
|
if config.sections.contains_key(&datastore.name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user