Class: Tupperware::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tupperware.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, kitchen_config = Kitchen::Config.new) ⇒ Base

Returns a new instance of Base.



41
42
43
44
45
# File 'lib/tupperware.rb', line 41

def initialize(options = {}, kitchen_config = Kitchen::Config.new)
  @kitchen_config = kitchen_config
  @options = options
  @supported_drivers = {'vagrant' => VagrantVirtualBox}
end

Instance Method Details

#check_driverObject



47
48
49
50
51
52
53
54
55
# File 'lib/tupperware.rb', line 47

def check_driver
  hash = @kitchen_config.loader.read
  driver = hash[:driver][:name]
  unless @supported_drivers.has_key?(driver)
    puts "#{driver} is not yet supported"
    exit
  end
  return @supported_drivers[driver]
end

#packageObject



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
# File 'lib/tupperware.rb', line 57

def package
  cls = check_driver
  instance = nil
  if cls == VagrantVirtualBox
    if @options[:instance]
      @kitchen_config.instances.each do |i|
        if i.name.to_s == @options[:instance]
          instance = i
          break
        end
      end
      unless instance
        puts "#{@options[:instance]} is not a valid kitchen instance"
        exit 1
      end
      instance_name = instance.name.to_s
      puts "\n*** Converging #{instance_name} ***\n"
      instance.converge
      packager = VagrantVirtualBox.new(@options, @kitchen_config)
      packager.provision_local_box(instance)
      packager.halt(instance_name)
      packager.package(instance_name)
      instance.destroy
    else
      packager = VagrantVirtualBox.new(@options, @kitchen_config)
      packager.kitchen_config.instances.each do |i|
        instance_name = i.name.to_s
        puts "\n*** Converging #{i.name.to_s} ***\n"
        i.converge
        packager.provision_local_box(i)
        packager.halt(i.name.to_s)
        packager.package(i.name.to_s)
        i.destroy
      end

     done = <<-DONE 


      Your vagrant box file is named #{instance_name}.box. Import it by
      running:

      vagrant box add --name NAME #{instance_name}.box

      Run the following command for more information on importing vagrant
      boxes:

      vagrant box add -h


      DONE

      puts done

    end
  end
end