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