Class: OsCtld::Commands::Self::Shutdown

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/commands/self/shutdown.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osctld/commands/self/shutdown.rb', line 7

def execute
  # Grab manipulation locks of all pools
  grab_pools

  # Disable all pools
  DB::Pools.get.each do |pool|
    progress("Disabling pool #{pool.name}")
    pool.exclusively { pool.disable }
  end

  # Grab manipulation locks of all containers
  grab_all_cts

  # Export pools one by one
  DB::Pools.get.each do |pool|
    progress("Exporting pool #{pool.name}")

    call_cmd!(
      Commands::Pool::Export,
      name: pool.name,
      force: true,
      grab_containers: false,
      stop_containers: true,
      unregister_users: false,
    )
  end

  ok
end

#grab_all_ctsObject (protected)



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/osctld/commands/self/shutdown.rb', line 59

def grab_all_cts
  progress('Grabbing all containers')
  cts = DB::Containers.get

  loop do
    cts.delete_if do |ct|
      begin
        ct.acquire_manipulation_lock(self)
        true

      rescue ResourceLocked => e
        progress(e.message)
        false
      end
    end

    break if cts.empty?
    sleep(1)
  end
end

#grab_poolsObject (protected)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/osctld/commands/self/shutdown.rb', line 38

def grab_pools
  progress('Grabbing pools')
  pools = DB::Pools.get

  loop do
    pools.delete_if do |pool|
      begin
        pool.acquire_manipulation_lock(self)
        true

      rescue ResourceLocked => e
        progress(e.message)
        false
      end
    end

    break if pools.empty?
    sleep(1)
  end
end