Class: Bosh::Director::VmCreator
- Includes:
- EncryptionHelper
- Defined in:
- lib/bosh/director/vm_creator.rb
Overview
Creates VM model and call out to CPI to create VM in IaaS
Constant Summary collapse
- MAX_CREATE_VM_TRIES =
this is used to retry VM creation on clouds that are unreliable (e.g. AWS)
5
Class Method Summary collapse
Instance Method Summary collapse
- #create(deployment, stemcell, cloud_properties, network_settings, disks = nil, env = {}) ⇒ Object
- #delete_vm(vm_cid) ⇒ Object
-
#initialize ⇒ VmCreator
constructor
A new instance of VmCreator.
- #logger ⇒ Object
Methods included from EncryptionHelper
Constructor Details
Class Method Details
.create(*args) ⇒ Object
11 12 13 |
# File 'lib/bosh/director/vm_creator.rb', line 11 def self.create(*args) new.create(*args) end |
.generate_agent_id ⇒ Object
71 72 73 |
# File 'lib/bosh/director/vm_creator.rb', line 71 def self.generate_agent_id SecureRandom.uuid end |
Instance Method Details
#create(deployment, stemcell, cloud_properties, network_settings, disks = nil, env = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bosh/director/vm_creator.rb', line 20 def create(deployment, stemcell, cloud_properties, network_settings, disks=nil, env={}) vm = nil vm_cid = nil env = Bosh::Common::DeepCopy.copy(env) agent_id = self.class.generate_agent_id = { :deployment => deployment, :agent_id => agent_id, :env => env } if Config.encryption? credentials = generate_agent_credentials env["bosh"] ||= {} env["bosh"]["credentials"] = credentials [:credentials] = credentials end count = 0 begin vm_cid = @cloud.create_vm(agent_id, stemcell.cid, cloud_properties, network_settings, disks, env) rescue Bosh::Clouds::VMCreationFailed => e count += 1 logger.error("failed to create VM, retrying (#{count})") retry if e.ok_to_retry && count < MAX_CREATE_VM_TRIES raise e end [:cid] = vm_cid vm = Models::Vm.new() vm.save VmMetadataUpdater.build.update(vm, {}) vm rescue => e logger.error("error creating vm: #{e.}") delete_vm(vm_cid) if vm_cid vm.destroy if vm raise e end |
#delete_vm(vm_cid) ⇒ Object
65 66 67 68 69 |
# File 'lib/bosh/director/vm_creator.rb', line 65 def delete_vm(vm_cid) @cloud.delete_vm(vm_cid) rescue => e logger.error("error cleaning up #{vm_cid}: #{e.}\n#{e.backtrace.join("\n")}") end |