below_dump/
ethtool.rs

1use super::*;
2
3pub struct EthtoolQueue {
4    opts: GeneralOpt,
5    fields: Vec<EthtoolQueueField>,
6}
7
8impl EthtoolQueue {
9    pub fn new(opts: &GeneralOpt, fields: Vec<EthtoolQueueField>) -> Self {
10        Self {
11            opts: opts.to_owned(),
12            fields,
13        }
14    }
15}
16
17impl Dumper for EthtoolQueue {
18    fn dump_model(
19        &self,
20        ctx: &CommonFieldContext,
21        model: &model::Model,
22        output: &mut dyn Write,
23        round: &mut usize,
24        comma_flag: bool,
25    ) -> Result<IterExecResult> {
26        let mut queues = Vec::new();
27        for nic in model.network.interfaces.values() {
28            for queue in &nic.queues {
29                queues.push(queue);
30            }
31        }
32
33        // Return if we filtered everything.
34        if queues.is_empty() {
35            return Ok(IterExecResult::Skip);
36        }
37
38        let mut json_output = json!([]);
39
40        queues
41            .into_iter()
42            .map(|queue| {
43                match self.opts.output_format {
44                    Some(OutputFormat::Raw) | None => write!(
45                        output,
46                        "{}",
47                        print::dump_raw(
48                            &self.fields,
49                            ctx,
50                            queue,
51                            *round,
52                            self.opts.repeat_title,
53                            self.opts.disable_title,
54                            self.opts.raw
55                        )
56                    )?,
57                    Some(OutputFormat::Csv) => write!(
58                        output,
59                        "{}",
60                        print::dump_csv(
61                            &self.fields,
62                            ctx,
63                            queue,
64                            *round,
65                            self.opts.disable_title,
66                            self.opts.raw
67                        )
68                    )?,
69                    Some(OutputFormat::Tsv) => write!(
70                        output,
71                        "{}",
72                        print::dump_tsv(
73                            &self.fields,
74                            ctx,
75                            queue,
76                            *round,
77                            self.opts.disable_title,
78                            self.opts.raw
79                        )
80                    )?,
81                    Some(OutputFormat::KeyVal) => write!(
82                        output,
83                        "{}",
84                        print::dump_kv(&self.fields, ctx, queue, self.opts.raw)
85                    )?,
86                    Some(OutputFormat::Json) => {
87                        let par = print::dump_json(&self.fields, ctx, queue, self.opts.raw);
88                        json_output.as_array_mut().unwrap().push(par);
89                    }
90                    Some(OutputFormat::OpenMetrics) => write!(
91                        output,
92                        "{}",
93                        print::dump_openmetrics(&self.fields, ctx, queue)
94                    )?,
95                }
96                *round += 1;
97                Ok(())
98            })
99            .collect::<Result<Vec<_>>>()?;
100
101        match (self.opts.output_format, comma_flag) {
102            (Some(OutputFormat::Json), true) => write!(output, ",{}", json_output)?,
103            (Some(OutputFormat::Json), false) => write!(output, "{}", json_output)?,
104            (Some(OutputFormat::OpenMetrics), _) => (),
105            _ => writeln!(output)?,
106        };
107
108        Ok(IterExecResult::Success)
109    }
110}