1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Jenkins Slaves Informations

use serde::{Deserialize, Serialize};

use crate::client_internals::{Name, Path, Result};
use crate::Jenkins;

pub mod computer;
pub mod monitor;

/// List of `Computer` associated to the `Jenkins` instance
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ComputerSet {
    /// Display name of the set
    pub display_name: String,
    /// Number of busy executors
    pub busy_executors: u32,
    /// Number of executors
    pub total_executors: u32,
    /// List of computers
    #[serde(rename = "computer")]
    pub computers: Vec<computer::CommonComputer>,
}

impl Jenkins {
    /// Get a `ComputerSet`
    pub fn get_nodes(&self) -> Result<ComputerSet> {
        Ok(self.get(&Path::Computers)?.json()?)
    }

    /// Get a `Computer`
    pub fn get_node<'a, C>(&self, computer_name: C) -> Result<computer::CommonComputer>
    where
        C: Into<computer::ComputerName<'a>>,
    {
        Ok(self
            .get(&Path::Computer {
                name: Name::Name(&computer_name.into().0),
            })?
            .json()?)
    }

    /// Get the master `Computer`
    pub fn get_master_node(&self) -> Result<computer::MasterComputer> {
        Ok(self
            .get(&Path::Computer {
                name: Name::Name("(master)"),
            })?
            .json()?)
    }
}