Skip to content

Commit

Permalink
Add AnsibleBridge object to the internals
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Dec 5, 2024
1 parent 8585d58 commit a9a1896
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions libsysinspect/src/pylang/pylib/pysystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustpython_vm::pymodule;
#[pymodule]
pub mod syscore {
use crate::{
cfg::{get_minion_config, mmconf::MinionConfig},
traits::{self, systraits::SystemTraits},
util::dataconv,
};
Expand Down Expand Up @@ -69,6 +70,42 @@ pub mod syscore {
Ok(MinionTraits::new())
}

#[pyattr]
#[pyclass(module = "syscore", name = "__AnsibleBridge")]
#[derive(Debug, PyPayload)]
pub struct AnsibleBridge {
cfg: MinionConfig,
}

#[pyclass]
impl AnsibleBridge {
#[pymethod]
pub fn sharelib(&self, _vm: &VirtualMachine) -> PyObjectRef {
_vm.ctx.new_str(self.cfg.sharelib_dir().to_string_lossy().to_string()).into()
}

#[pymethod]
pub fn root_dir(&self, _vm: &VirtualMachine) -> PyObjectRef {
_vm.ctx.new_str(self.cfg.root_dir().to_string_lossy().to_string()).into()
}

#[pymethod]
pub fn builtin_path(&self, name: String, _vm: &VirtualMachine) -> PyObjectRef {
let p = self.cfg.sharelib_dir().join(format!("lib/ansible/modules/{name}.py"));
if p.exists() {
return _vm.ctx.new_str(p.to_string_lossy().to_string()).into();
}

_vm.ctx.none()
}
}

#[pyfunction]
#[allow(non_snake_case)]
fn AnsibleBridge() -> PyResult<AnsibleBridge> {
Ok(AnsibleBridge { cfg: get_minion_config(None).unwrap() })
}

#[derive(Debug)]
struct Inner {
retcode: usize,
Expand Down

0 comments on commit a9a1896

Please sign in to comment.