Class: VagrantAWS::AWSCommands
- Inherits:
-
Vagrant::Command::GroupBase
- Object
- Vagrant::Command::GroupBase
- VagrantAWS::AWSCommands
- Defined in:
- lib/vagrant-aws/command.rb
Instance Method Summary collapse
- #box_add(name, uri) ⇒ Object
- #box_create(name = nil) ⇒ Object
- #box_list ⇒ Object
- #box_remove(name) ⇒ Object
- #destroy(name = nil) ⇒ Object
-
#initialize(*args) ⇒ AWSCommands
constructor
A new instance of AWSCommands.
- #provision(name = nil) ⇒ Object
- #resume(name = nil) ⇒ Object
- #ssh(name = nil) ⇒ Object
- #ssh_config(name = nil) ⇒ Object
- #status ⇒ Object
- #suspend(name = nil) ⇒ Object
- #up(name = nil) ⇒ Object
Constructor Details
#initialize(*args) ⇒ AWSCommands
Returns a new instance of AWSCommands.
8 9 10 11 |
# File 'lib/vagrant-aws/command.rb', line 8 def initialize(*args) super initialize_aws_environment(*args) end |
Instance Method Details
#box_add(name, uri) ⇒ Object
151 152 153 |
# File 'lib/vagrant-aws/command.rb', line 151 def box_add(name, uri) Box.add(env, name, uri) end |
#box_create(name = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/vagrant-aws/command.rb', line 136 def box_create(name=nil) raise Vagrant::Errors::MultiVMTargetRequired, :command => "box_create" if target_vms.length > 1 ami_vm = target_vms.first ami_vm.env.actions.run(:aws_create_image, { 'package.output' => [:image_name] || env.config.package.name, 'image.register' => [:register], 'image.name' => [:image_name] || "vagrantaws_#{rand(36**8).to_s(36)}", 'image.desc' => [:image_desc] || "Image created by vagrant-aws" }) end |
#box_list ⇒ Object
157 158 159 160 161 |
# File 'lib/vagrant-aws/command.rb', line 157 def box_list boxes = env.boxes.sort return env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), :prefix => false) if boxes.empty? boxes.each { |b| env.ui.info(b.name, :prefix => false) } end |
#box_remove(name) ⇒ Object
166 167 168 169 170 |
# File 'lib/vagrant-aws/command.rb', line 166 def box_remove(name) b = env.boxes.find(name) raise Vagrant::Errors::BoxNotFound, :name => name if !b b.remove({ 'image.deregister' => [:deregister] }) end |
#destroy(name = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/vagrant-aws/command.rb', line 28 def destroy(name=nil) target_vms(name).each do |vm| if vm.created? vm.env.actions.run(:aws_destroy) else vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end |
#provision(name = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/vagrant-aws/command.rb', line 78 def provision(name=nil) target_vms(name).each do |vm| if vm.created? && vm.vm.state == 'running' vm.env.actions.run(:aws_provision) else vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end |
#resume(name = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/vagrant-aws/command.rb', line 102 def resume(name=nil) target_vms(name).each do |vm| if vm.created? vm.env.actions.run(:aws_resume) else vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end |
#ssh(name = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vagrant-aws/command.rb', line 56 def ssh(name=nil) raise Vagrant::Errors::MultiVMTargetRequired, :command => "ssh" if target_vms.length > 1 ssh_vm = target_vms.first ssh_vm.env.actions.run(VagrantAWS::Action::PopulateSSH) if [:execute] ssh_vm.ssh.execute do |ssh| ssh_vm.env.ui.info I18n.t("vagrant.commands.ssh.execute", :command => [:execute]) ssh.exec!([:execute]) do |channel, type, data| ssh_vm.env.ui.info "#{data}" end end else raise Vagrant::Errors::VMNotCreatedError if !ssh_vm.created? raise Vagrant::Errors::VMNotRunningError if !ssh_vm.vm.running? ssh_vm.ssh.connect end end |
#ssh_config(name = nil) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/vagrant-aws/command.rb', line 115 def ssh_config(name=nil) raise Vagrant::Errors::MultiVMTargetRequired, :command => "ssh_config" if target_vms.length > 1 ssh_vm = target_vms.first raise Vagrant::Errors::VMNotCreatedError if !ssh_vm.created? ssh_vm.env.actions.run(VagrantAWS::Action::PopulateSSH) $stdout.puts(Vagrant::Util::TemplateRenderer.render("ssh_config", { :host_key => [:host] || "vagrant", :ssh_host => ssh_vm.env.config.ssh.host, :ssh_user => ssh_vm.env.config.ssh.username, :ssh_port => ssh_vm.ssh.port, :private_key_path => ssh_vm.env.config.ssh.private_key_path })) end |
#status ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vagrant-aws/command.rb', line 40 def status state = nil results = target_vms.collect do |vm| state = vm.created? ? vm.vm.state.to_s : 'not_created' "#{vm.name.to_s.ljust(25)}#{state.gsub("_", " ")}" end state = target_vms.length == 1 ? state : "listing" @env.ui.info(I18n.t("vagrant.commands.status.output", :states => results.join("\n"), :message => I18n.t("vagrant.plugins.aws.commands.status.#{state}")), :prefix => false) end |
#suspend(name = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/vagrant-aws/command.rb', line 90 def suspend(name=nil) target_vms(name).each do |vm| if vm.created? vm.env.actions.run(:aws_suspend) else vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created") end end end |
#up(name = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/vagrant-aws/command.rb', line 16 def up(name=nil) target_vms(name).each do |vm| if vm.created? vm.env.ui.info I18n.t("vagrant.commands.up.vm_created") else vm.env.actions.run(:aws_up, "provision.enabled" => [:provision]) end end end |