133
136
def virtual_interface_get_all(self, context):
136
def instance_get_id_to_uuid_mapping(self, context, ids):
137
# NOTE(jkoelker): This is just here until we can rely on UUIDs
140
mapping[id] = str(utils.gen_uuid())
143
139
def fixed_ips_by_virtual_interface(self, context, vif_id):
144
140
return [ip for ip in self.fixed_ips
145
141
if ip['virtual_interface_id'] == vif_id]
374
370
func = get_instance_nw_info
375
371
stubs.Set(nova.network.API, 'get_instance_nw_info', func)
377
def set_stub_network_methods(stubs):
378
global _real_functions
379
cm = compute_manager.ComputeManager
380
if not _real_functions:
382
'_get_instance_nw_info': cm._get_instance_nw_info,
383
'_allocate_network': cm._allocate_network,
384
'_deallocate_network': cm._deallocate_network}
386
def fake_networkinfo(*args, **kwargs):
387
return network_model.NetworkInfo()
389
stubs.Set(cm, '_get_instance_nw_info', fake_networkinfo)
390
stubs.Set(cm, '_allocate_network', fake_networkinfo)
391
stubs.Set(cm, '_deallocate_network', lambda *args, **kwargs: None)
394
def unset_stub_network_methods(stubs):
395
global _real_functions
397
cm = compute_manager.ComputeManager
398
for name in _real_functions:
399
stubs.Set(cm, name, _real_functions[name])
402
def stub_compute_with_ips(stubs):
403
orig_get = compute_api.API.get
404
orig_get_all = compute_api.API.get_all
406
def fake_get(*args, **kwargs):
407
return _get_instances_with_cached_ips(orig_get, *args, **kwargs)
409
def fake_get_all(*args, **kwargs):
410
return _get_instances_with_cached_ips(orig_get_all, *args, **kwargs)
412
stubs.Set(compute_api.API, 'get', fake_get)
413
stubs.Set(compute_api.API, 'get_all', fake_get_all)
416
def _get_fake_cache():
417
def _ip(ip, fixed=True, floats=None):
418
ip_dict = {'address': ip, 'type': 'fixed'}
420
ip_dict['type'] = 'floating'
422
ip_dict['floating_ips'] = [_ip(f, fixed=False) for f in floats]
425
info = [{'address': 'aa:bb:cc:dd:ee:ff',
427
'network': {'bridge': 'br0',
430
'subnets': [{'cidr': '192.168.0.0/24',
431
'ips': [_ip('192.168.0.3')]}]}}]
433
ipv6_addr = 'fe80:b33f::a8bb:ccff:fedd:eeff'
434
info[0]['network']['subnets'].append({'cidr': 'fe80:b33f::/64',
435
'ips': [_ip(ipv6_addr)]})
439
def _get_instances_with_cached_ips(orig_func, *args, **kwargs):
440
"""Kludge the cache into instance(s) without having to create DB
443
instances = orig_func(*args, **kwargs)
444
if isinstance(instances, list):
445
for instance in instances:
446
instance['info_cache'] = {'network_info': _get_fake_cache()}
448
instances['info_cache'] = {'network_info': _get_fake_cache()}