auser-poolparty 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. data/History.txt +22 -0
  2. data/License.txt +20 -0
  3. data/README.txt +52 -0
  4. data/Rakefile +4 -109
  5. data/bin/cloud +31 -0
  6. data/bin/cloud-add-keypair +23 -0
  7. data/bin/cloud-configure +35 -0
  8. data/bin/cloud-contract +27 -0
  9. data/bin/cloud-expand +27 -0
  10. data/bin/cloud-list +32 -0
  11. data/bin/cloud-maintain +36 -0
  12. data/bin/cloud-provision +30 -0
  13. data/bin/cloud-reconfigure +24 -0
  14. data/bin/cloud-ssh +18 -0
  15. data/bin/cloud-start +29 -0
  16. data/bin/pool +23 -75
  17. data/bin/pool-console +12 -0
  18. data/bin/pool-describe +9 -0
  19. data/bin/pool-list +28 -0
  20. data/bin/pool-provision +34 -0
  21. data/bin/pool-spec +17 -0
  22. data/bin/pool-start +32 -0
  23. data/examples/basic.rb +20 -0
  24. data/examples/plugin_without_plugin_directory.rb +13 -0
  25. data/examples/poolparty.rb +12 -0
  26. data/examples/with_apache_plugin.rb +22 -0
  27. data/generators/poolspec/USAGE +5 -0
  28. data/generators/poolspec/poolspec_generator.rb +65 -0
  29. data/generators/poolspec/templates/pool_spec_template.erb +9 -0
  30. data/lib/erlang/eb_server.erl +27 -0
  31. data/lib/poolparty.rb +40 -116
  32. data/lib/poolparty/base_packages/haproxy.rb +41 -0
  33. data/lib/poolparty/base_packages/heartbeat.rb +43 -0
  34. data/lib/poolparty/base_packages/poolparty.rb +18 -0
  35. data/lib/poolparty/base_packages/ruby.rb +27 -0
  36. data/lib/poolparty/core/array.rb +24 -0
  37. data/lib/{core → poolparty/core}/exception.rb +0 -0
  38. data/lib/{core → poolparty/core}/float.rb +0 -0
  39. data/lib/poolparty/core/hash.rb +29 -0
  40. data/lib/poolparty/core/kernel.rb +34 -0
  41. data/lib/{core → poolparty/core}/module.rb +18 -0
  42. data/lib/poolparty/core/my_open_struct.rb +18 -0
  43. data/lib/poolparty/core/object.rb +54 -0
  44. data/lib/poolparty/core/proc.rb +2 -0
  45. data/lib/poolparty/core/string.rb +72 -0
  46. data/lib/poolparty/core/symbol.rb +8 -0
  47. data/lib/{core → poolparty/core}/time.rb +15 -0
  48. data/lib/poolparty/exceptions/RemoteException.rb +12 -0
  49. data/lib/poolparty/exceptions/ResourceException.rb +7 -0
  50. data/lib/poolparty/exceptions/RuntimeException.rb +7 -0
  51. data/lib/poolparty/exceptions/SpecException.rb +7 -0
  52. data/lib/poolparty/exceptions/TemplateNotFound.rb +7 -0
  53. data/lib/poolparty/helpers/binary.rb +30 -0
  54. data/lib/poolparty/helpers/console.rb +30 -0
  55. data/lib/poolparty/helpers/display.rb +25 -0
  56. data/lib/poolparty/helpers/optioner.rb +61 -0
  57. data/lib/poolparty/helpers/provisioner_base.rb +226 -0
  58. data/lib/poolparty/helpers/provisioners/master.rb +120 -0
  59. data/lib/poolparty/helpers/provisioners/slave.rb +52 -0
  60. data/lib/poolparty/modules/cloud_resourcer.rb +72 -0
  61. data/lib/poolparty/modules/configurable.rb +34 -0
  62. data/lib/poolparty/modules/definable_resource.rb +59 -0
  63. data/lib/poolparty/modules/file_writer.rb +55 -0
  64. data/lib/poolparty/modules/method_missing_sugar.rb +17 -0
  65. data/lib/poolparty/modules/output.rb +13 -0
  66. data/lib/poolparty/modules/pretty_printer.rb +38 -0
  67. data/lib/{core/string.rb → poolparty/modules/s3_string.rb} +5 -29
  68. data/lib/{modules → poolparty/modules}/safe_instance.rb +0 -0
  69. data/lib/poolparty/monitors/base_monitor.rb +16 -0
  70. data/lib/poolparty/net/remote.rb +35 -0
  71. data/lib/poolparty/net/remote_bases/ec2.rb +145 -0
  72. data/lib/poolparty/net/remote_instance.rb +68 -0
  73. data/lib/poolparty/net/remoter.rb +209 -0
  74. data/lib/poolparty/net/remoter_base.rb +117 -0
  75. data/lib/poolparty/plugins/gem_package.rb +39 -0
  76. data/lib/poolparty/plugins/line.rb +76 -0
  77. data/lib/poolparty/plugins/svn.rb +48 -0
  78. data/lib/poolparty/pool/base.rb +74 -0
  79. data/lib/poolparty/pool/cloud.rb +132 -0
  80. data/lib/poolparty/pool/custom_resource.rb +61 -0
  81. data/lib/poolparty/pool/loggable.rb +29 -0
  82. data/lib/poolparty/pool/plugin.rb +42 -0
  83. data/lib/poolparty/pool/plugin_model.rb +48 -0
  84. data/lib/poolparty/pool/pool.rb +55 -0
  85. data/lib/poolparty/pool/resource.rb +235 -0
  86. data/lib/poolparty/pool/resources/class_package.rb +60 -0
  87. data/lib/poolparty/pool/resources/cron.rb +14 -0
  88. data/lib/poolparty/pool/resources/directory.rb +23 -0
  89. data/lib/poolparty/pool/resources/exec.rb +26 -0
  90. data/lib/poolparty/pool/resources/file.rb +23 -0
  91. data/lib/poolparty/pool/resources/gem.rb +14 -0
  92. data/lib/poolparty/pool/resources/host.rb +14 -0
  93. data/lib/poolparty/pool/resources/package.rb +14 -0
  94. data/lib/poolparty/pool/resources/remote_file.rb +20 -0
  95. data/lib/poolparty/pool/resources/service.rb +21 -0
  96. data/lib/poolparty/pool/resources/sshkey.rb +19 -0
  97. data/lib/poolparty/pool/resources/variable.rb +27 -0
  98. data/lib/poolparty/pool/script.rb +21 -0
  99. data/{config/heartbeat_authkeys.conf → lib/poolparty/templates/authkeys} +0 -0
  100. data/lib/poolparty/templates/cib.xml +1 -0
  101. data/lib/poolparty/templates/fileserver.conf +4 -0
  102. data/{config/heartbeat.conf → lib/poolparty/templates/ha.cf} +3 -1
  103. data/{config → lib/poolparty/templates}/haproxy.conf +13 -6
  104. data/lib/poolparty/templates/namespaceauth.conf +19 -0
  105. data/lib/poolparty/templates/puppet.conf +13 -0
  106. data/lib/poolparty/version.rb +9 -0
  107. data/lib/poolpartycl.rb +3 -0
  108. data/script/destroy +14 -0
  109. data/script/generate +14 -0
  110. data/script/txt2html +82 -0
  111. data/{lib/poolparty/tasks → tasks}/cloud.rake +1 -1
  112. data/tasks/deployment.rake +34 -0
  113. data/tasks/development.rake +78 -0
  114. data/{lib/poolparty/tasks → tasks}/ec2.rake +1 -1
  115. data/tasks/environment.rake +7 -0
  116. data/{lib/poolparty/tasks → tasks}/instance.rake +0 -0
  117. data/{lib/poolparty/tasks → tasks}/server.rake +0 -0
  118. data/tasks/spec.rake +17 -0
  119. data/tasks/website.rake +17 -0
  120. metadata +154 -249
  121. data/CHANGELOG +0 -23
  122. data/LICENSE +0 -22
  123. data/README +0 -139
  124. data/assets/clouds.png +0 -0
  125. data/bin/instance +0 -68
  126. data/bin/poolnotify +0 -34
  127. data/config/cloud_master_takeover +0 -17
  128. data/config/create_proxy_ami.sh +0 -582
  129. data/config/installers/ubuntu_install.sh +0 -77
  130. data/config/monit.conf +0 -9
  131. data/config/monit/haproxy.monit.conf +0 -8
  132. data/config/monit/nginx.monit.conf +0 -0
  133. data/config/nginx.conf +0 -24
  134. data/config/reconfigure_instances_script.sh +0 -37
  135. data/config/sample-config.yml +0 -23
  136. data/config/scp_instances_script.sh +0 -12
  137. data/lib/core/array.rb +0 -16
  138. data/lib/core/hash.rb +0 -11
  139. data/lib/core/kernel.rb +0 -12
  140. data/lib/core/object.rb +0 -21
  141. data/lib/core/proc.rb +0 -15
  142. data/lib/helpers/plugin_spec_helper.rb +0 -58
  143. data/lib/modules/callback.rb +0 -133
  144. data/lib/modules/ec2_wrapper.rb +0 -108
  145. data/lib/modules/file_writer.rb +0 -38
  146. data/lib/modules/sprinkle_overrides.rb +0 -27
  147. data/lib/modules/vlad_override.rb +0 -83
  148. data/lib/poolparty/application.rb +0 -199
  149. data/lib/poolparty/init.rb +0 -6
  150. data/lib/poolparty/master.rb +0 -492
  151. data/lib/poolparty/monitors.rb +0 -11
  152. data/lib/poolparty/monitors/cpu.rb +0 -23
  153. data/lib/poolparty/monitors/memory.rb +0 -33
  154. data/lib/poolparty/monitors/web.rb +0 -29
  155. data/lib/poolparty/optioner.rb +0 -20
  156. data/lib/poolparty/plugin.rb +0 -78
  157. data/lib/poolparty/provider.rb +0 -104
  158. data/lib/poolparty/provider/essential.rb +0 -6
  159. data/lib/poolparty/provider/git.rb +0 -8
  160. data/lib/poolparty/provider/haproxy.rb +0 -9
  161. data/lib/poolparty/provider/heartbeat.rb +0 -6
  162. data/lib/poolparty/provider/rsync.rb +0 -8
  163. data/lib/poolparty/provider/ruby.rb +0 -65
  164. data/lib/poolparty/provider/s3fuse.rb +0 -22
  165. data/lib/poolparty/remote_instance.rb +0 -250
  166. data/lib/poolparty/remoter.rb +0 -171
  167. data/lib/poolparty/remoting.rb +0 -137
  168. data/lib/poolparty/scheduler.rb +0 -93
  169. data/lib/poolparty/tasks.rb +0 -47
  170. data/lib/poolparty/tasks/development.rake +0 -78
  171. data/lib/poolparty/tasks/plugins.rake +0 -30
  172. data/lib/poolparty/thread_pool.rb +0 -94
  173. data/lib/s3/s3_object_store_folders.rb +0 -44
  174. data/poolparty.gemspec +0 -71
  175. data/spec/files/describe_response +0 -37
  176. data/spec/files/multi_describe_response +0 -69
  177. data/spec/files/remote_desc_response +0 -37
  178. data/spec/helpers/ec2_mock.rb +0 -57
  179. data/spec/lib/core/core_spec.rb +0 -26
  180. data/spec/lib/core/kernel_spec.rb +0 -24
  181. data/spec/lib/core/string_spec.rb +0 -28
  182. data/spec/lib/modules/callback_spec.rb +0 -213
  183. data/spec/lib/modules/file_writer_spec.rb +0 -74
  184. data/spec/lib/poolparty/application_spec.rb +0 -135
  185. data/spec/lib/poolparty/ec2_wrapper_spec.rb +0 -110
  186. data/spec/lib/poolparty/master_spec.rb +0 -479
  187. data/spec/lib/poolparty/optioner_spec.rb +0 -34
  188. data/spec/lib/poolparty/plugin_spec.rb +0 -115
  189. data/spec/lib/poolparty/poolparty_spec.rb +0 -60
  190. data/spec/lib/poolparty/provider_spec.rb +0 -74
  191. data/spec/lib/poolparty/remote_instance_spec.rb +0 -178
  192. data/spec/lib/poolparty/remoter_spec.rb +0 -72
  193. data/spec/lib/poolparty/remoting_spec.rb +0 -148
  194. data/spec/lib/poolparty/scheduler_spec.rb +0 -70
  195. data/spec/monitors/cpu_monitor_spec.rb +0 -39
  196. data/spec/monitors/memory_spec.rb +0 -51
  197. data/spec/monitors/misc_monitor_spec.rb +0 -51
  198. data/spec/monitors/web_spec.rb +0 -40
  199. data/spec/spec_helper.rb +0 -53
@@ -0,0 +1,120 @@
1
+ module PoolParty
2
+ module Provisioner
3
+ class Master < ProvisionerBase
4
+
5
+ def initialize(cloud=self, os=:ubuntu)
6
+ super(cloud.master, cloud)
7
+ end
8
+
9
+ def valid?
10
+ !(@cloud.nil? || @cloud.master.nil?)
11
+ end
12
+
13
+ def error
14
+ raise RemoteException.new(:could_not_install, "Your cloud does not have a master")
15
+ end
16
+
17
+ def install_tasks
18
+ [
19
+ install_puppet_master,
20
+ create_local_hosts_entry,
21
+ setup_basic_structure,
22
+ setup_configs,
23
+ setup_fileserver,
24
+ setup_autosigning,
25
+ start_puppetmaster
26
+ ] << configure_tasks
27
+ end
28
+
29
+ def configure_tasks
30
+ [
31
+ create_local_node,
32
+ move_templates,
33
+ create_poolparty_manifest,
34
+ restart_puppetd
35
+ ]
36
+ end
37
+
38
+ def install_puppet_master
39
+ "#{installer_for(@os)} #{get_puppet_packages_for(@os)}"
40
+ end
41
+
42
+ def create_local_hosts_entry
43
+ <<-EOS
44
+ if [ -z "grep -v '#' /etc/hosts | grep 'puppet'" ]; then echo '#{@master_ip} puppet master' >> /etc/hosts; fi
45
+ EOS
46
+ end
47
+
48
+ def setup_basic_structure
49
+ <<-EOS
50
+ puppetmasterd --mkusers
51
+ mkdir -p #{Base.remote_storage_path}
52
+ echo "import 'nodes/*.pp'" > /etc/puppet/manifests/site.pp
53
+ echo "import 'classes/*.pp'" >> /etc/puppet/manifests/site.pp
54
+ mkdir -p /etc/puppet/manifests/nodes
55
+ mkdir -p /etc/puppet/manifests/classes
56
+ mv #{Base.remote_storage_path}/#{Base.tmp_path}/namespaceauth.conf /etc/puppet/namespaceauth.conf
57
+ EOS
58
+ end
59
+
60
+ def setup_configs
61
+ <<-EOS
62
+ echo "#{open(File.join(template_directory, "puppet.conf")).read}" > /etc/puppet/puppet.conf
63
+ EOS
64
+ end
65
+
66
+ def setup_fileserver
67
+ <<-EOS
68
+ echo "
69
+ [files]
70
+ path #{Base.remote_storage_path}/#{Base.tmp_path}
71
+ allow *" > /etc/puppet/fileserver.conf
72
+ mkdir -p /var/poolparty/facts
73
+ mkdir -p /var/poolparty/files
74
+ mkdir -p /etc/poolparty
75
+ EOS
76
+ end
77
+ # Change this eventually for better security supportsetup_fileserver
78
+ def setup_autosigning
79
+ <<-EOS
80
+ echo "*" > /etc/puppet/autosign.conf
81
+ EOS
82
+ end
83
+
84
+ def create_local_node
85
+ str = <<-EOS
86
+ node default {
87
+ include poolparty
88
+ }
89
+ EOS
90
+ @cloud.list_of_running_instances.each do |ri|
91
+ str << <<-EOS
92
+ node "#{ri.name}" inherits default {}
93
+ EOS
94
+ end
95
+ "echo '#{str}' > /etc/puppet/manifests/nodes/nodes.pp"
96
+ end
97
+
98
+ def move_templates
99
+ <<-EOS
100
+ mkdir -p #{Base.template_path}
101
+ mv #{Base.remote_storage_path}/#{Base.template_directory}/* #{Base.template_path}
102
+ EOS
103
+ end
104
+
105
+ def create_poolparty_manifest
106
+ <<-EOS
107
+ mv #{Base.remote_storage_path}/#{Base.tmp_path}/poolparty.pp /etc/puppet/manifests/classes/poolparty.pp
108
+ EOS
109
+ end
110
+
111
+ def start_puppetmaster
112
+ "puppetmasterd && puppetd --listen"
113
+ end
114
+
115
+ def restart_puppetd # && puppetrun --host 127.0.0.1
116
+ # "puppetd --listen"
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,52 @@
1
+ module PoolParty
2
+ module Provisioner
3
+ class Slave < ProvisionerBase
4
+
5
+ def install_tasks
6
+ [
7
+ install_puppet,
8
+ setup_puppet
9
+ ] << configure_tasks
10
+ end
11
+
12
+ def configure_tasks
13
+ [
14
+ setup_configs,
15
+ start_puppet
16
+ ]
17
+ end
18
+
19
+ def install_puppet
20
+ <<-EOE
21
+ #{installer_for(@os)} #{get_puppet_packages_for(@os)}
22
+ echo 'DAEMON_OPTS="-w 120 –server puppet"' > /etc/default/puppet
23
+ EOE
24
+ end
25
+
26
+ def setup_puppet
27
+ <<-EOE
28
+ puppetd --mkusers
29
+ if [ -z "$(grep -v '#' /etc/hosts | grep 'puppet')" ]; then echo "#{master_ip} puppet" >> /etc/hosts; else echo "host already set"; fi
30
+ mv #{Base.remote_storage_path}/#{Base.tmp_path}/namespaceauth.conf /etc/puppet/namespaceauth.conf
31
+ EOE
32
+ end
33
+
34
+ def setup_configs
35
+ <<-EOS
36
+ echo "#{open(File.join(template_directory, "puppet.conf")).read}" > /etc/puppet/puppet.conf
37
+ EOS
38
+ end
39
+
40
+ def start_puppet
41
+ <<-EOS
42
+ puppetd --listen
43
+ EOS
44
+ end
45
+
46
+ def master_ip
47
+ @cloud.master.ip
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,72 @@
1
+ require "ftools"
2
+
3
+ module PoolParty
4
+ module CloudResourcer
5
+
6
+ # Set instances with a range
7
+ def instances(arg)
8
+ if arg.is_a?(Range)
9
+ minimum_instances arg.first
10
+ maximum_instances arg.last
11
+ end
12
+ end
13
+
14
+ def full_keypair_path
15
+ unless keypair_path
16
+ raise RuntimeException.new("Keypair cannot be found")
17
+ else
18
+ ::File.expand_path(keypair_path)
19
+ end
20
+ end
21
+
22
+ def keypair_path
23
+ keypair_paths.each do |path|
24
+ possible_keypair_basenames.each do |base|
25
+ full_path = ::File.join( File.expand_path(path), "#{base}#{keypair}")
26
+ return full_path if ::File.exists?(full_path)
27
+ end
28
+ end
29
+ return nil
30
+ end
31
+
32
+ def new_keypair_path
33
+ ::File.join( keypair_paths.first, "#{possible_keypair_basenames.first}#{keypair}" )
34
+ end
35
+
36
+ def possible_keypair_basenames
37
+ [
38
+ "id_rsa-",
39
+ ""
40
+ ]
41
+ end
42
+
43
+ def keypair_paths
44
+ [
45
+ Base.base_keypair_path,
46
+ Base.base_config_directory,
47
+ Base.remote_storage_path
48
+ ]
49
+ end
50
+
51
+ # Set the parent on the resource
52
+ def set_parent(pare)
53
+ @parent = pare
54
+ # Add self as a service on the parent
55
+ pare.add_service(self) if pare.respond_to?(:add_service)
56
+ # Take the options of the parents
57
+ configure(pare.options) if pare.respond_to?(:options)
58
+ end
59
+
60
+ def number_of_resources
61
+ arr = resources.map do |n, r|
62
+ r.size
63
+ end
64
+ resources.map {|n,r| r.size}.inject(0){|sum,i| sum+=i}
65
+ end
66
+
67
+ def parent
68
+ @parent ||= nil
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,34 @@
1
+ module PoolParty
2
+ module Configurable
3
+ module ClassMethods
4
+ def default_options(h={})
5
+ @default_options ||= h
6
+ end
7
+ end
8
+
9
+ module InstanceMethods
10
+ def options(h={})
11
+ @options ||= self.class.default_options.merge(h)
12
+ end
13
+
14
+ def configure(h={})
15
+ options(h).merge!(h)
16
+ end
17
+
18
+ def reconfigure(h={})
19
+ @options = nil
20
+ options(h)
21
+ end
22
+
23
+ def set_vars_from_options(opts={})
24
+ opts.each {|k,v| self.send k.to_sym, v } unless opts.empty?
25
+ end
26
+ end
27
+
28
+ def self.included(receiver)
29
+ receiver.extend ClassMethods
30
+ receiver.send :include, InstanceMethods
31
+ receiver.send :include, MethodMissingSugar
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,59 @@
1
+ module PoolParty
2
+ module DefinableResource
3
+ # Define a new resource that can be called like any other resource
4
+ # Similar to any other resource (like file or exec)
5
+ # but you define it how you want it to work
6
+ # Example:
7
+ #
8
+ # define_resource(:line_in_file) do
9
+ # end
10
+ #
11
+ # Within the block, you can define any methods you want to run as
12
+ # part of the resource
13
+ #
14
+ # One thing to note is that this is NOT like other resources in the sense
15
+ # that it does not give you any extra methods like the resources do
16
+ #
17
+ # For example usage, see lib/poolparty/plugins/line.rb
18
+ def define_resource(name, &block)
19
+ symc = "#{name}".classify
20
+ klass = symc.class_constant(PoolParty::Resources::CustomResource, {:preserve => true}, &block)
21
+ PoolParty::Resources.module_eval &block
22
+ klass
23
+ end
24
+
25
+ # Allow us to create virtual resources
26
+ # Generally, in plugins
27
+ # This sets a virtual resource against the Resource class
28
+ # Example:
29
+ #
30
+ # virtual_resource(:virtualhost) do
31
+ # end
32
+ #
33
+ # This defines a virtualhost as a virtual resource
34
+ # and consequently gives the methods has_virtualhost and does_not_have_virtualhost
35
+ #
36
+ # Note that you can define any resources within the virtual resource
37
+ # within the definition or the call.
38
+ # Call example:
39
+ # has_virtualhost do
40
+ # name "xnot.org"
41
+ # end
42
+ #
43
+ # Which sets the virtual host's name as xnot.org
44
+ #
45
+ # This is included in the poolparty-apache-plugin
46
+ def virtual_resource(name=:virtual_resource, opts={}, &block)
47
+ symc = "#{name}".classify
48
+ eval <<-EOE
49
+ class PoolParty::Resources::#{symc} < PoolParty::Resources::Resource
50
+ end
51
+ EOE
52
+ klass = "PoolParty::Resources::#{symc}".constantize
53
+ klass.module_eval &block if block
54
+ klass.send :define_method, :virtual_resource?, Proc.new{true}
55
+ klass
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ module PoolParty
2
+ module FileWriter
3
+ def copy_file_to_storage_directory(file)
4
+ make_base_directory
5
+ path = ::File.join( Base.storage_directory, ::File.basename(file) )
6
+ FileUtils.cp file, path
7
+ end
8
+ def copy_template_to_storage_directory(file)
9
+ make_template_directory
10
+ path = ::File.join( Base.template_directory, ::File.basename(file) )
11
+ FileUtils.cp file, path
12
+ end
13
+ def write_to_file_in_storage_directory(file, str, &block)
14
+ path = ::File.join( Base.storage_directory, ::File.basename(file) )
15
+ write_to_file(path, str, &block)
16
+ end
17
+ def write_to_file(file, str, &block)
18
+ path = ::File.join( Base.storage_directory, ::File.basename(file) )
19
+ make_base_path( Base.storage_directory )
20
+ ::File.open(path, "w+") do |f|
21
+ f.print str
22
+ f.flush
23
+ f.print block.call(f) if block
24
+ end
25
+ end
26
+ # Write a temp file with the content str and return the Tempfile
27
+ # It creates a random file name
28
+ def write_to_temp_file(str="", &block)
29
+ returning Tempfile.new("#{Base.storage_directory}/PoolParty-#{str[0..10].chomp}-#{rand(1000)}") do |fp|
30
+ fp.print str
31
+ fp.flush
32
+ block.call(fp)
33
+ end
34
+ end
35
+ def make_base_path(path)
36
+ unless FileTest.directory?(path)
37
+ begin
38
+ ::FileUtils.mkdir_p path
39
+ rescue Errno::ENOTDIR
40
+ rescue Errno::EEXIST
41
+ puts "There was an error"
42
+ end
43
+ end
44
+ end
45
+ def make_base_directory
46
+ FileUtils.mkdir_p Base.storage_directory unless ::File.directory?(Base.storage_directory)
47
+ end
48
+ def make_template_directory
49
+ FileUtils.mkdir_p Base.template_directory unless ::File.directory?(Base.template_directory)
50
+ end
51
+ def clear_base_directory
52
+ FileUtils::rm_rf "#{Base.storage_directory}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ module PoolParty
2
+ module MethodMissingSugar
3
+
4
+ def method_missing(m, *args, &block)
5
+ if block_given?
6
+ (args[0].class == self.class) ? args[0].instance_eval(&block) : super
7
+ else
8
+ get_from_options(m, *args)
9
+ end
10
+ end
11
+
12
+ def get_from_options(m, *args)
13
+ args.empty? ? options[m] : options[m] = (args.is_a?(Array) && args.size > 1) ? args : args[0]
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module PoolParty
2
+ module Output
3
+
4
+ def output(*args)
5
+ returning (@output ||= []) do |output|
6
+ args.each do |line|
7
+ (output ||= []) << line
8
+ end
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ module PoolParty
2
+ module PrettyPrinter
3
+
4
+ def pretty_print(prev="\t")
5
+ returning Array.new do |out|
6
+ out << pretty_name(prev, self)
7
+ out << pretty_options(prev, self)
8
+
9
+ if self.respond_to?(:clouds)
10
+ clouds.each do |name, cl|
11
+ out << pretty_name(prev*2, cl)
12
+ out << pretty_options(prev*2, cl) #cl.pretty_print("#{prev}\t")
13
+ end
14
+ end
15
+ if self.respond_to?(:plugins)
16
+ out << "#{prev}\t\tPlugins"
17
+ out << "#{prev}\t\t" + plugins.map {|a| a}.join("\n")
18
+ end
19
+ end.join("\n")
20
+ end
21
+
22
+ # Gather options on the object
23
+ # Do not print if the option is nil or empty.
24
+ # Also, don't show the option if the option is empty or the default option on the cloud
25
+ def pretty_options(prev, o)
26
+ print_options = (o.respond_to?(:parent) && o.parent) ?
27
+ (o.options.delete_if {|k,v| o.parent.options.has_key?(k) && o.parent.options[k] == o.options[k] && !o.options[k].nil? } ) :
28
+ o.options
29
+ print_options = print_options.map {|k,v| [k, o.send(k.to_sym).to_s] }.inject({}) { |r,e| r[e[0]] = e[1] unless o.class.default_options[e[0]] == e[1] || e[1].nil? || e[1].empty?; r }
30
+ print_options.flush_out("#{prev}\t")
31
+ end
32
+
33
+ def pretty_name(prev, o)
34
+ "#{prev}#{o.class.to_s.top_level_class.capitalize}: #{o.name if o.respond_to?(:name)}"
35
+ end
36
+
37
+ end
38
+ end