Class: Pec::CLI
- Inherits:
-
Thor
- Object
- Thor
- Pec::CLI
- Defined in:
- lib/pec/cli.rb
Instance Method Summary collapse
- #__print_version ⇒ Object
- #destroy(host_name = nil) ⇒ Object
- #init ⇒ Object
- #status(host_name = nil) ⇒ Object
- #up(host_name = nil) ⇒ Object
Instance Method Details
#__print_version ⇒ Object
100 101 102 |
# File 'lib/pec/cli.rb', line 100 def __print_version puts Pec::VERSION end |
#destroy(host_name = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pec/cli.rb', line 44 def destroy(host_name = nil) Pec.configure.each do |host| next if host_name && host.name != host_name Pec.init_yao(host.tenant) server = Yao::Server.list_detail.find {|s|s.name == host.name} unless server Pec::Logger.notice "not be created #{host.name}" next end if [:force] || yes?("#{host.name}: Are you sure you want to destroy the '#{host.name}' VM? [y/N]") Yao::Server.destroy(server.id) Pec::Logger.info "#{host.name} is deleted!" end end rescue => e print_exception(e) end |
#init ⇒ Object
6 7 8 9 10 |
# File 'lib/pec/cli.rb', line 6 def init Pec::Init.show_env_setting Pec::Init.create_template_dir Pec::Init.create_sample_config end |
#status(host_name = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pec/cli.rb', line 66 def status(host_name = nil) say("Current machine stasus:", :yellow) Pec.configure.each do |host| next if host_name && host.name != host_name Pec.init_yao(host.tenant) if server = Yao::Server.list_detail.find {|s|s.name == host.name} puts sprintf(" %-35s %-10s %-10s %-10s %-10s %-35s %-48s", host.name, server.status, Yao::Tenant.list.find {|tenant| tenant.id == server.tenant_id}.name, Yao::Flavor.get(server.flavor['id']).name, server.availability_zone, server.ext_srv_attr_host, server.addresses.map do |ethers| ethers[1].map do |ether| ether["addr"] end end.flatten.join(",") ) else puts sprintf(" %-35s %-10s", host.name, "uncreated" ) end end rescue => e print_exception(e) end |
#up(host_name = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pec/cli.rb', line 13 def up(host_name = nil) Pec.configure.each do |host| next if host_name && host.name != host_name Pec.init_yao(host.tenant) server = Yao::Server.list_detail.find {|s|s.name == host.name} if server Pec::Logger.notice "already exists: #{host.name}" next end Pec::Logger.info "make start #{host.name}" attribute = { name: host.name} host.keys.each do |k| Pec::Handler.constants.each do |c| if Object.const_get("Pec::Handler::#{c}").kind == k attribute.deep_merge!(Object.const_get("Pec::Handler::#{c}").build(host)) end end end attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data] Yao::Server.create(attribute) Pec::Logger.info "create success! #{host.name}" end rescue => e print_exception(e) end |