Ejemplo n.º 1
0
def import_vm_to_ovirt(params, address_cache, timeout=600):
    """
    Import VM from export domain to oVirt Data Center
    """
    vm_name = params.get('main_vm')
    os_type = params.get('os_type')
    export_name = params.get('export_name')
    storage_name = params.get('storage_name')
    cluster_name = params.get('cluster_name')
    output_method = params.get('output_method')
    # Check oVirt status
    dc = ovirt.DataCenterManager(params)
    logging.info("Current data centers list: %s", dc.list())
    cm = ovirt.ClusterManager(params)
    logging.info("Current cluster list: %s", cm.list())
    hm = ovirt.HostManager(params)
    logging.info("Current host list: %s", hm.list())
    sdm = ovirt.StorageDomainManager(params)
    logging.info("Current storage domain list: %s", sdm.list())
    vm = ovirt.VMManager(vm_name, params, address_cache=address_cache)
    logging.info("Current VM list: %s", vm.list())
    if vm_name in vm.list() and output_method != 'rhv_upload':
        logging.error("%s already exist", vm_name)
        return False
    wait_for_up = True
    if os_type == 'windows':
        wait_for_up = False

    # If output_method is None or "" or is not 'rhv_upload', treat it as
    # old way.
    if output_method != 'rhv_upload':
        try:
            # Import VM
            vm.import_from_export_domain(export_name,
                                         storage_name,
                                         cluster_name,
                                         timeout=timeout)
            logging.info("The latest VM list: %s", vm.list())
        except Exception as e:
            # Try to delete the vm from export domain
            vm.delete_from_export_domain(export_name)
            logging.error("Import %s failed: %s", vm.name, e)
            return False
    try:
        # Start VM
        vm.start(wait_for_up=wait_for_up)
    except Exception as e:
        logging.error("Start %s failed: %s", vm.name, e)
        return False
    return True
Ejemplo n.º 2
0
def run(test, params, env):
    """
    Test ovirt class
    """

    args_dict = get_args_dict(params)
    logging.debug("arguments dictionary: %s" % args_dict)

    vm_name = params.get('vm_name')
    export_name = params.get('export_name')
    storage_name = params.get('storage_name')
    cluster_name = params.get('cluster_name')
    address_cache = env.get('address_cache')

    # Run test case
    vm = ovirt.VMManager(params, address_cache)
    dc = ovirt.DataCenterManager(params)
    cls = ovirt.ClusterManager(params)
    ht = ovirt.HostManager(params)
    sd = ovirt.StorageDomainManager(params)

    logging.info("Current data centers list: %s" % dc.list())
    logging.info("Current cluster list: %s" % cls.list())
    logging.info("Current host list: %s" % ht.list())
    logging.info("Current storage domain list: %s" % sd.list())
    logging.info("Current vm list: %s" % vm.list())

    vm.import_from_export_domain(export_name, storage_name, cluster_name)
    logging.info("Current vm list: %s" % vm.list())

    vm.start()

    if vm.is_alive():
        logging.info("The %s is alive" % vm_name)

    vm.suspend()
    vm.resume()
    vm.shutdown()

    if vm.is_dead():
        logging.info("The %s is dead" % vm_name)