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
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
8 9 10 |
# File 'lib/bosh/director/vm_creator.rb', line 8 def self.create(*args) new.create(*args) end |
.generate_agent_id ⇒ Object
68 69 70 |
# File 'lib/bosh/director/vm_creator.rb', line 68 def self.generate_agent_id SecureRandom.uuid end |
Instance Method Details
#create(deployment, stemcell, cloud_properties, network_settings, disks = nil, env = {}) ⇒ Object
17 18 19 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 |
# File 'lib/bosh/director/vm_creator.rb', line 17 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 < Config.max_vm_create_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
62 63 64 65 66 |
# File 'lib/bosh/director/vm_creator.rb', line 62 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 |