tape: remove drive from pool config

This commit is contained in:
Dietmar Maurer 2021-02-01 09:14:28 +01:00
parent 83b8949a98
commit 9883b54cba
6 changed files with 38 additions and 44 deletions

View File

@ -11,7 +11,6 @@ use proxmox::{
use crate::{
api2::types::{
DRIVE_NAME_SCHEMA,
MEDIA_POOL_NAME_SCHEMA,
MEDIA_SET_NAMING_TEMPLATE_SCHEMA,
MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
@ -19,12 +18,7 @@ use crate::{
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
MediaPoolConfig,
},
config::{
self,
drive::{
check_drive_exists,
},
},
config,
};
#[api(
@ -34,9 +28,6 @@ use crate::{
name: {
schema: MEDIA_POOL_NAME_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
},
allocation: {
schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
optional: true,
@ -59,7 +50,6 @@ use crate::{
/// Create a new media pool
pub fn create_pool(
name: String,
drive: String,
allocation: Option<String>,
retention: Option<String>,
template: Option<String>,
@ -74,12 +64,8 @@ pub fn create_pool(
bail!("Media pool '{}' already exists", name);
}
let (drive_config, _) = config::drive::config()?;
check_drive_exists(&drive_config, &drive)?;
let item = MediaPoolConfig {
name: name.clone(),
drive,
allocation,
retention,
template,
@ -160,10 +146,6 @@ pub enum DeletableProperty {
name: {
schema: MEDIA_POOL_NAME_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
optional: true,
},
allocation: {
schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
optional: true,
@ -194,7 +176,6 @@ pub enum DeletableProperty {
/// Update media pool settings
pub fn update_pool(
name: String,
drive: Option<String>,
allocation: Option<String>,
retention: Option<String>,
template: Option<String>,
@ -219,7 +200,6 @@ pub fn update_pool(
}
}
if let Some(drive) = drive { data.drive = drive; }
if allocation.is_some() { data.allocation = allocation; }
if retention.is_some() { data.retention = retention; }
if template.is_some() { data.template = template; }

View File

@ -28,6 +28,7 @@ use crate::{
Authid,
DATASTORE_SCHEMA,
MEDIA_POOL_NAME_SCHEMA,
DRIVE_NAME_SCHEMA,
UPID_SCHEMA,
MediaPoolConfig,
},
@ -53,6 +54,9 @@ use crate::{
pool: {
schema: MEDIA_POOL_NAME_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
},
"eject-media": {
description: "Eject media upon job completion.",
type: bool,
@ -73,6 +77,7 @@ use crate::{
pub fn backup(
store: String,
pool: String,
drive: String,
eject_media: Option<bool>,
export_media_set: Option<bool>,
rpcenv: &mut dyn RpcEnvironment,
@ -87,7 +92,7 @@ pub fn backup(
let (drive_config, _digest) = config::drive::config()?;
// early check before starting worker
check_drive_exists(&drive_config, &pool_config.drive)?;
check_drive_exists(&drive_config, &drive)?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
@ -100,7 +105,7 @@ pub fn backup(
auth_id,
to_stdout,
move |worker| {
backup_worker(&worker, datastore, &pool_config, eject_media, export_media_set)?;
backup_worker(&worker, datastore, &drive, &pool_config, eject_media, export_media_set)?;
Ok(())
}
)?;
@ -115,6 +120,7 @@ pub const ROUTER: Router = Router::new()
fn backup_worker(
worker: &WorkerTask,
datastore: Arc<DataStore>,
drive: &str,
pool_config: &MediaPoolConfig,
eject_media: bool,
export_media_set: bool,
@ -125,13 +131,13 @@ fn backup_worker(
let _lock = MediaPool::lock(status_path, &pool_config.name)?;
task_log!(worker, "update media online status");
let has_changer = update_media_online_status(&pool_config.drive)?;
let has_changer = update_media_online_status(drive)?;
let use_offline_media = !has_changer;
let pool = MediaPool::with_config(status_path, &pool_config, use_offline_media)?;
let mut pool_writer = PoolWriter::new(pool, &pool_config.drive)?;
let mut pool_writer = PoolWriter::new(pool, drive)?;
let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?;

View File

@ -27,6 +27,7 @@ use crate::{
tools::compute_file_csum,
api2::types::{
DATASTORE_SCHEMA,
DRIVE_NAME_SCHEMA,
UPID_SCHEMA,
Authid,
MediaPoolConfig,
@ -82,6 +83,9 @@ pub const ROUTER: Router = Router::new()
store: {
schema: DATASTORE_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
},
"media-set": {
description: "Media set UUID.",
type: String,
@ -95,6 +99,7 @@ pub const ROUTER: Router = Router::new()
/// Restore data from media-set
pub fn restore(
store: String,
drive: String,
media_set: String,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
@ -110,12 +115,13 @@ pub fn restore(
let pool = inventory.lookup_media_set_pool(&media_set_uuid)?;
// check if pool exists
let (config, _digest) = config::media_pool::config()?;
let pool_config: MediaPoolConfig = config.lookup("pool", &pool)?;
let _pool_config: MediaPoolConfig = config.lookup("pool", &pool)?;
let (drive_config, _digest) = config::drive::config()?;
// early check before starting worker
check_drive_exists(&drive_config, &pool_config.drive)?;
check_drive_exists(&drive_config, &drive)?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
@ -153,8 +159,6 @@ pub fn restore(
}
}
let drive = &pool_config.drive;
worker.log(format!("Restore mediaset '{}'", media_set));
if let Some(fingerprint) = encryption_key_fingerprint {
worker.log(format!("Encryption key fingerprint: {}", fingerprint));
@ -175,7 +179,7 @@ pub fn restore(
&worker,
media_id,
&drive_config,
drive,
&drive,
&datastore,
&auth_id,
)?;

View File

@ -21,7 +21,6 @@ use crate::{
parse_calendar_event,
},
api2::types::{
DRIVE_NAME_SCHEMA,
PROXMOX_SAFE_ID_FORMAT,
SINGLE_LINE_COMMENT_FORMAT,
TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA,
@ -116,9 +115,6 @@ impl std::str::FromStr for RetentionPolicy {
name: {
schema: MEDIA_POOL_NAME_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
},
allocation: {
schema: MEDIA_SET_ALLOCATION_POLICY_SCHEMA,
optional: true,
@ -142,8 +138,6 @@ impl std::str::FromStr for RetentionPolicy {
pub struct MediaPoolConfig {
/// The pool name
pub name: String,
/// The associated drive
pub drive: String,
/// Media Set allocation policy
#[serde(skip_serializing_if="Option::is_none")]
pub allocation: Option<String>,

View File

@ -765,6 +765,10 @@ async fn clean_drive(param: Value) -> Result<(), Error> {
pool: {
schema: MEDIA_POOL_NAME_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
optional: true,
},
"eject-media": {
description: "Eject media upon job completion.",
type: bool,
@ -783,10 +787,14 @@ async fn clean_drive(param: Value) -> Result<(), Error> {
},
)]
/// Backup datastore to tape media pool
async fn backup(param: Value) -> Result<(), Error> {
async fn backup(mut param: Value) -> Result<(), Error> {
let output_format = get_output_format(&param);
let (config, _digest) = config::drive::config()?;
param["drive"] = lookup_drive_name(&param, &config)?.into();
let mut client = connect_to_localhost()?;
let result = client.post("api2/json/tape/backup", Some(param)).await?;
@ -802,6 +810,10 @@ async fn backup(param: Value) -> Result<(), Error> {
store: {
schema: DATASTORE_SCHEMA,
},
drive: {
schema: DRIVE_NAME_SCHEMA,
optional: true,
},
"media-set": {
description: "Media set UUID.",
type: String,
@ -814,10 +826,14 @@ async fn backup(param: Value) -> Result<(), Error> {
},
)]
/// Restore data from media-set
async fn restore(param: Value) -> Result<(), Error> {
async fn restore(mut param: Value) -> Result<(), Error> {
let output_format = get_output_format(&param);
let (config, _digest) = config::drive::config()?;
param["drive"] = lookup_drive_name(&param, &config)?.into();
let mut client = connect_to_localhost()?;
let result = client.post("api2/json/tape/restore", Some(param)).await?;

View File

@ -18,9 +18,6 @@ use proxmox_backup::{
},
},
config::{
drive::{
complete_drive_name,
},
media_pool::{
complete_pool_name,
},
@ -50,7 +47,6 @@ pub fn pool_commands() -> CommandLineInterface {
CliCommand::new(&api2::config::media_pool::API_METHOD_CREATE_POOL)
.arg_param(&["name"])
.completion_cb("name", complete_pool_name)
.completion_cb("drive", complete_drive_name)
.completion_cb("encrypt", complete_key_fingerprint)
)
.insert(
@ -58,7 +54,6 @@ pub fn pool_commands() -> CommandLineInterface {
CliCommand::new(&api2::config::media_pool::API_METHOD_UPDATE_POOL)
.arg_param(&["name"])
.completion_cb("name", complete_pool_name)
.completion_cb("drive", complete_drive_name)
.completion_cb("encrypt", complete_key_fingerprint)
)
;
@ -99,7 +94,6 @@ fn list_pools(
let options = default_table_format_options()
.column(ColumnConfig::new("name"))
.column(ColumnConfig::new("drive"))
.column(ColumnConfig::new("allocation"))
.column(ColumnConfig::new("retention"))
.column(ColumnConfig::new("template"))