Esempio n. 1
0
File: v2v.py Progetto: zofuthan/vdsm
def get_external_vms(uri, username, password):
    if not supported():
        return errCode["noimpl"]

    conn = libvirtconnection.open_connection(uri=uri,
                                             username=username,
                                             passwd=password)
    with closing(conn):
        ret = []
        for vm in conn.listAllDomains():
            root = ET.fromstring(vm.XMLDesc(0))
            params = {}
            _add_vm_info(vm, params)
            try:
                _add_general_info(root, params)
            except InvalidVMConfiguration as e:
                logging.error('error parsing domain xml, msg: %s  xml: %s',
                              e.message, vm.XMLDesc(0))
                continue
            _add_networks(root, params)
            _add_disks(root, params)
            for disk in params['disks']:
                _add_disk_info(conn, disk)
            ret.append(params)
        return ret
Esempio n. 2
0
def get_external_vms(uri, username, password, vm_names=None):
    if vm_names is not None:
        if not vm_names:
            vm_names = None
        else:
            vm_names = frozenset(vm_names)

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.exception('error connecting to hypervisor')
        return {
            'status': {
                'code': errCode['V2VConnection']['status']['code'],
                'message': str(e)
            }
        }

    with closing(conn):
        vms = []
        for vm in _list_domains(conn):
            if vm_names is not None and vm.name() not in vm_names:
                # Skip this VM.
                continue
            elif conn.getType() == "ESX" and _vm_has_snapshot(vm):
                logging.error(
                    "vm %r has snapshots and therefore can not be "
                    "imported since snapshot conversion is not "
                    "supported for VMware", vm.name())
                continue
            _add_vm(conn, vms, vm)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 3
0
    def _source_images(self):
        con = libvirtconnection.open_connection(uri=self._uri,
                                                username=self._username,
                                                passwd=self._password)

        with closing(con):
            vm = con.lookupByName(self._vminfo['vmName'])
            if vm:
                params = {}
                root = ET.fromstring(vm.XMLDesc(0))
                _add_disks(root, params)
                src = []
                fmt = []
                for disk in params['disks']:
                    disk_info = _get_disk_info(con, disk, vm)
                    if disk_info is None:
                        break
                    disk.update(disk_info)
                    if 'vol-key' in disk:
                        src.append(disk['vol-key'])
                        fmt.append('volume')
                    elif 'alias' in disk:
                        src.append(disk['alias'])
                        fmt.append('path')
                return src, fmt
Esempio n. 4
0
File: v2v.py Progetto: nickxiao/vdsm
def get_external_vms(uri, username, password):
    if not supported():
        return errCode["noimpl"]

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connection to hypervisor: %r', e.message)
        return {'status': {'code': errCode['V2VConnection']['status']['code'],
                           'message': e.message}}

    with closing(conn):
        vms = []
        for vm in conn.listAllDomains():
            root = ET.fromstring(vm.XMLDesc(0))
            params = {}
            _add_vm_info(vm, params)
            try:
                _add_general_info(root, params)
            except InvalidVMConfiguration as e:
                logging.error('error parsing domain xml, msg: %s  xml: %s',
                              e.message, vm.XMLDesc(0))
                continue
            _add_networks(root, params)
            _add_disks(root, params)
            for disk in params['disks']:
                _add_disk_info(conn, disk)
            vms.append(params)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 5
0
def get_external_vms(uri, username, password, vm_names=None):
    if vm_names is not None:
        if not vm_names:
            vm_names = None
        else:
            vm_names = frozenset(vm_names)

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connection to hypervisor: %r', e.message)
        return {
            'status': {
                'code': errCode['V2VConnection']['status']['code'],
                'message': e.message
            }
        }

    with closing(conn):
        vms = []
        for vm in _list_domains(conn):
            if vm_names is not None and vm.name() not in vm_names:
                # Skip this VM.
                continue
            _add_vm(conn, vms, vm)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 6
0
File: v2v.py Progetto: EdDev/vdsm
def get_external_vms(uri, username, password, vm_names=None):
    if vm_names is not None:
        if not vm_names:
            vm_names = None
        else:
            vm_names = frozenset(vm_names)

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.exception('error connecting to hypervisor')
        return {'status': {'code': errCode['V2VConnection']['status']['code'],
                           'message': str(e)}}

    with closing(conn):
        vms = []
        for vm in _list_domains(conn):
            if vm_names is not None and vm.name() not in vm_names:
                # Skip this VM.
                continue
            elif conn.getType() == "ESX" and _vm_has_snapshot(vm):
                logging.error("vm %r has snapshots and therefore can not be "
                              "imported since snapshot conversion is not "
                              "supported for VMware", vm.name())
                continue
            _add_vm(conn, vms, vm)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 7
0
File: v2v.py Progetto: eprasad/vdsm
def get_external_vms(uri, username, password):
    if not supported():
        return errCode["noimpl"]

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connection to hypervisor: %r', e.message)
        return {
            'status': {
                'code': errCode['V2VConnection']['status']['code'],
                'message': e.message
            }
        }

    with closing(conn):
        vms = []
        for vm in conn.listAllDomains():
            root = ET.fromstring(vm.XMLDesc(0))
            params = {}
            _add_vm_info(vm, params)
            try:
                _add_general_info(root, params)
            except InvalidVMConfiguration as e:
                logging.error('error parsing domain xml, msg: %s  xml: %s',
                              e.message, vm.XMLDesc(0))
                continue
            _add_networks(root, params)
            _add_disks(root, params)
            for disk in params['disks']:
                _add_disk_info(conn, disk)
            vms.append(params)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 8
0
def get_external_vm_names(uri, username, password):
    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.exception('error connecting to hypervisor')
        return response.error('V2VConnection', str(e))

    with closing(conn):
        vms = [vm.name() for vm in _list_domains(conn)]
        return response.success(vmNames=vms)
Esempio n. 9
0
def get_external_vm_names(uri, username, password):
    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connecting to hypervisor: %r', e.message)
        return response.error('V2VConnection', e.message)

    with closing(conn):
        vms = [vm.name() for vm in _list_domains(conn)]
        return response.success(vmNames=vms)
Esempio n. 10
0
File: v2v.py Progetto: kanalun/vdsm
def get_external_vms(uri, username, password):
    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connection to hypervisor: %r', e.message)
        return {'status': {'code': errCode['V2VConnection']['status']['code'],
                           'message': e.message}}

    with closing(conn):
        vms = []
        for vm in _list_domains(conn):
            _add_vm(conn, vms, vm)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 11
0
    def _source_images(self):
        con = libvirtconnection.open_connection(uri=self._uri,
                                                username=self._username,
                                                passwd=self._password)

        with closing(con):
            vm = con.lookupByName(self._vminfo['vmName'])
            if vm:
                params = {}
                root = ET.fromstring(vm.XMLDesc(0))
                _add_disks(root, params)
                ret = []
                for disk in params['disks']:
                    if 'alias' in disk:
                        ret.append(disk['alias'])
                return ret
Esempio n. 12
0
    def _source_images(self):
        con = libvirtconnection.open_connection(uri=self._uri,
                                                username=self._username,
                                                passwd=self._password)

        with closing(con):
            vm = con.lookupByName(self._vminfo['vmName'])
            if vm:
                params = {}
                root = ET.fromstring(vm.XMLDesc(0))
                _add_disks(root, params)
                ret = []
                for disk in params['disks']:
                    if 'alias' in disk:
                        ret.append(disk['alias'])
                return ret
Esempio n. 13
0
def main(argv=None):
    global _start
    _start = time.monotonic_time()

    options = arguments(argv or sys.argv)
    validate_disks(options)

    con = libvirtconnection.open_connection(options.uri, options.username,
                                            get_password(options))

    write_output('preparing for copy')
    disks = itertools.izip(options.source, options.dest, options.storagetype)
    for diskno, (src, dst, fmt) in enumerate(disks, start=1):
        if fmt == 'volume':
            handle_volume(con, diskno, src, dst, options)
        elif fmt == 'path':
            handle_path(con, diskno, src, dst, options)
        diskno = diskno + 1
    write_output('Finishing off')
Esempio n. 14
0
def main(argv=None):
    global _start
    _start = time.monotonic_time()

    options = arguments(argv or sys.argv)
    validate_disks(options)

    con = libvirtconnection.open_connection(options.uri,
                                            options.username,
                                            get_password(options))

    write_output('preparing for copy')
    disks = itertools.izip(options.source, options.dest, options.storagetype)
    for diskno, (src, dst, fmt) in enumerate(disks, start=1):
        if fmt == 'file':
            handle_file(con, diskno, src, dst, options)
        elif fmt == 'block':
            handle_block(con, diskno, src, dst, options)
        diskno = diskno + 1
    write_output('Finishing off')
Esempio n. 15
0
File: v2v.py Progetto: fancyKai/vdsm
def get_external_vms(uri, username, password):
    if not supported():
        return errCode["noimpl"]

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connection to hypervisor: %r', e.message)
        return {
            'status': {
                'code': errCode['V2VConnection']['status']['code'],
                'message': e.message
            }
        }

    with closing(conn):
        vms = []
        for vm in conn.listAllDomains():
            _add_vm(conn, vms, vm)
        return {'status': doneCode, 'vmList': vms}
Esempio n. 16
0
def get_external_vms(uri, username, password, vm_names=None):
    if vm_names is not None:
        if not vm_names:
            vm_names = None
        else:
            vm_names = frozenset(vm_names)

    try:
        conn = libvirtconnection.open_connection(uri=uri,
                                                 username=username,
                                                 passwd=password)
    except libvirt.libvirtError as e:
        logging.error('error connection to hypervisor: %r', e.message)
        return {'status': {'code': errCode['V2VConnection']['status']['code'],
                           'message': e.message}}

    with closing(conn):
        vms = []
        for vm in _list_domains(conn):
            if vm_names is not None and vm.name() not in vm_names:
                # Skip this VM.
                continue
            _add_vm(conn, vms, vm)
        return {'status': doneCode, 'vmList': vms}