Richard W.M. Jones
2017-Dec-10 15:46 UTC
[Libguestfs] [PATCH] v2v: -i vmx: Allow ssh URLs to use spaces.
In previous discussion here: https://www.redhat.com/archives/libguestfs/2017-December/thread.html#00027 we preferred to use ssh://... URLs instead of server:/path. However the URL approach had the problem that the user had to replace spaces with %20 in the paths. However since using space gives an error, we can replace spaces with %20 safely in code, thus removing one obstacle from users. Rich.
Richard W.M. Jones
2017-Dec-10 15:46 UTC
[Libguestfs] [PATCH] v2v: -i vmx: Allow ssh URLs to use spaces.
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
Pino Toscano
2017-Dec-11 17:34 UTC
Re: [Libguestfs] [PATCH] v2v: -i vmx: Allow ssh URLs to use spaces.
On Sunday, 10 December 2017 16:46:15 CET Richard W.M. Jones wrote:> In previous discussion here: > > https://www.redhat.com/archives/libguestfs/2017-December/thread.html#00027 > > we preferred to use ssh://... URLs instead of server:/path. However > the URL approach had the problem that the user had to replace spaces > with %20 in the paths. > > However since using space gives an error, we can replace spaces with > %20 safely in code, thus removing one obstacle from users.The idea is not bad. OTOH, this would introduce an inconsistency with the input URI, where all the "special" characters (spaces included) must be escaped. Because of this, IMHO it is better to use the same rules for all the URIs that libguestfs/v2v deals with, so there is less confusion. -- Pino Toscano
Apparently Analagous Threads
- Re: [PATCH v2 2/2] v2v: -i vmx: Enhance VMX support with ability to use ‘-it ssh’ transport.
- [PATCH] Introduce a wrapper around xmlParseURI.
- [PATCH REPOST] Introduce a wrapper around xmlParseURI.
- [PATCH] v2v: Implement SSH password authentication for Xen and VMX over SSH.
- [PATCH v2 0/2] v2v: Add -it vddk and -it ssh flags.