'Fakes a VM clone.'

def _clone_vm(self, method, *args, **kwargs):

    'Creates    and    registers    a    VM    object    with    the    Host    System.'
    source_vmref = args[0]
    source_vm_mdo = _get_vm_mdo(source_vmref)
    clone_spec = kwargs.get('spec')
    vm_dict = {'name': kwargs.get('name'), 'ds': source_vm_mdo.get('datastore'), 'runtime_host': source_vm_mdo.get('runtime.host'), 'powerstate': source_vm_mdo.get('runtime.powerState'), 'vmPathName': source_vm_mdo.get('config.files.vmPathName'), 'numCpu': source_vm_mdo.get('summary.config.numCpu'), 'mem': source_vm_mdo.get('summary.config.memorySizeMB'), 'extra_config': source_vm_mdo.get('config.extraConfig').OptionValue, 'virtual_device': source_vm_mdo.get('config.hardware.device').VirtualDevice, 'instanceUuid': source_vm_mdo.get('summary.config.instanceUuid')}
    if hasattr(clone_spec, 'config'):
        if (hasattr(clone_spec.config, 'instanceUuid') and (clone_spec.config.instanceUuid is not None)):
            vm_dict['instanceUuid'] = clone_spec.config.instanceUuid
        if hasattr(clone_spec.config, 'extraConfig'):
            extraConfigs = _merge_extraconfig(vm_dict['extra_config'], clone_spec.config.extraConfig)
            vm_dict['extra_config'] = extraConfigs
    virtual_machine = VirtualMachine(**vm_dict)
    _create_object('VirtualMachine', virtual_machine)
    task_mdo = create_task(method, 'success')
    return task_mdo.obj
