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, #run_command, #run_through_ssh, #ssh_available?, #symbolize_keys, #update_databags, #wait_until_available

Instance Method Details

#create(name) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gogetit/cli.rb', line 36

def create(name)
  abort("'vlans' and 'ipaddresses' can not be set together.") \
    if options['vlans'] and options['ipaddresses']

  abort("when 'no-maas', the network configuration have to be set by 'file'.") \
    if options['no-maas'] and (options['vlans'] or options['ipaddresses'])

  abort("'no-maas' and 'file' have to be set together.") \
    if options['no-maas'] ^ !!options['file']

  abort("'distro' has to be set with libvirt provider.") \
    if options['distro'] and options['provider'] == 'lxd'

  abort("'alias' has to be set with lxd provider.") \
    if options['alias'] and options['provider'] == 'libvirt'

  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, options[:provider], Gogetit.config, Gogetit.logger)
    update_databags(Gogetit.config, Gogetit.logger)
  end
end

#destroy(name) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/gogetit/cli.rb', line 70

def destroy(name)
  # Let Gogetit recognize the provider.
  provider = Gogetit.get_provider_of(name)
  if provider
    case provider
    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_databags(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][:nodes][0][:url]}.."
  system("lxc list #{Gogetit.config[:lxd][:nodes][0][:name]}:")
  puts ''
  puts "Listing KVM domains on #{Gogetit.config[:libvirt][:nodes][0][:url]}.."
  system("virsh -c #{Gogetit.config[:libvirt][:nodes][0][:url]} list --all")
end

#release(name) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/gogetit/cli.rb', line 92

def release(name)
  # Let Gogetit recognize the provider.
  provider = Gogetit.get_provider_of(name)
  if provider
    case provider
    when 'lxd'
      abort('This method is not available for LXD container.')
    when 'libvirt'
      Gogetit.libvirt.release(name)
    else
      abort('Invalid argument entered.')
    end
  end
  # post-tasks
  if options['chef']
    knife_remove(name, Gogetit.logger) if options[:chef]
    update_databags(Gogetit.config, Gogetit.logger)
  end
end