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.

extern crate openstack;

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

Find images

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

extern crate fallible_iterator;
extern crate openstack;

use fallible_iterator::FallibleIterator;

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);
    let image_names = os
        .find_images()
        .with_visibility(openstack::image::ImageVisibility::Public)
        .into_iter()
        // This `map` comes from fallible-iterator, thus the closure returns a `Result`.
        .map(|image| Ok(image.name().clone()))
        .collect()?;
    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 fallible iterator).

Create server

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

extern crate openstack;
extern crate waiter;

// Required for the `wait` call.
use waiter::Waiter;

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

Requirements

This crate requires Rust 2022 edition and rustc version 1.56.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.

Structs

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

Enums

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

Traits

Trait representing something that can be refreshed.

Type Definitions

A result of an OpenStack operation.