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.76.0 or newer.

Re-exports§

pub use crate::common::Refresh;

Modules§

auth
Reimports of authentication bits from osauth.
baremetal
Bare Metal API implementation bits.
block_storage
Block Storage API implementation bits.
common
Types and traits shared by all API parts.
compute
Compute API implementation bits.
image
Image API implementation bits.
network
Network API implementation bits.
object_storage
Object storage API implementation bits.
session
Synchronous sessions based on one from osauth.
waiter
Framework for waiting for asynchronous events.

Structs§

Cloud
OpenStack cloud API.
EndpointFilters
Endpoint filters for looking up endpoints.
Error
Error from an OpenStack call.
ValidInterfaces
A list of acceptable interface types.

Enums§

ErrorKind
Kind of an error.
IdOrName
A reference to a resource by either its ID or name.
InterfaceType
Interface type: public, internal or admin.
Sort
Sorting request.

Type Aliases§

Result
A result of an OpenStack operation.