[Libguestfs] [PATCH] v2v: -i vmx: Allow ssh URLs to use spaces.

Richard W.M. Jones rjones at redhat.com
Sun Dec 10 15:46:16 UTC 2017


As an enhancement to commit 1d38216d20141cef9ce83ca4ddbe9c79f5da4f39
allow the ssh URLs to contain spaces.

It is relatively common for VMware VM names to contain spaces.
libxml2 cannot parse these (giving an error), so that required the
user to manually replace spaces with %20.  Instead let the code
replace each space with %20 on behalf of the user.
---
 v2v/input_vmx.ml | 9 ++++++---
 v2v/virt-v2v.pod | 5 ++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/v2v/input_vmx.ml b/v2v/input_vmx.ml
index a8b33f66f..e51bf14fd 100644
--- a/v2v/input_vmx.ml
+++ b/v2v/input_vmx.ml
@@ -32,17 +32,20 @@ type vmx_source =
   | File of string              (* local file or NFS *)
   | SSH of Xml.uri              (* SSH URI *)
 
+let space = PCRE.compile " "
+
 (* The single filename on the command line is intepreted either as
  * a local file or a remote SSH URI (only if ‘-it ssh’).
  *)
 let vmx_source_of_arg input_transport arg =
   match input_transport, arg with
   | None, arg -> File arg
-  | Some `SSH, arg ->
+  | Some `SSH, uri ->
+     let uri = PCRE.replace ~global:true space "%20" uri in
      let uri =
-       try Xml.parse_uri arg
+       try Xml.parse_uri uri
        with Invalid_argument _ ->
-         error (f_"remote vmx ‘%s’ could not be parsed as a URI") arg in
+         error (f_"remote vmx ‘%s’ could not be parsed as a URI") uri in
      if uri.Xml.uri_scheme <> None && uri.Xml.uri_scheme <> Some "ssh" then
        error (f_"vmx URI start with ‘ssh://...’");
      if uri.Xml.uri_server = None then
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index cc4e90dff..9f4956548 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -1438,10 +1438,9 @@ authorized_keys.
 When using the SSH input transport you must specify a remote
 C<ssh://...> URI pointing to the VMX file.  A typical URI looks like:
 
- ssh://root@esxi.example.com/vmfs/volumes/datastore1/my%20guest/my%20guest.vmx
+ ssh://root@esxi.example.com/vmfs/volumes/datastore1/my guest/my guest.vmx
 
-Any space must be escaped with C<%20> and other non-ASCII characters
-may also need to be URI-escaped.
+Non-ASCII characters may need to be URI-escaped.
 
 The username is not required if it is the same as your local username.
 
-- 
2.13.2




More information about the Libguestfs mailing list