Class: Appfront::Command::Clusters

Inherits:
Base
  • Object
show all
Defined in:
lib/appfront/command/clusters.rb

Class Method Summary collapse

Class Method Details

.create(args, opts) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/appfront/command/clusters.rb', line 95

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

.info(args, opts) ⇒ Object



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
93
# File 'lib/appfront/command/clusters.rb', line 65

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

.lsObject



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



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/appfront/command/clusters.rb', line 127

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



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/appfront/command/clusters.rb', line 154

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



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/appfront/command/clusters.rb', line 141

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

.top(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
63
# File 'lib/appfront/command/clusters.rb', line 35

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