Class: Kontena::Plugin::Vagrant::Nodes::CreateCommand
- Inherits:
-
Command
- Object
- Command
- Kontena::Plugin::Vagrant::Nodes::CreateCommand
- Includes:
- Cli::Common, Cli::GridOptions
- Defined in:
- lib/kontena/plugin/vagrant/nodes/create_command.rb
Instance Method Summary collapse
- #ask_instance_memory ⇒ Object
- #ask_instances ⇒ Object
- #execute ⇒ Object
- #fetch_grid ⇒ Hash
- #provisioner(client) ⇒ Object
Instance Method Details
#ask_instance_memory ⇒ Object
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 || %w(1024 2048 4096).each do |mem| .choice "#{mem}MB", mem end end else self.memory end end |
#ask_instances ⇒ Object
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 |
#execute ⇒ Object
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_grid ⇒ 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
72 73 74 |
# File 'lib/kontena/plugin/vagrant/nodes/create_command.rb', line 72 def provisioner(client) Kontena::Machine::Vagrant::NodeProvisioner.new(client) end |