shelly 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTBiNDgwNzhlNDdhZGU5YmY3MjQ3YTUwNTJmNjY0YTEyMTA4YTlkNA==
4
+ ZWM1NDEyYjYzZTUyNGQ0NDVhMzg0NjdmM2QzNWM4MGQ3NTA0NDJmYQ==
5
5
  data.tar.gz: !binary |-
6
- NWQ3NTdjZGY4ZTFiNjgwMTQ2Y2FiMzYwYmNmMzRkMDcxZjA5ZGMwNQ==
6
+ ZjllMDk5Nzk2NjY5OWM4OTUxMTZiZmMzMDdlZWMxZDU3OGM4YzRiNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTczNTdhMjljZjEyY2ZiZDcyMDM0ODUxMDY5ZTZlYmE5YjQ0YjBlMGRlNTNj
10
- OTFmYzc1MzAzOGRhYzgxMDM2NWVhN2YwNzViMjljOTljMmFmMTY4MDQ0MzU3
11
- MzU3MWQ1NGFhOWUzMDg3NmNhZmZiNmFmMTFiMjY1NzUxNTk1MDk=
9
+ NDEzZTBmOTQ5YzA1NWY1YTEyNzQ3Njc5ZDAyOGEyNDZjMDJmM2YyZTZkOWQw
10
+ MGUxZmY5ODY4Y2NlZTNjZjgxYzQxMmNkNDMzMWE3NDdmNzhjMjM3ODFkYmVl
11
+ N2U2OGRiMTRkMTk2NmFkOGFiZWJiMWE1ZTJkMmRiNWI4MjFlY2M=
12
12
  data.tar.gz: !binary |-
13
- MjA4ZjQyODRhYjRjYjIzZGUwNjczM2QyMTM4MTY4NTBlYWVmM2FlNTQ4NmFk
14
- YjBiYWFhOTdkNTljOTNmODc3ZmZjNTBlMzU1YTU3MWVhNWMyNDExYjZmYzVj
15
- Y2VhNzY1ODZiYTAzZTA4MmY0NzkyYzQyNDQyNmY2OTRhMWIwOGE=
13
+ ZDk3OTg5NjVlYmVhYWI4NTVhY2U1MjUwZWZjYjUyMjFjZDc1YzgzYTA5YzM5
14
+ NWM3YmRhYzIxMWE1NDVlNTFkNzAzOTkxNTM5NjYyZWZlMDNiMDdjMzZlYjg2
15
+ OGIwZGIwMDdlOWU4ZjA1NTE0ODgzY2E0Y2RjMTI4NGQyYTU1OTc=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.2 / 2013-06-28
2
+
3
+ * [improvement] API changes to handle user virtual server interactions
4
+
1
5
  ## 0.3.1 / 2013-06-28
2
6
 
3
7
  * [feature] `shelly database reset` reset PostgreSQL or MongoDB database, also possible to use with `shelly backup import DB_KIND dump --reset` option
data/lib/shelly/app.rb CHANGED
@@ -129,12 +129,12 @@ module Shelly
129
129
  end
130
130
 
131
131
  def import_database(kind, filename, server)
132
- ssh(:command => "import_database #{kind.downcase} #{filename}",
133
- :server => server, :type => :db_server)
132
+ ssh_with_db_server(:command => "import_database #{kind.downcase} #{filename}",
133
+ :server => server)
134
134
  end
135
135
 
136
136
  def reset_database(kind)
137
- ssh(:command => "reset_database #{kind.downcase}", :type => :db_server)
137
+ ssh_with_db_server(:command => "reset_database #{kind.downcase}")
138
138
  end
139
139
 
140
140
  def request_backup(kinds)
@@ -201,7 +201,7 @@ module Shelly
201
201
  end
202
202
 
203
203
  def dbconsole
204
- ssh(:command => "dbconsole", :type => :db_server)
204
+ ssh_with_db_server(:command => "dbconsole")
205
205
  end
206
206
 
207
207
  def attributes
@@ -257,23 +257,23 @@ module Shelly
257
257
  end
258
258
 
259
259
  def list_files(path)
260
- ssh(:command => "ls -l #{persistent_disk}/#{path}", :type => :server)
260
+ ssh(:command => "ls -l #{persistent_disk}/#{path}")
261
261
  end
262
262
 
263
263
  def upload(source)
264
- server_connection.tap do |conn|
264
+ console_connection.tap do |conn|
265
265
  rsync(source, "#{conn['host']}:#{persistent_disk}", conn)
266
266
  end
267
267
  end
268
268
 
269
269
  def upload_database(source)
270
- db_server_connection.tap do |conn|
270
+ configured_db_server_connection.tap do |conn|
271
271
  rsync(source, "#{conn['host']}:#{persistent_disk}", conn)
272
272
  end
273
273
  end
274
274
 
275
275
  def download(relative_source, destination)
276
- server_connection.tap do |conn|
276
+ console_connection.tap do |conn|
277
277
  source = File.join("#{conn['host']}:#{persistent_disk}", relative_source)
278
278
  rsync(source, destination, conn)
279
279
  end
@@ -365,34 +365,23 @@ module Shelly
365
365
  content["servers"].any? {|_, settings| settings.has_key?(option)}
366
366
  end
367
367
 
368
+ # Returns first at least configured virtual server
368
369
  def console_connection(server = nil)
369
370
  shelly.console(code_name, server)
370
371
  end
371
372
 
372
- # Returns first configured virtual server
373
- def server_connection
374
- shelly.configured_server(code_name)
375
- end
376
-
377
- # Returns first configured virtual server with database
378
- def db_server_connection(server = nil)
373
+ # Returns first at least configured virtual server if databases are configured
374
+ def configured_db_server_connection(server = nil)
379
375
  shelly.configured_db_server(code_name, server)
380
376
  end
381
377
 
382
- def connection(options)
383
- case options[:type]
384
- when :console
385
- console_connection(options[:server])
386
- when :server
387
- server_connection
388
- when :db_server
389
- db_server_connection(options[:server])
390
- end
378
+ def ssh(options = {})
379
+ conn = console_connection(options[:server])
380
+ system "ssh #{ssh_options(conn)} -t #{conn['host']} #{options[:command]}"
391
381
  end
392
382
 
393
- def ssh(options = {})
394
- options[:type] = :console unless options[:type]
395
- conn = connection(options)
383
+ def ssh_with_db_server(options = {})
384
+ conn = configured_db_server_connection(options[:server])
396
385
  system "ssh #{ssh_options(conn)} -t #{conn['host']} #{options[:command]}"
397
386
  end
398
387
 
@@ -132,7 +132,7 @@ module Shelly
132
132
  app.import_database(kind, archive, connection["server"])
133
133
  say "Database imported successfully", :green
134
134
  rescue Client::ConflictException => e
135
- say_error e[:message]
135
+ say_error "Cloud #{app} wasn't deployed properly. Cannot import database."
136
136
  end
137
137
 
138
138
  no_tasks do
@@ -20,6 +20,8 @@ module Shelly
20
20
  say "All database objects and data will be removed"
21
21
  ask_to_reset_database
22
22
  app.reset_database(kind)
23
+ rescue Client::ConflictException
24
+ say_error "Cloud #{app} wasn't deployed properly. Cannot reset database."
23
25
  end
24
26
  end
25
27
  end
@@ -15,7 +15,7 @@ module Shelly
15
15
  app = multiple_clouds(options[:cloud], "file list #{path}")
16
16
  app.list_files(path)
17
17
  rescue Client::ConflictException
18
- say_error "Cloud #{app} is not running. Cannot list files."
18
+ say_error "Cloud #{app} wasn't deployed properly. Cannot list files."
19
19
  end
20
20
 
21
21
  desc "upload PATH", "Upload files to persistent data storage"
@@ -23,7 +23,7 @@ module Shelly
23
23
  app = multiple_clouds(options[:cloud], "file upload #{path}")
24
24
  app.upload(path)
25
25
  rescue Client::ConflictException
26
- say_error "Cloud #{app} is not running. Cannot upload files."
26
+ say_error "Cloud #{app} wasn't deployed properly. Cannot upload files."
27
27
  end
28
28
 
29
29
  desc "download [SOURCE_PATH] [DEST_PATH]", "Download files from persistent data storage"
@@ -36,7 +36,7 @@ module Shelly
36
36
  app = multiple_clouds(options[:cloud], "file download #{relative_source} #{destination}")
37
37
  app.download(relative_source, destination)
38
38
  rescue Client::ConflictException
39
- say_error "Cloud #{app} is not running. Cannot download files."
39
+ say_error "Cloud #{app} wasn't deployed properly. Cannot download files."
40
40
  end
41
41
 
42
42
  method_option :force, :type => :boolean, :aliases => "-f",
@@ -52,7 +52,7 @@ module Shelly
52
52
 
53
53
  app.delete_file(path)
54
54
  rescue Client::ConflictException
55
- say_error "Cloud #{app} is not running. Cannot delete files."
55
+ say_error "Cloud #{app} wasn't deployed properly. Cannot delete files."
56
56
  end
57
57
 
58
58
  no_tasks do
@@ -38,10 +38,6 @@ class Shelly::Client
38
38
  get("/apps/#{code_name}/console", {:server => server})
39
39
  end
40
40
 
41
- def configured_server(code_name)
42
- get("/apps/#{code_name}/configured_server")
43
- end
44
-
45
41
  def configured_db_server(code_name, server = nil)
46
42
  get("/apps/#{code_name}/configured_db_server", {:server => server})
47
43
  end
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -348,15 +348,14 @@ describe Shelly::App do
348
348
 
349
349
  describe "#list_files" do
350
350
  it "should list files for given subpath in disk" do
351
- @app.should_receive(:ssh).with(:command => "ls -l /home/foo-staging/disk/foo",
352
- :type => :server)
351
+ @app.should_receive(:ssh).with(:command => "ls -l /home/foo-staging/disk/foo")
353
352
  @app.list_files("foo")
354
353
  end
355
354
  end
356
355
 
357
356
  describe "#upload" do
358
357
  it "should run rsync with proper parameters" do
359
- @client.stub(:configured_server).and_return(
358
+ @client.stub(:console).and_return(
360
359
  {"host" => "console.example.com", "port" => "40010", "user" => "foo"})
361
360
  @app.should_receive(:system).with("rsync -avz -e 'ssh -o StrictHostKeyChecking=no -p 40010 -l foo' --progress /path console.example.com:/home/foo-staging/disk")
362
361
  @app.upload("/path")
@@ -365,7 +364,7 @@ describe Shelly::App do
365
364
 
366
365
  describe "#download" do
367
366
  it "should run rsync with proper parameters" do
368
- @client.stub(:configured_server).and_return(
367
+ @client.stub(:console).and_return(
369
368
  {"host" => "console.example.com", "port" => "40010", "user" => "foo"})
370
369
  @app.should_receive(:system).with("rsync -avz -e 'ssh -o StrictHostKeyChecking=no -p 40010 -l foo' --progress console.example.com:/home/foo-staging/disk/. /tmp")
371
370
  @app.download(".", "/tmp")
@@ -265,6 +265,7 @@ describe Shelly::CLI::Backup do
265
265
  before do
266
266
  FileUtils.touch("dump.sql")
267
267
  @app.stub(:upload_database => {"server" => "app1"}, :ssh => nil)
268
+ @app.stub(:import_database)
268
269
  @backup.stub(:system)
269
270
  $stdout.stub(:puts)
270
271
  $stdout.stub(:print)
@@ -292,8 +293,9 @@ describe Shelly::CLI::Backup do
292
293
  end
293
294
 
294
295
  it "should import given database from uploaded file" do
295
- @app.should_receive(:ssh).with(:command => "import_database postgresql dump.sql-1370879705.tar.bz2",
296
- :server => "app1", :type => :db_server)
296
+ @app.unstub(:import_database)
297
+ @app.should_receive(:ssh_with_db_server).with(:command => "import_database postgresql dump.sql-1370879705.tar.bz2",
298
+ :server => "app1")
297
299
  $stdout.should_receive(:puts).with(green "Importing database")
298
300
  fake_stdin(["yes"]) do
299
301
  invoke(@backup, :import, "PostgreSQL", "dump.sql")
@@ -327,10 +329,11 @@ describe Shelly::CLI::Backup do
327
329
 
328
330
  context "with --reset option" do
329
331
  it "should reset database first" do
332
+ @app.unstub(:import_database)
330
333
  @backup.options = {:cloud => "foo-staging", :reset => true}
331
334
  @app.should_receive(:reset_database).with("postgresql")
332
- @app.should_receive(:ssh).with(:command => "import_database postgresql dump.sql-1370879705.tar.bz2",
333
- :server => "app1", :type => :db_server)
335
+ @app.should_receive(:ssh_with_db_server).with(:command => "import_database postgresql dump.sql-1370879705.tar.bz2",
336
+ :server => "app1")
334
337
  $stdout.should_receive(:puts).with(green "Importing database")
335
338
  fake_stdin(["yes"]) do
336
339
  invoke(@backup, :import, "postgresql", "dump.sql")
@@ -28,8 +28,8 @@ describe Shelly::CLI::File do
28
28
 
29
29
  context "cloud is not running" do
30
30
  it "should display error" do
31
- @client.stub(:configured_server).and_raise(Shelly::Client::ConflictException)
32
- $stdout.should_receive(:puts).with(red "Cloud foo-production is not running. Cannot list files.")
31
+ @client.stub(:console).and_raise(Shelly::Client::ConflictException)
32
+ $stdout.should_receive(:puts).with(red "Cloud foo-production wasn't deployed properly. Cannot list files.")
33
33
  lambda {
34
34
  invoke(@cli_files, :list, "some/path")
35
35
  }.should raise_error(SystemExit)
@@ -59,8 +59,8 @@ describe Shelly::CLI::File do
59
59
 
60
60
  context "cloud is not running" do
61
61
  it "should display error" do
62
- @client.stub(:configured_server).and_raise(Shelly::Client::ConflictException)
63
- $stdout.should_receive(:puts).with(red "Cloud foo-production is not running. Cannot upload files.")
62
+ @client.stub(:console).and_raise(Shelly::Client::ConflictException)
63
+ $stdout.should_receive(:puts).with(red "Cloud foo-production wasn't deployed properly. Cannot upload files.")
64
64
  lambda {
65
65
  invoke(@cli_files, :upload, "some/path")
66
66
  }.should raise_error(SystemExit)
@@ -85,6 +85,16 @@ describe Shelly::CLI::File do
85
85
  @app.should_receive(:download).with("some/path", "/destination")
86
86
  invoke(@cli_files, :download, "some/path", "/destination")
87
87
  end
88
+
89
+ context "cloud is not running" do
90
+ it "should display error" do
91
+ @client.stub(:console).and_raise(Shelly::Client::ConflictException)
92
+ $stdout.should_receive(:puts).with(red "Cloud foo-production wasn't deployed properly. Cannot download files.")
93
+ lambda {
94
+ invoke(@cli_files, :download, "some/path")
95
+ }.should raise_error(SystemExit)
96
+ end
97
+ end
88
98
  end
89
99
 
90
100
  describe "#delete" do
@@ -130,5 +140,15 @@ describe Shelly::CLI::File do
130
140
  }.should raise_error(SystemExit)
131
141
  end
132
142
  end
143
+
144
+ context "cloud is not running" do
145
+ it "should display error" do
146
+ @app.stub(:delete_file).and_raise(Shelly::Client::ConflictException)
147
+ $stdout.should_receive(:puts).with(red "Cloud foo-production wasn't deployed properly. Cannot delete files.")
148
+ lambda {
149
+ fake_stdin(["yes"]) { invoke(@cli_files, :delete, "some/path") }
150
+ }.should raise_error(SystemExit)
151
+ end
152
+ end
133
153
  end
134
154
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shelly Cloud team