f5fd7244bea1bd51726a8f90259fdc1f910756fc
[ovsdb.git] / ovsdb / src / main / java / org / opendaylight / ovsdb / lib / database / OVSInstance.java
1 /*
2  * [[ Authors will Fill in the Copyright header ]]
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Brent Salisbury, Evan Zeller
9  */
10 package org.opendaylight.ovsdb.lib.database;\r
11 \r
12 \r
13 import org.opendaylight.ovsdb.plugin.Connection;\r
14 import org.opendaylight.ovsdb.plugin.OvsdbMessage;\r
15 \r
16 import java.util.ArrayList;\r
17 import java.util.HashMap;\r
18 import java.util.List;\r
19 import java.util.Map;\r
20 \r
21 public class OVSInstance {\r
22     private String uuid;\r
23 \r
24     public OVSInstance(){\r
25         this.uuid = null;\r
26     }\r
27 \r
28     public OVSInstance(String uuid){\r
29         this.uuid = uuid;\r
30     }\r
31 \r
32     @SuppressWarnings("unchecked")\r
33     public static OVSInstance monitorOVS(Connection connection){\r
34         List<String> columns = new ArrayList<String>();\r
35         columns.add("_uuid");\r
36         columns.add("bridges");\r
37 \r
38         Map<String, List<String>> row = new HashMap<String, List<String>>();\r
39         row.put("columns", columns);\r
40 \r
41         Map<String, Map> tables = new HashMap<String, Map>();\r
42         tables.put("Open_vSwitch", row);\r
43 \r
44         Object[] params = {"Open_vSwitch", null, tables};\r
45 \r
46         OvsdbMessage msg = new OvsdbMessage("monitor", params);\r
47         Map<String, Object> monitorResponse = new HashMap<String, Object>();\r
48 \r
49         Map<String, Object> vSwitchTable = (Map) monitorResponse.get("Open_vSwitch");\r
50         if(vSwitchTable != null){\r
51             String uuid = (String) vSwitchTable.keySet().toArray()[0];\r
52             return new OVSInstance(uuid);\r
53         }\r
54         return null;\r
55     }\r
56 \r
57     public String getUuid(){\r
58         return this.uuid;\r
59     }\r
60 \r
61 }\r