Module: PoolParty::CloudResourcer

Included in:
PoolParty::Cloud::Cloud, Plugin::Plugin, Pool::Pool
Defined in:
lib/poolparty/modules/cloud_resourcer.rb

Instance Method Summary collapse

Instance Method Details

#_keypairsObject



104
105
106
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 104

def _keypairs
  dsl_options[:keypairs] ||= [Key.new]
end

#full_keypair_pathObject



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_resourcesObject

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.expand_path(Dir.pwd)}/plugins",
    "#{::File.expand_path(Default.poolparty_home_path)}/plugins"
  ]
  arr.flatten.each {|arg|    
    Dir["#{arg}/*/*.rb"].each {|f| require f } if ::File.directory?(arg)
  }
end

#run_stored_blockObject

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_devObject



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_blockObject



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.options.delete(:keypairs).map {|a| PoolParty::Key.new(a.basename) }
  options.merge! schema.options
  dsl_options[:keypairs] = keypairs

  dsl_options[:dependency_resolver] = schema.options.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          
      options[: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?

Returns:

  • (Boolean)


88
89
90
# File 'lib/poolparty/modules/cloud_resourcer.rb', line 88

def using_remoter?
  !@remote_base.nil?
end