Class: HostRecord
Overview
:nodoc:
Class Method Summary collapse
- .define(name, security_groups, runlist = [], options = {}) ⇒ Object
- .destroy(name) ⇒ Object
- .get_instance(name) ⇒ Object
- .launch(name, security_groups, options) ⇒ Object
- .provision(name, runlist, options) ⇒ Object
Class Method Details
.define(name, security_groups, runlist = [], options = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ponyup.rb', line 126 def self.define name, security_groups, runlist=[], ={} namespace :host do namespace name do desc "Launch #{name} in the cloud" task :spinup do HostRecord.launch name, security_groups, end desc "Provision #{name} with chef" task :provision do HostRecord.provision name, runlist, end desc "Create #{name} host" task :create => [:spinup, :provision] desc "Delete #{name} security group" task :destroy do HostRecord.destroy name end end end "host:#{name}" end |
.destroy(name) ⇒ Object
183 184 185 |
# File 'lib/ponyup.rb', line 183 def self.destroy name get_instance(name).destroy end |
.get_instance(name) ⇒ Object
187 188 189 190 |
# File 'lib/ponyup.rb', line 187 def self.get_instance name Fog::Compute[:aws].servers.all('tag:Name' => name, 'instance-state-name' => 'running').first end |
.launch(name, security_groups, options) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/ponyup.rb', line 151 def self.launch name, security_groups, if existing=get_instance(name) existing.destroy end key = [:key_name] || Fog.credentials[:key_name] size = [:size] || Fog.credentials[:size] image = [:image_id] || Fog.credentials[:image_id] server = Fog::Compute[:aws].servers.create(groups: security_groups, key_name: key, flavor_id: size, image_id: image, tags: {'Name' => name}) Fog.wait_for { server.reload ; server.ready? } end |
.provision(name, runlist, options) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ponyup.rb', line 166 def self.provision name, runlist, return if runlist.to_s.empty? && ![:knife_solo] instance = get_instance(name) key_name = [:key_name] || Fog.credentials[:key_name] if [:knife_solo] system "knife solo bootstrap ubuntu@#{instance.dns_name} " + "#{[:attributes]} " + "--identity-file ~/.ssh/#{key_name}.pem --node-name #{name}" + "--run-list #{runlist}" else system "knife bootstrap #{instance.dns_name} " + "--identity-file ~/.ssh/#{key_name}.pem --forward-agent " + "--ssh-user ubuntu --sudo --node-name #{name} " + "--run-list #{runlist}" end end |