class Appfront::Command::Clusters
Public Class Methods
create(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 139 def self.create(args, opts) exit 1 unless opts[:provider] exit 1 unless opts[:provider] == 'amazon' or opts[:provider] == 'digitalocean' or opts[:provider] == 'manual' if args.count == 3 name = args[0] type = args[1] region = args[2] elsif args.count == 2 type = args[0] region = args[1] elsif args.count == 1 name = args[0] type = 'manual' region = 'manual' end tier = opts[:provider] if type == 'manual' spinner "Creating new manual cluster ..." do @info = api.post "/provider/#{tier}/cluster/#{region}/#{type}" unless name @info = api.post "/provider/#{tier}/cluster/#{region}/#{type}", name: name if name end else spinner "Creating new cluster on region #{region}..." do @info = api.post "/provider/#{tier}/cluster/#{region}/#{type}" unless name @info = api.post "/provider/#{tier}/cluster/#{region}/#{type}", name: name if name end end print "\n" end
deploys(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 94 def self.deploys(args, opts) exit 1 unless args[0] uuid = args[0] c = api.get "/cluster/#{uuid}/deploys" if c.count != 0 puts "=== Cluster #{uuid} deploys: \n" c.each do |d| puts "\t === Deploy: #{d['deploy']} uuid: #{d['uuid']}\n" end end puts "\n" end
info(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 109 def self.info(args, opts) exit 1 unless args[0] uuid = args[0] #exit 1 unless opts[:provider] #exit 1 unless opts[:provider] == 'amazon' or opts[:provider] == 'digitalocean' or opts[:provider] == 'manual' c = api.get "/cluster/#{uuid}" puts "=== Cluster #{uuid}: \n" puts "\t === Name: #{c['name']}\n" puts "\t === DNS Name: #{c['dns']}\n" puts "\t === Token: #{c['token']}\n" puts "\t === Region: #{c['region']}\n" puts "\n" puts "\t === Active Boxes: #{c['boxes']}\n" if c['addresses'] c['addresses'].each do |box| puts "\t box address:\t#{box}" end end puts "\n" if c['started'] puts "\t === Booting Boxes: #{c['started'].count}\n" c['started'].each do |box| puts "\t box address:\t#{box}" end end puts "\n" end
ls()
click to toggle source
# File lib/appfront/command/clusters.rb, line 3 def self.ls clusters = api.get "/clusters" puts '=== Clusters List:' clusters.each do |cl| puts "Cluster #{cl['uuid']} ---> Name: #{cl['name']} \tProvider: #{cl['provider']}" end print "\n" end
ps(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 12 def self.ps(args, opts) exit 1 unless args[0] uuid = args[0] puts "=== Cluster #{uuid} TOP: \n" data = api.get "/cluster/#{uuid}/top" unless data == {} data.each do |b| puts "\t ---" puts "\t Box: #{b['address']}\t started: #{b['started']} \t memory: #{b['free_memory']}/#{b['memory']} MB" puts "\n" deploys = b['deploys'] deploys.each do |d| puts "\t === #{d['deploy']} \t\t started: vuoto \t memory: #{d['memory']} MB \t cpu_usage: #{d['cpu']}%" end puts "\n" end end puts "\n" end
rm(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 171 def self.rm(args, opts) exit 1 unless args[0] uuid = args[0] exit 1 unless opts[:provider] exit 1 unless opts[:provider] == 'amazon' or opts[:provider] == 'digitalocean' or opts[:provider] == 'manual' tier = opts[:provider] spinner "Removing cluster #{uuid}..." do sleep 1 @info = api.delete "/provider/#{tier}/cluster/#{uuid}" end print "\n" end
scale_down(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 198 def self.scale_down(args, opts) uuid = args[0] exit 1 unless args[0] #exit 1 unless opts[:provider] #exit 1 unless opts[:provider] == 'amazon' or opts[:provider] == 'digitalocean' spinner "Scaling DOWN cluster #{uuid}..." do api.put "/provider/cluster/#{uuid}/scale/down" end print "\n" end
scale_up(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 185 def self.scale_up(args, opts) exit 1 unless args[0] uuid = args[0] #exit 1 unless opts[:provider] #exit 1 unless opts[:provider] == 'amazon' or opts[:provider] == 'digitalocean' spinner "Scaling UP cluster #{uuid}..." do api.put "/provider/cluster/#{uuid}/scale/up" end print "\n" end
status(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 35 def self.status(args, opts) exit 1 unless args[0] uuid = args[0] begin system("clear") puts "=== Cluster #{uuid} processes activities: \n" data = api.get "/cluster/#{uuid}/status" unless data == {} data.each do |f| puts "---" puts "Deploy: #{f['name']}\t uuid: #{f['flow']}" puts "\n" statuses = f['statuses'] statuses.each do |s| puts "\t instance: #{s['live_uuid']}\t task: #{s['name']}\t status: #{s['status']}\t last seen on: #{s['last_seen']}\n" end end end puts "\n" sleep 2 end while true rescue Exception system("clear") end
top(args, opts)
click to toggle source
# File lib/appfront/command/clusters.rb, line 64 def self.top(args, opts) exit 1 unless args[0] uuid = args[0] begin system("clear") puts "=== Cluster #{uuid} TOP: \n" data = api.get "/cluster/#{uuid}/top" unless data == {} data.each do |b| puts "\t ---" puts "\t Box: #{b['address']}\t started: #{b['started']} \t memory: #{b['free_memory']}/#{b['memory']} MB" puts "\n" deploys = b['deploys'] deploys.each do |d| puts "\t === #{d['deploy']} \t\t started: vuoto \t memory: #{d['memory']} MB \t cpu_usage: #{d['cpu']}%" end puts "\n" end end puts "\n" sleep 2 end while true rescue Exception system("clear") end