[PATCH] v2v: -o rhv-upload: Fix emulated zero
by Nir Soffer
Replace python 2 only "buffer" with "memoryview".
Falling back to emulated zero would fail with:
NameError: name 'buffer' is not defined
I did not test the changed code but it was not tested before so it is
unlikely to be worse.
Detected by pylint.
---
v2v/rhv-upload-plugin.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 3272c3ce3..12d4e68f7 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -416,41 +416,41 @@ def emulate_zero(h, count, offset):
transfer = h['transfer']
# qemu-img convert starts by trying to zero/trim the whole device.
# Since we've just created a new disk it's safe to ignore these
# requests as long as they are smaller than the highest write seen.
# After that we must emulate them with writes.
if offset+count < h['highestwrite']:
http.putrequest("PUT", h['path'])
if h['needs_auth']:
http.putheader("Authorization", transfer.signed_ticket)
http.putheader("Content-Range",
"bytes %d-%d/*" % (offset, offset+count-1))
http.putheader("Content-Length", str(count))
http.endheaders()
try:
buf = bytearray(128*1024)
while count > len(buf):
http.send(buf)
count -= len(buf)
- http.send(buffer(buf, 0, count))
+ http.send(memoryview(buf)[:count])
except BrokenPipeError:
pass
r = http.getresponse()
if r.status != 200:
request_failed(h, r,
"could not write zeroes offset %d size %d" %
(offset, count))
r.read()
def trim(h, count, offset):
http = h['http']
# Construct the JSON request for trimming.
buf = json.dumps({'op': "trim",
'offset': offset,
'size': count,
'flush': False}).encode()
--
2.17.2
5 years, 10 months
[PATCH] v2v: -o rhv-upload: Fix request headers in pread
by Nir Soffer
headers was initialized with a set literal {"key", "value"} instead of
dict literal {"key": "value"}.
Calling pread() will fail with:
AttributeError: 'set' object has no attribute 'items'
I did not test the changed code, but it was not tested before, so it is
unlikely to be worse.
Detected by pylint.
---
v2v/rhv-upload-plugin.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 3272c3ce3..e651bc686 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -321,41 +321,41 @@ def request_failed(h, r, msg):
body = "(Unable to read response body: %s)" % e
# Log the full error if we're verbose.
debug("unexpected response from imageio server:")
debug(msg)
debug("%d: %s" % (status, reason))
debug(body)
# Only a short error is included in the exception.
raise RuntimeError("%s: %d %s: %r" % (msg, status, reason, body[:200]))
# For documentation see:
# https://github.com/oVirt/ovirt-imageio/blob/master/docs/random-io.md
# For examples of working code to read/write from the server, see:
# https://github.com/oVirt/ovirt-imageio/blob/master/daemon/test/server_tes...
def pread(h, count, offset):
http = h['http']
transfer = h['transfer']
- headers = {"Range", "bytes=%d-%d" % (offset, offset+count-1)}
+ headers = {"Range": "bytes=%d-%d" % (offset, offset+count-1)}
if h['needs_auth']:
headers["Authorization"] = transfer.signed_ticket
http.request("GET", h['path'], headers=headers)
r = http.getresponse()
# 206 = HTTP Partial Content.
if r.status != 206:
request_failed(h, r,
"could not read sector offset %d size %d" %
(offset, count))
return r.read()
def pwrite(h, buf, offset):
http = h['http']
transfer = h['transfer']
count = len(buf)
h['highestwrite'] = max(h['highestwrite'], offset+count)
--
2.17.2
5 years, 10 months
[PATCH] v2v: -o rhv-upload: Fix upload when using https
by Nir Soffer
Fix rhv-cafile option access, broken by commit 6694028f9827 (v2v: -o
rhv-upload: Only set SSL context for https connections).
---
.gnulib | 2 +-
v2v/rhv-upload-plugin.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.gnulib b/.gnulib
index 6ccfbb4ce..646a44e1b 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit 6ccfbb4ce5d4fa79f7afb48f3648f2e0401523c3
+Subproject commit 646a44e1b190c4a7f6a9f32c63230c619e38d251
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 1a217b6dc..3272c3ce3 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -193,41 +193,41 @@ def open(readonly):
if transfer.phase != types.ImageTransferPhase.INITIALIZING:
break
if time.time() > endt:
raise RuntimeError("timed out waiting for transfer status "
"!= INITIALIZING")
# Now we have permission to start the transfer.
if params['rhv_direct']:
if transfer.transfer_url is None:
raise RuntimeError("direct upload to host not supported, "
"requires ovirt-engine >= 4.2 and only works "
"when virt-v2v is run within the oVirt/RHV "
"environment, eg. on an oVirt node.")
destination_url = urlparse(transfer.transfer_url)
else:
destination_url = urlparse(transfer.proxy_url)
if destination_url.scheme == "https":
context = \
ssl.create_default_context(purpose = ssl.Purpose.SERVER_AUTH,
- cafile = cafile)
+ cafile = params['rhv_cafile'])
if params['insecure']:
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
http = HTTPSConnection(
destination_url.hostname,
destination_url.port,
context = context
)
elif destination_url.scheme == "http":
http = HTTPConnection(
destination_url.hostname,
destination_url.port,
)
else:
raise RuntimeError("unknown URL scheme (%s)" % destination_url.scheme)
# The first request is to fetch the features of the server.
# Authentication was needed only for GET and PUT requests when
# communicating with old imageio-proxy.
--
2.17.2
5 years, 10 months
[PATCH 1/2] builder: Fix redirect in virt-builder configuration.
by Richard W.M. Jones
For a while libguestfs.org/builder has redirected to
builder.libguestfs.org. This change just makes virt-builder go direct
to the subsite instead of via the redirect.
---
builder/libguestfs.conf.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builder/libguestfs.conf.in b/builder/libguestfs.conf.in
index 633a0abaf..3b9e3854f 100644
--- a/builder/libguestfs.conf.in
+++ b/builder/libguestfs.conf.in
@@ -1,3 +1,3 @@
[libguestfs.org]
-uri=http://libguestfs.org/download/builder/index.asc
+uri=http://builder.libguestfs.org/index.asc
gpgkey=file://@SYSCONFDIR@/xdg/virt-builder/repos.d/libguestfs.gpg
--
2.19.0.rc0
5 years, 10 months
[PATCH FOR DISCUSSION ONLY 0/2] v2v: Copy static IP address information over for Windows guests (RHBZ#1626503)
by Brett Thurber
...adding a few thoughts around this proposal.
There are times when we need to preserve the IP/MAC address(s) for VM
migration for things such as:
1. Licensing tied to the IP/MAC address
2. Complex configurations such as HA clustering
3. Anytime network preservation is needed to run post configuration
playbooks in some migration solutions
4. Using in OS agents to manipulate networking may not be feasible for all
With the patch Richard is proposing it addresses the above items. My
suggestion is if MAC/IP preservation isn't desired then don't use the --mac
address option. If the --mac address option is used maybe flag it with
--preserve if persistence is desired/needed.
This should tackle both perspectives on if/should/could/need/don't. :)
--
Brett Thurber - RHCA, RHCVA
Engineering Manager and Sr. Principal Software Engineer, Solutions
Engineering
Products & Technologies Group, Red Hat
Mobile: +1 (512) 547-9282
5 years, 10 months
[PATCH] v2v: -o openstack: Check openstack binary exists before running it.
by Richard W.M. Jones
Improves the error message when openstack is not installed:
$ virt-v2v -i disk fedora-28.img -o openstack
virt-v2v: error: no binary called ‘openstack’ was found on the $PATH.
We use this program to communicate with OpenStack so it must be installed
to use this output mode.
---
v2v/output_openstack.ml | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/v2v/output_openstack.ml b/v2v/output_openstack.ml
index b5bbc9195..238ec99a9 100644
--- a/v2v/output_openstack.ml
+++ b/v2v/output_openstack.ml
@@ -28,6 +28,9 @@ open Common_gettext.Gettext
open Types
open Utils
+(* Name of the openstack CLI program (on $PATH). *)
+let openstack_binary = "openstack"
+
(* Timeout waiting for new Cinder volumes to move to "available" state.
* We assume this could be quite a long time on backends which want
* to preallocate the storage.
@@ -172,13 +175,20 @@ class output_openstack output_conn output_password output_storage
object_get_string "uuid" json
) in
+ let error_unless_openstack_command_exists () =
+ try ignore (which openstack_binary)
+ with Executable_not_found _ ->
+ error (f_"no binary called ‘%s’ was found on the $PATH. We use this program to communicate with OpenStack so it must be installed to use this output mode.")
+ openstack_binary
+ in
+
(* We use this convenient wrapper around [Tools_utils.run_command]
* for two reasons: (1) Because we want to run openstack with
* extra_args. (2) OpenStack commands are noisy so we want to
* direct stdout to /dev/null unless we're in verbose mode.
*)
let run_openstack_command args =
- let cmd = [ "openstack" ] @ extra_args @ args in
+ let cmd = [ openstack_binary ] @ extra_args @ args in
let stdout_fd =
if verbose () then None
else Some (openfile "/dev/null" [O_WRONLY] 0) in
@@ -191,7 +201,7 @@ class output_openstack output_conn output_password output_storage
* '-f json' to the args yourself.
*)
let run_openstack_command_capture_json args =
- let cmd = [ "openstack" ] @ extra_args @ args in
+ let cmd = [ openstack_binary ] @ extra_args @ args in
let json, chan = Filename.open_temp_file "v2vopenstack" ".json" in
unlink_on_exit json;
@@ -366,6 +376,9 @@ object
inherit output
method precheck () =
+ (* Check the openstack command exists. *)
+ error_unless_openstack_command_exists ();
+
(* Run the openstack command simply to check we can connect
* with the provided authentication parameters/environment
* variables. Issuing a token should have only a tiny
--
2.19.0.rc0
5 years, 10 months
[PATCH FOR DISCUSSION ONLY 0/2] v2v: Copy static IP address information over for Windows guests (RHBZ#1626503).
by Richard W.M. Jones
This patch is just for discussion. There are still a couple of issues
that I'm trying to fix.
One is that all of the test guests I have, even ones with static IPs,
have multiple interfaces, some using DHCP, so the conditions for
adding the Powershell script don't kick in. This makes testing very
awkward.
However a bigger issue is that I think the premise is wrong. In some
registries I've found that the MAC address _is_ stored (in
\CurrentControlSet\Control\NetworkSetup2\Interfaces\{GUID} key
PermanentAddress).
Rich.
5 years, 10 months
[PATCH] v2v: linux: improve regex for resume= entries (RHBZ#1651987)
by Pino Toscano
Add few more characters for the devices of resume= entries in the
command line of grub: this way it is possible to match also /dev/mapper
devices.
This should require no further processing, since the names of the
/dev/mapper devices do not change after the conversion.
---
v2v/convert_linux.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index be4905473..945c3aa32 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -1004,7 +1004,7 @@ let convert (g : G.guestfs) inspect source output rcaps =
List.flatten (List.map Array.to_list (List.map g#aug_match paths)) in
(* Map device names for each entry. *)
- let rex_resume = PCRE.compile "^resume=(/dev/[a-z\\d]+)(.*)$"
+ let rex_resume = PCRE.compile "^resume=(/dev/[-a-z\\d/_]+)(.*)$"
and rex_device_cciss = PCRE.compile "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$"
and rex_device = PCRE.compile "^/dev/([a-z]+)(\\d*)?$" in
--
2.17.2
5 years, 10 months