MachineConfigBuilder

Struct MachineConfigBuilder 

Source
pub struct MachineConfigBuilder { /* private fields */ }

Implementations§

Source§

impl MachineConfigBuilder

Source

pub fn new() -> Self

Source

pub fn image(self, image: &str) -> Self

Examples found in repository?
examples/machines.rs (line 34)
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}
Source

pub fn auto_destroy(self, auto_destroy: bool) -> Self

Source

pub fn restart_policy( self, policy: RestartPolicyEnum, max_retries: Option<u32>, gpu_bid_price: Option<f64>, ) -> Self

Source

pub fn cpus(self, cpus: u64) -> Self

Source

pub fn memory(self, memory_mb: u64) -> Self

Source

pub fn cpu_kind(self, cpu_kind: CpuKind) -> Self

Source

pub fn gpus(self, gpus: u64) -> Self

Source

pub fn gpu_kind(self, gpu_kind: GpuKind) -> Self

Source

pub fn checks(self, config: Checks) -> Self

Source

pub fn dns(self, dns_config: DnsConfig) -> Self

Source

pub fn add_env(self, key: &str, value: &str) -> Self

Source

pub fn add_file(self, file_config: FileConfig) -> Self

Source

pub fn init(self, init_config: InitConfig) -> Self

Source

pub fn metrics(self, metrics_config: MetricsConfig) -> Self

Source

pub fn add_mount(self, mount_config: MountConfig) -> Self

Source

pub fn add_process(self, process_config: ProcessConfig) -> Self

Source

pub fn schedule(self, schedule: &str) -> Self

Source

pub fn add_service(self, service_config: ServiceConfig) -> Self

Source

pub fn add_standby(self, standby: &str) -> Self

Source

pub fn add_static(self, static_config: StaticConfig) -> Self

Source

pub fn stop_config(self, stop_config: StopConfig) -> Self

Source

pub fn build(self) -> MachineConfig

Examples found in repository?
examples/machines.rs (line 34)
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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more