Exemplo n.º 1
0
def clone_vm(conn, uuid, *args, **kwargs):
    settings = kwargs
    settings.update(args[0] if (
        len(args) == 1 and type(args[0]) is dict) else {})
    if conn.getType() == 'OpenVZ':
        # XXX: Perform vzmlocal -C ctid:new_ctid - this changes uuid of new VM.
        openvz.clone_vm(openvz.get_ctid_by_uuid(conn, uuid), settings['ctid'])

        # XXX: If user changed target ctid in edit form then openvz.update_vm()
        # would perform another vzmlocal move.
        settings['ctid_old'] = settings['ctid']
        param_name_map = {
            'cpu_limit': 'vcpulimit',
            'swap_size': 'swap',
            'num_cores': 'vcpu'
        }
        openvz_settings = {}
        openvz_settings.update(
            dict((param_name_map.get(key, key), value)
                 for key, value in settings.iteritems()))

        # XXX: uuid must be re-read from disk.
        openvz_settings['uuid'] = openvz.get_uuid_by_ctid(settings['ctid'])
        # XXX: connection to libvirt must be re-opened as old connection does
        # not know about newly created VM.
        conn = _connection(openvz_settings['vm_uri'])
        openvz.update_vm(conn, openvz_settings)
        return
    else:
        raise NotImplementedError("VM type '%s' is not (yet) supported" %
                                  conn.getType())
Exemplo n.º 2
0
def update_vm(conn, uuid, *args, **kwargs):
    """
    Update VM parameters
    """
    settings = kwargs
    # allows mixed passing via a dict and/or keyword args
    settings.update(args[0] if (len(args) == 1 and type(args[0]) is dict) else {})

    if conn.getType() == "OpenVZ":
        param_name_map = {"cpu_limit": "vcpulimit", "swap_size": "swap", "num_cores": "vcpu"}
        openvz_settings = {"uuid": uuid}
        openvz_settings.update(dict((param_name_map.get(key, key), value) for key, value in settings.iteritems()))
        openvz.update_vm(conn, openvz_settings)
        return

    dom = conn.lookupByUUIDString(uuid)

    action_map = {"num_cores": dom.setVcpus, "memory": dom.setMemory}

    # XXX: libvirt wants memory in KiB
    if "memory" in settings:
        settings["memory"] = float(settings["memory"]) * (1024 ** 2)

    def unknown_param(*args):
        logger = kwargs.get("logger", None)
        if logger:
            logger("Updating of one of the parameters supplied " "is not supported by libvirt: %s" % settings)

    for key, value in settings.iteritems():
        action_map.get(key, unknown_param)(value)
Exemplo n.º 3
0
def clone_vm(conn, uuid, *args, **kwargs):
    settings = kwargs
    settings.update(args[0] if (len(args) == 1 and
                                type(args[0]) is dict) else {})
    if conn.getType() == 'OpenVZ':
        # XXX: Perform vzmlocal -C ctid:new_ctid - this changes uuid of new VM.
        openvz.clone_vm(openvz.get_ctid_by_uuid(conn, uuid), settings['ctid'])

        # XXX: If user changed target ctid in edit form then openvz.update_vm()
        # would perform another vzmlocal move.
        settings['ctid_old'] = settings['ctid']
        param_name_map = {'cpu_limit': 'vcpulimit',
                          'swap_size': 'swap',
                          'num_cores': 'vcpu'}
        openvz_settings = {}
        openvz_settings.update(dict((param_name_map.get(key, key), value)
                                    for key, value in settings.iteritems()))

        # XXX: uuid must be re-read from disk.
        openvz_settings['uuid'] = openvz.get_uuid_by_ctid(settings['ctid'])
        openvz.update_vm(conn, openvz_settings)
        return
    else:
        raise NotImplementedError("VM type '%s' is not (yet) supported" %
                                  conn.getType())
Exemplo n.º 4
0
def update_vm(conn, uuid, *args, **kwargs):
    """
    Update VM parameters
    """
    settings = kwargs
    # allows mixed passing via a dict and/or keyword args
    settings.update(args[0] if (len(args) == 1 and type(args[0]) is dict) else {})

    if conn.getType() == 'OpenVZ':
        param_name_map = {'cpu_limit': 'vcpulimit',
                          'swap_size': 'swap',
                          'num_cores': 'vcpu'}
        openvz_settings = {'uuid': uuid}
        openvz_settings.update(dict((param_name_map.get(key, key), value)
                                    for key, value in settings.iteritems()))
        openvz.update_vm(conn, openvz_settings)
        return

    dom = conn.lookupByUUIDString(uuid)

    action_map = {'num_cores': dom.setVcpus, 'memory': dom.setMemory}

    # XXX: libvirt wants memory in KiB
    if 'memory' in settings:
        settings['memory'] = float(settings['memory']) * (1024 ** 2)

    def unknown_param(*args):
        logger = kwargs.get('logger', None)
        if logger:
            logger('Updating of one of the parameters supplied '
                   'is not supported by libvirt: %s' % settings)

    for key, value in settings.iteritems():
        action_map.get(key, unknown_param)(value)
Exemplo n.º 5
0
def update_vm(conn, uuid, *args, **kwargs):
    """
    Update VM parameters
    """
    settings = kwargs
    # allows mixed passing via a dict and/or keyword args
    settings.update(args[0] if (
        len(args) == 1 and type(args[0]) is dict) else {})

    if conn.getType() == 'OpenVZ':
        param_name_map = {
            'cpu_limit': 'vcpulimit',
            'swap_size': 'swap',
            'num_cores': 'vcpu'
        }
        openvz_settings = {'uuid': uuid}
        openvz_settings.update(
            dict((param_name_map.get(key, key), value)
                 for key, value in settings.iteritems()))
        openvz.update_vm(conn, openvz_settings)
        return

    dom = conn.lookupByUUIDString(uuid)

    action_map = {'num_cores': dom.setVcpus, 'memory': dom.setMemory}

    # XXX: libvirt wants memory in KiB
    if 'memory' in settings:
        settings['memory'] = float(settings['memory']) * (1024**2)

    def unknown_param(*args):
        logger = kwargs.get('logger', None)
        if logger:
            logger('Updating of one of the parameters supplied '
                   'is not supported by libvirt: %s' % settings)

    for key, value in settings.iteritems():
        action_map.get(key, unknown_param)(value)
Exemplo n.º 6
0
def clone_vm(conn, uuid, *args, **kwargs):
    settings = kwargs
    settings.update(args[0] if (len(args) == 1 and type(args[0]) is dict) else {})
    if conn.getType() == "OpenVZ":
        # XXX: Perform vzmlocal -C ctid:new_ctid - this changes uuid of new VM.
        openvz.clone_vm(openvz.get_ctid_by_uuid(conn, uuid), settings["ctid"])

        # XXX: If user changed target ctid in edit form then openvz.update_vm()
        # would perform another vzmlocal move.
        settings["ctid_old"] = settings["ctid"]
        param_name_map = {"cpu_limit": "vcpulimit", "swap_size": "swap", "num_cores": "vcpu"}
        openvz_settings = {}
        openvz_settings.update(dict((param_name_map.get(key, key), value) for key, value in settings.iteritems()))

        # XXX: uuid must be re-read from disk.
        openvz_settings["uuid"] = openvz.get_uuid_by_ctid(settings["ctid"])
        # XXX: connection to libvirt must be re-opened as old connection does
        # not know about newly created VM.
        conn = _connection(openvz_settings["vm_uri"])
        openvz.update_vm(conn, openvz_settings)
        return
    else:
        raise NotImplementedError("VM type '%s' is not (yet) supported" % conn.getType())