]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/api2/node/disks/directory.rs: implement add-datastore feature
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 15 Jun 2020 08:00:55 +0000 (10:00 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 15 Jun 2020 08:01:50 +0000 (10:01 +0200)
src/api2/node/disks/directory.rs

index ed9fbdf7a34248e39de96c68f3e8eba7a34674e1..271f1bc7ecb9d519a0a30145e73b8575fd02e0f1 100644 (file)
@@ -1,4 +1,5 @@
 use anyhow::{Error};
+use serde_json::json;
 use ::serde::{Deserialize, Serialize};
 
 use proxmox::api::{api, Permission, RpcEnvironment, RpcEnvironmentType};
@@ -152,16 +153,16 @@ fn create_datastore_disk(
             let uuid = get_fs_uuid(&partition)?;
             let uuid_path = format!("/dev/disk/by-uuid/{}", uuid);
 
-            let mount_unit_name = create_datastore_mount_unit(&name, filesystem, &uuid_path)?;
-
-            if add_datastore {
-                unimplemented!(); // fixme
-            }
+            let (mount_unit_name, mount_point) = create_datastore_mount_unit(&name, filesystem, &uuid_path)?;
 
             systemd::reload_daemon()?;
             systemd::enable_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(())
         })?;
 
@@ -177,7 +178,7 @@ fn create_datastore_mount_unit(
     datastore_name: &str,
     fs_type: FileSystemType,
     what: &str,
-) -> Result<String, Error> {
+) -> Result<(String, String), Error> {
 
     let mount_point = format!("/mnt/datastore/{}", datastore_name);
     let mut mount_unit_name = systemd::escape_unit(&mount_point, true);
@@ -197,7 +198,7 @@ fn create_datastore_mount_unit(
 
     let mount = SystemdMountSection {
         What: what.to_string(),
-        Where: mount_point,
+        Where: mount_point.clone(),
         Type: Some(fs_type.to_string()),
         Options: Some(String::from("defaults")),
         ..Default::default()
@@ -210,5 +211,5 @@ fn create_datastore_mount_unit(
 
     systemd::config::save_systemd_mount(&mount_unit_path, &config)?;
 
-    Ok(mount_unit_name)
+    Ok((mount_unit_name, mount_point))
 }