Module: PoolParty::CloudResourcer
- Included in:
- PoolParty::Cloud::Cloud, Plugin::Plugin, Pool::Pool
- Defined in:
- lib/poolparty/modules/cloud_resourcer.rb
Instance Method Summary collapse
- #_keypairs ⇒ Object
- #full_keypair_path ⇒ Object
-
#instances(arg) ⇒ Object
Set instances with a range or a number if passed with a hash, call nodes(hash) to return filtered list of instances.
-
#keypair(*args) ⇒ Object
(also: #set_keypairs)
Keypairs Use the keypair path.
-
#number_of_resources ⇒ Object
TODO: deprecate.
- #plugin_directory(arr = []) ⇒ Object
-
#run_stored_block ⇒ Object
This will run the blocks after they are stored if there is a block associated.
- #setup_dev ⇒ Object
-
#store_block(&block) ⇒ Object
Store block.
- #stored_block ⇒ Object
- #update_from_schema(schema) ⇒ Object
-
#using(t, &block) ⇒ Object
Declare the remoter base Check to make sure the available_bases is available, otherwise raise Give access to the cloud the remote_base and instantiate a new instance of the remote base.
-
#using_remoter? ⇒ Boolean
Are we using a remoter?.
Instance Method Details
#_keypairs ⇒ Object
104 105 106 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 104 def _keypairs [:keypairs] ||= [Key.new] end |
#full_keypair_path ⇒ Object
108 109 110 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 108 def full_keypair_path @full_keypair_path ||= keypair.full_filepath end |
#instances(arg) ⇒ Object
Set instances with a range or a number if passed with a hash, call nodes(hash) to return filtered list of instances
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 43 def instances(arg) case arg when Range minimum_instances arg.first maximum_instances arg.last when Fixnum minimum_instances arg maximum_instances arg when Hash nodes(arg) else raise SpecException.new("Don't know how to handle instances cloud input #{arg}") end end |
#keypair(*args) ⇒ Object Also known as: set_keypairs
Keypairs Use the keypair path
94 95 96 97 98 99 100 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 94 def keypair(*args) if args && !args.empty? args.each {|arg| _keypairs.unshift Key.new(arg) unless arg.nil? || arg.empty? } else @keypair ||= _keypairs.select {|key| key.exists? }.first end end |
#number_of_resources ⇒ Object
TODO: deprecate
122 123 124 125 126 127 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 122 def number_of_resources arr = resources.map do |n, r| r.size end resources.map {|n,r| r.size}.inject(0){|sum,i| sum+=i} end |
#plugin_directory(arr = []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 14 def plugin_directory(arr=[]) arr = [arr] if arr.is_a?(String) arr << [ "#{::File.(Dir.pwd)}/plugins", "#{::File.(Default.poolparty_home_path)}/plugins" ] arr.flatten.each {|arg| Dir["#{arg}/*/*.rb"].each {|f| require f } if ::File.directory?(arg) } end |
#run_stored_block ⇒ Object
This will run the blocks after they are stored if there is a block associated
36 37 38 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 36 def run_stored_block self.run_in_context @stored_block if @stored_block end |
#setup_dev ⇒ Object
58 59 60 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 58 def setup_dev return true if keypair || master.nil? end |
#store_block(&block) ⇒ Object
Store block
26 27 28 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 26 def store_block(&block) @stored_block ||= block ? block : nil end |
#stored_block ⇒ Object
30 31 32 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 30 def stored_block @stored_block end |
#update_from_schema(schema) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 112 def update_from_schema(schema) keypairs = schema..delete(:keypairs).map {|a| PoolParty::Key.new(a.basename) } .merge! schema. [:keypairs] = keypairs [:dependency_resolver] = schema..dependency_resolver.split("::")[-1].gsub(/Resolver/, '').preserved_class_constant("Resolver") rescue PoolParty::Chef end |
#using(t, &block) ⇒ Object
Declare the remoter base Check to make sure the available_bases is available, otherwise raise Give access to the cloud the remote_base and instantiate a new instance of the remote base
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 66 def using(t, &block) @cloud = self if t && self.class.available_bases.include?(t.to_sym) unless using_remoter? self.class.send :attr_reader, :remote_base self.class.send :attr_reader, :parent_cloud klass_string = "#{t}".classify klass = "::PoolParty::Remote::#{klass_string}".constantize @remote_base = klass.send :new, self, &block @remote_base.instance_eval &block if block [:remote_base] = klass.to_s if respond_to?(:options) @parent_cloud = @cloud instance_eval "def #{t};@remote_base;end" end else raise "Unknown remote base: #{t}" end end |
#using_remoter? ⇒ Boolean
Are we using a remoter?
88 89 90 |
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 88 def using_remoter? !@remote_base.nil? end |