2012-12-13 15:05:22 -06:00
|
|
|
|
2014-02-07 13:08:32 -06:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-10 19:32:48 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-02-19 21:29:58 -06:00
|
|
|
extern crate collections;
|
2014-02-21 16:18:39 -06:00
|
|
|
extern crate serialize;
|
2013-05-24 21:35:29 -05:00
|
|
|
|
2014-05-29 21:03:06 -05:00
|
|
|
use std::collections::HashMap;
|
2014-02-21 16:18:39 -06:00
|
|
|
use serialize::json;
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::option;
|
2012-07-11 16:31:35 -05:00
|
|
|
|
2013-03-01 12:44:43 -06:00
|
|
|
enum object {
|
2012-07-11 16:31:35 -05:00
|
|
|
bool_value(bool),
|
|
|
|
int_value(i64),
|
|
|
|
}
|
|
|
|
|
2014-09-11 00:07:49 -05:00
|
|
|
fn lookup(table: json::JsonObject, key: String, default: String) -> String
|
2012-07-11 16:31:35 -05:00
|
|
|
{
|
2014-05-25 05:17:19 -05:00
|
|
|
match table.find(&key.to_string()) {
|
2014-02-21 16:18:39 -06:00
|
|
|
option::Some(&json::String(ref s)) => {
|
2014-06-28 10:27:29 -05:00
|
|
|
s.to_string()
|
2012-07-11 16:31:35 -05:00
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
option::Some(value) => {
|
2014-10-14 20:07:11 -05:00
|
|
|
println!("{} was expected to be a string but is a {}", key, value);
|
2012-07-11 16:31:35 -05:00
|
|
|
default
|
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
option::None => {
|
2012-07-11 16:31:35 -05:00
|
|
|
default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
fn add_interface(_store: int, managed_ip: String, data: json::Json) -> (String, object)
|
2012-07-11 16:31:35 -05:00
|
|
|
{
|
2013-07-02 14:47:32 -05:00
|
|
|
match &data {
|
2014-02-21 16:18:39 -06:00
|
|
|
&json::Object(ref interface) => {
|
2014-06-28 10:27:29 -05:00
|
|
|
let name = lookup(interface.clone(),
|
2014-05-25 05:17:19 -05:00
|
|
|
"ifDescr".to_string(),
|
|
|
|
"".to_string());
|
2014-05-27 22:44:58 -05:00
|
|
|
let label = format!("{}-{}", managed_ip, name);
|
2012-07-11 16:31:35 -05:00
|
|
|
|
|
|
|
(label, bool_value(false))
|
|
|
|
}
|
2013-07-02 14:47:32 -05:00
|
|
|
_ => {
|
2014-10-14 20:07:11 -05:00
|
|
|
println!("Expected dict for {} interfaces, found {}", managed_ip, data);
|
2014-05-25 05:17:19 -05:00
|
|
|
("gnos:missing-interface".to_string(), bool_value(true))
|
2012-07-11 16:31:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
fn add_interfaces(store: int, managed_ip: String, device: HashMap<String, json::Json>)
|
|
|
|
-> Vec<(String, object)> {
|
2014-10-15 01:05:01 -05:00
|
|
|
match device["interfaces".to_string()]
|
2012-07-11 16:31:35 -05:00
|
|
|
{
|
2014-10-15 01:05:01 -05:00
|
|
|
json::List(ref interfaces) =>
|
2012-07-11 16:31:35 -05:00
|
|
|
{
|
2014-03-05 17:28:08 -06:00
|
|
|
interfaces.iter().map(|interface| {
|
2013-07-02 14:47:32 -05:00
|
|
|
add_interface(store, managed_ip.clone(), (*interface).clone())
|
2014-03-05 17:28:08 -06:00
|
|
|
}).collect()
|
2012-07-11 16:31:35 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
_ =>
|
2012-07-11 16:31:35 -05:00
|
|
|
{
|
2014-10-14 20:07:11 -05:00
|
|
|
println!("Expected list for {} interfaces, found {}", managed_ip,
|
2014-10-15 01:05:01 -05:00
|
|
|
device["interfaces".to_string()]);
|
2014-03-05 16:02:44 -06:00
|
|
|
Vec::new()
|
2012-07-11 16:31:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {}
|