Class: OsCtl::Cli::Migration

Inherits:
Command
  • Object
show all
Defined in:
lib/osctl/cli/migration.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #gopts, #opts

Instance Method Summary collapse

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

#authorized_keys_addObject



53
54
55
56
57
58
59
# File 'lib/osctl/cli/migration.rb', line 53

def authorized_keys_add
  osctld_fmt(
    :migration_authkey_add,
    pool: gopts[:pool],
    public_key: STDIN.readline.strip
  )
end

#authorized_keys_deleteObject



61
62
63
64
65
66
67
68
# File 'lib/osctl/cli/migration.rb', line 61

def authorized_keys_delete
  require_args!('index')
  osctld_fmt(
    :migration_authkey_delete,
    pool: gopts[:pool],
    index: args[0].to_i
  )
end

#authorized_keys_listObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/osctl/cli/migration.rb', line 41

def authorized_keys_list
  keys = osctld_call(:migration_authkey_list, pool: gopts[:pool])

  i = 0

  format_output(keys.map do |key|
    ret = {index: i, key: key}
    i += 1
    ret
  end)
end

#key_genObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osctl/cli/migration.rb', line 5

def key_gen
  c = osctld_open

  unless opts[:force]
    ret = c.cmd_data!(:migration_key_path, pool: gopts[:pool])

    %i(public_key private_key).each do |v|
      if File.exist?(ret[v])
        fail "File #{ret[v]} already exists, use -f, --force to overwrite"
      end
    end
  end

  c.cmd_data!(
    :migration_key_gen,
    pool: gopts[:pool],
    type: opts[:type],
    bits: opts[:bits]
  )
end

#key_pathObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/osctl/cli/migration.rb', line 26

def key_path
  if args[0] && !%w(public private).include?(args[0])
    raise GLI::BadCommandLine, "expected public/private, got '#{args[0]}'"
  end

  ret = osctld_call(:migration_key_path, pool: gopts[:pool])

  if !args[0] || args[0] == 'public'
    puts ret[:public_key]

  else
    puts ret[:private_key]
  end
end