Crate openstack

source ·
Expand description

OpenStack SDK in Rust.

The goal of this project is to provide a simple API for working with OpenStack clouds.

Usage

Start with authentication, then create a Cloud object and use it for OpenStack API calls.

Examples

List servers

Get authentication parameters from the environment and get UUIDs of all servers.

async fn get_server_uuids() -> openstack::Result<Vec<String>> {
    let os = openstack::Cloud::from_env().await?;
    let server_names = os
        .list_servers()
        .await?
        .into_iter()
        .map(|server| server.id().clone())
        .collect();
    Ok(server_names)
}

Find images

Find public images using Identity password authentication with the default region:

use futures::TryStreamExt;

async fn get_public_image_names() -> openstack::Result<Vec<String>> {
    let scope = openstack::auth::Scope::Project {
        project: openstack::IdOrName::from_name("project1"),
        domain: Some(openstack::IdOrName::from_id("default")),
    };
    let auth = openstack::auth::Password::new(
        "https://cloud.local/identity",
        "admin",
        "pa$$w0rd",
        "Default"
    )
    .expect("Invalid auth_url")
    .with_scope(scope);

    let os = openstack::Cloud::new(auth).await?;
    let image_names = os
        .find_images()
        .with_visibility(openstack::image::ImageVisibility::Public)
        .into_stream()
        // This `map_ok` comes from `futures::TryStreamExt`, thus the closure returns a `Future`.
        .map_ok(|image| image.name().clone())
        .try_collect()
        .await?;
    Ok(image_names)
}

Notice the difference between list_* methods (return a result with a vector) and find_* methods (return a query builder that can be used to create a stream).

Create server

Create a server with authentication from a clouds.yaml file:

use openstack::waiter::Waiter;

async fn create_server() -> openstack::Result<openstack::compute::Server> {
    openstack::Cloud::from_config("my-cloud-1")
        .await?
        .new_server("test-server-1", "x-large")
        .with_image("centos-7")
        .with_network("private")
        .with_keypair("default")
        .create()
        .await?
        .wait()
        .await
}

Requirements

This crate requires Rust 2022 edition and rustc version 1.58.0 or newer.

Modules

  • Reimports of authentication bits from osauth.
  • Types and traits shared by all API parts.
  • Compute API implementation bits.
  • Image API implementation bits.
  • Network API implementation bits.
  • Object storage API implementation bits.
  • Synchronous sessions based on one from osauth.
  • Framework for waiting for asynchronous events.

Structs

Enums

Traits

  • Trait representing something that can be refreshed.

Type Definitions

  • A result of an OpenStack operation.