127
127
vm_rec = _db_content['VM'][vm_ref]
129
129
vbd_refs = vm_rec['VBDs']
130
for vbd_ref in vbd_refs:
130
# NOTE(johannes): Shallow copy since destroy_vbd will remove itself
132
for vbd_ref in vbd_refs[:]:
131
133
destroy_vbd(vbd_ref)
133
135
del _db_content['VM'][vm_ref]
136
138
def destroy_vbd(vbd_ref):
139
vbd_rec = _db_content['VBD'][vbd_ref]
141
vm_ref = vbd_rec['VM']
142
vm_rec = _db_content['VM'][vm_ref]
143
vm_rec['VBDs'].remove(vbd_ref)
145
vdi_ref = vbd_rec['VDI']
146
vdi_rec = _db_content['VDI'][vdi_ref]
147
vdi_rec['VBDs'].remove(vbd_ref)
137
149
del _db_content['VBD'][vbd_ref]
140
152
def destroy_vdi(vdi_ref):
153
vdi_rec = _db_content['VDI'][vdi_ref]
155
vbd_refs = vdi_rec['VBDs']
156
# NOTE(johannes): Shallow copy since destroy_vbd will remove itself
158
for vbd_ref in vbd_refs[:]:
141
161
del _db_content['VDI'][vdi_ref]
489
530
#Always return 12GB available
490
531
return 12 * 1024 * 1024 * 1024
492
def host_call_plugin(self, _1, _2, plugin, method, _5):
493
if (plugin, method) == ('agent', 'version'):
494
return as_json(returncode='0', message='1.0')
495
elif (plugin, method) == ('agent', 'key_init'):
496
return as_json(returncode='D0', message='1')
497
elif (plugin, method) == ('agent', 'password'):
498
return as_json(returncode='0', message='success')
499
elif (plugin, method) == ('agent', 'resetnetwork'):
500
return as_json(returncode='0', message='success')
501
elif (plugin, method) == ('glance', 'upload_vhd'):
503
elif (plugin, method) == ('kernel', 'copy_vdi'):
505
elif (plugin, method) == ('kernel', 'create_kernel_ramdisk'):
507
elif (plugin, method) == ('kernel', 'remove_kernel_ramdisk'):
509
elif (plugin, method) == ('migration', 'move_vhds_into_sr'):
511
elif (plugin, method) == ('migration', 'transfer_vhd'):
513
elif (plugin, method) == ('xenhost', 'host_data'):
533
def _plugin_agent_version(self, method, args):
534
return as_json(returncode='0', message='1.0')
536
def _plugin_agent_key_init(self, method, args):
537
return as_json(returncode='D0', message='1')
539
def _plugin_agent_password(self, method, args):
540
return as_json(returncode='0', message='success')
542
def _plugin_agent_inject_file(self, method, args):
543
return as_json(returncode='0', message='success')
545
def _plugin_agent_resetnetwork(self, method, args):
546
return as_json(returncode='0', message='success')
548
def _plugin_noop(self, method, args):
551
_plugin_glance_upload_vhd = _plugin_noop
552
_plugin_kernel_copy_vdi = _plugin_noop
553
_plugin_kernel_create_kernel_ramdisk = _plugin_noop
554
_plugin_kernel_remove_kernel_ramdisk = _plugin_noop
555
_plugin_migration_move_vhds_into_sr = _plugin_noop
556
_plugin_migration_transfer_vhd = _plugin_noop
558
def _plugin_xenhost_host_data(self, method, args):
514
559
return jsonutils.dumps({'host_memory': {'total': 10,
517
'free-computed': 40}, })
518
elif (plugin == 'xenhost' and method in ['host_reboot',
521
return jsonutils.dumps({"power_action": method[5:]})
522
elif (plugin, method) == ('xenhost', 'set_host_enabled'):
523
enabled = 'enabled' if _5.get('enabled') == 'true' else 'disabled'
524
return jsonutils.dumps({"status": enabled})
562
'free-computed': 40}})
564
def _plugin_poweraction(self, method, args):
565
return jsonutils.dumps({"power_action": method[5:]})
567
_plugin_xenhost_host_reboot = _plugin_poweraction
568
_plugin_xenhost_host_startup = _plugin_poweraction
569
_plugin_xenhost_host_shutdown = _plugin_poweraction
571
def _plugin_xenhost_set_host_enabled(self, method, args):
572
enabled = 'enabled' if args.get('enabled') == 'true' else 'disabled'
573
return jsonutils.dumps({"status": enabled})
575
def _plugin_xenhost_host_uptime(self, method, args):
576
return jsonutils.dumps({"uptime": "fake uptime"})
578
def host_call_plugin(self, _1, _2, plugin, method, args):
579
func = getattr(self, '_plugin_%s_%s' % (plugin, method), None)
526
581
raise Exception('No simulation in host_call_plugin for %s,%s' %
527
582
(plugin, method))
584
return func(method, args)
529
586
def VDI_get_virtual_size(self, *args):
530
587
return 1 * 1024 * 1024 * 1024
535
592
VDI_resize = VDI_resize_online
594
def _VM_reboot(self, session, vm_ref):
595
db_ref = _db_content['VM'][vm_ref]
596
if db_ref['power_state'] != 'Running':
597
raise Failure(['VM_BAD_POWER_STATE',
598
'fake-opaque-ref', db_ref['power_state'].lower(), 'halted'])
599
db_ref['power_state'] = 'Running'
537
601
def VM_clean_reboot(self, session, vm_ref):
602
return self._VM_reboot(session, vm_ref)
604
def VM_hard_reboot(self, session, vm_ref):
605
return self._VM_reboot(session, vm_ref)
540
607
def VM_hard_shutdown(self, session, vm_ref):
541
608
db_ref = _db_content['VM'][vm_ref]
551
618
def pool_set_name_label(self, session, pool_ref, name):
621
def host_migrate_receive(self, session, destref, nwref, options):
622
# The dictionary below represents the true keys, as
623
# returned by a destination host, but fake values.
624
return {'xenops': 'http://localhost/services/xenops?'
625
'session_id=OpaqueRef:81d00b97-b205-b34d-924e-6f9597854cc0',
626
'host': 'OpaqueRef:5e4a3dd1-b71c-74ba-bbc6-58ee9ff6a889',
627
'master': 'http://localhost/',
628
'session_id': 'OpaqueRef:81d00b97-b205-b34d-924e-6f9597854cc0',
629
'SM': 'http://localhost/services/SM?'
630
'session_id=OpaqueRef:81d00b97-b205-b34d-924e-6f9597854cc0'}
632
def VM_assert_can_migrate(self, session, vmref, migrate_data, live,
633
vdi_map, vif_map, options):
636
def VM_migrate_send(self, session, mref, migrate_data, live, vdi_map,
554
640
def network_get_all_records_where(self, _1, filter):
555
641
return self.xenapi.network.get_all_records()