use scaleway_rs::{
LocalImageListType, ScalewayApi, ScalewayArchitecture, ScalewayError, SecurityGroupRuleAction,
SecurityGroupRuleDirection, SecurityGroupRuleProtocol,
};
use std::env;
#[tokio::main]
async fn main() -> Result<(), ScalewayError> {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!("Call program with the following:");
println!("{} SCALEWAY_API_KEY ORGANIZATION_ID", args[0]);
std::process::exit(1);
}
let result = do_stuff(&args[1], &args[2]).await;
match result {
Ok(_) => {
println!("Finished sucessfully");
}
Err(e) => {
println!("Error: {:#?}", e);
}
}
Ok(())
}
async fn do_stuff(api_key: &str, organization_id: &str) -> Result<(), ScalewayError> {
let api = ScalewayApi::new(api_key);
let region = "fr-par-1";
let project = api
.create_project("test", organization_id)
.description("test description")
.run_async()
.await?;
println!("Created project: {:#?}", project);
let projects = api
.list_projects()
.organization_id(organization_id)
.run_async()
.await?;
println!("Projects: {:#?}", projects);
let ssh_keys = api.list_ssh_keys().run_async().await?;
println!("sshkeys: {:#?}", ssh_keys);
let ssh_key = api.get_ssh_key(&ssh_keys[0].id).run_async().await?;
println!("ssh_key: {:#?}", ssh_key);
let sgl = api.list_security_groups(region).run_async().await?;
println!("Security groups: {:#?}", sgl);
let sg = api
.create_security_group(region, "test", true)
.inbound_default_policy(scaleway_rs::SecurityGroupPolicy::Drop)
.outbound_default_policy(scaleway_rs::SecurityGroupPolicy::Accept)
.project(&project.id)
.description("description test")
.run_async()
.await?;
println!("Created security group: {:#?}", sg);
let sgr = api
.create_security_group_rule(
region,
&sg.id,
"10.0.0.0/8",
SecurityGroupRuleProtocol::Tcp,
SecurityGroupRuleDirection::Inbound,
SecurityGroupRuleAction::Accept,
)
.dest_port_from(22)
.run_async()
.await?;
println!("Security group rule: {:#?}", sgr);
let sgrl = api.list_security_group_rules(region, &sg.id).per_page(100).run_async().await?;
println!("Security group rules: {:#?}", sgrl);
api.delete_securitygroup_async(region, &sg.id).await?;
println!("Deleted security group");
api.delete_project_async(&project.id).await?;
println!("Deleted project");
for region in ScalewayApi::az_list() {
let types = api.get_server_types_async(region).await?;
println!("SERVERTYPES: {:#?}", types);
let images = api.list_images(region)
.arch(ScalewayArchitecture::Arm64)
.run_async().await?;
println!("IMAGES: {:#?}", images);
let instances = api
.list_instances(region)
.order("creation_date_asc")
.run_async()
.await?;
println!("INSTANCES: {:#?}", instances);
let availability = api.list_availability_async(region).await?;
println!("AVAILABILITY: {:#?}", availability);
let list_marketplace_images = api
.list_marketplace_instances()
.include_eol(false)
.arch(ScalewayArchitecture::Arm64)
.run_async()
.await?;
println!("MARKETPLACE IMAGES: {:#?}", list_marketplace_images);
let list_image_version = api
.list_marketplace_instance_versions(&list_marketplace_images[0].id)
.run_async()
.await?;
println!("MARKETPLACE IMAGE VERSION: {:#?}", list_image_version);
let list_local_images = api
.list_marketplace_local_images(LocalImageListType::ByImageId(
list_marketplace_images[0].id.to_string(),
))
.arch(ScalewayArchitecture::Arm64)
.run_async()
.await?;
println!("MARKETPLACE LOCAL IMAGES: {:#?}", list_local_images);
}
Ok(())
}