vagrant-clone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e45e9796de323bcd6fcc9cb86028b0ced7b036e3
4
+ data.tar.gz: 5fdcdeb758ebebdb422ae018a56ff8266a4fec43
5
+ SHA512:
6
+ metadata.gz: d1dc324a434b9c52c655638edc9ff83fde78c0e73bf0788c4938b3f0dd65a9edfd7c706a14b748ca47e16f984fd08602b7db68be9ec0a95030f2bc228ba6e2d3
7
+ data.tar.gz: cae48565d3ac76321d39384c8f2e007d941843932cd11321106c6ac7803124a49a251f1a5a43c201f54f3b2c603b293b4c2e9df18d3ce08c78a4db9cc01d549c
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-clone", path: "."
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ GIT
2
+ remote: git://github.com/mitchellh/vagrant.git
3
+ revision: 0cfdf6f1feb0b80bf93f91fc4723be0bc62b8692
4
+ specs:
5
+ vagrant (1.9.0.dev)
6
+ childprocess (~> 0.5.0)
7
+ erubis (~> 2.7.0)
8
+ hashicorp-checkpoint (~> 0.1.1)
9
+ i18n (>= 0.6.0, <= 0.8.0)
10
+ listen (~> 3.1.5)
11
+ log4r (~> 1.1.9, < 1.1.11)
12
+ net-scp (~> 1.1.0)
13
+ net-sftp (~> 2.1)
14
+ net-ssh (~> 3.0.1)
15
+ nokogiri (= 1.6.7.1)
16
+ rb-kqueue (~> 0.2.0)
17
+ rest-client (>= 1.6.0, < 3.0)
18
+ ruby_dep (<= 1.3.1)
19
+ wdm (~> 0.1.0)
20
+ winrm (~> 1.6)
21
+ winrm-fs (~> 0.3.0)
22
+
23
+ PATH
24
+ remote: .
25
+ specs:
26
+ vagrant-clone (0.0.1)
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ builder (3.2.2)
32
+ childprocess (0.5.9)
33
+ ffi (~> 1.0, >= 1.0.11)
34
+ domain_name (0.5.20161021)
35
+ unf (>= 0.0.5, < 1.0.0)
36
+ erubis (2.7.0)
37
+ ffi (1.9.14)
38
+ gssapi (1.2.0)
39
+ ffi (>= 1.0.1)
40
+ gyoku (1.3.1)
41
+ builder (>= 2.1.2)
42
+ hashicorp-checkpoint (0.1.4)
43
+ http-cookie (1.0.3)
44
+ domain_name (~> 0.5)
45
+ httpclient (2.8.2.4)
46
+ i18n (0.7.0)
47
+ listen (3.1.5)
48
+ rb-fsevent (~> 0.9, >= 0.9.4)
49
+ rb-inotify (~> 0.9, >= 0.9.7)
50
+ ruby_dep (~> 1.2)
51
+ little-plugger (1.1.4)
52
+ log4r (1.1.10)
53
+ logging (2.1.0)
54
+ little-plugger (~> 1.1)
55
+ multi_json (~> 1.10)
56
+ mime-types (3.1)
57
+ mime-types-data (~> 3.2015)
58
+ mime-types-data (3.2016.0521)
59
+ mini_portile2 (2.0.0)
60
+ multi_json (1.12.1)
61
+ net-scp (1.1.2)
62
+ net-ssh (>= 2.6.5)
63
+ net-sftp (2.1.2)
64
+ net-ssh (>= 2.6.5)
65
+ net-ssh (3.0.2)
66
+ netrc (0.11.0)
67
+ nokogiri (1.6.7.1)
68
+ mini_portile2 (~> 2.0.0.rc2)
69
+ nori (2.6.0)
70
+ rb-fsevent (0.9.8)
71
+ rb-inotify (0.9.7)
72
+ ffi (>= 0.5.0)
73
+ rb-kqueue (0.2.4)
74
+ ffi (>= 0.5.0)
75
+ rest-client (2.0.0)
76
+ http-cookie (>= 1.0.2, < 2.0)
77
+ mime-types (>= 1.16, < 4.0)
78
+ netrc (~> 0.8)
79
+ ruby_dep (1.3.1)
80
+ rubyntlm (0.6.1)
81
+ rubyzip (1.2.0)
82
+ unf (0.1.4)
83
+ unf_ext
84
+ unf_ext (0.0.7.2)
85
+ wdm (0.1.1)
86
+ winrm (1.8.1)
87
+ builder (>= 2.1.2)
88
+ gssapi (~> 1.2)
89
+ gyoku (~> 1.0)
90
+ httpclient (~> 2.2, >= 2.2.0.2)
91
+ logging (>= 1.6.1, < 3.0)
92
+ nori (~> 2.0)
93
+ rubyntlm (~> 0.6.0)
94
+ winrm-fs (0.3.2)
95
+ erubis (~> 2.7)
96
+ logging (>= 1.6.1, < 3.0)
97
+ rubyzip (~> 1.1)
98
+ winrm (~> 1.5)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ vagrant!
105
+ vagrant-clone!
106
+
107
+ BUNDLED WITH
108
+ 1.13.6
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # VagrantClone
2
+
3
+ vagrant-clone is a Vagrant plugin for creating and managing clones of Vagrant VM(s).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vagrant-clone'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vagrant-clone
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://bitbucket.org/galiaf95/vagrant-clone.
34
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $stdout.sync = true
5
+ $stderr.sync = true
6
+
7
+ Bundler::GemHelper.install_tasks
Binary file
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # vim: set fileencoding=utf-8
3
+
4
+ require "vagrant"
5
+
6
+ module VagrantClone
7
+ class Plugin < Vagrant.plugin("2")
8
+
9
+ name 'vagrant-clone'
10
+
11
+ command 'clone' do
12
+ require_relative 'vagrant-clone/command/clone'
13
+ Command
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../command/errors'
2
+ require_relative '../utils/vagrantfile_manager'
3
+ require_relative 'provider/docker'
4
+
5
+ require 'optparse'
6
+
7
+ module VagrantClone
8
+ class Command < Vagrant.plugin("2", "command")
9
+
10
+ def initialize(argv, env)
11
+ super
12
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
13
+ end
14
+
15
+ def execute
16
+ options = {}
17
+ opts = OptionParser.new do |o|
18
+ o.banner = 'Usage: vagrant clone origin [options] [-h]'
19
+ o.on('-n PATH_TO_NEW_VAGRANT_ENVIRONMENT', '--new-vagrant-env-path', 'Where to create new Vagrantfile') do |c|
20
+ options[:new_vagrant_env_path] = c
21
+ end
22
+ o.on('-h', '--help', 'Help') do |c|
23
+ @env.ui.info(opts.help, :prefix => false)
24
+ exit
25
+ end
26
+ end
27
+ argv = parse_options(opts)
28
+ timestamp = Time.new.to_i
29
+ options[:vagrantfile_name] = 'Vagrantfile'
30
+ options[:current_vagrant_env_path] = Dir.pwd
31
+ unless File.exists?("#{options[:current_vagrant_env_path]}/#{options[:vagrantfile_name]}")
32
+ raise VagrantClone::Errors::NotVagrantEnvironment
33
+ end
34
+ unless options[:new_vagrant_env_path]
35
+ options[:new_vagrant_env_path] = File.expand_path("#{Dir.pwd}/../#{File.basename options[:current_vagrant_env_path]}_#{timestamp}")
36
+ FileUtils.mkdir options[:new_vagrant_env_path]
37
+ end
38
+ all_machines = Array.new
39
+ current_vagrantfile = File.read("#{options[:current_vagrant_env_path]}/#{options[:vagrantfile_name]}")
40
+ if argv.empty?
41
+ if current_vagrantfile.match('config.vm.define')
42
+ current_vagrantfile.split("\n").each do |line|
43
+ match = line.match(/config\.vm\.define\s+([^\s]+)\s+/)
44
+ if match
45
+ all_machines.push match.captures[0].gsub("\"", '').gsub("'", '')
46
+ end
47
+ end
48
+ else
49
+ all_machines.push 'default'
50
+ end
51
+ else
52
+ all_machines.push argv
53
+ end
54
+ all_machines.uniq!
55
+ options[:vms_data] = Array.new
56
+ # Checking all machines to be alive
57
+ all_machines.each do |specific_machine|
58
+ with_target_vms(specific_machine) do |machine|
59
+ raise VagrantClone::Errors::VmNotCreated if machine.state.id == :not_created
60
+ end
61
+ end
62
+ all_machines.each do |specific_machine|
63
+ with_target_vms(specific_machine) do |machine|
64
+ vm_data = {
65
+ :cloned_name => "#{machine.name}",
66
+ :cloned_image_name => "#{machine.name}_#{timestamp}",
67
+ :origin_id => machine.id,
68
+ :provider => machine.provider
69
+ }
70
+ options[:vms_data].push (vm_data)
71
+ Docker.new(vm_data, @env) if /Docker/.match(machine.provider.to_s)
72
+ end
73
+ end
74
+ VagrantfileManager.new(options, @env)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantClone
2
+ module Errors
3
+ class Error < Vagrant::Errors::VagrantError
4
+ error_namespace('vagrant-clone.errors')
5
+ end
6
+ class VmNotCreated < VagrantClone::Errors::Error
7
+ error_key('vm_not_created')
8
+ end
9
+ class DockerCloningError < VagrantClone::Errors::Error
10
+ error_key('docker_cloning_error')
11
+ end
12
+ class NotVagrantEnvironment < VagrantClone::Errors::Error
13
+ error_key('not_vagrant_environment')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../../utils/vagrantfile_manager'
2
+ require 'fileutils'
3
+
4
+ module VagrantClone
5
+ class Docker
6
+ def initialize(options, env)
7
+ env.ui.info "making clone of VM: #{options[:origin_id]} to image #{options[:cloned_image_name]}"
8
+ `docker commit -p #{options[:origin_id]} #{options[:cloned_image_name]}`
9
+ raise VagrantClone::Errors::DockerCloningError if $?.exitstatus != 0
10
+ env.ui.info "clone of VM: #{options[:origin_id]} to image #{options[:cloned_image_name]} created successfully"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ module VagrantClone
2
+ class VagrantfileManager
3
+
4
+ VAGRANT_TEMPLATE = <<-HEREDOC
5
+ Vagrant.configure("2") do |config|
6
+ %s
7
+ end
8
+ HEREDOC
9
+
10
+ VAGRANT_BLOCK_DOCKER_TEMPLATE = <<-HEREDOC
11
+ config.vm.define '%s' do |machine|
12
+ machine.vm.provider 'docker' do |docker|
13
+ docker.image = '%s'
14
+ end
15
+ end
16
+
17
+ HEREDOC
18
+
19
+ def initialize(options, env)
20
+ @current_vagrant_env_path = options[:current_vagrant_env_path]
21
+ @new_vagrant_env_path = options[:new_vagrant_env_path]
22
+ @vagrantfile_name = options[:vagrantfile_name]
23
+ @provider = options[:provider]
24
+ @env = env
25
+ generate_vagrantfile options[:vms_data]
26
+ end
27
+
28
+ def generate_vagrantfile_block(vm_data)
29
+ VAGRANT_BLOCK_DOCKER_TEMPLATE % [vm_data[:cloned_name], vm_data[:cloned_image_name]]
30
+ end
31
+
32
+ def generate_vagrantfile(vms_data)
33
+ @env.ui.info "generating Vagrantfile in #{@new_vagrant_env_path}"
34
+ blocks = String.new
35
+ vms_data.each do |vm_data|
36
+ blocks = blocks + generate_vagrantfile_block(vm_data)
37
+ end
38
+ vagrantfile = VAGRANT_TEMPLATE % [blocks]
39
+ File.open("#{@new_vagrant_env_path}/#{@vagrantfile_name}", 'w+') do |f|
40
+ f.write vagrantfile
41
+ end
42
+ end
43
+
44
+ def extract_configs
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantClone
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/vagrant-clone/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "vagrant-clone"
6
+ spec.version = VagrantClone::VERSION
7
+ spec.authors = ["Alexander Kaluzny"]
8
+ spec.email = ["galiaf1995@gmail.com"]
9
+
10
+ spec.summary = 'Plugin for creating and managing clones of VM(s)'
11
+ spec.description = 'Plugin for creating and managing clones of VM(s)'
12
+ spec.homepage = 'https://bitbucket.org/galiaf95/vagrant-clone'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.13"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-clone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kaluzny
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-31 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Plugin for creating and managing clones of VM(s)
42
+ email:
43
+ - galiaf1995@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - README.md
51
+ - Rakefile
52
+ - doc/Vagrant_Up_And_Running.epub
53
+ - lib/vagrant-clone.rb
54
+ - lib/vagrant-clone/command/clone.rb
55
+ - lib/vagrant-clone/command/errors.rb
56
+ - lib/vagrant-clone/command/provider/docker.rb
57
+ - lib/vagrant-clone/utils/vagrantfile_manager.rb
58
+ - lib/vagrant-clone/version.rb
59
+ - vagrant-clone.gemspec
60
+ homepage: https://bitbucket.org/galiaf95/vagrant-clone
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.14
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Plugin for creating and managing clones of VM(s)
83
+ test_files: []