Class: OsUp::Cli::Main
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
- Defined in:
- lib/osup/cli/main.rb
Instance Method Summary collapse
- #active_pools ⇒ Object protected
- #check ⇒ Object
- #check_rollback ⇒ Object
- #gen_bash_completion ⇒ Object
- #global_check ⇒ Object protected
- #global_status ⇒ Object protected
- #init ⇒ Object
- #pool_check(pool) ⇒ Object protected
- #pool_flags(sequence) ⇒ Object protected
- #pool_flags_rollback(pool_migrations, version) ⇒ Object protected
- #pool_flags_upgrade(pool_migrations) ⇒ Object protected
- #pool_state(pool_migrations) ⇒ Object protected
- #pool_status(pool) ⇒ Object protected
- #rollback ⇒ Object
- #rollback_all ⇒ Object
- #status ⇒ Object
- #upgrade ⇒ Object
- #upgrade_all ⇒ Object
Methods inherited from Command
Instance Method Details
#active_pools ⇒ Object (protected)
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/osup/cli/main.rb', line 169 def active_pools ret = [] zfs( :list, '-r -d0 -H -o name,org.vpsadminos.osctl:active', '' ).output.strip.split("\n").each do |line| pool, active = line.split ret << pool if active == 'yes' end ret end |
#check ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/osup/cli/main.rb', line 19 def check require_args!(optional: %w[pool]) if args[0] pool_check(args[0]) else global_check end end |
#check_rollback ⇒ Object
30 31 32 33 |
# File 'lib/osup/cli/main.rb', line 30 def check_rollback require_args!('pool', 'version') puts pool_flags_rollback(PoolMigrations.new(args[0]), args[1].to_i) end |
#gen_bash_completion ⇒ Object
95 96 97 98 |
# File 'lib/osup/cli/main.rb', line 95 def gen_bash_completion c = OsCtl::Lib::Cli::Completion::Bash.new(Cli::App.get) puts c.generate end |
#global_check ⇒ Object (protected)
152 153 154 |
# File 'lib/osup/cli/main.rb', line 152 def global_check active_pools.each { |pool| pool_check(pool) } end |
#global_status ⇒ Object (protected)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/osup/cli/main.rb', line 102 def global_status unless opts['hide-header'] puts format( '%-15s %-12s %10s %10s %10s', 'POOL', 'STATUS', 'MIGRATIONS', 'UP', 'DOWN' ) end active_pools.each do |pool| pool_migrations = PoolMigrations.new(pool) total = pool_migrations.all.count up = pool_migrations.all.count { |_id, m| m ? pool_migrations.applied?(m) : true } down = total - up puts format( '%-15s %-12s %10d %10d %10d', pool, pool_state(pool_migrations), total, up, down ) end end |
#init ⇒ Object
35 36 37 38 39 |
# File 'lib/osup/cli/main.rb', line 35 def init require_args!('pool') OsUp.init(args[0], force: opts[:force]) end |
#pool_check(pool) ⇒ Object (protected)
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/osup/cli/main.rb', line 156 def pool_check(pool) pool_migrations = PoolMigrations.new(pool) state = pool_state(pool_migrations) puts format( '%-15s %-15s %-15s %s', pool, state, MigrationList.get.last.id, state == 'outdated' ? pool_flags_upgrade(pool_migrations) : '-' ) end |
#pool_flags(sequence) ⇒ Object (protected)
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/osup/cli/main.rb', line 203 def pool_flags(sequence) flags = [] all_not_export = sequence.all? { |m| !m.export_pool } flags << 'export' unless all_not_export all_not_stop = sequence.all? { |m| !m.stop_containers } flags << 'stop' unless all_not_stop flags.any? ? flags.join(',') : '-' end |
#pool_flags_rollback(pool_migrations, version) ⇒ Object (protected)
199 200 201 |
# File 'lib/osup/cli/main.rb', line 199 def pool_flags_rollback(pool_migrations, version) pool_flags(OsUp::Migrator.rollback_sequence(pool_migrations, to: version)) end |
#pool_flags_upgrade(pool_migrations) ⇒ Object (protected)
195 196 197 |
# File 'lib/osup/cli/main.rb', line 195 def pool_flags_upgrade(pool_migrations) pool_flags(OsUp::Migrator.upgrade_sequence(pool_migrations)) end |
#pool_state(pool_migrations) ⇒ Object (protected)
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/osup/cli/main.rb', line 183 def pool_state(pool_migrations) if !pool_migrations.upgradable? 'incompatible' elsif pool_migrations.uptodate? 'ok' else 'outdated' end end |
#pool_status(pool) ⇒ Object (protected)
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/osup/cli/main.rb', line 128 def pool_status(pool) pool_migrations = PoolMigrations.new(pool) unless opts['hide-header'] puts format( '%-20s %-10s %s', 'MIGRATION', 'STATUS', 'NAME' ) end pool_migrations.all.each do |id, m| puts format( '%-20d %-10s %s', id, if m pool_migrations.applied?(m) ? 'up' : 'down' else 'up' end, m ? m.name : '** migration not found **' ) end end |
#rollback ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/osup/cli/main.rb', line 72 def rollback require_args!('pool', optional: %w[version]) OsUp.rollback( args[0], to: args[1] && args[1].to_i, dry_run: gopts['dry-run'] ) end |
#rollback_all ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/osup/cli/main.rb', line 82 def rollback_all require_args!(optional: %w[version]) target = args[0] && args[0].to_i active_pools.each do |pool| OsUp.rollback(pool, to: target, dry_run: gopts['dry-run']) rescue RuntimeError => e warn e. next end end |
#status ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/osup/cli/main.rb', line 8 def status require_args!(optional: %w[pool]) if args[0] pool_status(args[0]) else global_status end end |
#upgrade ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/osup/cli/main.rb', line 41 def upgrade require_args!('pool', optional: %w[version]) OsUp.upgrade( args[0], to: args[1] && args[1].to_i, dry_run: gopts['dry-run'] ) rescue PoolUpToDate => e puts e. end |
#upgrade_all ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/osup/cli/main.rb', line 53 def upgrade_all require_args!(optional: %w[version]) target = args[0] && args[0].to_i active_pools.each do |pool| pool_migrations = PoolMigrations.new(pool) begin OsUp.upgrade(pool, version: target, dry_run: gops['dry-run']) rescue PoolUpToDate next rescue RuntimeError => e warn e. next end end end |