Class: OsCtl::Cli::Self

Inherits:
Command show all
Includes:
Assets
Defined in:
lib/osctl/cli/self.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

Methods included from Assets

#print_assets

Methods inherited from Command

#cli_opt, #format_output, #initialize, #osctld_call, #osctld_fmt, #osctld_open, #osctld_resp, #require_args!, run

Methods included from Utils::Humanize

#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data

Constructor Details

This class inherits a constructor from OsCtl::Cli::Command

Instance Method Details

#activateObject



58
59
60
# File 'lib/osctl/cli/self.rb', line 58

def activate
  osctld_fmt(:self_activate, system: opts[:system], lxcfs: opts[:lxcfs])
end

#assetsObject



8
9
10
# File 'lib/osctl/cli/self.rb', line 8

def assets
  print_assets(:self_assets)
end

#do_pingObject (protected)



79
80
81
82
83
84
85
86
87
88
# File 'lib/osctl/cli/self.rb', line 79

def do_ping
  return true if osctld_call(:self_ping) == 'pong'
  raise GLI::CustomExit.new('unexpected response', 3)

rescue Errno::ENOENT
  raise GLI::CustomExit.new('unable to connect', 2)

rescue OsCtl::Client::Error
  raise GLI::CustomExit.new('invalid response', 3)
end

#healthcheckObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/osctl/cli/self.rb', line 12

def healthcheck
  entities = osctld_call(
    :self_healthcheck,
    all: opts[:all],
    pools: (opts[:all] || args.empty?) ? nil : args
  )

  if gopts[:json]
    puts entities.to_json
    return
  end

  if entities.empty?
    puts 'No errors detected.'
    return
  end

  entities.each do |ent|
    puts "#{ent[:type]} #{ent[:pool] || '-'} #{ent[:id] || '-'}"

    ent[:assets].each do |asset|
      puts "\t#{asset[:type]} #{asset[:path]}: #{asset[:errors].join('; ')}"
    end
  end
end

#pingObject



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

def ping
  if args[0]
    secs = args[0].to_i

    (0..Float::INFINITY).each do |i|
      begin
        return if do_ping

      rescue GLI::CustomExit
        raise if secs > 0 && i >= secs
      end

      sleep(1)
    end

  else
    puts 'pong' if do_ping
  end
end

#shutdownObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/osctl/cli/self.rb', line 62

def shutdown
  unless opts[:force]
    STDOUT.write(
      'Do you really wish to stop all containers and export all pools? '+
      '[y/N]: '
    )

    if !%w(y yes).include?(STDIN.readline.strip.downcase)
      puts 'Aborting'
      return
    end
  end

  osctld_fmt(:self_shutdown)
end