Flucti-flucti-cli 0.1.16

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.
Files changed (65) hide show
  1. data/LICENSE +7 -0
  2. data/README.mdown +24 -0
  3. data/Rakefile +56 -0
  4. data/TODO.txt +19 -0
  5. data/bin/flucti +4 -0
  6. data/flucti-cli.gemspec +46 -0
  7. data/lib/flucti.rb +20 -0
  8. data/lib/flucti/api_access.rb +56 -0
  9. data/lib/flucti/cli.rb +107 -0
  10. data/lib/flucti/parameters.rb +37 -0
  11. data/lib/flucti/resources.rb +41 -0
  12. data/lib/flucti/resources/account.rb +7 -0
  13. data/lib/flucti/resources/app_type.rb +18 -0
  14. data/lib/flucti/resources/backend.rb +28 -0
  15. data/lib/flucti/resources/basic_resource.rb +16 -0
  16. data/lib/flucti/resources/container.rb +15 -0
  17. data/lib/flucti/resources/db_server.rb +38 -0
  18. data/lib/flucti/resources/domain.rb +8 -0
  19. data/lib/flucti/resources/general.rb +14 -0
  20. data/lib/flucti/resources/mail_client.rb +7 -0
  21. data/lib/flucti/resources/mail_server.rb +7 -0
  22. data/lib/flucti/resources/port_forwarding.rb +15 -0
  23. data/lib/flucti/resources/port_forwarding/services +13921 -0
  24. data/lib/flucti/resources/ssh_details.rb +96 -0
  25. data/lib/flucti/resources/webserver.rb +9 -0
  26. data/lib/flucti/resources/website.rb +9 -0
  27. data/lib/flucti/tasks.rb +3 -0
  28. data/lib/flucti/tasks/apikey_tasks.rb +57 -0
  29. data/lib/flucti/tasks/apptype_tasks.rb +264 -0
  30. data/lib/flucti/tasks/connect_pack.rb +161 -0
  31. data/lib/flucti/tasks/db_tasks.rb +158 -0
  32. data/lib/flucti/tasks/mail_tasks.rb +104 -0
  33. data/lib/flucti/tasks/miscellaneous_tasks.rb +6 -0
  34. data/lib/flucti/tasks/progress_tasks.rb +24 -0
  35. data/lib/flucti/tasks/sshkey_tasks.rb +151 -0
  36. data/lib/flucti/tasks/vps/firewall_tasks.rb +84 -0
  37. data/lib/flucti/tasks/vps_tasks.rb +37 -0
  38. data/lib/flucti/tasks/webserver_tasks.rb +154 -0
  39. data/lib/flucti/tasks/website/apptype_tasks.rb +42 -0
  40. data/lib/flucti/tasks/website/backends/instances_tasks.rb +37 -0
  41. data/lib/flucti/tasks/website/backends_tasks.rb +254 -0
  42. data/lib/flucti/tasks/website/capfile_tasks.rb +41 -0
  43. data/lib/flucti/tasks/website/domains_tasks.rb +107 -0
  44. data/lib/flucti/tasks/website_tasks.rb +221 -0
  45. data/lib/flucti/utilities.rb +20 -0
  46. data/lib/flucti/utilities/connection_error_handling.rb +50 -0
  47. data/lib/flucti/utilities/core_ext.rb +35 -0
  48. data/lib/flucti/utilities/list_displayer.rb +57 -0
  49. data/lib/flucti/utilities/miscellaneous.rb +65 -0
  50. data/lib/flucti/utilities/progress_bar.rb +17 -0
  51. data/lib/flucti/utilities/table.rb +25 -0
  52. data/lib/flucti/utilities/task_packing.rb +10 -0
  53. data/lib/flucti/utilities/user_interface.rb +117 -0
  54. data/lib/vendor/ruby-progressbar-0.9/lib/ChangeLog +113 -0
  55. data/lib/vendor/ruby-progressbar-0.9/lib/progressbar.en.rd +103 -0
  56. data/lib/vendor/ruby-progressbar-0.9/lib/progressbar.ja.rd +100 -0
  57. data/lib/vendor/ruby-progressbar-0.9/lib/progressbar.rb +236 -0
  58. data/lib/vendor/ruby-progressbar-0.9/lib/test.rb +105 -0
  59. data/test/flucti/resources_test.rb +32 -0
  60. data/test/flucti/tasks_test.rb +28 -0
  61. data/test/flucti/utilities/miscellaneous_test.rb +54 -0
  62. data/test/flucti/utilities/table_test.rb +28 -0
  63. data/test/flucti/utilities/user_interface_test.rb +161 -0
  64. data/test/test_helper.rb +5 -0
  65. metadata +221 -0
@@ -0,0 +1,57 @@
1
+ module Flucti
2
+ module Utilities
3
+ class ListDisplayer
4
+ attr_reader :options, :columns
5
+
6
+ def initialize(options={}, &block)
7
+ @options = options
8
+ @columns = build_column_list(&block)
9
+ end
10
+
11
+ def display(entries)
12
+ if options[:table] || entries.size > 3
13
+ puts entries.inject(Utilities::Table.new(*columns.map { |title,| title })) { |table, entry|
14
+ table << columns.map { |title, proc| proc.call(entry) }
15
+ }
16
+ else
17
+ entries.each do |entry|
18
+ if attribute = options[:title]
19
+ puts_subtitle(entry.send(attribute))
20
+ else
21
+ title, proc = columns.first
22
+ val = proc.call(entry)
23
+ puts_subtitle(val.to_s =~ /^\d+$/ ? "#{title}=#{val}" : val)
24
+ end
25
+ display_single_entry(entry)
26
+ end
27
+ end
28
+ puts "\nTotal: #{entries.size}"
29
+ end
30
+
31
+ def display_single_entry(entry)
32
+ columns.each do |title, proc|
33
+ puts "%-*s %s" % [column_width+1, "#{title}:", proc.call(entry)]
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def build_column_list
40
+ columns = []
41
+ def columns.col(title, method=nil, &proc)
42
+ push [title, proc || method.to_proc]
43
+ end
44
+ if attribute = options.fetch(:id, :id)
45
+ attribute = :id if ENV['NUMERIC_ID']
46
+ columns.col("ID", attribute)
47
+ end
48
+ yield columns
49
+ return columns
50
+ end
51
+
52
+ def column_width
53
+ @column_width ||= columns.map { |title,| title.to_s.length }.max
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,65 @@
1
+ module Flucti
2
+ module Utilities
3
+ module Miscellaneous
4
+ extend self
5
+
6
+ BOGUS_ERROR_MESSAGES = ['error']
7
+
8
+ def try_save(*resources)
9
+ resources.each do |resource|
10
+ begin
11
+ resource.save
12
+ rescue WebService::ResourceInvalid
13
+ error! $!.response.data, "(While attempting to save resource #{q resource}: #{resource.inspect}.)"
14
+ end
15
+ end
16
+ yield
17
+ end
18
+
19
+ def error!(messages, note=nil, io=$stderr)
20
+ messages = messages['errors'] if messages.respond_to?(:[]) && messages.include?('errors')
21
+ messages = messages['error'] if messages.respond_to?(:[]) && messages.include?('error')
22
+ messages = [messages].flatten.compact - BOGUS_ERROR_MESSAGES
23
+ messages << "An unknown error occured while processing your request." if messages.empty?
24
+ if method(:exit).arity == -1
25
+ puts_title(messages.size == 1 ? "Error" : "Errors", io)
26
+ io.puts(note, "\n") if note
27
+ messages.each do |message|
28
+ puts_long("! #{message.lstrip}", io)
29
+ end
30
+ exit 1
31
+ else
32
+ raise messages.map { |msg| msg.split("\n") }.flatten.map { |line| line.strip }.join(' ')
33
+ end
34
+ end
35
+
36
+ def command(task_name=nil)
37
+ @program ||= ((path = Pathname($0)).absolute? ? path.basename : path).to_s
38
+ [@program, task_name].compact.join(' ')
39
+ end
40
+
41
+ def sh(command)
42
+ command = command.to_s
43
+ displayable_command = command[0,20]
44
+ displayable_command += "..." if command.length > 20
45
+
46
+ print "Running locally: #{displayable_command} "
47
+ succeeded = system(command)
48
+
49
+ if succeeded
50
+ print "Done\n"
51
+ else
52
+ raise "command #{q displayable_command} failed (status: #{$?.exitstatus})"
53
+ end
54
+ end
55
+
56
+ def clean_name(name)
57
+ name.to_s.
58
+ gsub(/["']/, '').
59
+ gsub(/[^a-z0-9]+/i, "-").
60
+ gsub(/^\-|\-$/, '').
61
+ downcase
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,17 @@
1
+ module Flucti
2
+ module Utilities
3
+ class ProgressBar < ::ProgressBar
4
+ def initialize(*args)
5
+ super
6
+ @bar_mark = "="
7
+ end
8
+
9
+ private
10
+
11
+ def fmt_bar
12
+ bar_width = do_percentage * @terminal_width / 100
13
+ sprintf "|%s>%s|", @bar_mark * [bar_width - 1, 0].max, " " * (@terminal_width - bar_width)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Flucti
2
+ module Utilities
3
+ class Table
4
+ def initialize(*headings)
5
+ @headings, @rows = headings, []
6
+ end
7
+
8
+ def <<(row)
9
+ @rows << row
10
+ self
11
+ end
12
+
13
+ def to_s
14
+ widths = (0...@headings.size).map { |col| ([@headings] + @rows).map { |row| row[col].to_s.length }.max }
15
+ lines = []
16
+ lines << @headings.zip(widths).map { |heading, width| " %-*s " % [width, heading] }.join('|')
17
+ lines << widths.map { |width| '-' * (width + 2) }.join('+')
18
+ @rows.each do |row|
19
+ lines << row.zip(widths).map { |cell, width| " %#{cell.to_s =~ /^\d+\b/ ? '' : '-'}*s " % [width, cell] }.join('|')
20
+ end
21
+ lines * "\n"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module Flucti
2
+ module Utilities
3
+ module TaskPacking
4
+ def import_pack(pack, parent, resource_type)
5
+ parent.instance_eval \
6
+ "resource_type = #{resource_type.inspect}\n" + File.read(File.dirname(__FILE__) + "/../tasks/#{pack}_pack.rb")
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,117 @@
1
+ module Flucti
2
+ module Utilities
3
+ module UserInterface
4
+ extend self
5
+
6
+ def terminal_width
7
+ @terminal_width ||= begin
8
+ # Avoid error messages on Windows
9
+ result = RUBY_PLATFORM =~ /mswin/ ? "" : `stty size 2>/dev/null`
10
+ (result.split[1] || 80).to_i
11
+ end
12
+ end
13
+
14
+ def puts_title(title, io=$stdout)
15
+ generic_puts_title(io, title, "=", 3)
16
+ end
17
+
18
+ def puts_subtitle(title, io=$stdout)
19
+ generic_puts_title(io, title, "-", 6)
20
+ end
21
+
22
+ def puts_long(message, io=$stdout)
23
+ io.puts(adjust_to_terminal(message))
24
+ end
25
+
26
+ def puts_list(entries, *args, &block)
27
+ Utilities::ListDisplayer.new(*args, &block).display(entries)
28
+ end
29
+
30
+ def qcommand(task_name)
31
+ quote(command(task_name))
32
+ end
33
+
34
+ def quote(str)
35
+ %(`#{str}')
36
+ end
37
+ alias q :quote
38
+
39
+ def confirm(message)
40
+ puts_title("/!\\ Warning")
41
+ puts_long(message)
42
+ puts "(You now have 10 seconds to cancel by pressing CTRL+C.)"
43
+ puts
44
+
45
+ if ENV['FORCE']
46
+ puts "$FORCE set, proceeding forcefully."
47
+ else
48
+ # 10 second countdown to cancel
49
+ begin
50
+ 10.downto(0) { |left| print(left, " "); sleep 1 }
51
+ rescue Interrupt
52
+ puts "\nAction cancelled."
53
+ exit 0
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ POINT_START_FORMAT = '^ *[*$!] +'.freeze
61
+
62
+ def generic_puts_title(io, title, line_block, left_padding)
63
+ io.puts "", "#{line_block * left_padding} #{title} ".ljust(terminal_width, line_block)
64
+ end
65
+
66
+ def strip_margin(str)
67
+ str = str.to_s
68
+ margin = str.scan(/^\s*/).sort.first
69
+ str.gsub(/^#{Regexp.escape margin}/, '')
70
+ end
71
+
72
+ def adjust_to_terminal(str)
73
+ str = strip_margin(str.to_s)
74
+
75
+ result, paragraph = [], []
76
+ process_current_paragraph = lambda do
77
+ result << adjust_paragraph_to_terminal(paragraph.join("\n"), :auto) if paragraph.any?
78
+ paragraph = []
79
+ end
80
+ tail = str[/\s+\z/] || ""
81
+ str.split(/\n/).each do |line|
82
+ case line
83
+ when /^\s*$/
84
+ process_current_paragraph[]
85
+ result << nil
86
+ when /^-/
87
+ process_current_paragraph[]
88
+ paragraph << line
89
+ process_current_paragraph[]
90
+ when /#{POINT_START_FORMAT}[^ ]/
91
+ process_current_paragraph[]
92
+ paragraph << line
93
+ else
94
+ paragraph << line
95
+ end
96
+ end
97
+ process_current_paragraph[]
98
+ result.join("\n") + tail
99
+ end
100
+
101
+ def adjust_paragraph_to_terminal(paragraph, margin=0)
102
+ paragraph = paragraph.to_s
103
+ if margin == :auto
104
+ margin_top = paragraph[/#{POINT_START_FORMAT}/]
105
+ paragraph = $' if $'
106
+ margin = margin_top ? margin_top.length : 0
107
+ paragraph = paragraph.gsub(/^\s{0,#{margin}}/, '')
108
+ end
109
+ tail = paragraph[/\s+\z/] || ""
110
+ paragraph.
111
+ split(/\n/).map { |line| line.strip }.join(" ").scan(/(.{1,#{terminal_width - margin}})(\s|$)/).
112
+ map { |matches| (margin_top ? (old, margin_top = margin_top, nil; old) : " " * margin) + matches.first }.
113
+ join("\n") + tail
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,113 @@
1
+ 2005-05-21 Satoru Takabayashi <satoru@namazu.org>
2
+
3
+ * progressbar.rb (ProgressBar::show): Call IO#flush. Suggestted by
4
+ "Geert Fannes" <Geert.Fannes at ikanconsulting.com>
5
+
6
+ 2005-01-07 Satoru Takabayashi <satoru@namazu.org>
7
+
8
+ * progressbar.rb (ProgressBar::VERSION): Bumped version number to 0.9.
9
+ (ProgressBar::finished?): New method.
10
+ (ProgressBar::current): New attribute.
11
+ (ProgressBar::total): New attribute.
12
+ (ProgressBar::title): New attribute.
13
+ (ProgressBar::start_time): New attribute.
14
+ (ProgressBar::inspect): Change the format.
15
+ (ProgressBar::show_if_needed): Renamed from show_progress.
16
+ (ProgressBar::clear): New method.
17
+ (ProgressBar::initialize): Renamed a field: bar_width ->
18
+ terminal_width.
19
+ (ProgressBar::do_percentage): New method.
20
+ (ProgressBar::percentage): Use it.
21
+ (ReversedProgressBar): New class.
22
+ (ProgressBar::initialize): Use #clear.
23
+ (ProgressBar::fmt_bar): Ditto.
24
+ (ProgressBar::fmt_percentage): Renamed from percentage.
25
+ (ProgressBar::fmt_stat): Ditto.
26
+ (ProgressBar::fmt_stat_for_file_transfer): Ditto.
27
+ (ProgressBar::fmt_title): Ditto.
28
+
29
+ * test.rb: Use Test::Unit.
30
+
31
+ * Makefile (docs): Removed.
32
+ (progressbar.ja.html): Ditto.
33
+ (progressbar.en.html): Ditto.
34
+ (dist): New rule.
35
+ (check): New rule.
36
+
37
+ 2004-02-05 Satoru Takabayashi <satoru@namazu.org>
38
+
39
+ * Ruby/ProgressBar: Version 0.8 released!
40
+
41
+ * progressbar.rb (ProgressBar::set): Fixed the bug when caused by
42
+ the invalid count. <http://bugs.debian.org/231009>
43
+ (ProgressBar::VERSION): Bumped version number to 0.8.
44
+
45
+ 2004-01-19 Satoru Takabayashi <satoru@namazu.org>
46
+
47
+ * Ruby/ProgressBar: Version 0.7 released!
48
+
49
+ * progressbar.rb (ProgressBar::initialize): Rename a field:
50
+ @bar_length -> @bar_width.
51
+ (ProgressBar::initialize): New field: @title_width.
52
+ (ProgressBar::title): use it.
53
+ (ProgressBar::initialize): New field: @previous_time.
54
+ (ProgressBar::show_progress): Use it and update the progress bar
55
+ if one sec. elapsed.
56
+ (ProgressBar::initialize): Call show instead of show_progress.
57
+
58
+ 2004-01-16 Satoru Takabayashi <satoru@namazu.org>
59
+
60
+ * Ruby/ProgressBar: Version 0.6 released!
61
+
62
+ * progressbar.rb (ProgressBar::show): Remove the useless condition
63
+ after "else". Thanks to Neil Spring <nspring@cs.washington.edu>
64
+ for the report.
65
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=227966>
66
+ (ProgressBar):
67
+
68
+ 2003-07-24 Satoru Takabayashi <satoru@namazu.org>
69
+
70
+ * Ruby/ProgressBar: Version 0.5 released!
71
+
72
+ * progressbar.rb (ProgressBar::initialize): New parameter: config.
73
+ (ProgressBar::convert_prefix_multiplier): New method.
74
+ (ProgressBar::transfer_rate): New method.
75
+ (ProgressBar::percentage): New method.
76
+ (ProgressBar::title): New method.
77
+ (ProgressBar::initialize): New fields: @bar_mark, @format,
78
+ @arguments.
79
+ (ProgressBar::get_width): New method.
80
+ (ProgressBar::stat_for_file_transfer): New method.
81
+ (ProgressBar::stat): Renamed from time.
82
+ (ProgressBar::format=): New method.
83
+ (ProgressBar::format_arguments=): New method.
84
+ (ProgressBar::convert_bytes): New method.
85
+ (ProgressBar::file_transfer_mode): New method.
86
+
87
+ 2002-10-21 Satoru Takabayashi <satoru@namazu.org>
88
+
89
+ * Ruby/ProgressBar: Version 0.4 released!
90
+
91
+ * progressbar.rb (ProgressBar::halt): New method. allowing a
92
+ "broken" ProgressBar in the event of error.
93
+ - Suggestted by Austin Ziegler <austin@halostatue.ca>
94
+
95
+ 2002-01-05 Satoru Takabayashi <satoru@namazu.org>
96
+
97
+ * Ruby/ProgressBar: Version 0.3 released!
98
+
99
+ * progressbar.rb (ProgressBar::show): Shorten @title to fall into
100
+ the format well.
101
+
102
+ 2001-11-03 Satoru Takabayashi <satoru@namazu.org>
103
+
104
+ * Ruby/ProgressBar: Version 0.2 released!
105
+
106
+ * progressbar.rb (ProgressBar::eta): Remove an unnecessary condition.
107
+
108
+ * progressbar.rb (ProgressBar::eta): Fix the return value bug.
109
+
110
+ * progressbar.rb (ProgressBar::inc): Add an optional parameter `step'.
111
+
112
+ * Ruby/ProgressBar: Version 0.1 released!
113
+
@@ -0,0 +1,103 @@
1
+ =begin
2
+ index:Ej
3
+
4
+ = Ruby/ProgressBar: A Text Progress Bar Library for Ruby
5
+
6
+ Last Modified: 2005-05-22 00:28:04
7
+
8
+ --
9
+
10
+ Ruby/ProgressBar is a text progress bar library for Ruby.
11
+ It can indicate progress with percentage, a progress bar,
12
+ and estimated remaining time.
13
+
14
+ The latest version of Ruby/ProgressBar is available at
15
+ ((<URL:http://namazu.org/~satoru/ruby-progressbar/>))
16
+ .
17
+
18
+ == Examples
19
+
20
+ % irb --simple-prompt -r progressbar
21
+ >> pbar = ProgressBar.new("test", 100)
22
+ => (ProgressBar: 0/100)
23
+ >> 100.times {sleep(0.1); pbar.inc}; pbar.finish
24
+ test: 100% |oooooooooooooooooooooooooooooooooooooooo| Time: 00:00:10
25
+ => nil
26
+
27
+ >> pbar = ProgressBar.new("test", 100)
28
+ => (ProgressBar: 0/100)
29
+ >> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
30
+ test: 67% |oooooooooooooooooooooooooo | ETA: 00:00:03
31
+
32
+ == API
33
+
34
+ --- ProgressBar#new (title, total, out = STDERR)
35
+ Display the initial progress bar and return a
36
+ ProgressBar object. ((|title|)) specifies the title,
37
+ and ((|total|)) specifies the total cost of processing.
38
+ Optional parameter ((|out|)) specifies the output IO.
39
+
40
+ The display of the progress bar is updated when one or
41
+ more percent is proceeded or one or more seconds are
42
+ elapsed from the previous display.
43
+
44
+ --- ProgressBar#inc (step = 1)
45
+ Increase the internal counter by ((|step|)) and update
46
+ the display of the progress bar. Display the estimated
47
+ remaining time on the right side of the bar. The counter
48
+ does not go beyond the ((|total|)).
49
+
50
+ --- ProgressBar#set (count)
51
+ Set the internal counter to ((|count|)) and update the
52
+ display of the progress bar. Display the estimated
53
+ remaining time on the right side of the bar. Raise if
54
+ ((|count|)) is a negative number or a number more than
55
+ the ((|total|)).
56
+
57
+ --- ProgressBar#finish
58
+ Stop the progress bar and update the display of progress
59
+ bar. Display the elapsed time on the right side of the bar.
60
+ The progress bar always stops at 100 % by the method.
61
+
62
+ --- ProgressBar#halt
63
+ Stop the progress bar and update the display of progress
64
+ bar. Display the elapsed time on the right side of the bar.
65
+ The progress bar stops at the current percentage by the method.
66
+
67
+ --- ProgressBar#format=
68
+ Set the format for displaying a progress bar.
69
+ Default: "%-14s %3d%% %s %s".
70
+
71
+ --- ProgressBar#format_arguments=
72
+ Set the methods for displaying a progress bar.
73
+ Default: [:title, :percentage, :bar, :stat].
74
+
75
+ --- ProgressBar#file_transfer_mode
76
+ Use :stat_for_file_transfer instead of :stat to display
77
+ transfered bytes and transfer rate.
78
+
79
+
80
+ ReverseProgressBar class is also available. The
81
+ functionality is identical to ProgressBar but the direction
82
+ of the progress bar is just opposite.
83
+
84
+ == Limitations
85
+
86
+ Since the progress is calculated by the proportion to the
87
+ total cost of processing, Ruby/ProgressBar cannot be used if
88
+ the total cost of processing is unknown in advance.
89
+ Moreover, the estimation of remaining time cannot be
90
+ accurately performed if the progress does not flow uniformly.
91
+
92
+ == Download
93
+
94
+ Ruby/ProgressBar is a free software with ABSOLUTELY NO WARRANTY
95
+ under the terms of Ruby's license.
96
+
97
+ * ((<URL:http://namazu.org/~satoru/ruby-progressbar/ruby-progressbar-0.9.tar.gz>))
98
+ * ((<URL:http://cvs.namazu.org/ruby-progressbar/>))
99
+
100
+ --
101
+
102
+ - ((<Satoru Takabayashi|URL:http://namazu.org/~satoru/>)) -
103
+ =end