1 # Copyright (c) 2011, 2012 Nicira, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 class Session(object):
24 self.xenapi = XenAPI()
27 class Failure(Exception):
33 self.network = Network()
38 def login_with_password(self, unused_username, unused_password):
42 class RecordRef(object):
43 def __init__(self, attrs):
48 def __init__(self, records):
49 self.records = records
52 return [RecordRef(rec) for rec in self.records]
54 def get_all_records_where(self, condition):
55 k, v = re.match(r'field "([^"]*)"="([^"]*)"$', condition).groups()
58 # I'm sure that the keys used in the dictionary below are wrong
59 # but I can't find any documentation on get_all_records_where
60 # and this satisfies the current test case.
62 for rec in self.records:
68 def get_by_uuid(self, uuid):
69 recs = [rec for rec in self.records if rec["uuid"] == uuid]
71 raise Failure("No record with UUID %s" % uuid)
72 return RecordRef(recs[0])
74 def get_record(self, record_ref):
75 return record_ref.attrs
79 __records = ({"uuid": "9b66c68b-a74e-4d34-89a5-20a8ab352d1e",
82 {"vswitch-controller-fail-mode": "secure",
83 "nicira-bridge-id": "custom bridge ID"}},
84 {"uuid": "e1c9019d-375b-45ac-a441-0255dd2247de",
87 {"vswitch-disable-in-band": "true"}})
90 Table.__init__(self, Network.__records)
94 __records = ({"uuid": "7a793edf-e5f4-4994-a0f9-cee784c0cda3",
96 {"vswitch-controller-fail-mode": "secure"}},)
99 Table.__init__(self, Pool.__records)
103 __records = ({"uuid": "6ab1b260-398e-49ba-827b-c7696108964c",
105 {"nicira-iface-id": "custom iface ID"}},)
108 Table.__init__(self, VIF.__records)
112 __records = ({"uuid": "fcb8a3f6-dc04-41d2-8b8a-55afd2b755b8",
114 {"nicira-vm-id": "custom vm ID"}},)
117 Table.__init__(self, VM.__records)