class Ignition::CLI

version print version scan scan for running igntion daemons (UDP broadcast) send send a bundle definiion info print bundle information services print service information load load a bundle run run a bundle stop stop a bundle

Public Class Methods

add_shared_option(name, options = {}) click to toggle source
# File lib/ignition/cli.rb, line 23
def add_shared_option(name, options = {})
  @shared_options = {} if @shared_options.nil?
  @shared_options[name] =  options
end
is_thor_reserved_word?(word, type) click to toggle source

Hackery. Take the run method away from Thor so that we can redefine it.

Calls superclass method
# File lib/ignition/cli.rb, line 37
def is_thor_reserved_word?(word, type)
  return false if word == "run"
  super
end
shared_options(*option_names) click to toggle source
# File lib/ignition/cli.rb, line 28
def shared_options(*option_names)
  option_names.each do |option_name|
    opt =  @shared_options[option_name]
    raise "Tried to access shared option '#{option_name}' but it was not previously defined" if opt.nil?
    option option_name, opt
  end
end

Public Instance Methods

info() click to toggle source
# File lib/ignition/cli.rb, line 128
def info
    puts "info bundle id #{options[:bundle_id]}"
    puts "load hostname:#{options[:hostname]}"
    puts "load port:#{options[:port]}"
    puts "load scale:#{options[:scale]}"

    uri = URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundles")
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)

    if response.code.to_i == 200
      bundles = JSON.parse(response.body)
      if options[:bundle_id] != "*"
        bundles.reject!{ |b| b.id != options[:bundle_id]}
      end
      BundleHelper.print_bundles(options[:hostname],bundles)
    else
      puts "ERROR - #{response.code}"
      puts response.body
    end
end
load(bundle_path) click to toggle source
# File lib/ignition/cli.rb, line 78
def load(bundle_path)
  if (!File.exists?(bundle_path))
    puts "ERROR: bundle file missing on path #{bundle_path}"
  else
    puts "load file:#{bundle_path}"
    puts "load hostname:#{options[:hostname]}"
    puts "load port:#{options[:port]}"

    raw_data = File.read(bundle_path)
    data = JSON.parse(raw_data)
    # puts data.class
    # pp data.to_hash
    params = {'data' => raw_data}

    pp params
    
    x = Net::HTTP.post_form(URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundles"), params)
    pp x

    puts x.body  
    puts x.code
  end
end
logs(bundle_id) click to toggle source
# File lib/ignition/cli.rb, line 203
def logs(bundle_id)
    puts "info bundle id #{options[:bundle_id]}"
    puts "load hostname:#{options[:hostname]}"
    puts "load port:#{options[:port]}"

    uri = URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundle/#{bundle_id}/logs")
    http = Net::HTTP.new(uri.host, uri.port)
    req = Net::HTTP::Get.new(uri.path)
    response = http.request(req)

    if response.code.to_i == 200
      # puts "all ok"

      logs = JSON.parse(response.body)

      # pp logs
      logs.each do |log|
        puts log.strip
      end
    else
      puts "ERROR - #{response.code}"
      puts response.body
    end
end
nodes() click to toggle source
# File lib/ignition/cli.rb, line 55
def nodes
  # puts "Run Scan #{options[:port]}"
  # puts "TODO"

  uri = URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/nodes")
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)

  # puts response.body
  if response.code.to_i == 200
    nodes = JSON.parse(response.body)
    # BundleHelper.print_bundles(options[:hostname],bundles)
    # pp nodes
    tp(nodes.map{ |k,v| {:hostname => k, :last_seen => v, :secs_ago => (DateTime.now.to_time - DateTime.parse(v).to_time).to_i } })
  else
    puts "ERROR - #{response.code}"
    puts response.body
  end
end
run(bundle_id) click to toggle source
# File lib/ignition/cli.rb, line 107
def run(bundle_id)
    puts "run bundle id #{bundle_id}"
    puts "load hostname:#{options[:hostname]}"
    puts "load port:#{options[:port]}"
    puts "load scale:#{options[:scale]}"

    # Net::HTTP.post_form(URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundles"), params)
    uri = URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundle/#{bundle_id}/scale/#{options[:scale]}")
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)

    puts response.body  
    puts response.code
end
stop(bundle_id) click to toggle source
# File lib/ignition/cli.rb, line 156
def stop(bundle_id)
    puts "run bundle id #{bundle_id}"
    puts "load hostname:#{options[:hostname]}"
    puts "load port:#{options[:port]}"
    puts "load scale:#{options[:scale]}"

    # Net::HTTP.post_form(URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundles"), params)
    uri = URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundle/#{bundle_id}/scale/#{options[:scale]}")
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)

    puts response.body  
    puts response.code
end
unload(bundle_id) click to toggle source
# File lib/ignition/cli.rb, line 177
def unload(bundle_id)
    puts "info bundle id #{options[:bundle_id]}"
    puts "load hostname:#{options[:hostname]}"
    puts "load port:#{options[:port]}"
    puts "load scale:#{options[:scale]}"

    uri = URI.parse("http://#{options[:hostname]}:#{options[:port]}/v1/ignition/bundle/#{bundle_id}")
    http = Net::HTTP.new(uri.host, uri.port)
    req = Net::HTTP::Delete.new(uri.path)
    response = http.request(req)
    puts "deleted #{response}"

    if response.code.to_i == 200
      puts "all ok"
    else
      puts "ERROR - #{response.code}"
      puts response.body
    end
end