EndlessWaffleCLI 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 285c5dd61b48867ea4d8acfdb5bbedd0f61c0629
4
- data.tar.gz: 2cfd1f41858c840ca53772258f7ca941fafdaf40
3
+ metadata.gz: f6fd697518adcda1eef823e7d7f9fc6eca53d3ed
4
+ data.tar.gz: f27cf3123912138bbb336fa7c067a3802679931e
5
5
  SHA512:
6
- metadata.gz: 5f7c7a76172570daecd1951afd9da562f74c0ee5327b02030412255464abcca65c5d2accae025f2bd8294a863d70b07fad81d22e75a86846bd1430ff253b0207
7
- data.tar.gz: cac3f3ccbe8efa6561565c0165e4dedf698d0491cbbbcaee4ec8532bd7103488da207558547c8450d9b181f73f3f6fc11f83801224a2e34e40bcc5dcc978132b
6
+ metadata.gz: 720c8af9ff12750e2b073a35c59705a0e08edbf86a8bcbd53d0a4b7bea380596e362994e3717ac0856f68bd0feac427f2a77e8f69f07e5e176cb2ebcb0bf7357
7
+ data.tar.gz: ca28ebc75dcf08721c995f8d0b4e0c4630c7b3a42a6c8e90bdd9850fa371714edf4da331de814c265b67ae784f774c9c20df65b0f5b6a084a6fcb7b393705023
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "EndlessWaffleCLI"
5
+ require 'json'
6
+ require 'getoptlong'
7
+ require 'console_table'
8
+ require 'colorize'
9
+ require 'date'
10
+
11
+ require 'pp'
12
+
13
+ if ENV['EndlessWaffleURL'].nil?
14
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleURL' environment variable to be set."
15
+ exit 1
16
+ else
17
+ EndlessWaffleCLI.setServer ENV['EndlessWaffleURL']
18
+ end
19
+
20
+ if ENV['EndlessWaffleToken'].nil?
21
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleToken' environment variable to be set."
22
+ exit 1
23
+ else
24
+ EndlessWaffleCLI.setToken ENV['EndlessWaffleToken']
25
+ end
26
+
27
+
28
+
29
+ def showHelp
30
+ puts
31
+ puts "Endless Waffle Terminate"
32
+ puts "Usage example: #{$0} -n sandbox1.dev1"
33
+ puts
34
+ puts "Options:"
35
+ puts "-n or --name".ljust(30) +"-> name of ec2 instance you wish to terminate"
36
+ puts "-h or --help".ljust(30) +"-> Show this help message."
37
+ puts
38
+ end
39
+
40
+ def colorizeState(state)
41
+ if state == "running"
42
+ state.colorize(:green)
43
+ else
44
+ state.colorize(:red)
45
+ end
46
+ end
47
+
48
+ def showTable(result)
49
+ table_config = [
50
+ {:key=>:instanceId, :size=>13, :title=>"Instance Id"},
51
+ {:key=>:name, :size=>13, :title=>"Name"},
52
+ {:key=>:role, :size=>8, :title=>"Role"},
53
+ {:key=>:environment, :size=>14, :title=>"Env"},
54
+ {:key=>:instanceType, :size=>10, :title=>"Type"},
55
+ {:key=>:availabilityZone, :size=>12, :title=>"Zone"},
56
+ {:key=>:instanceState, :size=>12, :title=>"State"},
57
+ {:key=>:dnsName, :size=>"*", :title=>"DNS Name"},
58
+ ]
59
+ ConsoleTable.define(table_config) do |table|
60
+ result.each do |r|
61
+ table << [
62
+ r["instanceId"].colorize(:yellow),
63
+ r["nodemap"]["name"],
64
+ r["nodemap"]["role"],
65
+ r["nodemap"]["environment"],
66
+ r["instanceType"],
67
+ r["placement"]["availabilityZone"],
68
+ colorizeState(r["instanceState"]["name"]),
69
+ r["dnsName"]]
70
+ end
71
+ end
72
+ end
73
+
74
+ parser = GetoptLong.new
75
+ parser.set_options(["-n", "--name", GetoptLong::NO_ARGUMENT],
76
+ ["-h", "--help", GetoptLong::NO_ARGUMENT]
77
+ )
78
+
79
+
80
+ name = ""
81
+ begin
82
+ begin
83
+ opt,arg = parser.get_option
84
+ break if not opt
85
+ case opt
86
+ when "-h" || "--help"
87
+ showHelp
88
+ exit
89
+ when "-n" || "--name"
90
+ name = ARGV[0]
91
+ end
92
+ rescue => err
93
+ puts "#{err.class()}: #{err.message}"
94
+ exit 1
95
+ end
96
+ end while 1
97
+
98
+ if name.chomp == "" || name.chomp.empty?
99
+ showHelp
100
+ puts "Hint: you must specify a name of a instance to terminate, in the form of name.enviroment, for example sanbox24.dev1"
101
+ exit 1
102
+ end
103
+
104
+ puts ""
105
+ puts "Searching for possable matches, Note: the first match is allways selected if any found"
106
+ query = {:name => name.split('.')[0], :environment => name.split('.')[1]}
107
+ result = EndlessWaffleCLI.queryEc2 query
108
+
109
+ if result.length <1
110
+ puts "No results Found, Exiting now...".colorize(:red)
111
+ exit 1
112
+ end
113
+ showTable(result)
114
+
115
+ selected_instance = result.first
116
+
117
+ puts "\n\n"
118
+ puts "Selected Instance".colorize(:light_cyan)
119
+ puts "========================================"
120
+ puts "instanceId: ".ljust(15) + selected_instance["instanceId"].colorize(:yellow)
121
+ puts "Role: ".ljust(15) + selected_instance["nodemap"]["role"]
122
+ puts "Name: ".ljust(15) + selected_instance["nodemap"]["name"]
123
+ puts "Environment: ".ljust(15) + selected_instance["nodemap"]["environment"]
124
+ puts "Launch Time: ".ljust(15) + DateTime.parse(selected_instance["launchTime"]).strftime('%b %e, %Y %H:%M:%S %z')
125
+
126
+ puts "\n\n"
127
+
128
+ print "Are you sure you want to " + "TERMINATE".colorize(:red) +" this? (Y/N): "
129
+ user_choice=STDIN.gets
130
+ user_choice=user_choice.to_s.chomp
131
+
132
+ if ( (user_choice=="y") || (user_choice=="Y") )
133
+ puts "Proceeding with the TERMINATE:"
134
+ output = EndlessWaffleCLI.ec2terminate(selected_instance["instanceId"])
135
+ puts output["log"].join
136
+ else
137
+ puts "ABORTING NOW!"
138
+ end
@@ -225,4 +225,13 @@ module EndlessWaffleCLI
225
225
  end
226
226
  end
227
227
 
228
+ def self.ec2terminate(instanceId)
229
+ begin
230
+ result = RestClient.post "#{@@server}/ec2terminate/terminate", {:instanceId => instanceId}.to_json, :content_type => :json, :Authorization => "Token token=\"#{@@token}\""
231
+ JSON.parse(result.body)
232
+ rescue => e
233
+ raise e
234
+ end
235
+ end
236
+
228
237
  end
@@ -1,3 +1,3 @@
1
1
  module EndlessWaffleCLI
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: EndlessWaffleCLI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr. Ogg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -244,6 +244,7 @@ executables:
244
244
  - ewssh
245
245
  - ewssl
246
246
  - ewsubnets
247
+ - ewterminate
247
248
  - ewtoken
248
249
  extensions: []
249
250
  extra_rdoc_files: []
@@ -275,6 +276,7 @@ files:
275
276
  - exe/ewssh
276
277
  - exe/ewssl
277
278
  - exe/ewsubnets
279
+ - exe/ewterminate
278
280
  - exe/ewtoken
279
281
  - lib/EndlessWaffleCLI.rb
280
282
  - lib/EndlessWaffleCLI/version.rb