Class: Appfront::Command::Clusters
- Defined in:
- lib/appfront/command/clusters.rb
Class Method Summary collapse
- .create(args, opts) ⇒ Object
- .deploys(args, opts) ⇒ Object
- .info(args, opts) ⇒ Object
- .ls ⇒ Object
- .ps(args, opts) ⇒ Object
- .rm(args, opts) ⇒ Object
- .scale_down(args, opts) ⇒ Object
- .scale_up(args, opts) ⇒ Object
- .status(args, opts) ⇒ Object
- .top(args, opts) ⇒ Object
Class Method Details
.create(args, opts) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# 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) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# 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 ⇒ Object
3 4 5 6 7 8 9 10 |
# 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) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# 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) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# 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) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 |