Class: Pec::Director
- Inherits:
-
Object
- Object
- Pec::Director
- Defined in:
- lib/pec/director.rb
Class Method Summary collapse
- .destroy(host_name, options) ⇒ Object
- .excon_err_message(e) ⇒ Object
- .make(host_name) ⇒ Object
- .status(host_name) ⇒ Object
Class Method Details
.destroy(host_name, options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pec/director.rb', line 33 def self.destroy(host_name, ) Pec.load_config Pec.configure.each do |host| next if host_name && host.name != host_name Pec.compute.set_tenant(host.tenant) server = Pec.compute.servers.find {|s|s.name == host.name} unless server Pec::Logger.notice "not be created #{host.name}" next end if [:force] || Thor.new.yes?("#{host.name}: Are you sure you want to destroy the '#{host.name}' VM? [y/N]") Pec::Logger.info "#{host.name} is deleted!" if Pec.compute.servers.destroy(server.id) end end rescue Excon::Errors::Error => e (e) rescue => e Pec::Logger.critical(e) end |
.excon_err_message(e) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/pec/director.rb', line 89 def self.(e) if e.response JSON.parse(e.response[:body]).each { |e,m| Pec::Logger.critical("#{e}:#{m["message"]}") } else Pec::Logger.critical(e) end end |
.make(host_name) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pec/director.rb', line 3 def self.make(host_name) Pec.load_config Pec.configure.each do |host| next if host_name && host.name != host_name Pec::Logger.info "make start #{host.name}" Pec.compute.set_tenant(host.tenant) Pec.neutron.set_tenant_patch(host.tenant) port_builder = Pec::Builder::Port.new server_builder = Pec::Builder::Server.new user_data_builder = Pec::Builder::UserData.new attribute = {} attribute.merge!(server_builder.build(host)) attribute.merge!(port_builder.build(host)) if user_data = user_data_builder.build(host, port_builder.user_data) attribute.merge!(user_data) end Pec::Logger.info "create success! #{host.name}" if Pec.compute.servers.create(attribute) end rescue Excon::Errors::Error => e (e) rescue => e Pec::Logger.critical(e) end |
.status(host_name) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pec/director.rb', line 55 def self.status(host_name) Pec.load_config Pec.configure.each do |host| next if host_name && host.name != host_name server = Pec.compute.servers.find {|s|s.name == host.name} if server puts sprintf(" %-35s %-10s %-10s %-10s %-10s %-35s %-48s", host.name, server.state, Pec.identity.tenants.find_by_id(server.tenant_id), Pec.compute.flavors.get(server.flavor['id']).name, server.availability_zone, server.os_ext_srv_attr_host, server.addresses.map do |net, ethers| ethers.map do |ether| ether["addr"] end end.flatten.join(",") ) else puts sprintf(" %-35s %-10s", host.name, "uncreated" ) end end rescue Excon::Errors::Error => e (e) rescue => e Pec::Logger.critical(e) end |