c66 0.1.0 → 0.1.94

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of c66 might be problematic. Click here for more details.

data/.gitignore CHANGED
@@ -2,12 +2,8 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
5
  coverage
10
- doc/
6
+ InstalledFiles
11
7
  lib/bundler/man
12
8
  pkg
13
9
  rdoc
@@ -15,3 +11,13 @@ spec/reports
15
11
  test/tmp
16
12
  test/version_tmp
17
13
  tmp
14
+ .cloud66
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
20
+
21
+ .ruby-gemset
22
+ .ruby-version
23
+ /dev.sh
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ c66 (0.1.93)
5
+ bundler (~> 1.3)
6
+ httparty (~> 0.11.0)
7
+ json (~> 1.7.7)
8
+ oauth2 (~> 0.9.2)
9
+ rake (~> 10.1.0)
10
+ thor (~> 0.18.1)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ faraday (0.8.8)
16
+ multipart-post (~> 1.2.0)
17
+ httparty (0.11.0)
18
+ multi_json (~> 1.0)
19
+ multi_xml (>= 0.5.2)
20
+ httpauth (0.2.0)
21
+ json (1.7.7)
22
+ jwt (0.1.8)
23
+ multi_json (>= 1.5)
24
+ multi_json (1.8.2)
25
+ multi_xml (0.5.5)
26
+ multipart-post (1.2.0)
27
+ oauth2 (0.9.2)
28
+ faraday (~> 0.8)
29
+ httpauth (~> 0.2)
30
+ jwt (~> 0.1.4)
31
+ multi_json (~> 1.0)
32
+ multi_xml (~> 0.5)
33
+ rack (~> 1.2)
34
+ rack (1.5.2)
35
+ rake (10.1.0)
36
+ thor (0.18.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ c66!
data/README.md CHANGED
@@ -1,111 +1,200 @@
1
- # Cloud 66 Toolbelt: c66
2
-
3
- Cloud 66 Toolbelt is a simple command-line tool for the awesome Cloud 66 customers. It allows you to deploy, modify settings and retrieve the current status of your Cloud 66 stacks, and much more!
1
+ <h1 class="doc-title">Cloud 66 Toolbelt</h1>
2
+ <p class="lead">Cloud 66 Toolbelt is a simple command-line tool for the awesome Cloud 66 customers. It allows you to deploy, modify settings and retrieve the current status of your Cloud 66 stacks, and much more!</p>
4
3
 
5
4
  ## Installation
6
5
 
7
6
  You can install the Cloud 66 Toolbelt using [RubyGems](http://rubygems.org/):
7
+ <p>
8
+ <kbd>$ gem install c66</kbd>
9
+ </p>
8
10
 
9
- $ gem install c66
10
-
11
- ## Usage
11
+ ## Help
12
12
 
13
- ### Help
14
13
  With c66 installed, you can display the help with one of the following instructions:
14
+ <p>
15
+ <kbd>$ c66 help</kbd>
16
+ </p>
17
+
18
+ or
15
19
 
16
- $ c66 help
20
+ <p>
21
+ <kbd>$ c66</kbd>
22
+ </p>
17
23
 
18
- or
24
+ or for a specific command:
19
25
 
20
- $ c66
26
+ <p>
27
+ <kbd>$ c66 help &lt;command&gt;</kbd>
28
+ </p>
21
29
 
22
- ### Initialize the Toolbelt
30
+ ## Initialize the Toolbelt
23
31
 
24
32
  Firstly, to use the Toolbelt, you will need to initiate it using:
25
33
 
26
- $ c66 init
27
-
34
+ <p>
35
+ <kbd>$ c66 init</kbd>
36
+ </p>
37
+
28
38
  Then visit the URL given once authorized, copy and paste the `authorization code` into the command-line interface.
29
-
30
39
  You need to sign in and allow the Cloud 66 Toolbelt application to use your account to access to the authorization code.
31
40
 
32
- Note: This is a one-off task.
41
+ **Note**: This is a one-off task.
33
42
 
34
- ### List the Stacks
43
+ ## List the Stacks
35
44
 
36
45
  You can list all your stacks using:
37
46
 
38
- $ c66 list
47
+ <p>
48
+ <kbd>$ c66 list</kbd>
49
+ </p>
39
50
 
40
- ### Deploy a Stack
51
+ ## Deploy a Stack
41
52
 
42
53
  Deploy a stack using the command `deploy` with a stack UID (Unique Identifer):
43
54
 
44
- $ c66 deploy --stack <stack_UID>
45
-
55
+ <p>
56
+ <kbd>$ c66 deploy --stack &lt;stack_UID&gt;</kbd>
57
+ </p>
58
+
46
59
  or
47
60
 
48
- $ c66 deploy -s <stack_UID>
49
-
61
+ <p>
62
+ <kbd>$ c66 deploy -s &lt;stack_UID&gt;</kbd>
63
+ </p>
64
+
50
65
  You can retrieve the UID of a stack using the `list` command.
51
-
52
66
  Through the Cloud 66 interface, click on your stack, then click on the cog and select the stack information view to retrieve the UID:
53
-
54
67
  ![stack_uid](http://cdn.cloud66.com.s3.amazonaws.com/images/Toolbelt/exemple_stack_uid.PNG)
55
68
 
56
- The stack UID is saved when you deploy through the Cloud 66 Toolbelt. It allows you to deploy a stack without putting the stack UID every time:
69
+ There is a command to save a default stack UID:
70
+
71
+ <p>
72
+ <kbd>$ c66 save --stack &lt;stack_UID&gt;</kbd>
73
+ </p>
74
+
75
+ or
57
76
 
58
- $ c66 deploy
77
+ <p>
78
+ <kbd>$ c66 save -s &lt;stack_UID&gt;</kbd>
79
+ </p>
59
80
 
81
+ **Note:** The stack is saved in your current folder (.cloud66/stack.json) and only one default stack will be saved per folder.
82
+
83
+ When your stack UID is saved, you are able to use other commands without specify the stack UID.
84
+ For instance, it allows you to deploy a stack without putting the stack UID every time:
85
+
86
+ <p>
87
+ <kbd>$ c66 deploy</kbd>
88
+ </p>
89
+
60
90
  you can use a short-cut for this command:
61
91
 
62
- $ c66 d
92
+ <p>
93
+ <kbd>$ c66 d</kbd>
94
+ </p>
63
95
 
64
- ### Settings of a Stack
96
+ You can save multiple stack UID by giving an alias to a specific stack:
65
97
 
66
- It is possible to retrieve the settings of a specified stack and to easily modify them:
98
+ <p>
99
+ <kbd>$ c66 save --stack &lt;stack_UID&gt; --alias &lt;stack_alias&gt;</kbd>
100
+ </p>
67
101
 
68
- To display the settings:
102
+ Then you can use commands and specific a stack's alias, like so:
69
103
 
70
- $ c66 settings --stack <stack_UID>
104
+ <p>
105
+ <kbd>$ c66 deploy -s &lt;stack_alias&gt;</kbd>
106
+ </p>
71
107
 
72
- or
108
+ ## Settings of a Stack
109
+
110
+ It is possible to retrieve the settings of a specified stack and to easily modify them:
73
111
 
74
- $ c66 settings -s <stack_UID>
112
+ To display the settings:
75
113
 
76
- If your stack UID is saved:
114
+ <p>
115
+ <kbd>$ c66 settings --stack &lt;stack_UID&gt;</kbd>
116
+ </p>
117
+
118
+ or
77
119
 
78
- $ c66 settings
120
+ <p>
121
+ <kbd>$ c66 settings -s &lt;stack_UID&gt;</kbd>
122
+ </p>
123
+
124
+ If a default stack UID is saved:
79
125
 
126
+ <p>
127
+ <kbd>$ c66 settings</kbd>
128
+ </p>
129
+
80
130
  To modify a setting:
81
131
 
82
- $ c66 set --stack <stack_UID> --setting_name <setting_name> --value <value>
132
+ <p>
133
+ <kbd>$ c66 set --stack &lt;stack_UID&gt; --setting_name &lt;setting_name&gt; --value &lt;value&gt;</kbd>
134
+ </p>
135
+
136
+ or
137
+
138
+ <p>
139
+ <kbd>$ c66 set -s &lt;stack_UID&gt; -n &lt;setting_name&gt; -v &lt;value&gt;</kbd>
140
+ </p>
141
+
142
+ If a default stack UID is saved:
83
143
 
144
+ <p>
145
+ <kbd>$ c66 set --setting_name &lt;setting_name&gt; --value &lt;value&gt;</kbd>
146
+ </p>
147
+
84
148
  or
85
149
 
86
- $ c66 set -s <stack_UID> -n <setting_name> -v <value>
150
+ <p>
151
+ <kbd>$ c66 set -n &lt;setting_name&gt; -v &lt;value&gt;</kbd>
152
+ </p>
87
153
 
88
- If the stack UID is saved:
154
+ ## Lease an IP address (version &ge; 0.1.91
89
155
 
90
- $ c66 set --setting_name <setting_name> --value <value>
156
+ You can allow an IP address to connect temporarily to the specific stack through ssh (22):
91
157
 
92
- or
158
+ <p>
159
+ <kbd>$ c66 lease --stack &lt;stack_UID&gt; --ip-address &lt;ip_address&gt; --time-to-open &lt;time_to_open&gt;</kbd>
160
+ </p>
93
161
 
94
- $ c66 set -n <setting_name> -v <value>
162
+ or
95
163
 
164
+ <p>
165
+ <kbd>$ c66 lease -s &lt;stack_UID&gt; -i &lt;ip_address&gt; -t &lt;time_to_open&gt;</kbd>
166
+ </p>
96
167
 
97
- ## Contributing
168
+ Options *ip-address* and *time-to-open* are optional.
169
+ By default:
98
170
 
99
- 1. Fork it
171
+ - *ip-address* : your IP address
172
+ - *time-to-open* : 20 minutes
173
+
174
+ To allow your own IP address to connect temporarily to the specific stack:
100
175
 
101
- 2. Create your feature branch (`git checkout -b my-new-feature`)
176
+ <p>
177
+ <kbd>$ c66 lease --stack &lt;stack_UID&gt;</kbd>
178
+ </p>
102
179
 
103
- 3. Commit your changes (`git commit -am 'Add some feature'`)
180
+ If a default stack UID is saved:
104
181
 
105
- 4. Push to the branch (`git push origin my-new-feature`)
182
+ <p>
183
+ <kbd>$ c66 lease</kbd>
184
+ </p>
106
185
 
107
- 5. Create new Pull Request
186
+ ## Information of your toolbelt settings
108
187
 
109
- ## Copyright
188
+ At any time, you can see your toolbelt settings, it includes the version of the toolbelt but also some information about your saved stacks:
189
+
190
+ <p>
191
+ <kbd>$ c66 info</kbd>
192
+ </p>
110
193
 
111
- Copyright (c) 2013 Cloud66 Limited.. See LICENSE for details.
194
+ ## Contributing
195
+
196
+ 1. Fork it
197
+ 2. Create your feature branch `git checkout -b my-new-feature`
198
+ 3. Commit your changes `git commit -am 'Add some feature'`
199
+ 4. Push to the branch `git push origin my-new-feature`
200
+ 5. Create new Pull Request
@@ -8,6 +8,7 @@ module C66
8
8
  module Commands
9
9
 
10
10
  CLIENT_NAME = 'c66'
11
+ CLIENT_FULLNAME = 'Cloud 66 Toolbelt'
11
12
 
12
13
  STK_QUEUED = 0
13
14
  STK_SUCCESS = 1
@@ -18,6 +19,8 @@ module C66
18
19
  STK_DEPLOYING = 6
19
20
  STK_TERMINAL_FAILURE = 7
20
21
 
22
+ FORBIDDEN_STACKS_ALIAS = ['params', 'toolbelt']
23
+
21
24
  STATUS = {
22
25
  STK_QUEUED => 'Pending analysis',
23
26
  STK_SUCCESS => 'Deployed successfully',
@@ -30,16 +33,18 @@ module C66
30
33
  }
31
34
 
32
35
  VERSION_FILE = 'http://cdn.cloud66.com/config/cloud66_toolbelt.json'
33
- BASE_URL = 'https://www.cloud66.com'
36
+ BASE_URL = ENV['C66_API_ENDPOINT'] || 'https://www.cloud66.com'
37
+ CLIENT_ID = ENV['C66_CLIENT_ID'] || '638412995ee3da6f67e24564ac297f9554ee253a8fe1502348c4d6e845bd9d0d'
38
+ CLIENT_SECRET = ENV['C66_CLIENT_SECRET'] || '961398353aa6e7f0f36dfcd83e447d748c54481b7a3b143e0119441516e8b91f'
34
39
 
35
40
  class C66Toolbelt < Thor
36
41
  no_commands {
37
42
  def values
38
43
  @values ||=
39
44
  { :base_url => "#{BASE_URL}/api/2",
40
- :client_id => "638412995ee3da6f67e24564ac297f9554ee253a8fe1502348c4d6e845bd9d0d",
41
- :client_secret => "961398353aa6e7f0f36dfcd83e447d748c54481b7a3b143e0119441516e8b91f",
42
- :scope => "public redeploy",
45
+ :client_id => CLIENT_ID,
46
+ :client_secret => CLIENT_SECRET,
47
+ :scope => "public redeploy admin users jobs",
43
48
  :redirect_url => "urn:ietf:wg:oauth:2.0:oob",
44
49
  :auth_url => "#{BASE_URL}/oauth/authorize",
45
50
  :token_url => "#{BASE_URL}/oauth/token"
@@ -47,6 +52,7 @@ module C66
47
52
  end
48
53
 
49
54
  def base_url
55
+ load_params
50
56
  values[:base_url]
51
57
  end
52
58
 
@@ -74,8 +80,16 @@ module C66
74
80
  File.join(c66_path, "params.json")
75
81
  end
76
82
 
77
- def stack_file
78
- File.join(stack_path, "stack.json")
83
+ def stack_file(alias_name = nil)
84
+ if alias_name
85
+ if alias_name.match(/\w/)
86
+ File.join(stack_path, "#{alias_name}.json")
87
+ else
88
+ abort "#{alias_name} is an invalid alias."
89
+ end
90
+ else
91
+ File.join(stack_path, "stack.json")
92
+ end
79
93
  end
80
94
 
81
95
  def load_config
@@ -88,7 +102,7 @@ module C66
88
102
 
89
103
  def save_config
90
104
  if !File.directory?(c66_path)
91
- Dir.mkdir_p(c66_path)
105
+ Dir.mkdir(c66_path)
92
106
  end
93
107
 
94
108
  File.open(config_file,"w") do |f|
@@ -96,28 +110,27 @@ module C66
96
110
  end
97
111
  end
98
112
 
99
- def save_stack(stack_id)
100
- if !File.directory?(stack_path)
101
- Dir.mkdir(stack_path)
102
- end
103
- @stack_json = { :stack_id => stack_id}
104
- File.open(stack_file,"w") do |f|
105
- f.write(@stack_json.to_json)
113
+ def load_stack(alias_name)
114
+ if File.exists?(stack_file(alias_name))
115
+ if file = JSON.load(IO.read(stack_file(alias_name)))
116
+ if file.has_key? 'stack_id'
117
+ @stack = file['stack_id']
118
+ end
119
+ if file.has_key? 'stack_name' and !@stack.nil?
120
+ @stack_name = file['stack_name']
121
+ say "Stack #{@stack_name} loaded."
122
+ end
123
+ end
106
124
  end
107
- @stack = stack_id
108
- say "Stack #{stack_id} saved to #{stack_file}"
109
125
  end
110
126
 
111
- def load_stack
112
- if File.exists?(stack_file)
113
- if @stack = JSON.load(IO.read(stack_file))['stack_id']
114
- say "Stack #{@stack} loaded."
115
- else
116
- abort "No stack id found at #{stack_file}"
117
- end
118
- else
119
- say("No stack saved at #{stack_file}.")
120
- end
127
+ def abort_no_stack
128
+ abort "No stack provided or saved, please use '--stack' or '-s' option. "\
129
+ "You can also use the 'save' method with '--stack' or '-s' option."
130
+ end
131
+
132
+ def abort_no_server
133
+ abort "Cannot find the given server name in the stack."
121
134
  end
122
135
 
123
136
  def load_params
@@ -130,25 +143,40 @@ module C66
130
143
  if @params.has_key? 'base_url'
131
144
  values[:base_url] = @params['base_url']
132
145
  else
133
- abort "Missing 'base_url' parameter in #{params_file}"
146
+ abort "Missing 'base_url' parameter in #{params_file}"
134
147
  end
135
148
  if @params.has_key? 'client_id'
136
149
  values[:client_id] = @params['client_id']
137
150
  else
138
- abort "Missing 'client_id' parameter in #{params_file}"
151
+ abort "Missing 'client_id' parameter in #{params_file}"
139
152
  end
140
153
  if @params.has_key? 'client_secret'
141
154
  values[:client_secret] = @params['client_secret']
142
155
  else
143
- abort "Missing 'client_secret' parameter in #{params_file}"
156
+ abort "Missing 'client_secret' parameter in #{params_file}"
144
157
  end
145
- say "Parameters loaded."
158
+ #say "Parameters loaded."
146
159
  end
147
160
  end
148
161
 
149
- def get_stack(stack)
150
- save_stack(stack) if stack
151
- load_stack if stack.nil?
162
+ def get_stack(stack_id_or_alias_name)
163
+ if stack_id_or_alias_name && !File.exist?(stack_file(stack_id_or_alias_name))
164
+ @stack=stack_id_or_alias_name
165
+ else
166
+ load_stack(stack_id_or_alias_name)
167
+ end
168
+ end
169
+
170
+ def get_server_by_name(stack_id_or_alias_name, server_name)
171
+ get_stack(stack_id_or_alias_name)
172
+
173
+ # get stack servers
174
+ response = token.get("#{base_url}/stacks/#{@stack}/servers.json")
175
+ servers = parse_response(response)['response']
176
+ server = servers.select { |s| s['name'].downcase == server_name.downcase }
177
+
178
+ return nil if server.empty?
179
+ return server.first
152
180
  end
153
181
 
154
182
  def client
@@ -173,33 +201,60 @@ module C66
173
201
  end
174
202
  end
175
203
 
176
- def self.get_version
204
+ def error_message(error)
177
205
  begin
178
- JSON.load(HTTParty.get(VERSION_FILE)).fetch("version")
206
+ if !error.response.parsed.nil?
207
+ if (error.response.parsed.has_key? 'details')
208
+ say error.response.parsed['details']
209
+ else
210
+ say error.response.parsed['error_description']
211
+ end
212
+ end
179
213
  rescue => e
180
- puts "Failed to retrieve the latest version of Cloud 66 Toolbelt, please contact us"
214
+ abort e.message
181
215
  end
182
216
  end
183
217
 
184
-
185
- def self.compare_versions
186
- result = C66::Utils::VERSION<=>get_version
218
+ def get_version
219
+ begin
220
+ JSON.load(HTTParty.get(VERSION_FILE).response.body).fetch("version")
221
+ rescue => e
222
+ say "Failed to retrieve the latest version of Cloud 66 Toolbelt, please contact us"
223
+ end
224
+ end
225
+
226
+ def display_info
227
+ say "#{CLIENT_FULLNAME} version #{C66::Utils::VERSION}\n\n"
228
+ end
229
+
230
+ def compare_versions
231
+ result = C66::Utils::VERSION <=> Gem::Version.new(get_version)
187
232
  case result
188
233
  when 0..1
189
- #say "Version is up-to-date."
190
- when -1
191
- puts "There is a new version of Cloud66 Toolbelt. Pease run \"gem update #{CLIENT_NAME}\"."
234
+ #say "Version is up-to-date."
235
+ when -1
236
+ say "There is a new version of Cloud66 Toolbelt. Pease run \"gem update #{CLIENT_NAME}\".",:red
192
237
  end
193
- end
238
+ end
239
+
240
+ def before_each_action
241
+ compare_versions
242
+ # pending_intercom_messages
243
+ end
194
244
  }
195
245
 
196
- package_name "Cloud 66 Toolbelt"
197
- desc "init", "Initialize the toolbelt"
198
- map "d" => :deploy
246
+ package_name "#{CLIENT_FULLNAME}: version #{C66::Utils::VERSION}\n"
199
247
 
200
- compare_versions
201
-
248
+ default_task :default
249
+
250
+ desc "default", "hidden method", :hide => true
251
+ def default
252
+ before_each_action
253
+ help
254
+ end
202
255
 
256
+ desc "init", "Initialize the toolbelt"
257
+ map "d" => :deploy
203
258
  long_desc <<-LONGDESC
204
259
  Initialize Cloud 66 toolbelt
205
260
  LONGDESC
@@ -226,61 +281,225 @@ module C66
226
281
 
227
282
  desc "list", "Lists all the stacks"
228
283
  def list
229
- response = parse_response(token.get("#{base_url}/stacks.json"))
284
+ before_each_action
285
+ begin
286
+ response = parse_response(token.get("#{base_url}/stacks.json"))
230
287
 
231
- if response['count'] != 0
232
- response['response'].each do |stack|
233
- say "#{stack['name']} (#{stack['uid']}) : #{stack['environment']} - #{STATUS[stack['status']]}"
288
+ if response['count'] != 0
289
+ response['response'].each do |stack|
290
+ say "#{stack['name']} (#{stack['uid']}) : #{stack['environment']} - #{STATUS[stack['status']]}"
291
+ end
292
+ else
293
+ say "No stacks found"
234
294
  end
235
- else
236
- say "No stacks found"
295
+ rescue OAuth2::Error => e
296
+ error_message(e)
237
297
  end
238
298
  end
239
299
 
240
300
  desc "settings", "Get the list of settings for this stack"
241
301
  option :stack, :aliases => "-s", :required => false
242
- def settings()
302
+ def settings
303
+ before_each_action
243
304
  begin
244
305
  get_stack(options[:stack])
245
- abort "No stack provided or saved, please use '--stack' or '-s' option" if @stack.nil?
306
+ abort_no_stack if @stack.nil?
246
307
  response = token.get("#{base_url}/stacks/#{@stack}/settings.json")
247
308
  settings = JSON.parse(response.body)['response']
309
+ number_settings = JSON.parse(response.body)['count']
310
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{@stack}.json"))
311
+ stack_name = stack_details['response']['name']
248
312
 
249
313
  abort "No settings found" if settings.nil?
250
-
314
+ say "Getting #{stack_name} settings:"
251
315
  settings.each do |setting|
252
- say "#{setting['key']}\t\t#{setting['value']}\t#{setting['readonly'] ? '(readonly)' : ''}\r\n"
316
+ say "#{setting['key'].ljust(20)}\t\t#{setting['value']}\t#{setting['readonly'] ? '(readonly)' : ''}\r\n"
253
317
  end
254
318
  rescue OAuth2::Error => e
255
- abort e.message
319
+ error_message(e)
256
320
  end
257
321
  end
258
322
 
323
+ desc "ssh", "Start a SSH shell terminal with the given server"
324
+ option :stack, :aliases => "-s", :required => false
325
+ option :server_name, :aliases => "-n", :required => true
326
+ def ssh
327
+ before_each_action
328
+ begin
329
+ get_stack(options[:stack])
330
+ abort_no_stack if @stack.nil?
331
+ server = get_server_by_name(options[:stack], options[:server_name])
332
+ abort_no_server if server.nil?
333
+ say "Found server #{server['uid']} with name #{options[:server_name]}"
334
+
335
+ # get the SSH key
336
+ say "Requesting the SSH keys"
337
+ response = token.get("#{base_url}/servers/#{server['uid']}/ssh_private_key.json")
338
+ prv_key = parse_response(response)['response']['private_key']
339
+
340
+ say "Openning firewall temporarily for this IP address"
341
+ lease
342
+
343
+ path = File.join(Dir.home, '.ssh', "server_#{server['name'].downcase}")
344
+
345
+ # save it to user directory
346
+ File.open(path, 'w') do |file|
347
+ file.write(prv_key)
348
+ file.chmod(0600)
349
+ end
350
+
351
+ # let's do it
352
+ say "ssh '#{server['user_name']}'@'#{server['address']}' -i '#{path}'"
353
+ system "ssh '#{server['user_name']}'@'#{server['address']}' -i '#{path}'"
354
+ rescue OAuth2::Error => e
355
+ error_message(e)
356
+ end
357
+ end
358
+
259
359
  desc "set", "Set the value of a specific setting"
260
360
  option :stack, :aliases => "-s", :required => false
261
361
  option :setting_name, :aliases => "-n", :required => true
262
362
  option :value, :aliases => "-v", :required => true
263
363
  def set()
364
+ before_each_action
264
365
  begin
265
366
  get_stack(options[:stack])
266
- abort "No stack provided or saved, please use '--stack' or '-s' option" if @stack.nil?
367
+ abort_no_stack if @stack.nil?
368
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{@stack}.json"))
369
+ stack_name = stack_details['response']['name']
267
370
  response = token.post("#{base_url}/stacks/#{@stack}/setting.json", { :body => { :setting_name => options[:setting_name], :setting_value => options[:value] }})
268
- say "Setting applied" if JSON.parse(response.body)['response']['ok']
371
+ say "On #{stack_name}: applied value '#{options[:value]}' to setting '#{options[:setting_name]}'" if JSON.parse(response.body)['response']['ok']
269
372
  rescue OAuth2::Error => e
270
- abort e.message
373
+ error_message(e)
271
374
  end
272
375
  end
273
376
 
274
377
  desc "deploy", "Deploy the given stack"
275
378
  option :stack, :aliases => "-s", :required => false
276
- def deploy()
379
+ def deploy
380
+ before_each_action
277
381
  begin
278
382
  get_stack(options[:stack])
279
- abort "No stack provided or saved, please use '--stack' or '-s' option" if @stack.nil?
383
+ abort_no_stack if @stack.nil?
384
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{@stack}.json"))
385
+ stack_name = stack_details['response']['name']
386
+ say stack_name+": "
280
387
  response = token.post("#{base_url}/stacks/#{@stack}/redeploy.json", {})
281
388
  say JSON.parse(response.body)['response']['message']
282
389
  rescue OAuth2::Error => e
283
- abort "Could't find your stack, maybe it was moved, deleted or you accidentally mistyped the stack ID"
390
+ error_message(e)
391
+ end
392
+ end
393
+
394
+ desc "restart", "Restart the given stack"
395
+ option :stack, :aliases => "-s", :required => false
396
+ option :target, :aliases => "-t", :required => false
397
+ def restart
398
+ before_each_action
399
+ begin
400
+ get_stack(options[:stack])
401
+ abort_no_stack if @stack.nil?
402
+
403
+ target_option = options[:target]
404
+ target = target_option.nil? ? 'web' : target_option.to_s
405
+ abort "Only 'web' target is currently supported" unless target == 'web'
406
+
407
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{@stack}.json"))
408
+ stack_name = stack_details['response']['name']
409
+ say stack_name+": "
410
+ response = token.post("#{base_url}/stacks/#{@stack}/restart.json", {})
411
+ say JSON.parse(response.body)['response']['message']
412
+
413
+ rescue OAuth2::Error => e
414
+ error_message(e)
415
+ end
416
+ end
417
+
418
+ desc "save", "Save the given stack information in the current directory"
419
+ option :stack, :aliases => "-s", :required => true
420
+ option :alias, :aliases => "-a", :required => false
421
+ def save
422
+ before_each_action
423
+ begin
424
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{options[:stack]}.json"))
425
+ stack_name = stack_details['response']['name']
426
+ if !File.directory?(stack_path)
427
+ Dir.mkdir(stack_path)
428
+ end
429
+ @stack_json = { :stack_id => options[:stack], :stack_name => stack_name}
430
+ if (!FORBIDDEN_STACKS_ALIAS.include? options[:alias])
431
+ File.open(stack_file(options[:alias]),"w") do |f|
432
+ f.write(@stack_json.to_json)
433
+ end
434
+ else
435
+ abort 'Stack alias "'+options[:alias]+'" is forbidden, please retry with another alias.'
436
+ end
437
+ @stack = options[:stack]
438
+
439
+ say "Linked stack #{stack_name} to #{stack_file(options[:alias])}.\n"
440
+ if !options[:alias]
441
+ say "You are now able to use other commands without specify the stack UID."
442
+ else
443
+ say "You are now able to use other commands and specific this stack's alias, like so: "\
444
+ "`c66 deploy -s #{options[:alias]}`"
445
+ end
446
+ rescue OAuth2::Error => e
447
+ error_message(e)
448
+ end
449
+ end
450
+
451
+ desc "info", "#{CLIENT_FULLNAME} information"
452
+ def info
453
+ before_each_action
454
+ begin
455
+ say "#{CLIENT_FULLNAME} version #{C66::Utils::VERSION}\n\n"
456
+ Dir.glob("#{stack_path}/*.json") do |stack_file|
457
+ stack_alias = File.basename(stack_file, ".json")
458
+ if (!FORBIDDEN_STACKS_ALIAS.include? stack_alias)
459
+ load_stack(stack_alias)
460
+ if stack_alias == "stack"
461
+ say "Default stack: no alias"
462
+ else
463
+ say "Alias: #{stack_alias}"
464
+ end
465
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{@stack}.json"))
466
+ say "Name: #{stack_details['response']['name']}"
467
+ say "UID: #{stack_details['response']['uid']}"
468
+ say "Environment: #{stack_details['response']['environment']}"
469
+ say "Status: #{STATUS[stack_details['response']['status']]}\n\n"
470
+ end
471
+ end
472
+ rescue OAuth2::Error => e
473
+ puts "Didn't find any valid stacks, please use the 'save' method."
474
+ error_message(e)
475
+ end
476
+ end
477
+
478
+ desc "lease", "Allow an IP address to connect temporary to the specific stack through ssh (22)"
479
+ option :stack, :aliases => "-s", :required => false
480
+ option :ip_address, :aliases => "-i", :required => false
481
+ option :time_to_open, :aliases => "-t", :required => false, :default => 20
482
+ option :show_ip, :aliases => "-a", :required => false
483
+ def lease()
484
+ before_each_action
485
+ begin
486
+ abort "time_to_open value is invalid. The value must be an integer between 0 and 240 (~4 hours)." if !(0..240).include? options[:time_to_open].to_i
487
+ get_stack(options[:stack])
488
+ abort_no_stack if @stack.nil?
489
+ stack_details = parse_response(token.get("#{base_url}/stacks/#{@stack}.json"))
490
+ stack_name = stack_details['response']['name']
491
+ response = token.post("#{base_url}/stacks/#{@stack}/lease.json", { :body => { :ip_address => options[:ip_address], :time_to_open => options[:time_to_open] }})
492
+ say JSON.parse(response.body)['response']['message'] if JSON.parse(response.body)['response']['ok']
493
+
494
+ if options[:show_ip]
495
+ server_groups = token.get("#{base_url}/stacks/#{@stack}/server_groups.json")
496
+ rails_server_group = JSON.parse(server_groups.body)['response'].find { |sg| sg['name'] == 'Rails Server' }
497
+ servers = token.get("#{base_url}/stacks/#{@stack}/server_groups/#{rails_server_group['id']}/servers.json")
498
+ server_ip_address = JSON.parse(servers.body)['response'][0]['address']
499
+ say "For reference, here's the IP address for your first Rails server: #{server_ip_address}"
500
+ end
501
+ rescue OAuth2::Error => e
502
+ error_message(e)
284
503
  end
285
504
  end
286
505
  end
@@ -1,6 +1,7 @@
1
1
  module C66
2
2
  module Utils
3
- VERSION = "0.1.0"
3
+ #Version format
4
+ VERSION = Gem::Version.new("0.1.94")
4
5
  end
5
6
  end
6
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c66
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.94
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
12
+ date: 2013-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70093107966800 !ruby/object:Gem::Requirement
16
+ requirement: &70177442426140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70093107966800
24
+ version_requirements: *70177442426140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70093107966180 !ruby/object:Gem::Requirement
27
+ requirement: &70177442425560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 10.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70093107966180
35
+ version_requirements: *70177442425560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &70093107965480 !ruby/object:Gem::Requirement
38
+ requirement: &70177442425080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.18.1
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70093107965480
46
+ version_requirements: *70177442425080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: oauth2
49
- requirement: &70093107964520 !ruby/object:Gem::Requirement
49
+ requirement: &70177442424480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.9.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70093107964520
57
+ version_requirements: *70177442424480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: json
60
- requirement: &70093107963280 !ruby/object:Gem::Requirement
60
+ requirement: &70177442423920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.7.7
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70093107963280
68
+ version_requirements: *70177442423920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
- requirement: &70093107962820 !ruby/object:Gem::Requirement
71
+ requirement: &70177442423160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,21 +76,22 @@ dependencies:
76
76
  version: 0.11.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70093107962820
79
+ version_requirements: *70177442423160
80
80
  description: See https://www.cloud66.com for more info
81
81
  email:
82
82
  - hello@cloud66.com
83
83
  executables:
84
- - c66.rb
84
+ - c66
85
85
  extensions: []
86
86
  extra_rdoc_files: []
87
87
  files:
88
88
  - .gitignore
89
89
  - Gemfile
90
+ - Gemfile.lock
90
91
  - LICENSE.txt
91
92
  - README.md
92
93
  - Rakefile
93
- - bin/c66.rb
94
+ - bin/c66
94
95
  - c66.gemspec
95
96
  - lib/c66.rb
96
97
  - lib/c66/commands/c66_toolbelt.rb
File without changes