Sha256: dcf55b62f286c0bfc5bc412fd00a170402872c39615e8c3622a1d17f4061e2fc

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

#encoding: utf-8
module Vagabond
  module Actions
    module Init
      class << self
        def included(klass)
          klass.class_eval do
            class << self
              def _init_desc
                ['init', 'initialize the Vagabondfile and setup LXC if needed.']
              end
            end
          end
        end
      end

      def _init
        do_init
      end

      private

      def empty_vagabondfile_hash
        node = internal_config.cookbook_attributes(:vagabond)
        nodes = {}
        node[:bases].keys.each do |template|
          answer = nil
          until(%w(n y).include?(answer))
            answer = ui.ask_question("Include template: #{template} ", :default => 'y').downcase
          end
          if(answer.downcase == 'y')
            ui.info "Enabling template #{template} with node name #{template.gsub('_', '')}"
            nodes[template.gsub('_', '').to_sym] = {
              :template => template,
              :run_list => []
            }
          else
            ui.warn "Skipping instance for template #{template}"
          end
        end
        {
          :defaults => {
            :template => 'ubuntu_1204'
          },
          :nodes => nodes,
          :clusters => {},
          :server => {
            :zero => false,
            :berkshelf => false,
            :librarian => false,
            :enabled => false,
            :auto_upload => true
          },
          :sudo => true
        }
      end

      def do_init
        if(File.exists?(vagabondfile.path))
          ui.confirm('Overwrite existing Vagabondfile', true)
          ui.info 'Overwriting existing Vagabondfile'
        end
        require 'pp'
        File.open(vagabondfile.path, 'w') do |file|
          file.write(empty_vagabondfile_hash.pretty_inspect)
        end
        @vagabondfile.load_configuration!
        @internal_config = InternalConfiguration.new(@vagabondfile, ui, options)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagabond-0.2.10 lib/vagabond/actions/init.rb