pub struct FlyControl {
pub apps: AppManager,
pub machines: MachineManager,
pub volumes: VolumeManager,
pub secrets: SecretsManager,
}Fields§
§apps: AppManager§machines: MachineManager§volumes: VolumeManager§secrets: SecretsManagerImplementations§
Source§impl FlyControl
impl FlyControl
Sourcepub fn new(api_token: String) -> Self
pub fn new(api_token: String) -> Self
Examples found in repository?
examples/apps.rs (line 19)
6async fn main() -> Result<(), Box<dyn Error>> {
7 tracing_subscriber::registry()
8 .with(fmt::layer().with_writer(std::io::stdout))
9 .with(EnvFilter::new(
10 std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()),
11 ))
12 .init();
13 let api_token = std::env::var("FLY_ORG_TOKEN").expect("FLY_ORG_TOKEN must be set");
14 let args: Vec<String> = std::env::args().collect();
15 let org_slug = &args
16 .get(1)
17 .expect("Usage: cargo run --example apps <org_slug>");
18
19 let fly = FlyControl::new(api_token.to_string());
20
21 let app_name = "rusty-app";
22 fly.apps.create(app_name, org_slug).await?;
23 fly.apps.list(org_slug).await?;
24 fly.apps.delete(app_name, false).await?;
25
26 Ok(())
27}More examples
examples/secrets.rs (line 19)
6async fn main() -> Result<(), Box<dyn Error>> {
7 tracing_subscriber::registry()
8 .with(fmt::layer().with_writer(std::io::stdout))
9 .with(EnvFilter::new(
10 std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()),
11 ))
12 .init();
13 let api_token = std::env::var("FLY_ORG_TOKEN").expect("FLY_ORG_TOKEN must be set");
14 let args: Vec<String> = std::env::args().collect();
15 let org_slug = &args
16 .get(1)
17 .expect("Usage: cargo run --example apps <org_slug>");
18
19 let fly = FlyControl::new(api_token.to_string());
20
21 let app_name = "rusty-app";
22 fly.apps.create(app_name, org_slug).await?;
23
24 // SECRETS
25 let secret_label = "test_secret";
26 let secret_type = "secret";
27 fly.secrets
28 .create_secret(
29 app_name,
30 secret_label,
31 secret_type,
32 secrets::SecretValue::new(vec![123]),
33 )
34 .await?;
35 fly.secrets.list_secrets(app_name).await?;
36 fly.secrets.destroy_secret(app_name, secret_label).await?;
37
38 fly.apps.delete(app_name, false).await?;
39
40 Ok(())
41}examples/volumes.rs (line 20)
6async fn main() -> Result<(), Box<dyn Error>> {
7 tracing_subscriber::registry()
8 .with(fmt::layer().with_writer(std::io::stdout))
9 .with(EnvFilter::new(
10 std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()),
11 ))
12 .init();
13 let api_token = std::env::var("FLY_ORG_TOKEN").expect("FLY_ORG_TOKEN must be set");
14 let args: Vec<String> = std::env::args().collect();
15 let org_slug = &args
16 .get(1)
17 .expect("Usage: cargo run --example apps <org_slug>");
18
19 let app_name = "rusty-app";
20 let fly = FlyControl::new(api_token.to_string());
21
22 fly.apps.create(app_name, org_slug).await?;
23
24 // VOLUMES
25 let vol_name = "test_volume";
26 let resp = fly
27 .volumes
28 .create_volume(
29 app_name,
30 volumes::CreateVolumeRequest::builder(vol_name, machines::MachineRegions::Ams, 10)
31 .build(),
32 )
33 .await?;
34 fly.volumes.list_volumes(app_name, false).await?;
35 let vol_id = resp.id.unwrap();
36 fly.volumes.destroy_volume(app_name, &vol_id).await?;
37 fly.apps.delete(app_name, false).await?;
38
39 Ok(())
40}examples/machines.rs (line 23)
7async fn main() -> Result<(), Box<dyn Error>> {
8 tracing_subscriber::registry()
9 .with(fmt::layer().with_writer(std::io::stdout))
10 .with(EnvFilter::new(
11 std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()),
12 ))
13 .init();
14 let api_token = std::env::var("FLY_ORG_TOKEN").expect("FLY_ORG_TOKEN must be set");
15 let args: Vec<String> = std::env::args().collect();
16 let org_slug = &args
17 .get(1)
18 .expect("Usage: cargo run --example apps <org_slug>");
19
20 let app_name = "rusty-app";
21 let machine_id = "machine-name";
22 let app_image = "ubuntu:20.04";
23 let fly = FlyControl::new(api_token.to_string());
24
25 fly.apps.create(app_name, org_slug).await?;
26
27 // MACHINES
28 // create a machine
29 let response = fly
30 .machines
31 .create(
32 app_name,
33 machines::MachineRequest::new(
34 machines::MachineConfig::builder().image(app_image).build(),
35 Some(machine_id.to_string()),
36 Some(machines::MachineRegions::Iad),
37 ),
38 )
39 .await?;
40 info!("Created machine: {:?}", response.id);
41 let did = &response.id.unwrap();
42 let iid: &String = &response.instance_id.unwrap();
43
44 // wait for start state
45 fly.machines
46 .wait_for_machine_state(app_name, did, machines::MachineState::Started, None, None)
47 .await?;
48
49 // list machines
50 fly.machines.list(app_name).await?;
51
52 // stop/start machine
53 fly.machines.stop(app_name, did, iid).await?;
54 fly.machines.start(app_name, did).await?;
55
56 // list events/processes
57 let events = fly.machines.list_events(app_name, did).await?;
58 info!("Events: {:?}", events);
59 let processes = fly.machines.list_processes(app_name, did).await?;
60 info!("Processes: {:?}", processes);
61
62 // execute command
63 let resp = fly
64 .machines
65 .execute_command(
66 app_name,
67 did,
68 vec!["sh", "-c", "which echo && /bin/echo 'Hello, World!'"],
69 None,
70 )
71 .await?;
72 info!("Command response: {:?}", resp);
73
74 // restart/update machine
75 fly.machines.restart_machine(app_name, did, iid).await?;
76 fly.machines
77 .update_machine(
78 app_name,
79 did,
80 iid,
81 machines::MachineRequest::new(
82 machines::MachineConfig::builder().image(app_image).build(),
83 Some("foo".to_string()),
84 Some(machines::MachineRegions::Ams),
85 ),
86 )
87 .await?;
88
89 // delete machine/app
90 fly.machines.delete(app_name, did, true).await?;
91 fly.apps.delete(app_name, false).await?;
92
93 Ok(())
94}Auto Trait Implementations§
impl !RefUnwindSafe for FlyControl
impl !UnwindSafe for FlyControl
impl Freeze for FlyControl
impl Send for FlyControl
impl Sync for FlyControl
impl Unpin for FlyControl
impl UnsafeUnpin for FlyControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more