3 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4 // file at the top-level directory of this distribution and at
5 // http://rust-lang.org/COPYRIGHT.
7 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 // option. This file may not be copied, modified, or distributed
11 // except according to those terms.
13 extern crate collections;
14 extern crate serialize;
16 use collections::HashMap;
26 fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str
28 match table.find(&key) {
29 option::Some(&json::String(ref s)) => {
32 option::Some(value) => {
33 println!("{} was expected to be a string but is a {:?}", key, value);
42 fn add_interface(_store: int, managed_ip: ~str, data: json::Json) -> (~str, object)
45 &json::Object(ref interface) => {
46 let name = lookup((*interface).clone(), ~"ifDescr", ~"");
47 let label = format!("{}-{}", managed_ip, name);
49 (label, bool_value(false))
52 println!("Expected dict for {} interfaces but found {:?}", managed_ip, data);
53 (~"gnos:missing-interface", bool_value(true))
58 fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, json::Json>)
59 -> Vec<(~str, object)> {
60 match device.get(&~"interfaces")
62 &json::List(ref interfaces) =>
64 interfaces.iter().map(|interface| {
65 add_interface(store, managed_ip.clone(), (*interface).clone())
70 println!("Expected list for {} interfaces but found {:?}", managed_ip,
71 device.get(&~"interfaces"));