lsm/
lib.rs

1// Copyright (C) 2017-2018 Red Hat, Inc.
2//
3// Permission is hereby granted, free of charge, to any
4// person obtaining a copy of this software and associated
5// documentation files (the "Software"), to deal in the
6// Software without restriction, including without
7// limitation the rights to use, copy, modify, merge,
8// publish, distribute, sublicense, and/or sell copies of
9// the Software, and to permit persons to whom the Software
10// is furnished to do so, subject to the following
11// conditions:
12//
13// The above copyright notice and this permission notice
14// shall be included in all copies or substantial portions
15// of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26//
27// Author: Gris Ge <fge@redhat.com>
28
29//! # `LibStorageMgmt`
30//!
31//! `LibStorageMgmt` provides a set of API for programmatically manage their
32//! storage hardware in a vendor neutral way supporting these actions:
33//!
34//!  * List storage pools, volumes, access groups, or file systems.
35//!
36//!  * Create and delete volumes, access groups, file systems, or NFS exports.
37//!
38//!  * Grant and remove access to volumes, access groups, or initiators.
39//!
40//!  * Replicate volumes with snapshots, clones, and copies.
41//!
42//!  * Create and delete access groups and edit members of a group.
43//!
44//!  * List Linux local SCSI/ATA/NVMe disks.
45//!
46//!  * Control IDENT/FAULT LED of local disks via SES(SCSI Enclosure Service), NPEM, VMD (utilizes ledmon library)
47//!
48//! To use `LibStorageMgmt` rust binding, you need:
49//!
50//!  * Start the libstoragemgmt daemon(`lsmd`)
51//!
52//!  * Choose a URI after reading [`LibStorageMgmt` user guide][1]
53//!
54//!  * Make a connection to plugin via [`lsm::Client`][2].
55//!
56//!  * Check required [`lsm::Capabilities`][3] for supported functionality.
57//!
58//!  * Invoke required method of [`lsm::Client`][2].
59//!
60//! # Example code using simulator plugin
61//!
62//! ```rust
63//! extern crate lsm;
64//! use lsm::{Client, LsmError};
65//!
66//!     let mut c: Client = match Client::new("sim://", None, None) {
67//!         Ok(i) => i,
68//!         Err(e) => {
69//!             match e {
70//!                 // Error handling goes here
71//!                 LsmError::DaemonNotRunning(_) =>
72//!                     panic!("Please start the libstoragemgmt daemon"),
73//!                 _ => panic!("{}", e)
74//!             };
75//!         },
76//!     };
77//!     let syss = match c.systems() {
78//!         Ok(i) => i,
79//!         Err(e) => panic!("{}", e)         // Please use error handling as above.
80//!     };
81//!     for s in syss {
82//!         let cap = match c.capabilities(&s) {
83//!             Ok(i) => i,
84//!             Err(e) => panic!("{}", e)     // Please use error handling as above.
85//!         };
86//!         if cap.is_supported(lsm::Capability::Volumes) {
87//!             let vols = match c.volumes() {
88//!                 Ok(i) => i,
89//!                 Err(e) => panic!("{}", e) // Please use error handling as above.
90//!             };
91//!             for vol in vols {
92//!                 println!("Got volume: {} {}", vol.name, vol.id);
93//!             }
94//!         }
95//!     }
96//!
97//! ```
98//!
99//! [1]: https://libstorage.github.io/libstoragemgmt-doc/doc/user_guide.html
100//! [2]: struct.Client.html
101//! [3]: struct.Capabilities.html
102
103extern crate serde;
104#[macro_use]
105extern crate serde_derive;
106extern crate regex;
107extern crate serde_json;
108extern crate url;
109
110pub use self::client::{available_plugins, Client, PluginInfo};
111pub use self::data::*;
112pub use self::error::LsmError;
113pub use self::misc::{size_bytes_2_size_human, size_human_2_size_bytes};
114
115mod client;
116mod data;
117mod error;
118mod ipc;
119pub mod local_disk;
120mod misc;