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
use docker_api::{
models::VolumeList200Response,
models::VolumePrune200Response,
opts::{VolumeCreateOpts, VolumeListOpts, VolumePruneOpts},
Volume, Volumes,
};
use pyo3::prelude::*;
use crate::Pyo3Docker;
use pyo3::exceptions;
use pyo3::types::PyDict;
use pythonize::pythonize;
#[pymodule]
pub fn volume(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<Pyo3Volumes>()?;
m.add_class::<Pyo3Volume>()?;
Ok(())
}
#[derive(Debug)]
#[pyclass(name = "Volumes")]
pub struct Pyo3Volumes(pub Volumes);
#[derive(Debug)]
#[pyclass(name = "Volume")]
pub struct Pyo3Volume(pub Volume);
#[pymethods]
impl Pyo3Volumes {
#[new]
pub fn new(docker: Pyo3Docker) -> Self {
Pyo3Volumes(Volumes::new(docker.0))
}
pub fn get(&self, name: &str) -> Pyo3Volume {
Pyo3Volume(self.0.get(name))
}
pub fn prune(&self) -> PyResult<Py<PyAny>> {
let rv = __volumes_prune(&self.0, &Default::default());
match rv {
Ok(rv) => Ok(pythonize_this!(rv)),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
pub fn list(&self) -> PyResult<Py<PyAny>> {
let rv = __volumes_list(&self.0, &Default::default());
match rv {
Ok(rv) => Ok(pythonize_this!(rv)),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
pub fn create(
&self,
name: Option<&str>,
driver: Option<&str>,
_driver_opts: Option<&PyDict>,
_labels: Option<&PyDict>,
) -> PyResult<Py<PyAny>> {
let mut opts = VolumeCreateOpts::builder();
bo_setter!(name, opts);
bo_setter!(driver, opts);
let rv = __volumes_create(&self.0, &opts.build());
match rv {
Ok(rv) => Ok(pythonize_this!(rv)),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
}
#[tokio::main]
async fn __volumes_prune(
volumes: &Volumes,
opts: &VolumePruneOpts,
) -> Result<VolumePrune200Response, docker_api::Error> {
volumes.prune(opts).await
}
#[tokio::main]
async fn __volumes_list(
volumes: &Volumes,
opts: &VolumeListOpts,
) -> Result<VolumeList200Response, docker_api::Error> {
volumes.list(opts).await
}
#[tokio::main]
async fn __volumes_create(
volumes: &Volumes,
opts: &VolumeCreateOpts,
) -> Result<docker_api::models::Volume, docker_api::Error> {
volumes.create(opts).await
}
#[pymethods]
impl Pyo3Volume {
#[new]
pub fn new(docker: Pyo3Docker, name: &str) -> Self {
Pyo3Volume(Volume::new(docker.0, name))
}
pub fn name(&self) -> String {
self.0.name().to_string()
}
pub fn inspect(&self) -> PyResult<Py<PyAny>> {
let rv = __volume_inspect(&self.0);
match rv {
Ok(rv) => Ok(pythonize_this!(rv)),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
pub fn delete(&self) -> PyResult<()> {
let rv = __volume_delete(&self.0);
match rv {
Ok(rv) => Ok(rv),
Err(rv) => Err(py_sys_exception!(rv)),
}
}
}
#[tokio::main]
async fn __volume_inspect(
volume: &Volume,
) -> Result<docker_api::models::Volume, docker_api::Error> {
volume.inspect().await
}
#[tokio::main]
async fn __volume_delete(volume: &Volume) -> Result<(), docker_api::Error> {
volume.delete().await
}