Shahar Havivi has uploaded a new change for review. Change subject: v2v: add support for importing kvm based vms from libvirt ......................................................................
v2v: add support for importing kvm based vms from libvirt Change-Id: I0ddbab700f2e0c54d53ed02ec61477b92c9c7960 Signed-off-by: Shahar Havivi <[email protected]> --- M lib/vdsm/constants.py.in M lib/vdsm/v2v.py 2 files changed, 69 insertions(+), 20 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/56459/1 diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in index 7f3962d..29a208d 100644 --- a/lib/vdsm/constants.py.in +++ b/lib/vdsm/constants.py.in @@ -152,4 +152,5 @@ EXT_CURL_IMG_WRAP = '@LIBEXECDIR@/curl-img-wrap' EXT_FC_SCAN = '@LIBEXECDIR@/fc-scan' +EXT_KVM_2_OVIRT = '@LIBEXECDIR@/kvm2ovirt' EXT_SYSTEMD_RUN = '@SYSTEMD_RUN_PATH@' diff --git a/lib/vdsm/v2v.py b/lib/vdsm/v2v.py index f96bda6..0336102 100644 --- a/lib/vdsm/v2v.py +++ b/lib/vdsm/v2v.py @@ -41,7 +41,7 @@ import libvirt from vdsm.commands import execCmd -from vdsm.constants import P_VDSM_RUN +from vdsm.constants import P_VDSM_RUN, EXT_KVM_2_OVIRT from vdsm.define import errCode, doneCode from vdsm import libvirtconnection, response, concurrent from vdsm.infra import zombiereaper @@ -56,6 +56,7 @@ _SSH_AGENT = CommandPath('ssh-agent', '/usr/bin/ssh-agent') _SSH_ADD = CommandPath('ssh-add', '/usr/bin/ssh-add') _XEN_SSH_PROTOCOL = 'xen+ssh' +_VMWARE_PROTOCOL = 'vpx' _SSH_AUTH_RE = '(SSH_AUTH_SOCK)=([^;]+).*;\nSSH_AGENT_PID=(\d+)' _OVF_RESOURCE_CPU = 3 _OVF_RESOURCE_MEMORY = 4 @@ -155,8 +156,10 @@ def convert_external_vm(uri, username, password, vminfo, job_id, irs): if uri.startswith(_XEN_SSH_PROTOCOL): command = XenCommand(uri, vminfo, job_id, irs) - else: + elif uri.startswith(_VMWARE_PROTOCOL): command = LibvirtCommand(uri, username, password, vminfo, job_id, irs) + else: + command = KVMCommand(uri, username, password, vminfo, job_id, irs) job = ImportVm(job_id, command) job.start() _add_job(job_id, job) @@ -347,6 +350,8 @@ self._irs = irs self._prepared_volumes = [] + self._passwd_file = os.path.join(_V2V_DIR, "%s.tmp" % vmid) + def execute(self): raise NotImplementedError("Subclass must implement this") @@ -427,6 +432,22 @@ env['VIRTIO_WIN'] = self._vminfo['virtio_iso_path'] return env + @contextmanager + def _password_file(self): + fd = os.open(self._passwd_file, os.O_WRONLY | os.O_CREAT, 0o600) + try: + os.write(fd, self._password.value) + finally: + os.close(fd) + try: + yield + finally: + try: + os.remove(self._passwd_file) + except Exception: + logging.exception("Job %r error removing passwd file: %s", + self._vmid, self._passwd_file) + class LibvirtCommand(V2VCommand): def __init__(self, uri, username, password, vminfo, vmid, irs): @@ -434,8 +455,6 @@ self._uri = uri self._username = username self._password = password - - self._passwd_file = os.path.join(_V2V_DIR, "%s.tmp" % vmid) def _command(self): cmd = [_VIRT_V2V.cmd, @@ -461,22 +480,6 @@ def execute(self): with self._volumes(), self._password_file(): yield self._start_virt_v2v() - - @contextmanager - def _password_file(self): - fd = os.open(self._passwd_file, os.O_WRONLY | os.O_CREAT, 0o600) - try: - os.write(fd, self._password.value) - finally: - os.close(fd) - try: - yield - finally: - try: - os.remove(self._passwd_file) - except Exception: - logging.exception("Job %r error removing passwd file: %s", - self._vmid, self._passwd_file) class OvaCommand(V2VCommand): @@ -551,6 +554,51 @@ return env +class KVMCommand(V2VCommand): + def __init__(self, uri, username, password, vminfo, vmid, irs): + super(KVMCommand, self).__init__(vminfo, vmid, irs) + self._uri = uri + self._username = username + self._password = password + + def _command(self): + cmd = [EXT_KVM_2_OVIRT, + '--uri', self._uri, + '--username', self._username, + '--password-file', self._passwd_file, + '--source', self._source_images(), + '--dest', self._dest_images()] + return cmd + + @contextmanager + def execute(self): + with self._volumes(), self._password_file(): + yield self._start_virt_v2v() + + 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 ' '.join(ret) + + def _dest_images(self): + ret = [] + for vol in self._prepared_volumes: + ret.append(vol['path']) + return ' '.join(ret) + + class ImportVm(object): TERM_DELAY = 30 PROC_WAIT_TIMEOUT = 30 -- To view, visit https://gerrit.ovirt.org/56459 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0ddbab700f2e0c54d53ed02ec61477b92c9c7960 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Shahar Havivi <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
