~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/fake.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
    vm_rec = _db_content['VM'][vm_ref]
128
128
 
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
 
131
    # from the list
 
132
    for vbd_ref in vbd_refs[:]:
131
133
        destroy_vbd(vbd_ref)
132
134
 
133
135
    del _db_content['VM'][vm_ref]
134
136
 
135
137
 
136
138
def destroy_vbd(vbd_ref):
 
139
    vbd_rec = _db_content['VBD'][vbd_ref]
 
140
 
 
141
    vm_ref = vbd_rec['VM']
 
142
    vm_rec = _db_content['VM'][vm_ref]
 
143
    vm_rec['VBDs'].remove(vbd_ref)
 
144
 
 
145
    vdi_ref = vbd_rec['VDI']
 
146
    vdi_rec = _db_content['VDI'][vdi_ref]
 
147
    vdi_rec['VBDs'].remove(vbd_ref)
 
148
 
137
149
    del _db_content['VBD'][vbd_ref]
138
150
 
139
151
 
140
152
def destroy_vdi(vdi_ref):
 
153
    vdi_rec = _db_content['VDI'][vdi_ref]
 
154
 
 
155
    vbd_refs = vdi_rec['VBDs']
 
156
    # NOTE(johannes): Shallow copy since destroy_vbd will remove itself
 
157
    # from the list
 
158
    for vbd_ref in vbd_refs[:]:
 
159
        destroy_vbd(vbd_ref)
 
160
 
141
161
    del _db_content['VDI'][vdi_ref]
142
162
 
143
163
 
155
175
        'sm_config': {},
156
176
        'physical_utilisation': '123',
157
177
        'managed': True,
158
 
        'VBDs': {},
159
178
    }
160
179
    vdi_rec.update(kwargs)
161
 
    return _create_object('VDI', vdi_rec)
 
180
    vdi_ref = _create_object('VDI', vdi_rec)
 
181
    after_VDI_create(vdi_ref, vdi_rec)
 
182
    return vdi_ref
 
183
 
 
184
 
 
185
def after_VDI_create(vdi_ref, vdi_rec):
 
186
    vdi_rec.setdefault('VBDs', [])
162
187
 
163
188
 
164
189
def create_vbd(vm_ref, vdi_ref, userdevice=0):
172
197
 
173
198
 
174
199
def after_VBD_create(vbd_ref, vbd_rec):
175
 
    """Create read-only fields and backref from VM to VBD when VBD is
176
 
    created."""
 
200
    """Create read-only fields and backref from VM and VDI to VBD when VBD
 
201
    is created."""
177
202
    vbd_rec['currently_attached'] = False
178
203
    vbd_rec['device'] = ''
 
204
 
179
205
    vm_ref = vbd_rec['VM']
180
206
    vm_rec = _db_content['VM'][vm_ref]
181
207
    vm_rec['VBDs'].append(vbd_ref)
182
208
 
 
209
    vdi_ref = vbd_rec['VDI']
 
210
    vdi_rec = _db_content['VDI'][vdi_ref]
 
211
    vdi_rec['VBDs'].append(vbd_ref)
 
212
 
183
213
    vm_name_label = _db_content['VM'][vm_ref]['name_label']
184
214
    vbd_rec['vm_name_label'] = vm_name_label
185
215
 
262
292
                              'physical': True,
263
293
                              'VLAN': -1,
264
294
                              'device': 'fake0',
265
 
                              'host_uuid': host_ref})
 
295
                              'host_uuid': host_ref,
 
296
                              'network': ''})
266
297
    return pif_ref
267
298
 
268
299
 
458
489
            db_ref['xenstore_data'] = {}
459
490
        db_ref['xenstore_data'][key] = value
460
491
 
 
492
    def VM_pool_migrate(self, _1, vm_ref, host_ref, options):
 
493
        pass
 
494
 
 
495
    def VM_migrate_send(self, vmref, migrate_data, islive, vdi_map,
 
496
                        vif_map, options):
 
497
        pass
 
498
 
461
499
    def VDI_remove_from_other_config(self, _1, vdi_ref, key):
462
500
        db_ref = _db_content['VDI'][vdi_ref]
463
501
        if not 'other_config' in db_ref:
469
507
        db_ref = _db_content['VDI'][vdi_ref]
470
508
        if not 'other_config' in db_ref:
471
509
            db_ref['other_config'] = {}
 
510
        if key in db_ref['other_config']:
 
511
            raise Failure(['MAP_DUPLICATE_KEY', 'VDI', 'other_config',
 
512
                           vdi_ref, key])
472
513
        db_ref['other_config'][key] = value
473
514
 
474
515
    def VDI_copy(self, _1, vdi_to_copy_ref, sr_ref):
489
530
        #Always return 12GB available
490
531
        return 12 * 1024 * 1024 * 1024
491
532
 
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'):
502
 
            return ''
503
 
        elif (plugin, method) == ('kernel', 'copy_vdi'):
504
 
            return ''
505
 
        elif (plugin, method) == ('kernel', 'create_kernel_ramdisk'):
506
 
            return ''
507
 
        elif (plugin, method) == ('kernel', 'remove_kernel_ramdisk'):
508
 
            return ''
509
 
        elif (plugin, method) == ('migration', 'move_vhds_into_sr'):
510
 
            return ''
511
 
        elif (plugin, method) == ('migration', 'transfer_vhd'):
512
 
            return ''
513
 
        elif (plugin, method) == ('xenhost', 'host_data'):
 
533
    def _plugin_agent_version(self, method, args):
 
534
        return as_json(returncode='0', message='1.0')
 
535
 
 
536
    def _plugin_agent_key_init(self, method, args):
 
537
        return as_json(returncode='D0', message='1')
 
538
 
 
539
    def _plugin_agent_password(self, method, args):
 
540
        return as_json(returncode='0', message='success')
 
541
 
 
542
    def _plugin_agent_inject_file(self, method, args):
 
543
        return as_json(returncode='0', message='success')
 
544
 
 
545
    def _plugin_agent_resetnetwork(self, method, args):
 
546
        return as_json(returncode='0', message='success')
 
547
 
 
548
    def _plugin_noop(self, method, args):
 
549
        return ''
 
550
 
 
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
 
557
 
 
558
    def _plugin_xenhost_host_data(self, method, args):
514
559
            return jsonutils.dumps({'host_memory': {'total': 10,
515
560
                                                    'overhead': 20,
516
561
                                                    'free': 30,
517
 
                                                    'free-computed': 40}, })
518
 
        elif (plugin == 'xenhost' and method in ['host_reboot',
519
 
                                                 'host_startup',
520
 
                                                 'host_shutdown']):
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})
525
 
        else:
 
562
                                                    'free-computed': 40}})
 
563
 
 
564
    def _plugin_poweraction(self, method, args):
 
565
        return jsonutils.dumps({"power_action": method[5:]})
 
566
 
 
567
    _plugin_xenhost_host_reboot = _plugin_poweraction
 
568
    _plugin_xenhost_host_startup = _plugin_poweraction
 
569
    _plugin_xenhost_host_shutdown = _plugin_poweraction
 
570
 
 
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})
 
574
 
 
575
    def _plugin_xenhost_host_uptime(self, method, args):
 
576
        return jsonutils.dumps({"uptime": "fake uptime"})
 
577
 
 
578
    def host_call_plugin(self, _1, _2, plugin, method, args):
 
579
        func = getattr(self, '_plugin_%s_%s' % (plugin, method), None)
 
580
        if not func:
526
581
            raise Exception('No simulation in host_call_plugin for %s,%s' %
527
582
                            (plugin, method))
528
583
 
 
584
        return func(method, args)
 
585
 
529
586
    def VDI_get_virtual_size(self, *args):
530
587
        return 1 * 1024 * 1024 * 1024
531
588
 
534
591
 
535
592
    VDI_resize = VDI_resize_online
536
593
 
 
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'
 
600
 
537
601
    def VM_clean_reboot(self, session, vm_ref):
538
 
        pass
 
602
        return self._VM_reboot(session, vm_ref)
 
603
 
 
604
    def VM_hard_reboot(self, session, vm_ref):
 
605
        return self._VM_reboot(session, vm_ref)
539
606
 
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):
552
619
        pass
553
620
 
 
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'}
 
631
 
 
632
    def VM_assert_can_migrate(self, session, vmref, migrate_data, live,
 
633
                              vdi_map, vif_map, options):
 
634
        pass
 
635
 
 
636
    def VM_migrate_send(self, session, mref, migrate_data, live, vdi_map,
 
637
                        vif_map, options):
 
638
        pass
 
639
 
554
640
    def network_get_all_records_where(self, _1, filter):
555
641
        return self.xenapi.network.get_all_records()
556
642
 
725
811
        ref = params[1]
726
812
        if ref not in _db_content[table]:
727
813
            raise Failure(['HANDLE_INVALID', table, ref])
728
 
        del _db_content[table][ref]
 
814
 
 
815
        # Call destroy function (if exists)
 
816
        destroy_func = globals().get('destroy_%s' % table.lower())
 
817
        if destroy_func:
 
818
            destroy_func(ref)
 
819
        else:
 
820
            del _db_content[table][ref]
729
821
 
730
822
    def _async(self, name, params):
731
823
        task_ref = create_task(name)