コード例 #1
0
ファイル: setup_vms.py プロジェクト: lowang-bh/dev_virt
            log.info("Start to config vm [%s].", vmname)

            virthost.config_vcpus(vmname, vcpu_max=vm['cpumax'])
            if vm['maxMemory']:
                virthost.config_max_memory(vmname, static_max=vm['maxMemory'])
            if vm['minMemory']:
                virthost.config_min_memory(vmname, static_min=vm['minMemory'])
            if vm['memory']:
                virthost.config_memory(vmname,
                                       dynamic_min=vm['memory'],
                                       dynamic_max=vm['memory'])

            for ipdic in vm['ips']:
                virthost.config_vif(vmname, ipdic['vifIndex'], ipdic['device'],
                                    ipdic['network'], ipdic['bridge'],
                                    ipdic['ip'])

            for diskdic in vm['disks']:
                storage = diskdic['storage']
                if not storage:
                    storage = virthost.get_max_free_size_storage(
                    )  # calc the default sr online
                virthost.add_vm_disk(vmname, storage, diskdic['size'])

            ret = virthost.power_on_vm(vmname)
            if not ret:
                log.warn(
                    "Create VM [%s] successfully, but power on vm return False.",
                    vmname)
            else:
コード例 #2
0
ファイル: create_vm.py プロジェクト: lishuo3331/dev_virt
                                             static_min=min_memory)
            if not ret:
                log.warn(
                    "Config min memory size failed, keep same as before...")
        if memory_size:
            ret = virthost.config_memory(new_vm_name,
                                         dynamic_min=memory_size,
                                         dynamic_max=memory_size)
            if not ret:
                log.warn(
                    "Config target memory size failed, keep same as before...")

        # 3. config VM IP
        if options.vif_ip is not None:
            config_ret = virthost.config_vif(new_vm_name, options.vif_index,
                                             options.device, options.network,
                                             options.bridge, options.vif_ip)
            if not config_ret:
                log.warn("Vif configure failed.")
            else:
                log.info(
                    "Successfully configured the virtual interface device [%s] to VM [%s].",
                    options.vif_index, new_vm_name)
        # 4. config VM disk
        if options.disk_size is not None:
            ret = virthost.add_vm_disk(new_vm_name,
                                       storage_name=options.storage_name,
                                       size=size)
            if ret:
                log.info(
                    "Successfully add a new disk with size [%s]GB to VM [%s].",
コード例 #3
0
ファイル: config_vm.py プロジェクト: lishuo3331/dev_virt
                log.fail("Virtual interface with index %s already exist.",
                         vif_index)
                exit(1)

            if virthost.create_new_vif(inst_name, vif_index, device_name,
                                       network, bridge, options.vif_ip):
                log.success(
                    "New virtual interface device created successfully.")
                exit(0)
            else:
                log.fail(
                    "New virtual interface device created or attached failed.")
                exit(1)
        elif options.vif_index:
            vif_index = options.vif_index
            if virthost.config_vif(inst_name, vif_index, device_name, network,
                                   bridge, options.vif_ip):
                log.success(
                    "New virtual interface device configured successfully.")
                exit(0)
            else:
                log.fail("New virtual interface device configured failed.")
                exit(1)

    elif options.del_index is not None:
        vif_index = options.del_index

        ret = virthost.destroy_old_vif(inst_name, vif_index)
        if ret:
            log.success("Successfully delete the virtual interface device.")
            exit(0)
        else:
コード例 #4
0
ファイル: schedule_node.py プロジェクト: lowang-bh/dev_virt
              memory)
    ret = virthost.config_max_memory(new_vm_name, static_max=memory)
    if not ret:
        log.warn("Configure max memory size failed, keep same as before...")
    ret = virthost.config_min_memory(new_vm_name, static_min=memory)
    if not ret:
        log.warn("Config min memory size failed, keep same as before...")
    ret = virthost.config_memory(new_vm_name,
                                 dynamic_min=memory,
                                 dynamic_max=memory)
    if not ret:
        log.warn("Config target memory size failed, keep same as before...")

    # config IP
    ret = virthost.config_vif(new_vm_name,
                              "0",
                              network=DEFAULT_NETWORK,
                              ip=vm_ip)
    if not ret:
        log.warn("Vif configure failed.")
    else:
        log.info(
            "Successfully configured the virtual interface device [0] to VM [%s].",
            new_vm_name)

    # add disk
    if "add_disk_num" in config_dict[role_name]:
        add_disk_num = config_dict[role_name]["add_disk_num"]
        disk_size = config_dict[role_name]["disk_size"]
        while add_disk_num > 0:
            add_disk_num -= 1
            ret = virthost.add_vm_disk(new_vm_name,