Class: Kontena::Plugin::Vagrant::Nodes::CreateCommand

Inherits:
Command
  • Object
show all
Includes:
Cli::Common, Cli::GridOptions
Defined in:
lib/kontena/plugin/vagrant/nodes/create_command.rb

Instance Method Summary collapse

Instance Method Details

#ask_instance_memoryObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/kontena/plugin/vagrant/nodes/create_command.rb', line 59

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

#ask_instancesObject



51
52
53
54
55
56
57
# File 'lib/kontena/plugin/vagrant/nodes/create_command.rb', line 51

def ask_instances
  if self.instances.nil?
    prompt.ask("How many nodes?: ", default: 1, in: '1..10')
  else
    self.instances
  end
end

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kontena/plugin/vagrant/nodes/create_command.rb', line 14

def execute
  api_url = require_api_url
  require_current_grid

  instance_count = ask_instances
  instance_memory = ask_instance_memory

  require_relative '../../../machine/vagrant'

  grid = fetch_grid
  provisioner = provisioner(client(require_token))

  require 'ipaddr'
  ip_address = if network_address == "dhcp"
    nil
  else
    IPAddr.new network_address
  end

  instance_count.to_i.times do |i|
    provisioner.run!(
      master_uri: api_url,
      grid_token: grid['token'],
      grid: current_grid,
      name: name,
      instance_number: i + 1,
      network_address: ip_address ? ip_address.to_s : "dhcp",
      cpus: cpus,
      memory: instance_memory,
      version: version,
      coreos_channel: coreos_channel
    )

    ip_address = ip_address.succ if ip_address
  end
end

#fetch_gridHash

Returns:

  • (Hash)


77
78
79
# File 'lib/kontena/plugin/vagrant/nodes/create_command.rb', line 77

def fetch_grid
  client(require_token).get("grids/#{current_grid}")
end

#provisioner(client) ⇒ Object

Parameters:

  • client (Kontena::Client)


72
73
74
# File 'lib/kontena/plugin/vagrant/nodes/create_command.rb', line 72

def provisioner(client)
  Kontena::Machine::Vagrant::NodeProvisioner.new(client)
end