2012-12-13 21:05:22 +00:00
|
|
|
|
2014-02-07 19:08:32 +00:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-11 01:32:48 +00: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-20 03:29:58 +00:00
|
|
|
extern crate collections;
|
2014-02-21 22:18:39 +00:00
|
|
|
extern crate serialize;
|
2013-05-25 02:35:29 +00:00
|
|
|
|
2014-05-30 02:03:06 +00:00
|
|
|
use std::collections::HashMap;
|
2014-02-21 22:18:39 +00:00
|
|
|
use serialize::json;
|
2013-05-25 02:35:29 +00:00
|
|
|
use std::option;
|
2012-07-11 21:31:35 +00:00
|
|
|
|
2013-03-01 18:44:43 +00:00
|
|
|
enum object {
|
2012-07-11 21:31:35 +00:00
|
|
|
bool_value(bool),
|
|
|
|
int_value(i64),
|
|
|
|
}
|
|
|
|
|
2014-09-11 05:07:49 +00:00
|
|
|
fn lookup(table: json::JsonObject, key: String, default: String) -> String
|
2012-07-11 21:31:35 +00:00
|
|
|
{
|
2014-05-25 10:17:19 +00:00
|
|
|
match table.find(&key.to_string()) {
|
2014-02-21 22:18:39 +00:00
|
|
|
option::Some(&json::String(ref s)) => {
|
2014-06-28 15:27:29 +00:00
|
|
|
s.to_string()
|
2012-07-11 21:31:35 +00:00
|
|
|
}
|
2013-07-02 19:47:32 +00:00
|
|
|
option::Some(value) => {
|
2014-10-15 01:07:11 +00:00
|
|
|
println!("{} was expected to be a string but is a {}", key, value);
|
2012-07-11 21:31:35 +00:00
|
|
|
default
|
|
|
|
}
|
2013-07-02 19:47:32 +00:00
|
|
|
option::None => {
|
2012-07-11 21:31:35 +00:00
|
|
|
default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn add_interface(_store: int, managed_ip: String, data: json::Json) -> (String, object)
|
2012-07-11 21:31:35 +00:00
|
|
|
{
|
2013-07-02 19:47:32 +00:00
|
|
|
match &data {
|
2014-02-21 22:18:39 +00:00
|
|
|
&json::Object(ref interface) => {
|
2014-06-28 15:27:29 +00:00
|
|
|
let name = lookup(interface.clone(),
|
2014-05-25 10:17:19 +00:00
|
|
|
"ifDescr".to_string(),
|
|
|
|
"".to_string());
|
2014-05-28 03:44:58 +00:00
|
|
|
let label = format!("{}-{}", managed_ip, name);
|
2012-07-11 21:31:35 +00:00
|
|
|
|
|
|
|
(label, bool_value(false))
|
|
|
|
}
|
2013-07-02 19:47:32 +00:00
|
|
|
_ => {
|
2014-10-15 01:07:11 +00:00
|
|
|
println!("Expected dict for {} interfaces, found {}", managed_ip, data);
|
2014-05-25 10:17:19 +00:00
|
|
|
("gnos:missing-interface".to_string(), bool_value(true))
|
2012-07-11 21:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:57:53 +00:00
|
|
|
fn add_interfaces(store: int, managed_ip: String, device: HashMap<String, json::Json>)
|
|
|
|
-> Vec<(String, object)> {
|
2014-10-15 06:05:01 +00:00
|
|
|
match device["interfaces".to_string()]
|
2012-07-11 21:31:35 +00:00
|
|
|
{
|
2014-10-15 06:05:01 +00:00
|
|
|
json::List(ref interfaces) =>
|
2012-07-11 21:31:35 +00:00
|
|
|
{
|
2014-03-05 23:28:08 +00:00
|
|
|
interfaces.iter().map(|interface| {
|
2013-07-02 19:47:32 +00:00
|
|
|
add_interface(store, managed_ip.clone(), (*interface).clone())
|
2014-03-05 23:28:08 +00:00
|
|
|
}).collect()
|
2012-07-11 21:31:35 +00:00
|
|
|
}
|
2012-08-04 02:59:04 +00:00
|
|
|
_ =>
|
2012-07-11 21:31:35 +00:00
|
|
|
{
|
2014-10-15 01:07:11 +00:00
|
|
|
println!("Expected list for {} interfaces, found {}", managed_ip,
|
2014-10-15 06:05:01 +00:00
|
|
|
device["interfaces".to_string()]);
|
2014-03-05 22:02:44 +00:00
|
|
|
Vec::new()
|
2012-07-11 21:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {}
|