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,100 @@
1
+ =begin
2
+ index:eJ
3
+
4
+ = Ruby/ProgressBar: �ץ����쥹�С���ƥ����Ȥ�ɽ������ Ruby�ѤΥ饤�֥��
5
+
6
+ �ǽ�������: 2005-05-22 00:28:53
7
+
8
+
9
+ --
10
+
11
+ Ruby/ProgressBar �ϥץ����쥹�С���ƥ����Ȥ�ɽ������ Ruby��
12
+ �Υ饤�֥��Ǥ��������ο�Ľ������ѡ�����ȡ��ץ����쥹�С���
13
+ ����ӿ���Ĥ���֤Ȥ���ɽ�����ޤ���
14
+
15
+ �ǿ��Ǥ�
16
+ ((<URL:http://namazu.org/~satoru/ruby-progressbar/>))
17
+ ���������ǽ�Ǥ�
18
+
19
+ == ������
20
+
21
+ % irb --simple-prompt -r progressbar
22
+ >> pbar = ProgressBar.new("test", 100)
23
+ => (ProgressBar: 0/100)
24
+ >> 100.times {sleep(0.1); pbar.inc}; pbar.finish
25
+ test: 100% |oooooooooooooooooooooooooooooooooooooooo| Time: 00:00:10
26
+ => nil
27
+
28
+ >> pbar = ProgressBar.new("test", 100)
29
+ => (ProgressBar: 0/100)
30
+ >> (1..100).each{|x| sleep(0.1); pbar.set(x)}; pbar.finish
31
+ test: 67% |oooooooooooooooooooooooooo | ETA: 00:00:03
32
+
33
+ == API
34
+
35
+ --- ProgressBar#new (title, total, out = STDERR)
36
+ �ץ����쥹�С��ν�����֤�ɽ������������ ProgressBar����
37
+ �������Ȥ��֤���((|title|)) �Ǹ��Ф���((|total|)) �ǽ�
38
+ �������פ�((|out|)) �ǽ������ IO �����ꤹ�롣
39
+
40
+ �ץ����쥹�С���ɽ���ϡ������ɽ�������Ľ�� 1%�ʾ夢��
41
+ ���Ȥ������뤤�� 1�ðʾ�вᤷ�����˹�������ޤ���
42
+
43
+ --- ProgressBar#inc (step = 1)
44
+ �����Υ����󥿤� ((|step|)) �������ʤ�ơ��ץ����쥹�С�
45
+ ��ɽ���򹹿����롣�С��α�¦�ˤϿ���Ĥ���֤�ɽ�����롣
46
+ �����󥿤� ((|total|)) ��ۤ��ƿʤळ�ȤϤʤ���
47
+
48
+ --- ProgressBar#set (count)
49
+ �����󥿤��ͤ� ((|count|)) �����ꤷ���ץ����쥹�С���
50
+ ɽ���򹹿����롣�С��α�¦�ˤϿ���Ĥ���֤�ɽ�����롣
51
+ ((|count|)) �˥ޥ��ʥ����ͤ��뤤�� ((|total|)) ����礭
52
+ ���ͤ��Ϥ����㳰��ȯ�����롣
53
+
54
+ --- ProgressBar#finish
55
+ �ץ����쥹�С�����ߤ����ץ����쥹�С���ɽ���򹹿����롣
56
+ �ץ����쥹�С��α�¦�ˤϷв���֤�ɽ�����롣
57
+ ���ΤȤ����ץ����쥹�С��� 100% �ǽ�λ���롣
58
+
59
+ --- ProgressBar#halt
60
+ �ץ����쥹�С�����ߤ����ץ����쥹�С���ɽ���򹹿����롣
61
+ �ץ����쥹�С��α�¦�ˤϷв���֤�ɽ�����롣
62
+ ���ΤȤ����ץ����쥹�С��Ϥ��λ����Υѡ�����ơ����ǽ�λ���롣
63
+
64
+ --- ProgressBar#format=
65
+ �ץ����쥹�С�ɽ���Υե����ޥåȤ����ꤹ�롣
66
+ ̤�ѹ����� "%-14s %3d%% %s %s"
67
+
68
+ --- ProgressBar#format_arguments=
69
+ �ץ����쥹�С�ɽ���˻Ȥ��ؿ������ꤹ�롣
70
+ ̤�ѹ����� [:title, :percentage, :bar, :stat]
71
+ �ե�����ž�����ˤ� :stat ���Ѥ��� :stat_for_file_transfer
72
+ ��Ȥ���ž���Х��ȿ���ž��®�٤�ɽ���Ǥ��롣
73
+
74
+ --- ProgressBar#file_transfer_mode
75
+ �ץ����쥹�С�ɽ���� :stat ���Ѥ��� :stat_for_file_transfer
76
+ ��Ȥ���ž���Х��ȿ���ž��®�٤�ɽ�����롣
77
+
78
+
79
+ ReverseProgressBar �Ȥ������饹���󶡤���ޤ�����ǽ��
80
+ ProgressBar �Ȥޤä���Ʊ���Ǥ������ץ����쥹�С��οʹ�������
81
+ �դˤʤäƤ��ޤ���
82
+
83
+ == ���»���
84
+
85
+ ��Ľ��������������פ��Ф�����Ȥ��Ʒ׻����뤿�ᡢ��������
86
+ �פ������ˤ狼��ʤ������ǤϻȤ��ޤ��󡣤ޤ�����Ľ��ή�줬��
87
+ ��Ǥʤ��Ȥ��ˤϻĤ���֤ο�����������Ԥ��ޤ���
88
+
89
+ == �����������
90
+
91
+ Ruby �Υ饤���󥹤˽��ä��ե꡼���եȥ������Ȥ��Ƹ������ޤ���
92
+ ������̵�ݾڤǤ���
93
+
94
+ * ((<URL:http://namazu.org/~satoru/ruby-progressbar/ruby-progressbar-0.9.tar.gz>))
95
+ * ((<URL:http://cvs.namazu.org/ruby-progressbar/>))
96
+
97
+ --
98
+
99
+ - ((<Satoru Takabayashi|URL:http://namazu.org/~satoru/>)) -
100
+ =end
@@ -0,0 +1,236 @@
1
+ #
2
+ # Ruby/ProgressBar - a text progress bar library
3
+ #
4
+ # Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
5
+ # All rights reserved.
6
+ # This is free software with ABSOLUTELY NO WARRANTY.
7
+ #
8
+ # You can redistribute it and/or modify it under the terms
9
+ # of Ruby's license.
10
+ #
11
+
12
+ class ProgressBar
13
+ VERSION = "0.9"
14
+
15
+ def initialize (title, total, out = STDERR)
16
+ @title = title
17
+ @total = total
18
+ @out = out
19
+ @terminal_width = 80
20
+ @bar_mark = "o"
21
+ @current = 0
22
+ @previous = 0
23
+ @finished_p = false
24
+ @start_time = Time.now
25
+ @previous_time = @start_time
26
+ @title_width = 14
27
+ @format = "%-#{@title_width}s %3d%% %s %s"
28
+ @format_arguments = [:title, :percentage, :bar, :stat]
29
+ clear
30
+ show
31
+ end
32
+ attr_reader :title
33
+ attr_reader :current
34
+ attr_reader :total
35
+ attr_accessor :start_time
36
+
37
+ private
38
+ def fmt_bar
39
+ bar_width = do_percentage * @terminal_width / 100
40
+ sprintf("|%s%s|",
41
+ @bar_mark * bar_width,
42
+ " " * (@terminal_width - bar_width))
43
+ end
44
+
45
+ def fmt_percentage
46
+ do_percentage
47
+ end
48
+
49
+ def fmt_stat
50
+ if @finished_p then elapsed else eta end
51
+ end
52
+
53
+ def fmt_stat_for_file_transfer
54
+ if @finished_p then
55
+ sprintf("%s %s %s", bytes, transfer_rate, elapsed)
56
+ else
57
+ sprintf("%s %s %s", bytes, transfer_rate, eta)
58
+ end
59
+ end
60
+
61
+ def fmt_title
62
+ @title[0,(@title_width - 1)] + ":"
63
+ end
64
+
65
+ def convert_bytes (bytes)
66
+ if bytes < 1024
67
+ sprintf("%6dB", bytes)
68
+ elsif bytes < 1024 * 1000 # 1000kb
69
+ sprintf("%5.1fKB", bytes.to_f / 1024)
70
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
71
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
72
+ else
73
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
74
+ end
75
+ end
76
+
77
+ def transfer_rate
78
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
79
+ sprintf("%s/s", convert_bytes(bytes_per_second))
80
+ end
81
+
82
+ def bytes
83
+ convert_bytes(@current)
84
+ end
85
+
86
+ def format_time (t)
87
+ t = t.to_i
88
+ sec = t % 60
89
+ min = (t / 60) % 60
90
+ hour = t / 3600
91
+ sprintf("%02d:%02d:%02d", hour, min, sec);
92
+ end
93
+
94
+ # ETA stands for Estimated Time of Arrival.
95
+ def eta
96
+ if @current == 0
97
+ "ETA: --:--:--"
98
+ else
99
+ elapsed = Time.now - @start_time
100
+ eta = elapsed * @total / @current - elapsed;
101
+ sprintf("ETA: %s", format_time(eta))
102
+ end
103
+ end
104
+
105
+ def elapsed
106
+ elapsed = Time.now - @start_time
107
+ sprintf("Time: %s", format_time(elapsed))
108
+ end
109
+
110
+ def eol
111
+ if @finished_p then "\n" else "\r" end
112
+ end
113
+
114
+ def do_percentage
115
+ if @total.zero?
116
+ 100
117
+ else
118
+ @current * 100 / @total
119
+ end
120
+ end
121
+
122
+ def get_width
123
+ # FIXME: I don't know how portable it is.
124
+ default_width = 80
125
+ begin
126
+ tiocgwinsz = 0x5413
127
+ data = [0, 0, 0, 0].pack("SSSS")
128
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
129
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
130
+ if cols >= 0 then cols else default_width end
131
+ else
132
+ default_width
133
+ end
134
+ rescue Exception
135
+ default_width
136
+ end
137
+ end
138
+
139
+ def show
140
+ arguments = @format_arguments.map {|method|
141
+ method = sprintf("fmt_%s", method)
142
+ send(method)
143
+ }
144
+ line = sprintf(@format, *arguments)
145
+
146
+ width = get_width
147
+ if line.length == width - 1
148
+ @out.print(line + eol)
149
+ @out.flush
150
+ elsif line.length >= width
151
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
152
+ if @terminal_width == 0 then @out.print(line + eol) else show end
153
+ else # line.length < width - 1
154
+ @terminal_width += width - line.length + 1
155
+ show
156
+ end
157
+ @previous_time = Time.now
158
+ end
159
+
160
+ def show_if_needed
161
+ if @total.zero?
162
+ cur_percentage = 100
163
+ prev_percentage = 0
164
+ else
165
+ cur_percentage = (@current * 100 / @total).to_i
166
+ prev_percentage = (@previous * 100 / @total).to_i
167
+ end
168
+
169
+ # Use "!=" instead of ">" to support negative changes
170
+ if cur_percentage != prev_percentage ||
171
+ Time.now - @previous_time >= 1 || @finished_p
172
+ show
173
+ end
174
+ end
175
+
176
+ public
177
+ def clear
178
+ @out.print "\r"
179
+ @out.print(" " * (get_width - 1))
180
+ @out.print "\r"
181
+ end
182
+
183
+ def finish
184
+ @current = @total
185
+ @finished_p = true
186
+ show
187
+ end
188
+
189
+ def finished?
190
+ @finished_p
191
+ end
192
+
193
+ def file_transfer_mode
194
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
195
+ end
196
+
197
+ def format= (format)
198
+ @format = format
199
+ end
200
+
201
+ def format_arguments= (arguments)
202
+ @format_arguments = arguments
203
+ end
204
+
205
+ def halt
206
+ @finished_p = true
207
+ show
208
+ end
209
+
210
+ def inc (step = 1)
211
+ @current += step
212
+ @current = @total if @current > @total
213
+ show_if_needed
214
+ @previous = @current
215
+ end
216
+
217
+ def set (count)
218
+ if count < 0 || count > @total
219
+ raise "invalid count: #{count} (total: #{@total})"
220
+ end
221
+ @current = count
222
+ show_if_needed
223
+ @previous = @current
224
+ end
225
+
226
+ def inspect
227
+ "#<ProgressBar:#{@current}/#{@total}>"
228
+ end
229
+ end
230
+
231
+ class ReversedProgressBar < ProgressBar
232
+ def do_percentage
233
+ 100 - super
234
+ end
235
+ end
236
+
@@ -0,0 +1,105 @@
1
+ require 'test/unit'
2
+ require 'progressbar'
3
+
4
+ class ProgressBarTest < Test::Unit::TestCase
5
+ SleepUnit = 0.01
6
+
7
+ def do_make_progress_bar (title, total)
8
+ ProgressBar.new(title, total)
9
+ end
10
+
11
+ def test_bytes
12
+ total = 1024 * 1024
13
+ pbar = do_make_progress_bar("test(bytes)", total)
14
+ pbar.file_transfer_mode
15
+ 0.step(total, 2**14) {|x|
16
+ pbar.set(x)
17
+ sleep(SleepUnit)
18
+ }
19
+ pbar.finish
20
+ end
21
+
22
+ def test_clear
23
+ total = 100
24
+ pbar = do_make_progress_bar("test(clear)", total)
25
+ total.times {
26
+ sleep(SleepUnit)
27
+ pbar.inc
28
+ }
29
+ pbar.clear
30
+ puts
31
+ end
32
+
33
+ def test_halt
34
+ total = 100
35
+ pbar = do_make_progress_bar("test(halt)", total)
36
+ (total / 2).times {
37
+ sleep(SleepUnit)
38
+ pbar.inc
39
+ }
40
+ pbar.halt
41
+ end
42
+
43
+ def test_inc
44
+ total = 100
45
+ pbar = do_make_progress_bar("test(inc)", total)
46
+ total.times {
47
+ sleep(SleepUnit)
48
+ pbar.inc
49
+ }
50
+ pbar.finish
51
+ end
52
+
53
+ def test_inc_x
54
+ total = File.size("progressbar.rb")
55
+ pbar = do_make_progress_bar("test(inc(x))", total)
56
+ File.new("progressbar.rb").each {|line|
57
+ sleep(SleepUnit)
58
+ pbar.inc(line.length)
59
+ }
60
+ pbar.finish
61
+ end
62
+
63
+ def test_invalid_set
64
+ total = 100
65
+ pbar = do_make_progress_bar("test(invalid set)", total)
66
+ begin
67
+ pbar.set(200)
68
+ rescue RuntimeError => e
69
+ puts e.message
70
+ end
71
+ end
72
+
73
+ def test_set
74
+ total = 1000
75
+ pbar = do_make_progress_bar("test(set)", total)
76
+ (1..total).find_all {|x| x % 10 == 0}.each {|x|
77
+ sleep(SleepUnit)
78
+ pbar.set(x)
79
+ }
80
+ pbar.finish
81
+ end
82
+
83
+ def test_slow
84
+ total = 100000
85
+ pbar = do_make_progress_bar("test(slow)", total)
86
+ 0.step(500, 1) {|x|
87
+ pbar.set(x)
88
+ sleep(SleepUnit)
89
+ }
90
+ pbar.halt
91
+ end
92
+
93
+ def test_total_zero
94
+ total = 0
95
+ pbar = do_make_progress_bar("test(total=0)", total)
96
+ pbar.finish
97
+ end
98
+ end
99
+
100
+ class ReversedProgressBarTest < ProgressBarTest
101
+ def do_make_progress_bar (title, total)
102
+ ReversedProgressBar.new(title, total)
103
+ end
104
+ end
105
+
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class Flucti::Resources::BasicResourceTest < Test::Unit::TestCase
4
+ include Flucti::Resources
5
+
6
+ class Foo < BasicResource
7
+ self.attribute_for_to_s = :name
8
+ end
9
+
10
+ class HostedService < BasicResource
11
+ end
12
+
13
+ def test_to_s
14
+ foo = Foo.new
15
+ assert_match(/Foo/, foo.to_s)
16
+
17
+ foo.name = nil
18
+ assert_match(/Foo/, foo.to_s)
19
+
20
+ foo.name = "test"
21
+ assert_match("test", foo.to_s)
22
+ end
23
+
24
+ def test_vps_accessor
25
+ foo = Foo.new "vps" => {"id" => 1}
26
+ assert_equal VPS.new("id" => 1), foo.vps
27
+ assert_equal 1, foo.vps_id
28
+
29
+ assert_equal VPS.new("id" => 1), foo.container
30
+ assert_equal 1, foo.container_id
31
+ end
32
+ end