-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathparse_system_info.java
More file actions
55 lines (45 loc) · 1.65 KB
/
Copy pathparse_system_info.java
File metadata and controls
55 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright (c) 2013 Juniper Networks, Inc.
* All Rights Reserved
*
* Use is subject to license terms.
*
*/
// Code to parse following rpc-reply
/* <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/14.2I0/junos">
* <system-information>
* <hardware-model>abc</hardware-model>
* <os-name>junos</os-name>
* <os-version>14.2I20</os-version>
* <host-name>server</host-name>
* </system-information>
* </rpc-reply>
*/
import net.juniper.netconf.Device;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class parse_system_info {
public static void main(String[] args) throws
SAXException, IOException {
Device device = CreateDevice.createDevice();
device.connect();
//Send RPC and receive RPC Reply as XML
XML rpc_reply = device.executeRPC("get-system-information");
List<String> list1 = Arrays.asList("system-information","hardware-model");
List<String> list2 = Arrays.asList("system-information","os-name");
List<String> list3 = Arrays.asList("system-information","os-version");
List<String> list4 = Arrays.asList("system-information","host-name");
String val1= rpc_reply.findValue(list1);
String val2= rpc_reply.findValue(list2);
String val3= rpc_reply.findValue(list3);
String val4= rpc_reply.findValue(list4);
System.out.println(val1);
System.out.println(val2);
System.out.println(val3);
System.out.println(val4);
device.close();
}
}