Class: Bosh::Director::DeploymentPlan::Vm

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/vm.rb

Overview

Represents a resource pool VM.

It represents a VM until it’s officially bound to an instance. It can be reserved for an instance to minimize the number of CPI operations (network & storage) required for the VM to match the instance requirements.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_pool) ⇒ Vm

Creates a new idle VM reference for the specific resource pool

Parameters:



36
37
38
39
40
41
42
# File 'lib/bosh/director/deployment_plan/vm.rb', line 36

def initialize(resource_pool)
  @resource_pool = resource_pool
  @current_state = nil
  @bound_instance = nil
  @network_reservation = nil
  @model = nil
end

Instance Attribute Details

#bound_instanceDeploymentPlan::Instance?

Returns Instance that reserved this VM.

Returns:



24
25
26
# File 'lib/bosh/director/deployment_plan/vm.rb', line 24

def bound_instance
  @bound_instance
end

#current_stateObject



26
27
28
29
30
31
# File 'lib/bosh/director/deployment_plan/vm.rb', line 26

def current_state
  if @current_state
    @current_state.delete('release')
  end
  @current_state
end

#modelModels::Vm

Returns Associated DB model.

Returns:



18
19
20
# File 'lib/bosh/director/deployment_plan/vm.rb', line 18

def model
  @model
end

#network_reservationNetworkReservation

Returns VM network reservation.

Returns:



15
16
17
# File 'lib/bosh/director/deployment_plan/vm.rb', line 15

def network_reservation
  @network_reservation
end

#resource_poolDeploymentPlan::ResourcePool (readonly)

Returns Associated resource pool.

Returns:



12
13
14
# File 'lib/bosh/director/deployment_plan/vm.rb', line 12

def resource_pool
  @resource_pool
end

Instance Method Details

#changed?Boolean

Returns true if the any of the expected specifications differ from the ones provided by the VM

Returns:

  • (Boolean)

    returns true if the any of the expected specifications differ from the ones provided by the VM



109
110
111
# File 'lib/bosh/director/deployment_plan/vm.rb', line 109

def changed?
  resource_pool_changed? || networks_changed?
end

#clean_vmObject

TODO: rename ‘clean’



114
115
116
117
# File 'lib/bosh/director/deployment_plan/vm.rb', line 114

def clean_vm
  self.model = nil
  self.current_state = nil
end

#has_network_reservation?Boolean

Returns Does this VM have a network reservation?.

Returns:

  • (Boolean)

    Does this VM have a network reservation?



46
47
48
# File 'lib/bosh/director/deployment_plan/vm.rb', line 46

def has_network_reservation?
  !@network_reservation.nil?
end

#network_settingsHash

Returns BOSH network settings used for Agent apply call.

Returns:

  • (Hash)

    BOSH network settings used for Agent apply call



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bosh/director/deployment_plan/vm.rb', line 69

def network_settings
  # use the instance network settings if bound, otherwise use the one
  # provided by the resource pool
  if @bound_instance
    @bound_instance.network_settings
  else
    unless @network_reservation
      raise NetworkReservationMissing,
            'Missing network reservation for resource pool VM'
    end

    network_settings = {}
    network = @resource_pool.network
    network_settings[network.name] = network.network_settings(
        @network_reservation)
    network_settings
  end
end

#networks_changed?Boolean

Returns true if the expected network configuration differs from the one provided by the VM

Returns:

  • (Boolean)

    returns true if the expected network configuration differs from the one provided by the VM



91
92
93
# File 'lib/bosh/director/deployment_plan/vm.rb', line 91

def networks_changed?
  network_settings != @current_state['networks']
end

#release_reservationvoid

This method returns an undefined value.

Releases current network reservation (if any)



60
61
62
63
64
65
# File 'lib/bosh/director/deployment_plan/vm.rb', line 60

def release_reservation
  if has_network_reservation?
    @resource_pool.network.release(@network_reservation)
    @network_reservation = nil
  end
end

#resource_pool_changed?Boolean

Returns true if the expected resource pool specification differs from the one provided by the VM

Returns:

  • (Boolean)

    returns true if the expected resource pool specification differs from the one provided by the VM



98
99
100
101
102
103
104
# File 'lib/bosh/director/deployment_plan/vm.rb', line 98

def resource_pool_changed?
  return true if resource_pool.spec != @current_state['resource_pool']
  return true if resource_pool.deployment_plan.recreate
  return true if @model && @model.env != resource_pool.env

  false
end

#use_reservation(reservation) ⇒ Object

Uses provided network reservation

Parameters:



53
54
55
# File 'lib/bosh/director/deployment_plan/vm.rb', line 53

def use_reservation(reservation)
  @network_reservation = reservation
end