Class: MachineConfigure::Importer

Inherits:
Object
  • Object
show all
Includes:
Helpers::Message, Helpers::Shared
Defined in:
lib/machine_configure/importer.rb

Overview

The Importer takes a zip file, processes the files, and extracts them into the proper directories.

Constant Summary

Constants included from Helpers::Message

Helpers::Message::MESSAGE_PADDING, Helpers::Message::STACK_TRACE_PADDING, Helpers::Message::STACK_TRACE_SIZE

Instance Method Summary collapse

Methods included from Helpers::Message

error_no_stack_trace!, error_yes_stack_trace!

Constructor Details

#initializeImporter

Returns a new instance of Importer.



9
10
11
12
# File 'lib/machine_configure/importer.rb', line 9

def initialize
  @contents     = nil
  @machine_name = nil
end

Instance Method Details

#import_from(zip_file) ⇒ Object

Import given zip_file as a new docker-machine.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/machine_configure/importer.rb', line 16

def import_from zip_file
  VALIDATOR.validate_zip_file_import zip_file
  @contents     = get_contents_from_zip zip_file
  @machine_name = @contents[MACHINE_NAME_FILENAME]
  @contents.delete MACHINE_NAME_FILENAME
  @dir = {
    machine: DM_MACHINES_PATH.join(@machine_name),
    certs:   DM_CERTS_PATH.join(@machine_name)
  }
  #VALIDATOR.validate_directories_dont_exist *@dir.values
  VALIDATOR.validate_no_machine_name @machine_name
  config_json_path = get_config_json_path
  @contents[config_json_path] = insert_home_in @contents[config_json_path]
  write_contents
  # Finally, check that the newly imported machine is recognized by docker-machine.
  VALIDATOR.validate_machine_name @machine_name
  message(
    "Successfully imported docker-machine configuration files from archive",
    "  `#{zip_file.to_s}'",
    "for docker-machine",
    "  `#{@machine_name}'"
  )
end