-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #566 Adds the missing api examples for rust on how to use BlueChi's D-Bus API. Signed-off-by: Michael Engel <mengel@redhat.com>
- Loading branch information
Showing
15 changed files
with
913 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[package] | ||
name = "bluechi" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.4.6", features = ["derive"] } | ||
dbus = "0.9.7" | ||
|
||
[[bin]] | ||
name = "enable-unit" | ||
path = "enable-unit.rs" | ||
|
||
[[bin]] | ||
name = "get-cpuweight" | ||
path = "get-cpuweight.rs" | ||
|
||
[[bin]] | ||
name = "list-node-units" | ||
path = "list-node-units.rs" | ||
|
||
[[bin]] | ||
name = "list-nodes" | ||
path = "list-nodes.rs" | ||
|
||
[[bin]] | ||
name = "monitor-agent-connection" | ||
path = "monitor-agent-connection.rs" | ||
|
||
[[bin]] | ||
name = "monitor-node-connections" | ||
path = "monitor-node-connections.rs" | ||
|
||
[[bin]] | ||
name = "monitor-unit" | ||
path = "monitor-unit.rs" | ||
|
||
[[bin]] | ||
name = "set-cpuweight" | ||
path = "set-cpuweight.rs" | ||
|
||
[[bin]] | ||
name = "start-unit" | ||
path = "start-unit.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: MIT-0 | ||
|
||
use clap::Parser; | ||
use dbus::blocking::Connection; | ||
use dbus::Path; | ||
use std::time::Duration; | ||
|
||
#[derive(Parser)] | ||
struct Cli { | ||
/// The node name to list the units for | ||
#[clap(short, long)] | ||
node_name: String, | ||
|
||
/// The names of the units to enable. Names are separated by ','. | ||
#[clap(short, long, value_delimiter = ',')] | ||
unit_names: Vec<String>, | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args = Cli::parse(); | ||
|
||
let conn = Connection::new_system()?; | ||
|
||
let bluechi = conn.with_proxy( | ||
"org.eclipse.bluechi", | ||
"/org/eclipse/bluechi", | ||
Duration::from_millis(5000), | ||
); | ||
|
||
let (node,): (Path,) = | ||
bluechi.method_call("org.eclipse.bluechi.Manager", "GetNode", (args.node_name,))?; | ||
|
||
let node_proxy = conn.with_proxy("org.eclipse.bluechi", node, Duration::from_millis(5000)); | ||
|
||
let (carries_install_info, changes): (bool, Vec<(String, String, String)>) = node_proxy | ||
.method_call( | ||
"org.eclipse.bluechi.Node", | ||
"EnableUnitFiles", | ||
(args.unit_names, false, false), | ||
)?; | ||
|
||
if carries_install_info { | ||
println!("The unit files included enablement information"); | ||
} else { | ||
println!("The unit files did not include any enablement information"); | ||
} | ||
|
||
for (op_type, file_name, file_dest) in changes { | ||
if op_type == "symlink" { | ||
println!("Created symlink {} -> {}", file_name, file_dest); | ||
} else if op_type == "unlink" { | ||
println!("Removed '{}'", file_name); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.