Class: VpsAdminOS::Converter::Cli::App

Inherits:
Object
  • Object
show all
Includes:
GLI::App
Defined in:
lib/vpsadminos-converter/cli/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



8
9
10
11
12
# File 'lib/vpsadminos-converter/cli/app.rb', line 8

def self.run
  cli = new
  cli.setup
  exit(cli.run(ARGV))
end

Instance Method Details

#setupObject



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
108
109
110
111
112
113
114
115
# File 'lib/vpsadminos-converter/cli/app.rb', line 14

def setup
  Thread.abort_on_exception = true

  program_desc 'Convert OpenVZ containers into vpsAdminOS'
  version VpsAdminOS::Converter::VERSION
  subcommand_option_handling :normal
  preserve_argv true
  arguments :strict

  desc 'Log file'
  flag 'log-file'

  desc 'Convert containers from OpenVZ Legacy'
  command :vz6 do |vz|
    vz.desc 'Export OpenVZ container into vpsAdminOS-compatible archive'
    vz.arg_name '<ctid> <file>'
    vz.command :export do |c|
      c.desc 'Stop the container during the export'
      c.switch :consistent, default_value: true

      c.desc 'Compression'
      c.flag %i[c compression], must_match: %w[auto off gzip],
                                default_value: 'gzip'

      vz6_opts(c)

      c.action(&Command.run(Vz6::Export, :export))
    end

    vz.desc 'Migrate OpenVZ container onto vpsAdminOS node'
    vz.command :migrate do |m|
      m.desc 'Step 1., copy configs to target node'
      m.arg_name '<id> <dst>'
      m.command :stage do |c|
        c.desc 'SSH port'
        c.flag %i[p port], type: Integer

        vz6_opts(c)

        c.action(&Command.run(Vz6::Migrate, :stage))
      end

      m.desc 'Step 2., do an initial copy of container rootfs'
      m.arg_name '<id>'
      m.command :sync do |c|
        c.action(&Command.run(Vz6::Migrate, :sync))
      end

      m.desc 'Step 3., transfer the container to target node'
      m.arg_name '<id>'
      m.command :transfer do |c|
        c.action(&Command.run(Vz6::Migrate, :transfer))
      end

      m.desc 'Step 4., cleanup the container on the source node'
      m.arg_name '<id>'
      m.command :cleanup do |c|
        c.desc 'Delete the container'
        c.switch %i[d delete], default_value: false

        c.action(&Command.run(Vz6::Migrate, :cleanup))
      end

      m.desc 'Cancel ongoing migration in mid-step'
      m.arg_name '<id>'
      m.command :cancel do |c|
        c.desc 'Cancel the migration on the local node, even if remote fails'
        c.switch %i[f force], negatable: false

        c.action(&Command.run(Vz6::Migrate, :cancel))
      end

      m.desc 'Migrate container at once (equals to steps 1-4 in succession)'
      m.arg_name '<id> <dst>'
      m.command :now do |c|
        c.desc 'SSH port'
        c.flag %i[p port], type: Integer

        c.desc 'Delete the container after migration'
        c.switch %i[d delete], default_value: false

        c.desc 'Proceed with the migration or ask after successful staging'
        c.switch %i[y proceed]

        vz6_opts(c)

        c.action(&Command.run(Vz6::Migrate, :now))
      end
    end
  end

  desc 'Read man page'
  command :man do |c|
    c.action do
      manpath = File.realpath(File.join(
                                __dir__,
                                '..', '..', '..', 'man'
                              ))
      system("man -M #{manpath} vpsadminos-convert")
    end
  end
end

#vz6_opts(c) ⇒ Object (protected)



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/vpsadminos-converter/cli/app.rb', line 119

def vz6_opts(c)
  c.desc "Use when the container's private area is on a ZFS dataset"
  c.switch :zfs

  c.desc "Dataset with the container's private area"
  c.flag 'zfs-dataset'

  c.desc "Directory in the container's dataset with the rootfs"
  c.flag 'zfs-subdir'

  c.desc 'Enable ZFS compressed send (zfs send -c)'
  c.switch 'zfs-compressed-send', negatable: false

  c.desc 'Network interface type'
  c.flag 'netif-type', must_match: %w[bridge routed], default_value: 'bridge'

  c.desc 'Network interface name within the container'
  c.flag 'netif-name', default_value: 'eth0'

  c.desc 'Network interface hwaddr (MAC)'
  c.flag 'netif-hwaddr'

  c.desc 'Bridge name (for bridged network interface)'
  c.flag 'bridge-link', default_value: 'lxcbr0'

  c.desc 'Overrides options to conform to vpsAdmin settings, see the manual'
  c.switch :vpsadmin, negatable: false
end