1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
use crate::{api::ApiResource, conn::Payload, models, opts, util::url, Result};
impl_api_ty!(
Volume => name
);
impl<'podman> Volume<'podman> {
api_doc! {
Volume => ExistsLibpod
/// Quick way to determine if this volume exists.
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// match podman.volumes().get("some_vol").exists().await {
/// Ok(exists) => if exists {
/// println!("volume exists!");
/// } else {
/// println!("volume doesn't exists!");
/// },
/// Err(e) => eprintln!("check failed: {}", e),
/// }
/// };
/// ```
|
pub async fn exists(&self) -> Result<bool> {
self.podman
.resource_exists(ApiResource::Volumes, &self.name)
.await
}}
api_doc! {
Volume => InspectLibpod
/// Obtain low-level information about this volume.
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// match podman.volumes().get("my-vol").inspect().await {
/// Ok(info) => println!("{:?}", info),
/// Err(e) => eprintln!("{}", e),
/// }
/// };
/// ```
|
pub async fn inspect(&self) -> Result<models::LibpodVolumeInspectResponse> {
self.podman
.get_json(&format!("/libpod/volumes/{}/json", &self.name))
.await
}}
api_doc! {
Volume => DeleteLibpod
/// Delete this volume. To forcefully remove an volume use
/// [`Volume::remove`](Volume::remove).
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// if let Err(e) = podman.volumes().get("my-vol").delete().await {
/// eprintln!("{}", e);
/// }
/// };
/// ```
|
pub async fn delete(&self) -> Result<()> {
self.podman.delete(&format!("/libpod/volumes/{}", &self.name)).await.map(|_| ())
}}
api_doc! {
Volume => DeleteLibpod
/// Remove this volume forcefully. To remove the volume normally use
/// [`Volume::delete`](Volume::delete).
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// if let Err(e) = podman.volumes().get("my-vol").remove().await {
/// eprintln!("{}", e);
/// }
/// };
/// ```
|
pub async fn remove(&self) -> Result<()> {
let ep = url::construct_ep(
format!("/libpod/volumes/{}", &self.name),
Some(url::encoded_pair("force", true)),
);
self.podman.delete(&ep).await.map(|_| ())
}}
}
impl<'podman> Volumes<'podman> {
api_doc! {
Volume => CreateLibpod
/// Create a volume with specified options.
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// use podman_api::opts::VolumeCreateOpts;
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// match podman
/// .volumes()
/// .create(
/// &VolumeCreateOpts::builder()
/// .driver("my-driver")
/// .name("my-vol")
/// .build(),
/// )
/// .await
/// {
/// Ok(info) => println!("{:?}", info),
/// Err(e) => eprintln!("{}", e),
/// }
/// };
/// ```
|
pub async fn create(
&self,
opts: &opts::VolumeCreateOpts,
) -> Result<models::LibpodContainerInspectResponse> {
self.podman
.post_json(
"/libpod/volumes/create",
Payload::Json(opts.serialize()?),
)
.await
}}
api_doc! {
Volume => ListLibpod
/// Returns a list of volumes.
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// use podman_api::opts::{VolumeListOpts, VolumeListFilter};
///
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// for volume in podman
/// .volumes()
/// .list(
/// &VolumeListOpts::builder()
/// .filter([VolumeListFilter::Driver("my-sd".into())])
/// .build(),
/// )
/// .await
/// .unwrap()
/// {
/// println!("{:?}", volume);
/// }
/// };
/// ```
|
pub async fn list(&self, opts: &opts::VolumeListOpts) -> Result<Vec<models::Volume>> {
let ep = url::construct_ep("/libpod/volumes/json", opts.serialize());
self.podman.get_json(&ep).await
}}
api_doc! {
Volume => PruneLibpod
/// Delete unused volumes.
///
/// Examples:
///
/// ```no_run
/// async {
/// use podman_api::Podman;
/// let podman = Podman::unix("/run/user/1000/podman/podman.sock");
///
/// match podman.volumes().prune(&Default::default()).await {
/// Ok(info) => println!("{:?}", info),
/// Err(e) => eprintln!("{}", e),
/// }
/// };
/// ```
|
pub async fn prune(&self, opts: &opts::VolumePruneOpts) -> Result<Vec<models::PruneReport>> {
let ep = url::construct_ep("/libpod/volumes/prune", opts.serialize());
self.podman.post_json(&ep, Payload::empty()).await
}}
}