Permalink
Browse files

Add vagrant base sharing support (NFS,Rsync)

  • Loading branch information...
Loïc PORTE
Loïc PORTE committed Jun 19, 2014
1 parent 6c5c70b commit e2390ebcfef19a76744e9cddbccf0fba3f6c89c7
View
@@ -6,5 +6,5 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git", :tag => "v1.6.3"
end
View
@@ -140,7 +140,8 @@ This provider exposes quite a few provider-specific configuration options:
* `ssl_verify_peer` - sets the ssl_verify_peer on the underlying excon connection - useful for self signed certs etc.
* `floating_ip` - Floating ip. The floating IP to assign for this instance. If
set to :auto, then this assigns any available floating IP to the instance.
* `nfs_host_ip` - the prefered ip of the host to be use for nfs connection
*
These can be set like typical provider-specific configuration:
```ruby
@@ -163,13 +164,8 @@ the OpenStack server.
## Synced Folders
There is minimal support for synced folders. Upon `vagrant up`,
`vagrant reload`, and `vagrant provision`, the OpenStack provider will use
`rsync` (if available) to uni-directionally sync the folder to
the remote machine over SSH.
There is full support for vagrant sharing system. [Rsync](http://docs.vagrantup.com/v2/synced-folders/rsync.html), [NFS](http://docs.vagrantup.com/v2/synced-folders/nfs.html) ar supported and [SMB](http://docs.vagrantup.com/v2/synced-folders/smb.html) probably work
This is good enough for all built-in Vagrant provisioners (shell,
chef, and puppet) to work!
## Command
@@ -16,6 +16,8 @@ def self.action_destroy
if env[:result]
b1.use ConnectOpenStack
b1.use DeleteServer
b1.use PrepareNFSValidIds
b1.use SyncedFolderCleanup
else
b1.use MessageWillNotDestroy
end
@@ -77,7 +79,6 @@ def self.action_ssh_run
def self.action_prepare_boot
Vagrant::Action::Builder.new.tap do |b|
b.use Provision
b.use SyncFolders
b.use WarnNetworks
b.use SetHostname
end
@@ -86,17 +87,24 @@ def self.action_prepare_boot
# This action is called when `vagrant up` is executed.
def self.action_up
Vagrant::Action::Builder.new.tap do |b|
b.use HandleBoxUrl
b.use HandleBox
b.use ConfigValidate
b.use Call, IsCreated do |env, b1|
unless env[:result]
b1.use action_prepare_boot
b1.use ConnectOpenStack
b1.use CreateServer
b1.use PrepareNFSValidIds
b1.use SyncedFolderCleanup
b1.use SyncedFolders
b1.use PrepareNFSSettings
else
b1.use action_resume
end
end
end
end
@@ -112,7 +120,7 @@ def self.action_provision
b1.use ConnectOpenStack
b1.use Provision
b1.use SyncFolders
end
end
end
@@ -134,6 +142,12 @@ def self.action_reload
b2.use HardRebootServer
end
end
b1.use PrepareNFSValidIds
b1.use SyncedFolderCleanup
b1.use SyncedFolders
b1.use PrepareNFSSettings
end
end
end
@@ -170,7 +184,11 @@ def self.action_resume
b1.use ConnectOpenStack
b1.use ResumeServer
b1.use SyncFolders
b1.use PrepareNFSValidIds
b1.use SyncedFolderCleanup
b1.use SyncedFolders
b1.use PrepareNFSSettings
end
end
end
@@ -224,6 +242,7 @@ def self.action_take_snapshot
end
end
# The autoload farm
action_root = Pathname.new(File.expand_path("../action", __FILE__))
autoload :ConnectOpenStack, action_root.join("connect_openstack")
@@ -244,12 +263,13 @@ def self.action_take_snapshot
autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
autoload :MessageServerRunning, action_root.join("message_server_running")
autoload :PauseServer, action_root.join("pause_server")
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
autoload :ReadState, action_root.join("read_state")
autoload :RebootServer, action_root.join("reboot_server")
autoload :ResumeServer, action_root.join("resume_server")
autoload :SuspendServer, action_root.join("suspend_server")
autoload :SyncFolders, action_root.join("sync_folders")
autoload :TakeSnapshot, action_root.join("take_snapshot")
autoload :WaitForState, action_root.join("wait_for_state")
autoload :WaitForTask, action_root.join("wait_for_task")
@@ -0,0 +1,127 @@
require 'socket'
module VagrantPlugins
module OpenStack
module Action
class PrepareNFSSettings
def initialize(app,env)
@app = app
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
end
def call(env)
@app.call(env)
@machine = env[:machine]
@openstack = env[:openstack_compute]
@floating_ip = env[:floating_ip]
if using_nfs?
config = env[:machine].provider_config
if config.nfs_host_ip.nil? or config.nfs_host_ip.empty?
env[:nfs_host_ip] = read_host_ip
else
env[:nfs_host_ip] = config.nfs_host_ip
end
env[:nfs_machine_ip] = read_machine_ip
end
end
def using_nfs?
@machine.config.vm.synced_folders.any? { |_, opts| opts[:type] == :nfs }
end
# Returns the IP address of the host
#
# @param [Machine] machine
# @return [String]
def read_host_ip
#Get First private ip
Socket.ip_address_list.detect do |intf|
if intf.ipv4_private?
ip = intf.ip_address
end
end
if ip.nil? or ip.empty?
@logger.debug("No valid host ip could be found.")
raise Errors::Exception
end
@logger.info("Host IP : " + ip )
return ip
end
# Returns the IP address of the guest by looking at the first
# enabled host only network.
#
# @return [String]
def read_machine_ip
id = @machine.id || @openstack.servers.all( :name => @machine.name ).first.id rescue nil
return nil if id.nil?
server = @openstack.servers.get(id)
if server.nil?
# The machine can't be found
@logger.info("Machine couldn't be found, assuming it got destroyed.")
@machine.id = nil
return nil
end
config = @machine.provider_config
# Print a list of the available networks
server.addresses.each do |network_name, network_info|
@logger.debug("OpenStack Network Name: #{network_name}")
end
if config.network
host = server.addresses[config.network].last['addr'] rescue nil
else
if config.address_id.to_sym == :floating_ip
host = @floating_ip
else
host = server.addresses[config.address_id].last['addr'] rescue nil
end
end
# If host is still nil, try to find the IP address another way
if host.nil?
@logger.debug("Was unable to determine what network to use. Trying to find a valid IP to use.")
if server.public_ip_addresses.length > 0
@logger.debug("Public IP addresses available: #{server.public_ip_addresses}")
if @floating_ip
if server.public_ip_addresses.include?(@floating_ip)
@logger.debug("Using the floating IP defined in Vagrantfile.")
host = @machine.floating_ip
else
@logger.debug("The floating IP that was specified is not available to this instance.")
raise Errors::FloatingIPNotValid
end
else
host = server.public_ip_address
@logger.debug("Using the first available public IP address: #{host}.")
end
elsif server.private_ip_addresses.length > 0
@logger.debug("Private IP addresses available: #{server.private_ip_addresses}")
host = server.private_ip_address
@logger.debug("Using the first available private IP address: #{host}.")
end
end
# If host got this far and is still nil/empty, raise an error or
# else vagrant will try connecting to localhost which will never
# make sense in this scenario
if host.nil? or host.empty?
@logger.debug("No valid SSH host could be found.")
raise Errors::SSHNoValidHost
end
return host
end
end
end
end
end
@@ -0,0 +1,22 @@
module VagrantPlugins
module OpenStack
module Action
class PrepareNFSValidIds
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
end
def call(env)
servers = []
env[:openstack_compute].list_servers.body['servers'].each do |server|
servers.push(server['id'])
end
env[:nfs_valid_ids] = servers
@app.call(env)
end
end
end
end
end
@@ -17,6 +17,17 @@ def call(env)
# TODO: Validate the fact that we get a server back from the API.
server = env[:openstack_compute].servers.get(env[:machine].id)
server.reboot('SOFT')
env[:ui].info(I18n.t("vagrant_openstack.waiting_for_ssh"))
while true
begin
# If we're interrupted then just back out
break if env[:interrupted]
break if env[:machine].communicate.ready?
rescue Errno::ENETUNREACH, Errno::EHOSTUNREACH
end
sleep 2
end
end
@app.call(env)

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit e2390eb

Please sign in to comment.