Crate juju

Source
Expand description

A library to interface with Juju. For more information about Juju see Juju

A hello world Juju charm example in Rust: You will need a working Juju environment for this to function properly. See [Setting up Juju] (https://jujucharms.com/docs/stable/getting-started). After Juju is functioning see What makes a Charm for the base components of a charm.

Our src/main.rs will contain the following:

§Examples

#[macro_use]
extern crate juju;
extern crate log;
use log::LogLevel;

fn config_changed()->Result<(), String>{
    juju::log("Hello Juju from Rust!", Some(LogLevel::Debug));
    return Ok(());
}

fn main(){
    let hook_registry: Vec<juju::Hook> = vec![
        hook!("config-changed", config_changed)
    ];
    let result =  juju::process_hooks(hook_registry);

    if result.is_err(){
        juju::log(&format!("Hook failed with error: {:?}", result.err()),
            Some(LogLevel::Error));
    }else{
        juju::log("Hook call was successful!", Some(LogLevel::Debug));
    }
}

Now you can build with cargo build and install the binary in the hooks directory.

Create a symlink in the hooks directory with ln -s hello-world config-changed. Juju will attempt to run that symlink and our Juju library will map that to our config_changed function.

We can test our hello-world charm by deploying with juju and watching the debug logs. See Deploying a Charm for more information.

You should see a message in juju debug-log like this unit-hello-world-0[6229]: 2015-08-21 16:16:05 INFO unit.hello-world/0.juju-log server.go:254 Hello Juju from Rust!

Modules§

macros
unitdata

Macros§

hook
A basic macro to ease creation and management of Hooks
log
status_set
A Macro to set Juju’s status

Structs§

Config
A HashMap representation of the charm’s config.yaml, with some extra features:
Context
Hook
Relation
Status

Enums§

JujuError
LogLevel
An enum representing the available verbosity levels of the logging framework
StatusType
For information about what these StatusType variants mean see: [Status reference] (https://jujucharms.com/docs/stable/reference-status)
Transport

Functions§

action_fail
See Juju Actions for more information
action_get
action_get gets the value of the parameter at the given key See Juju Actions for more information
action_get_all
action_get_all gets all values that are set See Juju Actions for more information
action_name
Get the name of the currently executing action
action_set
action_set permits the Action to set results in a map to be returned at completion of the Action. See Juju Actions for more information
action_tag
Get the tag of the currently executing action
action_uuid
Get the uuid of the currently executing action
add_metric
Add metric values See Juju Metrics for more information May only be called from the collect-metrics hook
application_version_set
Charm authors may trigger this command from any hook to output what version of the application is running. This could be a package version, for instance postgres version 9.5. It could also be a build number or version control revision identifier, for instance git sha 6fb7ba68.
az_info
Get the availability zone
close_port
This will hide a port on the unit. The transport argument will indicate whether tcp or udp should be exposed
config_get
This will return a configuration item that corresponds to the key passed in
config_get_all
config_get_all will return all configuration options as a HashMap<String,String>
is_leader
Returns true/false if this unit is the leader
leader_get
Juju leader get value(s)
leader_set
Juju leader set value(s)
log
Log a message, at an optional log::LogLevel, to the Juju log
meter_info
Get the meter status information, if running in the meter-status-changed hook
meter_status
Get the meter status, if running in the meter-status-changed hook
open_port
This will expose a port on the unit. The transport argument will indicate whether tcp or udp should be exposed
process_hooks
Call this to process your cmd line arguments and call any needed hooks
reboot
This will reboot your juju instance. Examples of using this are when a new kernel is installed and the virtual machine or server needs to be rebooted to use it.
relation_get
Get relation information for the current unit
relation_get_by_id
Get relation information using a specific relation ID. Used outside of relation hooks
relation_get_by_unit
Get relation information for a specific unit
relation_ids
relation_ids_by_identifier
Gets the relation IDs by their identifier
relation_list
Returns a list of all related units
relation_list_by_id
Returns a list of all related units for the supplied identifier
relation_set
Set relation information for the current unit
relation_set_by_id
Sets relation information using a specific relation ID. Used outside of relation hooks
status_get
Retrieve the previously set juju workload state
status_set
Set the status of your unit to indicate to the Juju if everything is ok or something is wrong. See the Status enum for information about what can be set.
storage_get
Return the location of the mounted storage device. The mounted storage devices can be gotten by calling storage_list() and then passed into this function to get their mount location.
storage_get_location
If storage drives were allocated to your unit this will get the path of them. In the storage-attaching hook this will tell you the location where the storage is attached to. IE: /dev/xvdf for block devices or /mnt/{name} for filesystem devices
storage_list
Used to list storage instances that are attached to the unit. The names returned may be passed through to storage_get
unit_get_private_addr
This will return the private IP address associated with the unit. It can be very useful for services that require communicating with the other units related to it.
unit_get_public_addr
This will return the public IP address associated with the unit.