Ejemplo n.º 1
0
        vnet_driver = virthost.vnet_driver
        virt_driver = virthost.virt_driver

        log.info("Start to create VMs in server: %s", hostname)
        for vm in server['vms']:
            vmname = vm['vmname']
            log.info("Start to create vm [%s]!", vmname)
            ret = virthost.create_vm(vmname, vm['template'])
            if not ret:
                log.fail("Failed to create VM [%s].Exiting....", vmname)
                exit(1)
            log.info("New instance [%s] created successfully.", vmname)

            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']:
Ejemplo n.º 2
0
                exit(1)
            if size >= storage_info['size_free'] - 1:
                log.fail(
                    "No enough volume on storage:[%s], at most [%s] GB is available",
                    options.storage_name, storage_info['size_free'] - 1)
                exit(1)

        # 1. create VM
        ret = virthost.create_vm(new_vm_name, template_name)
        if not ret:
            log.fail("Failed to create VM [%s].Exiting....", new_vm_name)
            exit(1)
        log.info("New instance [%s] created successfully.", new_vm_name)

        # 2. config cpu cores and memory
        ret = virthost.config_vcpus(new_vm_name, vcpu_max=max_cores)
        if not ret:
            log.warn("Config VCPU cores failed, keep same as before...")

        log.debug("memory_size:%s, min_memory:%s, max_memory:%s", memory_size,
                  min_memory, max_memory)
        if max_memory:
            ret = virthost.config_max_memory(new_vm_name,
                                             static_max=max_memory)
            if not ret:
                log.warning(
                    "Configure max memory size failed, keep same as before...")
        if min_memory:
            ret = virthost.config_min_memory(new_vm_name,
                                             static_min=min_memory)
            if not ret:
Ejemplo n.º 3
0
                     size, inst_name)
            exit(1)

    elif options.cpu_cores is not None or options.max_cores is not None:
        cpu_cores, max_cores = None, None
        try:
            if options.cpu_cores is not None:
                cpu_cores = int(options.cpu_cores)
            if options.max_cores is not None:
                max_cores = int(options.max_cores)
        except ValueError:
            log.fail("Please input a integer for cpu cores.")
            exit(1)

        ret = virthost.config_vcpus(inst_name,
                                    vcpu_nums=cpu_cores,
                                    vcpu_max=max_cores)
        if ret:
            log.success("Config VCPU cores successfully.")
            exit(0)
        else:
            log.fail("Config VCPU cores failed.")
            exit(1)

    elif options.memory_size is not None or options.min_memory is not None or options.max_memory is not None:
        memory_size, min_memory, max_memory = None, None, None
        try:
            if options.memory_size is not None:
                memory_size = float(options.memory_size)
            if options.min_memory is not None:
                min_memory = float(options.min_memory)
Ejemplo n.º 4
0
    template_name = config_dict[role_name]["template"]
    if template_name not in virt_driver.get_templates_list():
        log.fail("No template named: %s", template_name)
        exit(1)
    ret = virthost.create_vm(new_vm_name, template_name)
    if not ret:
        log.fail("Failed to create VM [%s].Exiting....", new_vm_name)
        exit(1)

    log.info("New instance [%s] created successfully.", new_vm_name)

    # config cpu cores and memory
    memory, cpu_cores = config_dict[role_name]["memory"], config_dict[
        role_name]["cpu"]
    ret = virthost.config_vcpus(new_vm_name,
                                vcpu_max=cpu_cores,
                                vcpu_nums=cpu_cores)
    if not ret:
        log.warn("Config VCPU cores failed, keep same as before...")

    log.debug("memory_size:%s, min_memory:%s, max_memory:%s", memory, memory,
              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)