Class: Bosh::Director::VmReuser
- Defined in:
- lib/bosh/director/vm_reuser.rb
Overview
A class for maintaining VmData objects, making reusing VMs easier.
Instance Method Summary collapse
-
#add_vm(reservation, vm, stemcell, network_settings) ⇒ VmData
Adds a VM’s information to the pool of VMs that can be reused.
-
#each {|VmData| ... } ⇒ Object
An iterator for all compilation VMs on all stemcells.
-
#get_num_vms(stemcell) ⇒ Integer
Gets the total number of compilation VMs created with a given stemcell.
-
#get_vm(stemcell) ⇒ VmData?
Returns the VmData instance of a VM that is not in use and can be reused.
-
#initialize ⇒ VmReuser
constructor
A new instance of VmReuser.
- #remove_vm(vm) ⇒ Object
Constructor Details
#initialize ⇒ VmReuser
Returns a new instance of VmReuser.
4 5 6 |
# File 'lib/bosh/director/vm_reuser.rb', line 4 def initialize @stemcells_to_vms = {} end |
Instance Method Details
#add_vm(reservation, vm, stemcell, network_settings) ⇒ VmData
Adds a VM’s information to the pool of VMs that can be reused.
14 15 16 17 18 19 20 |
# File 'lib/bosh/director/vm_reuser.rb', line 14 def add_vm(reservation, vm, stemcell, network_settings) vm_d = VmData.new(reservation, vm, stemcell, network_settings) @stemcells_to_vms[stemcell] ||= [] @stemcells_to_vms[stemcell] << vm_d vm_d.mark_in_use vm_d end |
#each {|VmData| ... } ⇒ Object
An iterator for all compilation VMs on all stemcells.
53 54 55 56 57 58 59 |
# File 'lib/bosh/director/vm_reuser.rb', line 53 def each @stemcells_to_vms.each do |stemcell, vms| vms.each do |vm| yield vm end end end |
#get_num_vms(stemcell) ⇒ Integer
Gets the total number of compilation VMs created with a given stemcell.
47 48 49 |
# File 'lib/bosh/director/vm_reuser.rb', line 47 def get_num_vms(stemcell) @stemcells_to_vms[stemcell].nil? ? 0 : @stemcells_to_vms[stemcell].size end |
#get_vm(stemcell) ⇒ VmData?
Returns the VmData instance of a VM that is not in use and can be reused.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bosh/director/vm_reuser.rb', line 25 def get_vm(stemcell) unless @stemcells_to_vms[stemcell].nil? @stemcells_to_vms[stemcell].each do |vm_data| if vm_data.mark_in_use return vm_data end end end nil end |
#remove_vm(vm) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/bosh/director/vm_reuser.rb', line 36 def remove_vm(vm) @stemcells_to_vms.each_value do |vms| vms.each do |vm_data| vms.delete(vm_data) if vm_data.vm == vm end end end |