Class: VSphereCloud::LeaseUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/vsphere/lease_updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, lease) ⇒ LeaseUpdater

Returns a new instance of LeaseUpdater.



5
6
7
8
9
10
11
12
# File 'lib/cloud/vsphere/lease_updater.rb', line 5

def initialize(client, lease)
  @progress = 0
  @client = client
  @lease = lease
  @state = :running
  @lock = Mutex.new
  @thread = Thread.new { run }
end

Instance Attribute Details

#progressObject

Returns the value of attribute progress.



3
4
5
# File 'lib/cloud/vsphere/lease_updater.rb', line 3

def progress
  @progress
end

Instance Method Details

#abortObject



24
25
26
27
28
29
# File 'lib/cloud/vsphere/lease_updater.rb', line 24

def abort
  @lock.synchronize do
    @state = :abort
    @lease.abort
  end
end

#finishObject



31
32
33
34
35
36
37
# File 'lib/cloud/vsphere/lease_updater.rb', line 31

def finish
  @lock.synchronize do
    @state = :finish
    @lease.progress(100)
    @lease.complete
  end
end

#runObject



14
15
16
17
18
19
20
21
22
# File 'lib/cloud/vsphere/lease_updater.rb', line 14

def run
  loop do
    @lock.synchronize do
      break if @state != :running
      @lease.progress(@progress)
    end
    sleep(1)
  end
end