Class: Bosh::Director::VmData

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

Overview

A class for storing VMs and their associated data so that they can be accessed and deleted easily.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reservation, vm, stemcell, network_settings) ⇒ VmData

Initializes a VmData.

Parameters:

  • reservation (NetworkReservation)

    The network reservation for this VM.

  • vm (Models::Vm)

    The VM to be reused.

  • stemcell (Models::Stemcell)

    The Stemcell to make the VM on.

  • network_settings (Hash)

    A hash containing the network reservation.



29
30
31
32
33
34
35
36
37
# File 'lib/bosh/director/vm_data.rb', line 29

def initialize(reservation, vm, stemcell, network_settings)
  @reservation = reservation
  @vm = vm
  @stemcell = stemcell
  @network_settings = network_settings
  @agent_id = vm.agent_id
  @being_used = false
  @being_used_mutex = Mutex.new
end

Instance Attribute Details

#agentObject



22
23
24
# File 'lib/bosh/director/vm_data.rb', line 22

def agent
  @agent
end

#agent_idObject (readonly)



19
20
21
# File 'lib/bosh/director/vm_data.rb', line 19

def agent_id
  @agent_id
end

#network_settingsObject (readonly)



16
17
18
# File 'lib/bosh/director/vm_data.rb', line 16

def network_settings
  @network_settings
end

#reservationObject (readonly)



7
8
9
# File 'lib/bosh/director/vm_data.rb', line 7

def reservation
  @reservation
end

#stemcellObject (readonly)

@attr The Stemcell this VM is running.



13
14
15
# File 'lib/bosh/director/vm_data.rb', line 13

def stemcell
  @stemcell
end

#vmObject (readonly)



10
11
12
# File 'lib/bosh/director/vm_data.rb', line 10

def vm
  @vm
end

Instance Method Details

#in_use?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/bosh/director/vm_data.rb', line 59

def in_use?
  @being_used
end

#mark_in_useBoolean

Marks that this VM is being used.

Returns:

  • (Boolean)

    Returns whether it could successfully mark this VM as in use.



41
42
43
44
45
46
47
48
49
50
# File 'lib/bosh/director/vm_data.rb', line 41

def mark_in_use
  @being_used_mutex.synchronize do
    if @being_used
      return false
    else
      @being_used = true
      return true
    end
  end
end

#releaseObject

Releases the current VM to be reused.



53
54
55
56
57
# File 'lib/bosh/director/vm_data.rb', line 53

def release
  @being_used_mutex.synchronize do
    @being_used = false
  end
end