Class: OsCtld::Commands::Migration::KeyGen

Inherits:
Logged
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/commands/migration/key_gen.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Logged

#base_execute

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

#execute(pool) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/osctld/commands/migration/key_gen.rb', line 21

def execute(pool)
  privkey = pool.migration_key_chain.private_key_path
  pubkey = pool.migration_key_chain.public_key_path

  [privkey, pubkey].each do |v|
    File.unlink(v) if File.exist?(v)
  end

  type = opts[:type] || 'rsa'

  if opts[:bits]
    bits = opts[:bits]

  elsif type == 'ecdsa'
    bits = 521

  else
    bits = 4096
  end

  syscmd("ssh-keygen -q -t #{type} -b #{bits} -N '' -f #{privkey}")

  [privkey, pubkey].each do |v|
    File.chmod(0400, v)
  end

  ok
end

#findObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/osctld/commands/migration/key_gen.rb', line 10

def find
  if opts[:pool]
    pool = DB::Pools.find(opts[:pool])

  else
    pool = DB::Pools.get_or_default(nil)
  end

  pool || error!('pool not found')
end