Class: Gogetit::CLI
Class Attribute Summary collapse
-
.result ⇒ Object
Returns the value of attribute result.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#libvirt ⇒ Object
readonly
Returns the value of attribute libvirt.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#lxd ⇒ Object
readonly
Returns the value of attribute lxd.
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
Instance Method Summary collapse
- #create(name) ⇒ Object
- #deploy(name) ⇒ Object
- #destroy(name) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #rebuild(name) ⇒ Object
- #release(name) ⇒ Object
Methods included from Util
#check_ip_available, #get_gateway, #get_http_content, #get_provider_of, #is_port_open?, #knife_bootstrap_chef, #knife_bootstrap_zero, #knife_remove, #ping_available?, #run_command, #run_through_ssh, #ssh_available?, #update_databags, #wait_until_available
Constructor Details
Class Attribute Details
.result ⇒ Object
Returns the value of attribute result.
13 14 15 |
# File 'lib/gogetit/cli.rb', line 13 def result @result end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/gogetit/cli.rb', line 16 def config @config end |
#libvirt ⇒ Object (readonly)
Returns the value of attribute libvirt.
16 17 18 |
# File 'lib/gogetit/cli.rb', line 16 def libvirt @libvirt end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
16 17 18 |
# File 'lib/gogetit/cli.rb', line 16 def logger @logger end |
#lxd ⇒ Object (readonly)
Returns the value of attribute lxd.
16 17 18 |
# File 'lib/gogetit/cli.rb', line 16 def lxd @lxd end |
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
16 17 18 |
# File 'lib/gogetit/cli.rb', line 16 def providers @providers end |
Instance Method Details
#create(name) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/gogetit/cli.rb', line 79 def create(name) abort("'vlans' and 'ipaddresses' can not be set together.") \ if ['vlans'] and ['ipaddresses'] abort("'chef' and 'zero' can not be set together.") \ if ['chef'] and ['zero'] abort("when 'no-maas', the network configuration have to be set by 'file'.") \ if ['no-maas'] and (['vlans'] or ['ipaddresses']) abort("'no-maas' and 'file' have to be set together.") \ if ['no-maas'] ^ !!['file'] abort("'maas-on-lxc' has to be set with 'no-maas'.") \ if ['maas-on-lxc'] and !['no-maas'] abort("'distro' has to be set with libvirt provider.") \ if ['distro'] and ['provider'] == 'lxd' abort("'alias' has to be set with lxd provider.") \ if ['alias'] and ['provider'] == 'libvirt' case ['provider'] when 'lxd' Gogetit::CLI.result = lxd.create(name, .to_hash) when 'libvirt' Gogetit::CLI.result = libvirt.create(name, .to_hash) else abort('Invalid argument entered.') end # post-tasks if ['chef'] knife_bootstrap_chef(name, [:provider], config) update_databags(config) elsif ['zero'] knife_bootstrap_zero(name, [:provider], config) end end |
#deploy(name) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/gogetit/cli.rb', line 149 def deploy(name) abort("'chef' and 'zero' can not be set together.") \ if ['chef'] and ['zero'] Gogetit::CLI.result = libvirt.deploy(name, .to_hash) # post-tasks if ['chef'] knife_bootstrap(name, [:provider], config) update_databags(config) elsif ['zero'] knife_bootstrap_zero(name, [:provider], config) end end |
#destroy(name) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gogetit/cli.rb', line 118 def destroy(name) abort("'chef' and 'zero' can not be set together.") \ if ['chef'] and ['zero'] provider = get_provider_of(name, providers) if provider case provider when 'lxd' Gogetit::CLI.result = lxd.destroy(name) when 'libvirt' Gogetit::CLI.result = libvirt.destroy(name) else abort('Invalid argument entered.') end end # post-tasks if ['chef'] knife_remove(name, ) update_databags(config) elsif ['zero'] knife_remove(name, ) end end |
#list ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gogetit/cli.rb', line 33 def list case [:out] when 'custom' Gogetit.list_all_types when 'all' config[:lxd][:nodes].each do |node| puts "Listing LXD containers on #{node[:url]}.." system("lxc list #{node[:name]}:") end puts "Listing KVM domains on #{config[:libvirt][:nodes][0][:url]}.." system("virsh -c #{config[:libvirt][:nodes][0][:url]} list --all") when '' puts "Listing LXD containers on #{config[:lxd][:nodes][0][:url]}.." system("lxc list #{config[:lxd][:nodes][0][:name]}:") puts '' puts "Listing KVM domains on #{config[:libvirt][:nodes][0][:url]}.." system("virsh -c #{config[:libvirt][:nodes][0][:url]} list --all") else puts "Invalid option or command" end end |
#rebuild(name) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/gogetit/cli.rb', line 191 def rebuild(name) abort("'chef' and 'zero' can not be set together.") \ if ['chef'] and ['zero'] provider = get_provider_of(name, providers) if provider case provider when 'lxd' 1.upto(100) { print '_' }; puts puts "Destroying #{name}.." invoke :destroy, [name] alias_name = YAML.load( Gogetit::CLI.result[:info][:config][:"user.user-data"] )['source_image_alias'] 1.upto(100) { print '_' }; puts puts "Creating #{name}.." invoke :create, [name], :alias => alias_name when 'libvirt' invoke :release, [name] distro_name = Gogetit::CLI.result[:info][:machine]['distro_series'] invoke :deploy, [name], :distro => distro_name else abort('Invalid argument entered.') end end # post-tasks if ['chef'] knife_remove(name) if [:chef] update_databags(config) end end |
#release(name) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gogetit/cli.rb', line 170 def release(name) abort("'chef' and 'zero' can not be set together.") \ if ['chef'] and ['zero'] Gogetit::CLI.result = libvirt.release(name) # post-tasks if ['chef'] knife_remove(name, ) update_databags(config) elsif ['zero'] knife_remove(name, ) end end |