vagrant-provider 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +54 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/Vagrantfile +5 -0
- data/lib/vagrant-provider/base-command.rb +66 -0
- data/lib/vagrant-provider/command.rb +71 -0
- data/lib/vagrant-provider/list-command.rb +31 -0
- data/lib/vagrant-provider/pick-command.rb +50 -0
- data/lib/vagrant-provider/stash-command.rb +49 -0
- data/lib/vagrant-provider.rb +14 -0
- data/vagrant-provider.gemspec +20 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c236101358d3c6019739c1041b9a936d6129bcba
|
4
|
+
data.tar.gz: 873a57fa6b59074710d21ff01678513f8ea28d6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 678facfc07e3a5fd8c67f9c69b077c086fbd8e55e2507a552f31bc4f72bb165d1bace3ae9f4e2655ba1ff9d4829a9fcde5cb39502f4467a932c187327e0ea961
|
7
|
+
data.tar.gz: 497788de461af7f48b56cc7c5c96046514ac25882e3bef700102ba1b60f9e5a38c04f3d432c4c267d9bb913c0c8a0880cdcfedf86076c488438a914a1d841b3b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
source "http://gems.hashicorp.com"
|
3
|
+
|
4
|
+
# see https://github.com/scalefactory/vagrant-cucumber/blob/master/Gemfile
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
embedded_locations = %w{/Applications/Vagrant/embedded /opt/vagrant/embedded}
|
9
|
+
|
10
|
+
embedded_locations.each do |p|
|
11
|
+
ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] = p if File.directory?(p)
|
12
|
+
end
|
13
|
+
|
14
|
+
unless ENV.has_key?('VAGRANT_INSTALLER_EMBEDDED_DIR')
|
15
|
+
$stderr.puts "Couldn't find a packaged install of vagrant, and we need this"
|
16
|
+
$stderr.puts "in order to make use of the RubyEncoder libraries."
|
17
|
+
$stderr.puts "I looked in:"
|
18
|
+
embedded_locations.each do |p|
|
19
|
+
$stderr.puts " #{p}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
|
25
|
+
|
26
|
+
# Jump through annoying hoops so we can use this plugin in the
|
27
|
+
# bundler environment.
|
28
|
+
|
29
|
+
fusion_path = Gem::Specification.find_by_name('vagrant-vmware-fusion').gem_dir
|
30
|
+
|
31
|
+
unless File.symlink?( File.join( fusion_path, 'rgloader' ) )
|
32
|
+
$stderr.puts "Linking local 'rgloader' file to embedded installer"
|
33
|
+
FileUtils.ln_s(
|
34
|
+
File.join( ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"], 'rgloader' ),
|
35
|
+
File.join( fusion_path, 'rgloader' )
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
unless File.symlink?( File.join( fusion_path, 'license-vagrant-vmware-fusion.lic' ) )
|
40
|
+
$stderr.puts "Linking your license file for vmware plugin"
|
41
|
+
FileUtils.ln_s(
|
42
|
+
File.join( ENV["HOME"], '.vagrant.d', 'license-vagrant-vmware-fusion.lic' ),
|
43
|
+
File.join( fusion_path, 'license-vagrant-vmware-fusion.lic' )
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
group :plugins do
|
49
|
+
gem "vagrant-vmware-fusion"
|
50
|
+
gem "vagrant-provider", path: "."
|
51
|
+
end
|
52
|
+
|
53
|
+
# Specify your gem's dependencies in vagrant-provider.gemspec
|
54
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Glen Mailer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Vagrant Provider Swapper
|
2
|
+
|
3
|
+
Some rather hacky tricks to swap between different providers for a single
|
4
|
+
vagrant machine without destroying anything.
|
5
|
+
|
6
|
+
Useful for building a VM locally, then pushing up to a cloud provider,
|
7
|
+
for example.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
vagrant plugin install provider
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```
|
16
|
+
# list machines and providers
|
17
|
+
$ vagrant provider list
|
18
|
+
|
19
|
+
Machines
|
20
|
+
--------
|
21
|
+
|
22
|
+
default:
|
23
|
+
virtualbox (current)
|
24
|
+
vmware_fusion
|
25
|
+
digital_ocean
|
26
|
+
|
27
|
+
# stash the current provider state for later
|
28
|
+
$ vagrant provider stash [machine-name]
|
29
|
+
|
30
|
+
# bring back the named provider state
|
31
|
+
$ vagrant provider pick <provider> [machine-name]
|
32
|
+
|
33
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Vagrantfile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module VagrantPlugins::Provider
|
2
|
+
class BaseCommand < Vagrant.plugin('2', :command)
|
3
|
+
|
4
|
+
def machine_names
|
5
|
+
@env.machine_names
|
6
|
+
end
|
7
|
+
|
8
|
+
def providers_for(name)
|
9
|
+
return [] unless machine_folder.directory?
|
10
|
+
|
11
|
+
name = name.to_s
|
12
|
+
|
13
|
+
machine_folder.children(true)
|
14
|
+
.select(&:directory?)
|
15
|
+
.map { |f| f.basename.to_s }
|
16
|
+
.select { |f| f.start_with?(name) }
|
17
|
+
.map do |f|
|
18
|
+
{
|
19
|
+
name: provider_name(machine_folder.join(f)),
|
20
|
+
active: f == name
|
21
|
+
}
|
22
|
+
end
|
23
|
+
.select { |f| f[:name] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def provider_name(folder)
|
27
|
+
folder.children(true)
|
28
|
+
.select(&:directory?)
|
29
|
+
.select { |f| f.join("id").file? }
|
30
|
+
.map { |f| f.basename.to_s.to_sym }
|
31
|
+
.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def active_provider(machine_name)
|
35
|
+
providers_for(machine_name).detect { |p| p[:active] }
|
36
|
+
end
|
37
|
+
|
38
|
+
def machine_provider(machine_name, provider)
|
39
|
+
providers_for(machine_name).detect { |p| p[:name] == provider }
|
40
|
+
end
|
41
|
+
|
42
|
+
def machine_folder
|
43
|
+
@env.local_data_path.join("machines")
|
44
|
+
end
|
45
|
+
|
46
|
+
def line(msg = "")
|
47
|
+
@env.ui.info msg
|
48
|
+
end
|
49
|
+
|
50
|
+
class NoActiveProvider < ::Vagrant::Errors::VagrantError
|
51
|
+
error_message "There is no currently active provider"
|
52
|
+
end
|
53
|
+
|
54
|
+
class HasActiveProvider < ::Vagrant::Errors::VagrantError
|
55
|
+
error_message "Sorry, you cannot replace an active provider"
|
56
|
+
end
|
57
|
+
|
58
|
+
class NoStashedProvider < ::Vagrant::Errors::VagrantError
|
59
|
+
error_message "There is no matching stashed provider"
|
60
|
+
end
|
61
|
+
|
62
|
+
class AlreadyStashedProvider < ::Vagrant::Errors::VagrantError
|
63
|
+
error_message "There is already a stashed provider of this type"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantPlugins::Provider
|
4
|
+
class Command < Vagrant.plugin('2', :command)
|
5
|
+
|
6
|
+
def self.synopsis
|
7
|
+
"hacky stuff for switching providers around"
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(argv, env)
|
11
|
+
super
|
12
|
+
|
13
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
14
|
+
|
15
|
+
@subcommands = Vagrant::Registry.new
|
16
|
+
|
17
|
+
@subcommands.register(:list) do
|
18
|
+
require_relative "list-command"
|
19
|
+
ListCommand
|
20
|
+
end
|
21
|
+
|
22
|
+
@subcommands.register(:stash) do
|
23
|
+
require_relative "stash-command"
|
24
|
+
StashCommand
|
25
|
+
end
|
26
|
+
|
27
|
+
@subcommands.register(:pick) do
|
28
|
+
require_relative "pick-command"
|
29
|
+
PickCommand
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
if @main_args.include?("-h") || @main_args.include?("--help")
|
36
|
+
return help
|
37
|
+
end
|
38
|
+
|
39
|
+
# If we reached this far then we must have a subcommand. If not,
|
40
|
+
# then we also just print the help and exit.
|
41
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
42
|
+
return help if !command_class || !@sub_command
|
43
|
+
|
44
|
+
# Initialize and execute the command class
|
45
|
+
command_class.new(@sub_args, @env).execute
|
46
|
+
end
|
47
|
+
|
48
|
+
def help
|
49
|
+
opts = OptionParser.new do |opts|
|
50
|
+
opts.banner = "Usage: vagrant provider <subcommand> [<args>]"
|
51
|
+
opts.separator ""
|
52
|
+
opts.separator "Available subcommands:"
|
53
|
+
|
54
|
+
# Add the available subcommands as separators in order to print them
|
55
|
+
# out as well.
|
56
|
+
keys = []
|
57
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
58
|
+
|
59
|
+
keys.sort.each do |key|
|
60
|
+
opts.separator " #{key}"
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.separator ""
|
64
|
+
opts.separator "For help on any individual subcommand run `vagrant provider <subcommand> -h`"
|
65
|
+
end
|
66
|
+
|
67
|
+
@env.ui.info(opts.help, prefix: false)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "base-command"
|
2
|
+
|
3
|
+
module VagrantPlugins::Provider
|
4
|
+
class ListCommand < BaseCommand
|
5
|
+
def execute
|
6
|
+
opts = OptionParser.new do |o|
|
7
|
+
o.banner = "Usage: vagrant provider list"
|
8
|
+
o.separator ""
|
9
|
+
o.separator "List all active providers"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Parse the options
|
13
|
+
argv = parse_options(opts)
|
14
|
+
return if !argv
|
15
|
+
|
16
|
+
line "Machines"
|
17
|
+
line "--------"
|
18
|
+
line
|
19
|
+
|
20
|
+
machine_names.each do |machine_name|
|
21
|
+
line "#{machine_name}:"
|
22
|
+
providers_for(machine_name).each do |provider|
|
23
|
+
line " #{provider[:name]}" << (provider[:active] ? " (active)" : "")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Success, exit status 0
|
28
|
+
0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative "base-command"
|
2
|
+
|
3
|
+
module VagrantPlugins::Provider
|
4
|
+
class PickCommand < BaseCommand
|
5
|
+
def execute
|
6
|
+
opts = OptionParser.new do |o|
|
7
|
+
o.banner = "Usage: vagrant provider pick <provider> [machine-name]"
|
8
|
+
o.separator ""
|
9
|
+
o.separator "Bring back previously stored provider state"
|
10
|
+
o.separator ""
|
11
|
+
end
|
12
|
+
|
13
|
+
# Parse the options
|
14
|
+
argv = parse_options(opts)
|
15
|
+
return if !argv
|
16
|
+
if argv.empty? or argv.length > 2
|
17
|
+
raise Vagrant::Errors::CLIInvalidUsage,
|
18
|
+
help: opts.help.chomp
|
19
|
+
end
|
20
|
+
|
21
|
+
provider_name = argv[0].to_sym
|
22
|
+
machine_name = (argv[1] || @env.primary_machine_name).to_sym
|
23
|
+
|
24
|
+
if not machine_names.include? machine_name
|
25
|
+
raise Vagrant::Errors::MachineNotFound,
|
26
|
+
name: machine_name
|
27
|
+
end
|
28
|
+
|
29
|
+
if active_provider(machine_name)
|
30
|
+
raise HasActiveProvider
|
31
|
+
end
|
32
|
+
|
33
|
+
provider = machine_provider(machine_name, provider_name)
|
34
|
+
if not provider
|
35
|
+
raise NoStashedProvider
|
36
|
+
end
|
37
|
+
|
38
|
+
source = machine_folder.join("#{machine_name}_#{provider_name}")
|
39
|
+
target = machine_folder.join("#{machine_name}")
|
40
|
+
|
41
|
+
target.rmtree if target.exist?
|
42
|
+
source.rename(target)
|
43
|
+
|
44
|
+
line "Restored #{provider[:name]} provider from stash"
|
45
|
+
|
46
|
+
# Success, exit status 0
|
47
|
+
0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative "base-command"
|
2
|
+
|
3
|
+
module VagrantPlugins::Provider
|
4
|
+
class StashCommand < BaseCommand
|
5
|
+
def execute
|
6
|
+
opts = OptionParser.new do |o|
|
7
|
+
o.banner = "Usage: vagrant provider stash [machine-name]"
|
8
|
+
o.separator ""
|
9
|
+
o.separator "Store current provider state for later"
|
10
|
+
o.separator ""
|
11
|
+
end
|
12
|
+
|
13
|
+
# Parse the options
|
14
|
+
argv = parse_options(opts)
|
15
|
+
return if !argv
|
16
|
+
if argv.length > 1
|
17
|
+
raise Vagrant::Errors::CLIInvalidUsage,
|
18
|
+
help: opts.help.chomp
|
19
|
+
end
|
20
|
+
|
21
|
+
machine_name = (argv[0] || @env.primary_machine_name).to_sym
|
22
|
+
|
23
|
+
if not machine_names.include? machine_name
|
24
|
+
raise Vagrant::Errors::MachineNotFound,
|
25
|
+
name: machine_name
|
26
|
+
end
|
27
|
+
|
28
|
+
provider = active_provider(machine_name)
|
29
|
+
|
30
|
+
if not provider
|
31
|
+
raise NoActiveProvider
|
32
|
+
end
|
33
|
+
|
34
|
+
source = machine_folder.join("#{machine_name}")
|
35
|
+
target = machine_folder.join("#{machine_name}_#{provider[:name]}")
|
36
|
+
|
37
|
+
if target.exist?
|
38
|
+
raise AlreadyStashedProvider
|
39
|
+
end
|
40
|
+
|
41
|
+
source.rename(target)
|
42
|
+
|
43
|
+
line "Stored #{provider[:name]} provider for later use"
|
44
|
+
|
45
|
+
# Success, exit status 0
|
46
|
+
0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "vagrant-provider"
|
5
|
+
spec.version = "0.1.0"
|
6
|
+
spec.authors = ["Glen Mailer"]
|
7
|
+
spec.email = ["glenjamin@gmail.com"]
|
8
|
+
spec.description = %q{Vagrant plugin for provider swapping}
|
9
|
+
spec.summary = %q{Vagrant plugin for provider swapping}
|
10
|
+
spec.homepage = "http://github.com/glenjamin/vagrant-provider"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Glen Mailer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Vagrant plugin for provider swapping
|
42
|
+
email:
|
43
|
+
- glenjamin@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- Vagrantfile
|
54
|
+
- lib/vagrant-provider.rb
|
55
|
+
- lib/vagrant-provider/base-command.rb
|
56
|
+
- lib/vagrant-provider/command.rb
|
57
|
+
- lib/vagrant-provider/list-command.rb
|
58
|
+
- lib/vagrant-provider/pick-command.rb
|
59
|
+
- lib/vagrant-provider/stash-command.rb
|
60
|
+
- vagrant-provider.gemspec
|
61
|
+
homepage: http://github.com/glenjamin/vagrant-provider
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Vagrant plugin for provider swapping
|
85
|
+
test_files: []
|