]>
git.proxmox.com Git - proxmox-backup.git/blob - src/api2/tape/drive.rs
1 use anyhow
::{bail, Error}
;
4 use proxmox
::api
::{api, Router, SubdirMap}
;
5 use proxmox
::list_subdirs_api_method
;
19 linux_tape_device_list
,
29 schema
: DRIVE_ID_SCHEMA
,
32 description
: "Source slot number",
38 /// Load media via changer from slot
43 ) -> Result
<(), Error
> {
45 let (config
, _digest
) = config
::drive
::config()?
;
47 let drive
: LinuxTapeDrive
= config
.lookup("linux", &name
)?
;
49 let changer
: ScsiTapeChanger
= match drive
.changer
{
50 Some(ref changer
) => config
.lookup("changer", changer
)?
,
51 None
=> bail
!("drive '{}' has no associated changer", name
),
56 mtx_load(&changer
.path
, slot
, drivenum
)
63 schema
: DRIVE_ID_SCHEMA
,
66 description
: "Target slot number. If omitted, defaults to the slot that the drive was loaded from.",
73 /// Unload media via changer
78 ) -> Result
<(), Error
> {
80 let (config
, _digest
) = config
::drive
::config()?
;
82 let mut drive
: LinuxTapeDrive
= config
.lookup("linux", &name
)?
;
84 let changer
: ScsiTapeChanger
= match drive
.changer
{
85 Some(ref changer
) => config
.lookup("changer", changer
)?
,
86 None
=> bail
!("drive '{}' has no associated changer", name
),
89 let drivenum
: u64 = 0;
91 if let Some(slot
) = slot
{
92 mtx_unload(&changer
.path
, slot
, drivenum
)
103 description
: "The list of autodetected tape drives.",
106 type: TapeDeviceInfo
,
111 pub fn scan_drives(_param
: Value
) -> Result
<Vec
<TapeDeviceInfo
>, Error
> {
113 let list
= linux_tape_device_list();
122 schema
: DRIVE_ID_SCHEMA
,
125 description
: "Use fast erase.",
134 pub fn erase_media(drive
: String
, fast
: Option
<bool
>) -> Result
<(), Error
> {
136 let (config
, _digest
) = config
::drive
::config()?
;
138 let mut drive
= open_drive(&config
, &drive
)?
;
140 drive
.erase_media(fast
.unwrap_or(true))?
;
149 schema
: DRIVE_ID_SCHEMA
,
155 pub fn rewind(drive
: String
) -> Result
<(), Error
> {
157 let (config
, _digest
) = config
::drive
::config()?
;
159 let mut drive
= open_drive(&config
, &drive
)?
;
170 schema
: DRIVE_ID_SCHEMA
,
175 /// Eject/Unload drive media
176 pub fn eject_media(drive
: String
) -> Result
<(), Error
> {
178 let (config
, _digest
) = config
::drive
::config()?
;
180 let (mut changer
, _
) = media_changer(&config
, &drive
, false)?
;
182 if !changer
.eject_on_unload() {
183 let mut drive
= open_drive(&config
, &drive
)?
;
184 drive
.eject_media()?
;
187 changer
.unload_media()?
;
192 pub const SUBDIRS
: SubdirMap
= &[
196 .put(&API_METHOD_REWIND
)
201 .put(&API_METHOD_ERASE_MEDIA
)
206 .put(&API_METHOD_EJECT_MEDIA
)
211 .put(&API_METHOD_LOAD_SLOT
)
216 .get(&API_METHOD_SCAN_DRIVES
)
221 .put(&API_METHOD_UNLOAD
)
225 pub const ROUTER
: Router
= Router
::new()
226 .get(&list_subdirs_api_method
!(SUBDIRS
))