src/api2/node/disks/directory.rs: implement add-datastore feature
This commit is contained in:
parent
7a6b549270
commit
fbbcd85839
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::{Error};
|
use anyhow::{Error};
|
||||||
|
use serde_json::json;
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType};
|
use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType};
|
||||||
|
@ -152,16 +153,16 @@ 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);
|
||||||
|
|
||||||
let mount_unit_name = create_datastore_mount_unit(&name, filesystem, &uuid_path)?;
|
let (mount_unit_name, mount_point) = create_datastore_mount_unit(&name, filesystem, &uuid_path)?;
|
||||||
|
|
||||||
if add_datastore {
|
|
||||||
unimplemented!(); // fixme
|
|
||||||
}
|
|
||||||
|
|
||||||
systemd::reload_daemon()?;
|
systemd::reload_daemon()?;
|
||||||
systemd::enable_unit(&mount_unit_name)?;
|
systemd::enable_unit(&mount_unit_name)?;
|
||||||
systemd::start_unit(&mount_unit_name)?;
|
systemd::start_unit(&mount_unit_name)?;
|
||||||
|
|
||||||
|
if add_datastore {
|
||||||
|
crate::api2::config::datastore::create_datastore(json!({ "name": name, "path": mount_point }))?
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ fn create_datastore_mount_unit(
|
||||||
datastore_name: &str,
|
datastore_name: &str,
|
||||||
fs_type: FileSystemType,
|
fs_type: FileSystemType,
|
||||||
what: &str,
|
what: &str,
|
||||||
) -> Result<String, Error> {
|
) -> Result<(String, String), Error> {
|
||||||
|
|
||||||
let mount_point = format!("/mnt/datastore/{}", datastore_name);
|
let mount_point = format!("/mnt/datastore/{}", datastore_name);
|
||||||
let mut mount_unit_name = systemd::escape_unit(&mount_point, true);
|
let mut mount_unit_name = systemd::escape_unit(&mount_point, true);
|
||||||
|
@ -197,7 +198,7 @@ fn create_datastore_mount_unit(
|
||||||
|
|
||||||
let mount = SystemdMountSection {
|
let mount = SystemdMountSection {
|
||||||
What: what.to_string(),
|
What: what.to_string(),
|
||||||
Where: mount_point,
|
Where: mount_point.clone(),
|
||||||
Type: Some(fs_type.to_string()),
|
Type: Some(fs_type.to_string()),
|
||||||
Options: Some(String::from("defaults")),
|
Options: Some(String::from("defaults")),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -210,5 +211,5 @@ fn create_datastore_mount_unit(
|
||||||
|
|
||||||
systemd::config::save_systemd_mount(&mount_unit_path, &config)?;
|
systemd::config::save_systemd_mount(&mount_unit_path, &config)?;
|
||||||
|
|
||||||
Ok(mount_unit_name)
|
Ok((mount_unit_name, mount_point))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue