Skip to content

Commit

Permalink
Drop "model://" targeting as there will be always only one scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Dec 10, 2024
1 parent 9de87c0 commit 304810d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
13 changes: 9 additions & 4 deletions docs/genusage/targeting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ in the following format:
.. code-block:: text
:caption: Precise model query synopsis
"model://<model>/[entity]/[state] [traits query]"
"/<model>/[entity]/[state] [traits query]"
.. code-block:: text
:caption: Checkbook model query synopsis
"model://<model>/[entity]:[checkbook labels]"
"/<model>/[entity]:[checkbook labels]"
Since there can be many models, it is essential to select one, therefore a model Id is
always required. If ``entity`` and/or ``state`` are not specified, they are defaulted to
Expand All @@ -61,7 +61,7 @@ always required. If ``entity`` and/or ``state`` are not specified, they are defa
.. code-block:: bash
:caption: Example of Model targeting by precise query
sysinspect "model://router/network,devices/online"
sysinspect "/router/network,devices/online"
In the example above, a network is verified in a router only when it supposed to be online.
Under the hood, omitted parts are translated to "all" (``$``). E.g. ``router/network`` is
Expand All @@ -74,11 +74,16 @@ values and logical operations. See :ref:`query_targeting` for more details.
.. code-block:: bash
:caption: Example of Model targeting by checkbook labels
sysinspect "model://router:network,devices"
sysinspect "/router:network,devices"
The example above is the same as the previous one, except it is using Checkbook. Entities
in the Checkbook are basically the top-high groups of other entities.

.. hint::

Trailing slash in model specification path can be omitted: ``router/network/online`` would also working
the same way.

Using Traits
------------

Expand Down
9 changes: 7 additions & 2 deletions docs/modeldescr/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ Model Description

.. _model_description:

The Model is essentially a configuration of a system. It is written in YAML format,
and it is following a specific expression schema and logic.
The Model is essentially a configuration of a system. It serves two purposes:

- An assertion verification about system integrity (information only)
- A state enforcement as a configuration management system does


The Aodel is written in YAML format, and it is following a specific expression schema and logic.

This document explains each part of the Model Description.

Expand Down
2 changes: 1 addition & 1 deletion docs/modeldescr/states.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ is passed, then default state is selected:

.. code-block:: text
syspect --model ./my_model --states=online,active
sysinspect --model ./my_model --states=online,active
2 changes: 1 addition & 1 deletion libsysinspect/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub struct MinionTarget {
/// Session Id
sid: String, // XXX: Should be gone

/// Scheme to call (model:// or state://)
/// Which scheme must be called (model://)
#[serde(rename = "s")]
scheme: String,

Expand Down
18 changes: 4 additions & 14 deletions libsysinspect/src/proto/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::SysinspectError;

/// Targeting schemes
pub static SCHEME_MODEL: &str = "model://";
pub static SCHEME_STATE: &str = "state://";

///
/// Query parser (scheme).
Expand All @@ -25,21 +24,12 @@ pub struct MinionQuery {

impl MinionQuery {
pub fn new(q: &str) -> Result<Arc<Mutex<Self>>, SysinspectError> {
let q = q.trim();
if !q.starts_with(SCHEME_STATE) && !q.starts_with(SCHEME_MODEL) {
return Err(SysinspectError::ProtoError("Query has unknown scheme".to_string()));
}

let sq: Vec<&str> = q.split("://").collect();
if sq.len() != 2 {
return Err(SysinspectError::ProtoError("Unable to parse scheme".to_string()));
}

let q = q.trim().trim_matches('/');
let mut instance = Self { ..Default::default() };
instance.scheme = sq[0].to_owned();
instance.scheme = SCHEME_MODEL.to_string(); // XXX: Drop "model://" scheme entirely

let precise = sq[1].contains('/');
let sq: Vec<&str> = sq[1].split(if precise { '/' } else { ':' }).filter(|s| !s.is_empty()).collect();
let precise = q.contains('/');
let sq: Vec<&str> = q.split(if precise { '/' } else { ':' }).filter(|s| !s.is_empty()).collect();
match sq.len() {
0 => {
return Err(SysinspectError::ProtoError("No model has been targeted".to_string()));
Expand Down
4 changes: 2 additions & 2 deletions src/clidef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn cli(version: &'static str) -> Command {
// Sysinspect
.next_help_heading("Main")
.arg(
Arg::new("scheme")
.help("Specify scheme that needs to be requested (model:// or state://)")
Arg::new("path")
.help("Specify model path that needs to be requested")
.required(false)
.index(1)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn main() {
}
};

if let Some(model) = params.get_one::<String>("scheme") {
if let Some(model) = params.get_one::<String>("path") {
let query = params.get_one::<String>("query");
let traits = params.get_one::<String>("traits");
if let Err(err) = call_master_fifo(model, query.unwrap_or(&"".to_string()), traits, &cfg.socket()) {
Expand Down

0 comments on commit 304810d

Please sign in to comment.