Class: OsCtl::Image::Operations::Image::Export

Inherits:
Base
  • Object
show all
Includes:
Lib::Utils::Log
Defined in:
lib/osctl/image/operations/image/export.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(build) ⇒ Export

Returns a new instance of Export.

Parameters:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/osctl/image/operations/image/export.rb', line 13

def initialize(build)
  @build = build
  @container_config = ContainerConfig.new

  container_config.distribution = build.image.distribution
  container_config.version = build.image.version
  container_config.arch = build.image.arch
  container_config.dataset = OsCtl::Lib::Zfs::Dataset.new(
    build.output_dataset,
    base: build.output_dataset,
  )
  container_config.rootfs = build.install_dir

  if build.has_config_file?
    container_config.override_with(build.read_config_file)
  end
end

Instance Attribute Details

#buildOperations::Image::Build (readonly)



10
11
12
# File 'lib/osctl/image/operations/image/export.rb', line 10

def build
  @build
end

#container_configObject (readonly, protected)

Returns the value of attribute container_config.



37
38
39
# File 'lib/osctl/image/operations/image/export.rb', line 37

def container_config
  @container_config
end

Instance Method Details

#executeObject



31
32
33
34
# File 'lib/osctl/image/operations/image/export.rb', line 31

def execute
  export_archive
  export_stream
end

#export_archiveObject (protected)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/osctl/image/operations/image/export.rb', line 39

def export_archive
  f = File.open(build.output_tar, 'w')
  exporter = OsCtl::Lib::Exporter::Tar.new(
    container_config,
    f,
    compression: :auto,
  )

  exporter.('full')
  exporter.dump_configs
  exporter.pack_rootfs

ensure
  f && f.close
end

#export_streamObject (protected)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/osctl/image/operations/image/export.rb', line 55

def export_stream
  f = File.open(build.output_stream, 'w')
  exporter = OsCtl::Lib::Exporter::Zfs.new(
    container_config,
    f,
    compression: :gzip,
    compressed_send: true,
  )

  exporter.('full')
  exporter.dump_configs
  exporter.dump_rootfs do
    exporter.dump_base
  end

ensure
  f && f.close
end