Class: Bosh::Director::DeploymentPlan::IdleVm

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/idle_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) ⇒ IdleVm

Creates a new idle VM reference for the specific resource pool

Parameters:



31
32
33
34
35
36
37
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 31

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

Instance Attribute Details

#bound_instanceDeploymentPlan::Instance?

Returns Instance that reserved this VM.

Returns:



26
27
28
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 26

def bound_instance
  @bound_instance
end

#current_stateHash

Returns Current state as provided by the BOSH Agent.

Returns:

  • (Hash)

    Current state as provided by the BOSH Agent



23
24
25
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 23

def current_state
  @current_state
end

#network_reservationNetworkReservation

Returns VM network reservation.

Returns:



17
18
19
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 17

def network_reservation
  @network_reservation
end

#resource_poolDeploymentPlan::ResourcePool (readonly)

Returns Associated resource pool.

Returns:



14
15
16
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 14

def resource_pool
  @resource_pool
end

#vmModels::Vm

Returns Associated model.

Returns:



20
21
22
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 20

def vm
  @vm
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



104
105
106
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 104

def changed?
  resource_pool_changed? || networks_changed?
end

#has_network_reservation?Boolean

Returns Does this VM have a network reservation?.

Returns:

  • (Boolean)

    Does this VM have a network reservation?



41
42
43
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 41

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



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 64

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



86
87
88
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 86

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

#release_reservationvoid

This method returns an undefined value.

Releases current network reservation (if any)



55
56
57
58
59
60
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 55

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



93
94
95
96
97
98
99
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 93

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 @vm && @vm.env != resource_pool.env

  false
end

#use_reservation(reservation) ⇒ Object

Uses provided network reservation

Parameters:



48
49
50
# File 'lib/bosh/director/deployment_plan/idle_vm.rb', line 48

def use_reservation(reservation)
  @network_reservation = reservation
end