ofproto: Inline trivial functions.
[sliver-openvswitch.git] / tests / MockXenAPI.py
index f6ac22f..cca1571 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 Nicira Networks
+# Copyright (c) 2011, 2012 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import re
+
 def xapi_local():
     return Session()
 
@@ -30,6 +32,7 @@ class XenAPI(object):
         self.network = Network()
         self.pool = Pool()
         self.VIF = VIF()
+        self.VM = VM()
 
     def login_with_password(self, unused_username, unused_password):
         pass
@@ -47,6 +50,20 @@ class Table(object):
     def get_all(self):
         return [RecordRef(rec) for rec in self.records]
 
+    def get_all_records_where(self, condition):
+        k, v = re.match(r'field "([^"]*)"="([^"]*)"$', condition).groups()
+        d = {}
+
+        # I'm sure that the keys used in the dictionary below are wrong
+        # but I can't find any documentation on get_all_records_where
+        # and this satisfies the current test case.
+        i = 0
+        for rec in self.records:
+            if rec[k] == v:
+                d[i] = rec
+                i += 1
+        return d
+
     def get_by_uuid(self, uuid):
         recs = [rec for rec in self.records if rec["uuid"] == uuid]
         if len(recs) != 1:
@@ -87,3 +104,11 @@ class VIF(Table):
 
     def __init__(self):
         Table.__init__(self, VIF.__records)
+
+class VM(Table):
+    __records = ({"uuid": "fcb8a3f6-dc04-41d2-8b8a-55afd2b755b8",
+                  "other_config":
+                      {"nicira-vm-id": "custom vm ID"}},)
+
+    def __init__(self):
+        Table.__init__(self, VM.__records)