-
Notifications
You must be signed in to change notification settings - Fork 1
/
volume.rs
71 lines (66 loc) · 2.36 KB
/
volume.rs
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
use outscale_api::apis::configuration::{AWSv4Key, Configuration};
use outscale_api::apis::volume_api::{create_volume, delete_volume, read_volumes};
use outscale_api::models::{
CreateVolumeRequest, DeleteVolumeRequest, FiltersVolume, ReadVolumesRequest,
};
use secrecy::SecretString;
use std::env;
fn main() {
let mut config = Configuration::new();
config.aws_v4_key = Some(AWSv4Key {
access_key: env::var("OSC_ACCESS_KEY").unwrap(),
secret_key: SecretString::new(env::var("OSC_SECRET_KEY").unwrap()),
region: "eu-west-2".to_string(),
service: "oapi".to_string(),
});
match env::var("OSC_ENDPOINT_API") {
Ok(enpoint) => config.base_path = enpoint,
_ => (),
};
// Example reading all volumes
print!("Reading all volumes... ");
let request = ReadVolumesRequest::new();
let response = match read_volumes(&config, Some(request)) {
Err(error) => {
println!("Error: {:?}", error);
return;
}
Ok(resp) => resp,
};
if let Some(volumes) = response.volumes {
println!("OK -> there are {} volumes", volumes.len());
}
// Example creating a volume
print!("Creating new volume... ");
let mut request = CreateVolumeRequest::new("eu-west-2a".to_string());
request.volume_type = Some("gp2".to_string());
request.size = Some(10);
let response = match create_volume(&config, Some(request)) {
Err(error) => {
println!("Error: {:?}", error);
return;
}
Ok(resp) => resp,
};
let volume_id = response.volume.unwrap().volume_id.unwrap();
println!("OK -> created volume id {}", volume_id);
// Filtering on newly created volume
print!("Filtering on {}... ", volume_id);
let mut filters = FiltersVolume::new();
filters.volume_ids = Some(vec![volume_id.clone()]);
let mut request = ReadVolumesRequest::new();
request.filters = Some(Box::new(filters));
if let Err(error) = read_volumes(&config, Some(request)) {
println!("Error: {:?}", error);
return;
}
println!("OK");
// Deleting a volume
print!("Deleting volume {}... ", volume_id);
let request = DeleteVolumeRequest::new(volume_id.clone());
if let Err(error) = delete_volume(&config, Some(request)) {
println!("Error: {:?}", error);
return;
}
println!("OK");
}