pub struct Cloud { /* private fields */ }
Expand description
OpenStack cloud API.
Provides high-level API for working with OpenStack clouds.
Implementations§
source§impl Cloud
impl Cloud
sourcepub async fn new<Auth: AuthType + 'static>(auth_type: Auth) -> Result<Cloud>
pub async fn new<Auth: AuthType + 'static>(auth_type: Auth) -> Result<Cloud>
Create a new cloud object with a given authentication plugin.
See auth
module for details on how to authenticate
against OpenStack clouds.
Example
async fn cloud() -> openstack::Result<openstack::Cloud> {
let scope = openstack::auth::Scope::Project {
project: openstack::IdOrName::from_name("project1"),
domain: Some(openstack::IdOrName::from_name("Default")),
};
let auth = openstack::auth::Password::new(
"https://cloud.example.com",
"user1", "pa$$word", "Default")
.expect("Invalid authentication URL")
.with_scope(scope);
openstack::Cloud::new(auth).await
}
See Also
- from_config to create a Cloud from clouds.yaml
- from_env to create a Cloud from environment variables
sourcepub async fn from_config<S: AsRef<str>>(cloud_name: S) -> Result<Cloud>
pub async fn from_config<S: AsRef<str>>(cloud_name: S) -> Result<Cloud>
Create a new cloud object from a configuration file
Example
let os = openstack::Cloud::from_config("cloud-1").await?;
sourcepub async fn from_env() -> Result<Cloud>
pub async fn from_env() -> Result<Cloud>
Create a new cloud object from environment variables.
Example
let os = openstack::Cloud::from_env().await?;
sourcepub fn endpoint_filters(&self) -> &EndpointFilters
pub fn endpoint_filters(&self) -> &EndpointFilters
Endpoint filters for this cloud.
sourcepub fn endpoint_filters_mut(&mut self) -> &mut EndpointFilters
pub fn endpoint_filters_mut(&mut self) -> &mut EndpointFilters
Modify endpoint filters for this cloud.
Example
async fn cloud_from_env() -> openstack::Result<openstack::Cloud> {
let mut cloud = openstack::Cloud::from_env().await?;
{
let mut filters = cloud.endpoint_filters_mut();
filters.set_region("internal-1");
// Give priority to internal endpoints.
filters.set_interfaces(&[
openstack::InterfaceType::Internal,
openstack::InterfaceType::Public,
][..])
}
Ok(cloud)
}
Removes cached endpoint information and detaches this object from a shared Session
.
sourcepub fn with_endpoint_interface(self, endpoint_interface: InterfaceType) -> Cloud
pub fn with_endpoint_interface(self, endpoint_interface: InterfaceType) -> Cloud
Convert this cloud into one using the given endpoint interface.
Example
async fn cloud_from_env() -> openstack::Result<openstack::Cloud> {
openstack::Cloud::from_env().await
.map(|os| os.with_endpoint_interface(openstack::InterfaceType::Internal))
}
Removes cached endpoint information and detaches this object from a shared Session
.
sourcepub fn with_endpoint_filters(self, endpoint_filters: EndpointFilters) -> Cloud
pub fn with_endpoint_filters(self, endpoint_filters: EndpointFilters) -> Cloud
Convert this cloud into one using the given endpoint filters.
Removes cached endpoint information and detaches this object from a shared Session
.
sourcepub async fn refresh(&mut self) -> Result<()>
pub async fn refresh(&mut self) -> Result<()>
Refresh this Cloud
object (renew token, refetch service catalog, etc).
sourcepub async fn create_container<Id: AsRef<str>>(
&self,
name: Id
) -> Result<Container>
pub async fn create_container<Id: AsRef<str>>( &self, name: Id ) -> Result<Container>
Create a new container.
If the container already exists, this call returns successfully.
sourcepub async fn create_object<C, Id, R>(
&self,
container: C,
name: Id,
body: R
) -> Result<Object>where
C: Into<ContainerRef>,
Id: AsRef<str>,
R: AsyncRead + Send + Sync + 'static,
pub async fn create_object<C, Id, R>( &self, container: C, name: Id, body: R ) -> Result<Object>where C: Into<ContainerRef>, Id: AsRef<str>, R: AsyncRead + Send + Sync + 'static,
Create a new object.
sourcepub fn find_containers(&self) -> ContainerQuery
pub fn find_containers(&self) -> ContainerQuery
Build a query against container list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_objects<C>(&self, container: C) -> ObjectQuerywhere
C: Into<ContainerRef>,
pub fn find_objects<C>(&self, container: C) -> ObjectQuerywhere C: Into<ContainerRef>,
Build a query against object list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_flavors(&self) -> FlavorQuery
pub fn find_flavors(&self) -> FlavorQuery
Build a query against flavor list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_floating_ips(&self) -> FloatingIpQuery
pub fn find_floating_ips(&self) -> FloatingIpQuery
Build a query against floating IP list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_images(&self) -> ImageQuery
pub fn find_images(&self) -> ImageQuery
Build a query against image list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_keypairs(&self) -> KeyPairQuery
pub fn find_keypairs(&self) -> KeyPairQuery
Build a query against key pairs list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_networks(&self) -> NetworkQuery
pub fn find_networks(&self) -> NetworkQuery
Build a query against network list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_ports(&self) -> PortQuery
pub fn find_ports(&self) -> PortQuery
Build a query against port list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_routers(&self) -> RouterQuery
pub fn find_routers(&self) -> RouterQuery
Build a query against router list.
The returned object is a builder that should be used to construct the query.
sourcepub fn find_servers(&self) -> ServerQuery
pub fn find_servers(&self) -> ServerQuery
Build a query against server list.
The returned object is a builder that should be used to construct the query.
Example
Sorting servers by access_ip_v4
and getting first 5 results:
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let sorting = openstack::compute::ServerSortKey::AccessIpv4;
let server_list = os.find_servers()
.sort_by(openstack::Sort::Asc(sorting)).with_limit(5)
.all().await.expect("Unable to fetch servers");
sourcepub fn find_subnets(&self) -> SubnetQuery
pub fn find_subnets(&self) -> SubnetQuery
Build a query against subnet list.
The returned object is a builder that should be used to construct the query.
sourcepub async fn get_container<Id: AsRef<str>>(&self, name: Id) -> Result<Container>
pub async fn get_container<Id: AsRef<str>>(&self, name: Id) -> Result<Container>
Get object container metadata by its name.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let ctr = os.get_container("www").await.expect("Unable to get a container");
sourcepub async fn get_object<C, Id>(&self, container: C, name: Id) -> Result<Object>where
C: Into<ContainerRef>,
Id: AsRef<str>,
pub async fn get_object<C, Id>(&self, container: C, name: Id) -> Result<Object>where C: Into<ContainerRef>, Id: AsRef<str>,
Get object metadata by its name.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let obj = os.get_object("www", "/foo/bar").await.expect("Unable to get an object");
sourcepub async fn get_flavor<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Flavor>
pub async fn get_flavor<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Flavor>
Find a flavor by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_flavor("m1.medium").await.expect("Unable to get a flavor");
sourcepub async fn get_floating_ip<Id: AsRef<str>>(&self, id: Id) -> Result<FloatingIp>
pub async fn get_floating_ip<Id: AsRef<str>>(&self, id: Id) -> Result<FloatingIp>
Find a floating IP by its ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_floating_ip("031e08c7-2ca7-4c0b-9923-030c8d946ba4")
.await
.expect("Unable to get a floating IP");
sourcepub async fn get_image<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Image>
pub async fn get_image<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Image>
Find an image by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_image("centos7").await.expect("Unable to get a image");
sourcepub async fn get_keypair<Id: AsRef<str>>(&self, name: Id) -> Result<KeyPair>
pub async fn get_keypair<Id: AsRef<str>>(&self, name: Id) -> Result<KeyPair>
Find a key pair by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_keypair("default").await.expect("Unable to get a key pair");
sourcepub async fn get_network<Id: AsRef<str>>(
&self,
id_or_name: Id
) -> Result<Network>
pub async fn get_network<Id: AsRef<str>>( &self, id_or_name: Id ) -> Result<Network>
Find an network by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_network("centos7").await.expect("Unable to get a network");
sourcepub async fn get_port<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Port>
pub async fn get_port<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Port>
Find an port by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_port("4d9c1710-fa02-49f9-8218-291024ef4140")
.await
.expect("Unable to get a port");
sourcepub async fn get_router<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Router>
pub async fn get_router<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Router>
Find a router by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let router = os.get_router("router_name").await.expect("Unable to get a router");
sourcepub async fn get_server<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Server>
pub async fn get_server<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Server>
Find a server by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_server("8a1c355b-2e1e-440a-8aa8-f272df72bc32")
.await
.expect("Unable to get a server");
sourcepub async fn get_subnet<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Subnet>
pub async fn get_subnet<Id: AsRef<str>>(&self, id_or_name: Id) -> Result<Subnet>
Find an subnet by its name or ID.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server = os.get_subnet("private-subnet")
.await
.expect("Unable to get a subnet");
sourcepub async fn list_containers(&self) -> Result<Vec<Container>>
pub async fn list_containers(&self) -> Result<Vec<Container>>
List all containers.
This call can yield a lot of results, use the find_containers call to limit the number of containers to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_containers().await.expect("Unable to fetch containers");
sourcepub async fn list_objects<C>(&self, container: C) -> Result<Vec<Object>>where
C: Into<ContainerRef>,
pub async fn list_objects<C>(&self, container: C) -> Result<Vec<Object>>where C: Into<ContainerRef>,
List all objects.
This call can yield a lot of results, use the find_objects call to limit the number of objects to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_objects("www").await.expect("Unable to fetch objects");
sourcepub async fn list_flavors(&self) -> Result<Vec<FlavorSummary>>
pub async fn list_flavors(&self) -> Result<Vec<FlavorSummary>>
List all flavors.
This call can yield a lot of results, use the find_flavors call to limit the number of flavors to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_flavors().await.expect("Unable to fetch flavors");
sourcepub async fn list_floating_ips(&self) -> Result<Vec<FloatingIp>>
pub async fn list_floating_ips(&self) -> Result<Vec<FloatingIp>>
List all floating IPs
This call can yield a lot of results, use the find_floating_ips call to limit the number of networks to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_floating_ips().await.expect("Unable to fetch floating IPs");
sourcepub async fn list_images(&self) -> Result<Vec<Image>>
pub async fn list_images(&self) -> Result<Vec<Image>>
List all images.
This call can yield a lot of results, use the find_images call to limit the number of images to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_images().await.expect("Unable to fetch images");
sourcepub async fn list_keypairs(&self) -> Result<Vec<KeyPair>>
pub async fn list_keypairs(&self) -> Result<Vec<KeyPair>>
List all key pairs.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let result = os.list_keypairs().await.expect("Unable to fetch key pairs");
sourcepub async fn list_networks(&self) -> Result<Vec<Network>>
pub async fn list_networks(&self) -> Result<Vec<Network>>
List all networks.
This call can yield a lot of results, use the find_networks call to limit the number of networks to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_networks().await.expect("Unable to fetch networks");
sourcepub async fn list_ports(&self) -> Result<Vec<Port>>
pub async fn list_ports(&self) -> Result<Vec<Port>>
List all ports.
This call can yield a lot of results, use the find_ports call to limit the number of ports to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_ports().await.expect("Unable to fetch ports");
sourcepub async fn list_routers(&self) -> Result<Vec<Router>>
pub async fn list_routers(&self) -> Result<Vec<Router>>
List all routers.
This call can yield a lot of results, use the find_routers call to limit the number of routers to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let router_list = os.list_routers().await.expect("Unable to fetch routers");
sourcepub async fn list_servers(&self) -> Result<Vec<ServerSummary>>
pub async fn list_servers(&self) -> Result<Vec<ServerSummary>>
List all servers.
This call can yield a lot of results, use the find_servers call to limit the number of servers to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_servers().await.expect("Unable to fetch servers");
sourcepub async fn list_subnets(&self) -> Result<Vec<Subnet>>
pub async fn list_subnets(&self) -> Result<Vec<Subnet>>
List all subnets.
This call can yield a lot of results, use the find_subnets call to limit the number of subnets to receive.
Example
use openstack;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let server_list = os.list_subnets().await.expect("Unable to fetch subnets");
sourcepub fn new_object<C, O, B>(&self, container: C, object: O, body: B) -> NewObject<B>where
C: Into<ContainerRef>,
O: Into<String>,
B: AsyncRead + Sync + Send + 'static,
pub fn new_object<C, O, B>(&self, container: C, object: O, body: B) -> NewObject<B>where C: Into<ContainerRef>, O: Into<String>, B: AsyncRead + Sync + Send + 'static,
Prepare a new object for creation.
This call returns a NewObject
object, which is a builder
to create object in object storage.
sourcepub fn new_floating_ip<N>(&self, floating_network: N) -> NewFloatingIpwhere
N: Into<NetworkRef>,
pub fn new_floating_ip<N>(&self, floating_network: N) -> NewFloatingIpwhere N: Into<NetworkRef>,
Prepare a new floating IP for creation.
This call returns a NewFloatingIp
object, which is a builder
to populate floating IP fields.
sourcepub fn new_keypair<S>(&self, name: S) -> NewKeyPairwhere
S: Into<String>,
pub fn new_keypair<S>(&self, name: S) -> NewKeyPairwhere S: Into<String>,
Prepare a new key pair for creation.
This call returns a NewKeyPair
object, which is a builder to populate
key pair fields.
sourcepub fn new_network(&self) -> NewNetwork
pub fn new_network(&self) -> NewNetwork
Prepare a new network for creation.
This call returns a NewNetwork
object, which is a builder to populate
network fields.
sourcepub fn new_port<N>(&self, network: N) -> NewPortwhere
N: Into<NetworkRef>,
pub fn new_port<N>(&self, network: N) -> NewPortwhere N: Into<NetworkRef>,
Prepare a new port for creation.
This call returns a NewPort
object, which is a builder to populate
port fields.
sourcepub fn new_router(&self) -> NewRouter
pub fn new_router(&self) -> NewRouter
Prepare a new router for creation.
This call returns a NewRouter
object, which is a builder to populate
router fields.
sourcepub fn new_server<S, F>(&self, name: S, flavor: F) -> NewServerwhere
S: Into<String>,
F: Into<FlavorRef>,
pub fn new_server<S, F>(&self, name: S, flavor: F) -> NewServerwhere S: Into<String>, F: Into<FlavorRef>,
Prepare a new server for creation.
This call returns a NewServer
object, which is a builder to populate
server fields.
sourcepub fn new_subnet<N>(&self, network: N, cidr: IpNet) -> NewSubnetwhere
N: Into<NetworkRef>,
pub fn new_subnet<N>(&self, network: N, cidr: IpNet) -> NewSubnetwhere N: Into<NetworkRef>,
Prepare a new subnet for creation.
This call returns a NewSubnet
object, which is a builder to populate
subnet fields.
Example
extern crate ipnet;
extern crate openstack;
use std::net;
let os = openstack::Cloud::from_env().await.expect("Unable to authenticate");
let cidr = ipnet::Ipv4Net::new(net::Ipv4Addr::new(192, 168, 1, 0), 24)
.unwrap().into();
let new_subnet = os.new_subnet("private-net", cidr)
.with_name("private-subnet")
.create().await.expect("Unable to create subnet");