Class: VpsAdminOS::Converter::Cli::Vz6::Base

Inherits:
Command
  • Object
show all
Defined in:
lib/vpsadminos-converter/cli/vz6/base.rb

Direct Known Subclasses

Export, Migrate

Instance Method Summary collapse

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from VpsAdminOS::Converter::Cli::Command

Instance Method Details

#convert_ct(ctid) ⇒ Object (protected)



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
# File 'lib/vpsadminos-converter/cli/vz6/base.rb', line 7

def convert_ct(ctid)
  if opts[:vpsadmin]
    opts[:zfs] = true
    opts['zfs-dataset'] = "vz/private/#{ctid}"
    opts['zfs-subdir'] = 'private'
    opts['netif-type'] = 'routed'
    opts['netif-name'] = 'eth0'
  end

  if opts[:zfs] && opts['zfs-subdir'] != 'private'
    # TODO
    raise "unsupported configuration, only '--zfs-subdir private' is implemented"
  end

  vz_ct = Vz6::Container.new(ctid)
  raise 'container not found' unless vz_ct.exist?

  begin
    puts 'Parsing config'
    vz_ct.load
  rescue RuntimeError => e
    raise "unable to parse config: #{e.message}"
  end

  if opts[:zfs] && vz_ct.ploop?
    raise 'container uses ploop, but ZFS was enabled'
  end

  target_ct = vz_ct.convert(
    User.default,
    Group.default,
    netif: {
      type: opts['netif-type'].to_sym,
      name: opts['netif-name'],
      hwaddr: opts['netif-hwaddr'],
      link: opts['bridge-link']
    }
  )

  if opts[:zfs]
    target_ct.dataset = OsCtl::Lib::Zfs::Dataset.new(
      opts['zfs-dataset'],
      base: opts['zfs-dataset']
    )
  end

  [vz_ct, target_ct]
end

#exporter_classObject (protected)



72
73
74
# File 'lib/vpsadminos-converter/cli/vz6/base.rb', line 72

def exporter_class
  opts[:zfs] ? Exporter::Zfs : Exporter::Tar
end


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vpsadminos-converter/cli/vz6/base.rb', line 56

def print_convert_status(vz_ct)
  puts 'Consumed config items:'
  vz_ct.config.each do |it|
    next unless it.consumed?

    puts "  #{it.key} = #{it.value.inspect}"
  end
  puts
  puts 'Ignored config items:'
  vz_ct.config.each do |it|
    next if it.consumed?

    puts "  #{it.key} = #{it.value.inspect}"
  end
end