File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 44require_relative 'actions/find_host'
55require_relative 'actions/run_instance'
66require_relative 'actions/start_instance'
7+ require_relative 'actions/stop_instance'
78require_relative 'actions/terminate_instance'
89require_relative 'actions/wait_for_state'
910
@@ -55,6 +56,26 @@ def self.resume
5556 when :running
5657 env [ :ui ] . info I18n . t ( 'vagrant_ec2.info.state.already_running' )
5758 next
59+ end
60+ end
61+ end
62+ end
63+
64+ def self . suspend
65+ return Vagrant ::Action ::Builder . new . tap do |builder |
66+ builder . use ConfigValidate
67+ builder . use ConnectAWS
68+ builder . use Call , CheckState do |env , b |
69+ case env [ :result ]
70+ when :running
71+ b . use StopInstance
72+ b . use WaitForState , :stopped
73+ when :stopped
74+ env [ :ui ] . info I18n . t ( 'vagrant_ec2.info.state.already_stopped' )
75+ next
76+ when :not_created
77+ env [ :ui ] . info I18n . t ( 'vagrant_ec2.info.state.not_created' )
78+ next
5879 else
5980 env [ :ui ] . info I18n . t ( 'vagrant_ec2.info.state.unexpected_state' , :state => env [ :result ] )
6081 next
Original file line number Diff line number Diff line change 1+ require 'aws-sdk'
2+
3+ module VagrantPlugins
4+ module Ec2
5+ module Actions
6+ class StopInstance
7+ def initialize ( app , env )
8+ @app = app
9+ end
10+
11+ def call ( env )
12+ ec2 = Aws ::EC2 ::Resource . new ( env [ :connection_options ] )
13+
14+ instance = ec2 . instance ( env [ :machine ] . id )
15+ instance . stop
16+ env [ :ui ] . info I18n . t ( 'vagrant_ec2.info.action.stop_instance' , :instance_id => env [ :machine ] . id )
17+
18+ @app . call ( env )
19+ end
20+ end
21+ end
22+ end
23+ end
You can’t perform that action at this time.
0 commit comments