@@ -121,6 +121,9 @@ def __init__(self, **kwargs):
121121 self .hypervisors = mock .Mock ()
122122 self .hypervisors .resource_class = fakes .FakeResource (None , {})
123123
124+ self .hypervisors_stats = mock .Mock ()
125+ self .hypervisors_stats .resource_class = fakes .FakeResource (None , {})
126+
124127 self .security_groups = mock .Mock ()
125128 self .security_groups .resource_class = fakes .FakeResource (None , {})
126129
@@ -235,6 +238,64 @@ def create_hypervisors(attrs={}, count=2):
235238 return hypervisors
236239
237240
241+ class FakehypervisorStats (object ):
242+ """Fake one or more hypervisor stats."""
243+
244+ @staticmethod
245+ def create_one_hypervisor_stats (attrs = {}, methods = {}):
246+ """Create a fake hypervisor stats.
247+
248+ :param Dictionary attrs:
249+ A dictionary with all attributes
250+ :return:
251+ A FakeResource object, with id, hypervisor_hostname, and so on
252+ """
253+ # Set default attributes.
254+ stats_info = {
255+ 'count' : 2 ,
256+ 'current_workload' : 0 ,
257+ 'disk_available_least' : 50 ,
258+ 'free_disk_gb' : 100 ,
259+ 'free_ram_mb' : 23000 ,
260+ 'local_gb' : 100 ,
261+ 'local_gb_used' : 0 ,
262+ 'memory_mb' : 23800 ,
263+ 'memory_mb_used' : 1400 ,
264+ 'running_vms' : 3 ,
265+ 'vcpus' : 8 ,
266+ 'vcpus_used' : 3 ,
267+ }
268+ stats_info .update (attrs )
269+
270+ # Set default method.
271+ hypervisor_stats_method = {'to_dict' : stats_info }
272+ hypervisor_stats_method .update (methods )
273+
274+ hypervisor_stats = fakes .FakeResource (
275+ info = copy .deepcopy (stats_info ),
276+ methods = copy .deepcopy (hypervisor_stats_method ),
277+ loaded = True )
278+ return hypervisor_stats
279+
280+ @staticmethod
281+ def create_hypervisors_stats (attrs = {}, count = 2 ):
282+ """Create multiple fake hypervisors stats.
283+
284+ :param Dictionary attrs:
285+ A dictionary with all attributes
286+ :param int count:
287+ The number of hypervisors to fake
288+ :return:
289+ A list of FakeResource objects faking the hypervisors
290+ """
291+ hypervisors = []
292+ for i in range (0 , count ):
293+ hypervisors .append (
294+ FakehypervisorStats .create_one_hypervisor_stats (attrs ))
295+
296+ return hypervisors
297+
298+
238299class FakeSecurityGroupRule (object ):
239300 """Fake one or more security group rules."""
240301
0 commit comments