Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 0.2.1 (unreleased)

* Confirm before destroying server
* Handle BoxURL before validate on box startup.
* HandleBox before validate on box startup.
* Use fog-brightbox module to reduce dependencies.

# 0.2.0 (April 19, 2013)

Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ group :development do
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
end

group :plugins do
gem "vagrant-brightbox", :path => "."
end
145 changes: 72 additions & 73 deletions lib/vagrant-brightbox/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@ module Action
# This action is called to destroy the remote machine.
def self.action_destroy
Vagrant::Action::Builder.new.tap do |b|
b.use Call, DestroyConfirm do |env, b2|
if env[:result]
b2.use ConfigValidate
b2.use Call, IsCreated do |env2, b3|
if env2[:result]
b3.use ConnectBrightbox
b3.use DeleteServer
else
b3.use MessageNotCreated
end
end
else
b2.use MessageWillNotDestroy
end
end
b.use Call, DestroyConfirm do |env, b2|
if env[:result]
b2.use ConfigValidate
b2.use Call, IsCreated do |env2, b3|
if env2[:result]
b3.use ConnectBrightbox
b3.use DeleteServer
else
b3.use MessageNotCreated
end
end
else
b2.use MessageWillNotDestroy
end
end
end
end

# This action is called to halt the server - gracefully or by force.
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 Call, GracefulHalt, :inactive, :active do |env2, b3|
if !env2[:result]
b3.use ConnectBrightbox
b3.use ForcedHalt
end
end
else
b2.use MessageNotCreated
end
end
end
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use Call, GracefulHalt, :inactive, :active do |env2, b3|
if !env2[:result]
b3.use ConnectBrightbox
b3.use ForcedHalt
end
end
else
b2.use MessageNotCreated
end
end
end
end

# This action reloads the machine - essentially shutting it down
# and bringing it back up again in the new configuration.
def self.action_reload
Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use action_halt
b2.use action_up
else
b2.use MessageNotCreated
end
end
end
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use action_halt
b2.use action_up
else
b2.use MessageNotCreated
end
end
end
end

# This action is called when `vagrant provision` is called.
Expand All @@ -69,15 +69,14 @@ def self.action_provision
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use Provision
b2.use SyncFolders
else
b2.use Provision
b2.use SyncFolders
else
b2.use MessageNotCreated
end
end
end
end


# This action is called to read the SSH info of the machine. The
# resulting state is expected to be put into the `:machine_ssh_info`
Expand Down Expand Up @@ -106,8 +105,8 @@ def self.action_ssh
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use SSHExec
else
b2.use SSHExec
else
b2.use MessageNotCreated
end
end
Expand All @@ -116,53 +115,53 @@ def self.action_ssh

def self.action_ssh_run
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use SSHRun
else
b2.use MessageNotCreated
end
end
end
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use SSHRun
else
b2.use MessageNotCreated
end
end
end
end

def self.action_up
Vagrant::Action::Builder.new.tap do |b|
b.use HandleBoxUrl
b.use HandleBox
b.use ConfigValidate
b.use ConnectBrightbox
b.use ConnectBrightbox
b.use Call, IsCreated do |env, b2|
if env[:result]
b2.use Call, IsRunning do |env2, b3|
if env2[:result]
b3.use MessageAlreadyCreated
else
b3.use StartServer
b3.use MapCloudIp
end
end
else
b2.use TimedProvision
b2.use SyncFolders
b2.use CreateServer
b2.use MapCloudIp
b2.use Call, IsRunning do |env2, b3|
if env2[:result]
b3.use MessageAlreadyCreated
else
b3.use StartServer
b3.use MapCloudIp
end
end
else
b2.use TimedProvision
b2.use SyncFolders
b2.use CreateServer
b2.use MapCloudIp
end
end
end
end

def self.action_package
Vagrant::Action::Builder.new.tap do |b|
b.use Unsupported
end
b.use Unsupported
end
end

class << self
alias action_resume action_package
alias action_suspend action_package
alias action_resume action_package
alias action_suspend action_package
end

# The autoload farm
action_root = Pathname.new(File.expand_path("../action", __FILE__))
autoload :ConnectBrightbox, action_root.join("connect_brightbox")
Expand Down
40 changes: 20 additions & 20 deletions lib/vagrant-brightbox/action/connect_brightbox.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "fog"
require "fog/brightbox"
require "log4r"

module VagrantPlugins
Expand All @@ -20,32 +20,32 @@ def call(env)
# Get the configs
region_config = env[:machine].provider_config.get_region_config(region)
client_id = region_config.client_id
client_secret = region_config.secret
username = region_config.username
password = region_config.password
account = region_config.account
auth_url = region_config.auth_url
api_url = region_config.api_url
client_secret = region_config.secret
username = region_config.username
password = region_config.password
account = region_config.account
auth_url = region_config.auth_url
api_url = region_config.api_url

@logger.info("Connecting to Brightbox...")
@logger.info("Fog credentials are: #{Fog.credentials.inspect}")
fog_options={
@logger.info("Fog credentials are: #{Fog.credentials.inspect}")
fog_options = {
:provider => :brightbox,
:brightbox_auth_url => auth_url,
:brightbox_api_url => api_url,
:brightbox_client_id => client_id,
:brightbox_secret => client_secret,
:brightbox_username => username,
:brightbox_password => password,
:brightbox_account => account,
:brightbox_auth_url => auth_url,
:brightbox_api_url => api_url,
:brightbox_client_id => client_id,
:brightbox_secret => client_secret,
:brightbox_username => username,
:brightbox_password => password,
:brightbox_account => account
}
fog_options.delete_if {|k, v| v.nil? }
@logger.info("Fog compute options are: #{fog_options.inspect}")
fog_options.delete_if { |k, v| v.nil? }
@logger.info("Fog compute options are: #{fog_options.inspect}")
env[:brightbox_compute] = Fog::Compute.new(fog_options)

@app.call(env)
rescue ArgumentError => e
raise Errors::FogError, :message => e.message
rescue ArgumentError => e
raise Errors::FogError, :message => e.message
end
end
end
Expand Down
Loading