Class: Gogetit::CLI

Inherits:
Thor
  • Object
show all
Includes:
Util
Defined in:
lib/gogetit/cli.rb

Instance Method Summary collapse

Methods included from Util

#check_ip_available, #get_gateway, #knife_bootstrap, #knife_remove, #ping_available?, #recognize_env, #ssh_available?, #symbolize_keys, #update_vault, #wait_until_available

Instance Method Details

#create(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gogetit/cli.rb', line 29

def create(name)
  abort("vlans and ipaddresses can not be used at the same time.") \
    if options['vlans'] and options['ipaddresses']

  case options[:provider]
  when 'lxd'
    Gogetit.lxd.create(name, options.to_hash)
  when 'libvirt'
    Gogetit.libvirt.create(name, options.to_hash)
  else
    abort('Invalid argument entered.')
  end

  # post-tasks
  if options[:chef]
    knife_bootstrap(name, type, Gogetit.config, Gogetit.logger)
    update_vault(Gogetit.config, Gogetit.logger)
  end
  Gogetit.config[:default][:user] ||= ENV['USER']
  puts "ssh #{Gogetit.config[:default][:user]}@#{name}"
end

#destroy(name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gogetit/cli.rb', line 53

def destroy(name)
  type = Gogetit.get_provider_of(name)
  if type
    case type
    when 'lxd'
      Gogetit.lxd.destroy(name)
    when 'libvirt'
      Gogetit.libvirt.destroy(name)
    else
      abort('Invalid argument entered.')
    end
  end
  # post-tasks
  if options[:chef]
    knife_remove(name, Gogetit.logger) if options[:chef]
    update_vault(Gogetit.config, Gogetit.logger)
  end
end

#listObject



11
12
13
14
15
16
17
# File 'lib/gogetit/cli.rb', line 11

def list
  puts "Listing LXD containers on #{Gogetit.config[:lxd][:url]}.."
  system("lxc list #{Gogetit.config[:lxd][:name]}:")
  puts ''
  puts "Listing KVM domains on #{Gogetit.config[:libvirt][:url]}.."
  system("virsh -c #{Gogetit.config[:libvirt][:url]} list --all")
end

#rebuild(type = nil, name) ⇒ Object



73
74
75
76
# File 'lib/gogetit/cli.rb', line 73

def rebuild(type=nil, name)
  invoke :destroy, [name]
  invoke :create, [type, name]
end