lib/shelly/app.rb in shelly-0.3.0 vs lib/shelly/app.rb in shelly-0.3.1

- old
+ new

@@ -128,13 +128,17 @@ shelly.restore_backup(code_name, filename) end def import_database(kind, filename, server) ssh(:command => "import_database #{kind.downcase} #{filename}", - :server => server) + :server => server, :type => :db_server) end + def reset_database(kind) + ssh(:command => "reset_database #{kind.downcase}", :type => :db_server) + end + def request_backup(kinds) Array(kinds).each do |kind| shelly.request_backup(code_name, kind) end end @@ -195,11 +199,11 @@ def rake(task) ssh(:command => "rake_runner \"#{task}\"") end def dbconsole - ssh(:command => "dbconsole") + ssh(:command => "dbconsole", :type => :db_server) end def attributes @attributes ||= shelly.app(code_name) end @@ -251,23 +255,30 @@ def console(server = nil) ssh(:server => server) end def list_files(path) - ssh(:command => "ls -l /srv/glusterfs/disk/#{path}") + ssh(:command => "ls -l #{persistent_disk}/#{path}", :type => :server) end def upload(source) - console_connection.tap do |conn| - rsync(source, "#{conn['host']}:/srv/glusterfs/disk") + server_connection.tap do |conn| + rsync(source, "#{conn['host']}:#{persistent_disk}", conn) end end + def upload_database(source) + db_server_connection.tap do |conn| + rsync(source, "#{conn['host']}:#{persistent_disk}", conn) + end + end + def download(relative_source, destination) - conn = console_connection - source = File.join("#{conn['host']}:/srv/glusterfs/disk", relative_source) - rsync(source, destination) + server_connection.tap do |conn| + source = File.join("#{conn['host']}:#{persistent_disk}", relative_source) + rsync(source, destination, conn) + end end def delete_file(remote_path) ssh(:command => "delete_file #{remote_path}") end @@ -339,10 +350,14 @@ self.domains = response["domains"] self.ruby_version = jruby? ? 'jruby' : response["ruby_version"] self.environment = response["environment"] end + def persistent_disk + "/home/#{code_name}/disk" + end + def jruby? RUBY_PLATFORM == 'java' end # Internal: Checks if specified option is present in Cloudfile @@ -352,19 +367,41 @@ def console_connection(server = nil) shelly.console(code_name, server) end + # Returns first configured virtual server + def server_connection + shelly.configured_server(code_name) + end + + # Returns first configured virtual server with database + def db_server_connection(server = nil) + shelly.configured_db_server(code_name, server) + end + + def connection(options) + case options[:type] + when :console + console_connection(options[:server]) + when :server + server_connection + when :db_server + db_server_connection(options[:server]) + end + end + def ssh(options = {}) - conn = console_connection(options[:server]) + options[:type] = :console unless options[:type] + conn = connection(options) system "ssh #{ssh_options(conn)} -t #{conn['host']} #{options[:command]}" end - def ssh_options(conn = console_connection) + def ssh_options(conn) "-o StrictHostKeyChecking=no -p #{conn['port']} -l #{conn['user']}" end - def rsync(source, destination) - system "rsync -avz -e 'ssh #{ssh_options}' --progress #{source} #{destination}" + def rsync(source, destination, conn) + system "rsync -avz -e 'ssh #{ssh_options(conn)}' --progress #{source} #{destination}" end end end