Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #8 #22

Merged
merged 1 commit into from
May 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions source/lib/vagrant-openstack-provider/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,26 @@ def self.action_up
end
end

def self.action_halt
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if !env[:result]
b2.use MessageNotCreated
next
end
b2.use ConnectOpenstack
b2.use StopServer
end
end
end

# The autoload farm
action_root = Pathname.new(File.expand_path("../action", __FILE__))
autoload :ConnectOpenstack, action_root.join("connect_openstack")
autoload :CreateServer, action_root.join("create_server")
autoload :DeleteServer, action_root.join("delete_server")
autoload :StopServer, action_root.join("stop_server")
autoload :IsCreated, action_root.join("is_created")
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
autoload :MessageNotCreated, action_root.join("message_not_created")
Expand Down
24 changes: 24 additions & 0 deletions source/lib/vagrant-openstack-provider/action/stop_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "log4r"

module VagrantPlugins
module Openstack
module Action
class StopServer
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::stop_server")
end

def call(env)
if env[:machine].id
env[:ui].info(I18n.t("vagrant_openstack.stopping_server"))
client = env[:openstack_client]
client.stop_server(env, env[:machine].id)
env[:machine].id = nil
end
@app.call(env)
end
end
end
end
end
8 changes: 8 additions & 0 deletions source/lib/vagrant-openstack-provider/openstack_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def delete_server(env, server_id)
:accept => :json)
end

def stop_server(env, server_id)
config = env[:machine].provider_config
server = RestClient.post("#{config.openstack_compute_url}/#{@projectId}/servers/#{server_id}/action", '{ "os-stop": null }',
"X-Auth-Token" => @token,
:accept => :json,
:content_type => :json)
end

def get_server_details(env, server_id)
config = env[:machine].provider_config
server_details = RestClient.get(config.openstack_compute_url + "/servers/" + server_id,
Expand Down
6 changes: 6 additions & 0 deletions source/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ en:
The server hasn't been created yet. Run `vagrant up` first.
ready: |-
The server is ready!
stopping_server: |-
Stopping server...
timeout: |-
Timeout!
rsync_folder: |-
Expand Down Expand Up @@ -68,6 +70,10 @@ en:
active
long_active: |-
The server is up and running. Run `vagrant ssh` to access it.
short_shutoff: |-
shutoff
long_shutoff: |-
The server exists but is not running. Run `vagrant up` to start it.
short_build: |-
building
long_build: |-
Expand Down