File: select_input.ml

package info (click to toggle)
virt-v2v 2.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,256 kB
  • sloc: ml: 19,861; sh: 8,454; ansic: 6,880; makefile: 2,797; python: 1,114; perl: 854; xml: 117
file content (107 lines) | stat: -rw-r--r-- 3,572 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(* helper-v2v-input
 * Copyright (C) 2009-2025 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *)

open Tools_utils
open Common_gettext.Gettext

type input_mode =
  | Disk
  | Libvirt
  | LibvirtXML
  | OVA
  | VMX

let input_modes = [
    Disk;
    Libvirt;
    LibvirtXML;
    OVA;
    VMX;
  ]

let string_of_input_mode = function
  | Disk -> "disk"
  | Libvirt -> "libvirt"
  | LibvirtXML -> "libvirtxml"
  | OVA -> "ova"
  | VMX -> "vmx"

let input_mode_of_string = function
  | "disk" | "local" -> Disk
  | "libvirt" -> Libvirt
  | "libvirtxml" -> LibvirtXML
  | "ova" -> OVA
  | "vmx" -> VMX
  | s -> error (f_"unknown -i option: %s") s

let select_input ?(allow_remote = true) input_mode input_conn input_transport =
  match input_mode with
  | Some Disk -> (module Input_disk.Disk : Input.INPUT)
  | Some LibvirtXML -> (module Input_libvirt.LibvirtXML)
  | Some OVA -> (module Input_ova.OVA)
  | Some VMX -> (module Input_vmx.VMX)
  | None | Some Libvirt ->
     match input_conn with
     | None -> (module Input_libvirt.Libvirt_)
     | Some orig_uri ->
        let { Xml.uri_server = server; uri_scheme = scheme } =
          try Xml.parse_uri orig_uri
          with Invalid_argument msg ->
            error (f_"could not parse '-ic %s'.  \
                      Original error message was: %s")
              orig_uri msg in

        match server, scheme, input_transport, allow_remote with
        | None, _, _, _
        | Some "", _, _, _    (* Not a remote URI. *)

        | Some _, None, _, _  (* No scheme? *)
        | Some _, Some "", _, _ ->
           (module Input_libvirt.Libvirt_)

        (* All the input method below here are remote, but virt-v2v-in-place
         * cannot work with remote disks.  If remote is not allowed
         * then fail here.
         *)
        | _, _, _, false ->
           error (f_"virt-v2v-in-place does not support remote \
                     libvirt URIs")

        (* vCenter over https. *)
        | Some server, Some ("esx"|"gsx"|"vpx"), None, true ->
           (module Input_vcenter_https.VCenterHTTPS)

        (* vCenter or ESXi using nbdkit vddk plugin *)
        | Some server, Some ("esx"|"gsx"|"vpx"), Some Input.VDDK, true ->
           (module Input_vddk.VDDK)

        (* Xen over SSH *)
        | Some server, Some "xen+ssh", _, true ->
           (module Input_xen_ssh.XenSSH)

        (* Old virt-v2v also supported qemu+ssh://.  However I am
         * deliberately not supporting this in new virt-v2v.  Don't
         * use virt-v2v if a guest already runs on KVM.
         *)

        (* Unknown remote scheme. *)
        | Some _, Some _, _, true ->
           warning (f_"no support for remote libvirt connections \
                       to '-ic %s'.  The conversion may fail when it \
                       tries to read the source disks.") orig_uri;
           (module Input_libvirt.Libvirt_)