+ public OvsdbConnectionInstance getConnectionInstance(OvsdbClientKey key) {
+ return clients.get(key);
+ }
+
+ public OvsdbConnectionInstance getConnectionInstance(IpPortLocator loc) {
+ Preconditions.checkNotNull(loc);
+ return getConnectionInstance(new OvsdbClientKey(loc));
+ }
+
+ public OvsdbConnectionInstance getConnectionInstance(OvsdbBridgeAttributes mn) {
+ Preconditions.checkNotNull(mn);
+ try {
+ OvsdbNodeRef ref = mn.getManagedBy();
+ if(ref != null) {
+ ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
+ CheckedFuture<?, ReadFailedException> nf = transaction.read(LogicalDatastoreType.OPERATIONAL, ref.getValue());
+ transaction.close();
+ Object obj = nf.get();
+ if(obj instanceof Node) {
+ OvsdbNodeAugmentation ovsdbNode = ((Node)obj).getAugmentation(OvsdbNodeAugmentation.class);
+ if(ovsdbNode !=null) {
+ return getConnectionInstance(ovsdbNode);
+ } else {
+ LOG.warn("OvsdbManagedNode {} claims to be managed by {} but that OvsdbNode does not exist",mn,ref.getValue());
+ return null;
+ }
+ } else {
+ LOG.warn("Mysteriously got back a thing which is *not* a topology Node: {}",obj);
+ return null;
+ }
+ } else {
+ LOG.warn("Cannot find client for OvsdbManagedNode without a specified ManagedBy {}",mn);
+ return null;
+ }
+ } catch (Exception e) {
+ LOG.warn("Failed to get OvsdbNode that manages OvsdbManagedNode {}",mn, e);
+ return null;
+ }
+ }
+
+ public OvsdbConnectionInstance getConnectionInstance(Node node) {
+ Preconditions.checkNotNull(node);
+ OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class);
+ OvsdbBridgeAugmentation ovsdbManagedNode = node.getAugmentation(OvsdbBridgeAugmentation.class);
+ if(ovsdbNode != null) {
+ return getConnectionInstance(ovsdbNode);
+ } else if (ovsdbManagedNode != null) {
+ return getConnectionInstance(ovsdbManagedNode);
+ } else {
+ LOG.warn("This is not a node that gives any hint how to find its OVSDB Manager: {}",node);
+ return null;
+ }
+ }
+
+ public OvsdbClient getClient(OvsdbClientKey key) {
+ return getConnectionInstance(key);
+ }