Class: PoolParty::Provisioner::ProvisionerBase

Inherits:
Object
  • Object
show all
Includes:
CloudResourcer, Configurable
Defined in:
lib/poolparty/helpers/provisioner_base.rb

Direct Known Subclasses

Master, Slave

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CloudResourcer

#full_keypair_path, #instances, #keypair_path, #keypair_paths, #new_keypair_path, #number_of_resources, #parent, #possible_keypair_basenames, #set_parent

Methods included from Configurable

included

Constructor Details

#initialize(instance, cloud = self, os = :ubuntu) ⇒ ProvisionerBase

Returns a new instance of ProvisionerBase.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/poolparty/helpers/provisioner_base.rb', line 44

def initialize(instance,cloud=self, os=:ubuntu)
  @instance = instance
  @cloud = cloud
  
  options(cloud.options) if cloud && cloud.respond_to?(:options)
  set_vars_from_options(instance.options) unless instance.options.empty?                
  options(instance.options) if instance.respond_to?(:options)
  
  @os = os.to_s.downcase.to_sym
  loaded
end

Class Method Details

.configure(instance, cl = self) ⇒ Object



193
194
195
# File 'lib/poolparty/helpers/provisioner_base.rb', line 193

def self.configure(instance, cl=self)
  new(instance, cl).configure
end

.install(instance, cl = self) ⇒ Object

Install from the class-level



189
190
191
# File 'lib/poolparty/helpers/provisioner_base.rb', line 189

def self.install(instance, cl=self)
  new(instance, cl).install
end

.installers ⇒ Object

Package installers for general *nix operating systems



177
178
179
180
181
182
183
# File 'lib/poolparty/helpers/provisioner_base.rb', line 177

def self.installers
  @installers ||= {
    :ubuntu => "apt-get install -y",
    :fedora => "yum install",
    :gentoo => "emerge"
  }
end

Instance Method Details

#configure ⇒ Object



82
83
84
# File 'lib/poolparty/helpers/provisioner_base.rb', line 82

def configure
  valid? ? configure_string : error
end

#configure_string ⇒ Object



123
124
125
126
127
128
129
130
131
132
# File 'lib/poolparty/helpers/provisioner_base.rb', line 123

def configure_string
  (default_configure_tasks << custom_configure_tasks).each do |task|
    case task.class
    when String
      task
    when Method
      self.send(task.to_sym)
    end
  end.nice_runnable
end

#configure_tasks(a = []) ⇒ Object



151
152
153
# File 'lib/poolparty/helpers/provisioner_base.rb', line 151

def configure_tasks(a=[])
  @configure_tasks ||= a
end

#create_local_node ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/poolparty/helpers/provisioner_base.rb', line 201

def create_local_node
  str = <<-EOS
  node default {
    include poolparty
  }
  EOS
   @cloud.list_of_running_instances.each do |ri|
     str << <<-EOS           
  node "#{ri.name}" {}
     EOS
   end
  "echo '#{str}' > /etc/puppet/manifests/nodes/nodes.pp"
end

#create_poolparty_manifest ⇒ Object



215
216
217
218
219
# File 'lib/poolparty/helpers/provisioner_base.rb', line 215

def create_poolparty_manifest
  <<-EOS
    mv #{Base.remote_storage_path}/poolparty.pp /etc/puppet/manifests/classes
  EOS
end

#custom_configure_tasks ⇒ Object

Custom configure tasks Allows the remoter bases to attach their own custom configuration tasks to the configuration process



163
164
165
# File 'lib/poolparty/helpers/provisioner_base.rb', line 163

def custom_configure_tasks
  @cloud.custom_configure_tasks_for(@instance) || []
end

#custom_install_tasks ⇒ Object

Custom installation tasks Allow the remoter bases to attach their own tasks on the installation process



157
158
159
# File 'lib/poolparty/helpers/provisioner_base.rb', line 157

def custom_install_tasks
  @cloud.custom_install_tasks_for(@instance) || []
end

#default_configure_tasks ⇒ Object

Tasks with default configuration tasks This is run on the provisioner, regardless



143
144
145
146
# File 'lib/poolparty/helpers/provisioner_base.rb', line 143

def default_configure_tasks
  [
  ] << configure_tasks
end

#default_install_tasks ⇒ Object

Tasks with default tasks These are run on all the provisioners, master or slave



135
136
137
138
139
140
# File 'lib/poolparty/helpers/provisioner_base.rb', line 135

def default_install_tasks
  [
    "export AWS_ACCESS_KEY_ID=#{@cloud.access_key}",
    "export AWS_SECRET_ACCESS_ID=#{@cloud.secret_access_key}"
  ] << install_tasks
end

#error ⇒ Object



109
110
111
# File 'lib/poolparty/helpers/provisioner_base.rb', line 109

def error
  "Error in installation"
end

#get_puppet_packages_for(os) ⇒ Object

Get the packages associated with each os



168
169
170
171
172
173
174
175
# File 'lib/poolparty/helpers/provisioner_base.rb', line 168

def get_puppet_packages_for(os)
  case os
  when :fedora
    "puppet-server puppet factor"
  else
    "puppet puppetmaster"
  end
end

#install ⇒ Object

This is the actual runner for the installation



59
60
61
# File 'lib/poolparty/helpers/provisioner_base.rb', line 59

def install
  valid? ? install_string : error
end

#install_string ⇒ Object

Gather all the tasks into one string



113
114
115
116
117
118
119
120
121
122
# File 'lib/poolparty/helpers/provisioner_base.rb', line 113

def install_string
  (default_install_tasks << custom_install_tasks).each do |task|
    case task.class
    when String
      task
    when Method
      self.send(task.to_sym)
    end
  end.nice_runnable
end

#install_tasks(a = []) ⇒ Object

Build a list of the tasks to run on the instance



148
149
150
# File 'lib/poolparty/helpers/provisioner_base.rb', line 148

def install_tasks(a=[])
  @install_task ||= a
end

#installer_for(name) ⇒ Object

Convenience method to grab the installer



185
186
187
# File 'lib/poolparty/helpers/provisioner_base.rb', line 185

def installer_for(name)
  self.class.installers[name.to_sym]
end

#loaded ⇒ Object

Callback after initialized



56
57
# File 'lib/poolparty/helpers/provisioner_base.rb', line 56

def loaded      
end

#process_configure!(testing = false) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/poolparty/helpers/provisioner_base.rb', line 90

def process_configure!(testing=false)
  error unless valid?
  setup_runner(@cloud)
  write_configure_file
  
  unless testing
    @cloud.rsync_storage_files_to(@instance)

    cmd = "cd #{Base.remote_storage_path}/#{Base.tmp_path} && chmod +x configure_#{name}.sh && /bin/sh configure_#{name}.sh && rm -rf *"
    @cloud.run_command_on(cmd, @instance)
  end
end

#process_install!(testing = false) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/poolparty/helpers/provisioner_base.rb', line 67

def process_install!(testing=false)
  error unless valid?
  write_install_file
  setup_runner(@cloud)
  
  unless testing
    puts "Logging on to #{@instance.ip}"
    @cloud.rsync_storage_files_to(@instance)
    
    cmd = "cd #{Base.remote_storage_path}/#{Base.tmp_path} && chmod +x install_#{name}.sh && /bin/sh install_#{name}.sh && rm -rf *"
    hide_output do
      @cloud.run_command_on(cmd, @instance)
    end          
  end        
end

#setup_runner(cloud) ⇒ Object



102
103
104
105
# File 'lib/poolparty/helpers/provisioner_base.rb', line 102

def setup_runner(cloud)
  cloud.prepare_to_configuration
  cloud.build_and_store_new_config_file
end

#template_directory ⇒ Object



197
198
199
# File 'lib/poolparty/helpers/provisioner_base.rb', line 197

def template_directory
  File.join(File.dirname(__FILE__), "..", "templates")
end

#valid? ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/poolparty/helpers/provisioner_base.rb', line 106

def valid?
  true
end

#write_configure_file ⇒ Object



85
86
87
88
89
# File 'lib/poolparty/helpers/provisioner_base.rb', line 85

def write_configure_file
  error unless valid?
  provisioner_file = ::File.join(Base.storage_directory, "configure_#{name}.sh")
  ::File.open(provisioner_file, "w+") {|f| f << configure }
end

#write_install_file ⇒ Object



62
63
64
65
66
# File 'lib/poolparty/helpers/provisioner_base.rb', line 62

def write_install_file
  error unless valid?
  provisioner_file = ::File.join(Base.storage_directory, "install_#{name}.sh")
  ::File.open(provisioner_file, "w+") {|f| f << install }
end