Crate juju [] [src]

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. 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

extern crate juju;
use std::env;

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

fn main(){
   let args: Vec<String> = env::args().collect();
   if args.len() > 0{
        let mut hook_registry: Vec<juju::Hook> = Vec::new();

        //Register our hooks with the Juju library
        hook_registry.push(juju::Hook{
            name: "config-changed".to_string(),
            callback: Box::new(config_changed),
        });
        let result =  juju::process_hooks(args, hook_registry);

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

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!

Structs

Context
Hook
Relation
Status

Enums

JujuError
StatusType

For information about what these StatusType variants mean see: Status reference

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_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

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

is_leader

Returns true/false if this unit is the leader

log

Logs the msg passed to it

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
relation_get_by_unit
relation_ids
relation_list

Returns a list of all related units

relation_set
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.