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§
- 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§
- Juju
Error - LogLevel
- An enum representing the available verbosity levels of the logging framework
- Status
Type - 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.