Sha256: b9bf9d01b7c855709166322b1022f8fda7b776a47bfb21a8f7b8745c7939ee99

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'securerandom'

module Kontena
  module Plugin
    module Vagrant
      module Master
        class CreateCommand < Kontena::Command
          include Kontena::Cli::Common

          option "--name", "NAME", "Set master name"
          option "--memory", "MEMORY", "How much memory node has"
          option "--version", "VERSION", "Define installed Krates version", default: 'latest'
          option "--vault-secret", "VAULT_SECRET", "Secret key for Vault"
          option "--vault-iv", "VAULT_IV", "Initialization vector for Vault"
          option "--coreos-channel", "CHANNEL", "CoreOS release channel", default: 'stable'

          def execute
            require_relative '../../../machine/vagrant'
            mem = ask_instance_memory
            provisioner.run!(
              name: name,
              memory: mem,
              version: version,
              vault_secret: vault_secret || SecureRandom.hex(24),
              vault_iv: vault_iv || SecureRandom.hex(24),
              initial_admin_code: SecureRandom.hex(16),
              coreos_channel: coreos_channel
            )
          end

          def ask_instance_memory
            if self.memory.nil?
              prompt.select("Choose a size") do |menu|
                %w(512 1024 2048).each do |mem|
                  menu.choice "#{mem}MB", mem
                end
              end
            else
              self.memory
            end
          end

          def provisioner
            Kontena::Machine::Vagrant::MasterProvisioner.new
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
krates-plugin-vagrant-0.3.6 lib/kontena/plugin/vagrant/master/create_command.rb
krates-plugin-vagrant-0.3.5 lib/kontena/plugin/vagrant/master/create_command.rb
krates-plugin-vagrant-0.3.4 lib/kontena/plugin/vagrant/master/create_command.rb