vagrant_commands 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/vagrant_commands/boxes.rb +64 -0
- data/lib/vagrant_commands/commands.rb +21 -0
- data/lib/vagrant_commands/plugins.rb +93 -0
- data/lib/vagrant_commands/shell.rb +15 -0
- data/lib/vagrant_commands/version.rb +3 -0
- data/lib/vagrant_commands.rb +6 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7ee969164608b47a7ef2ecce4d49ea41e320fec
|
4
|
+
data.tar.gz: 5c4a7414e41b16f1262dd1e179d518fd53495266
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27744c2db9a4f2318beb703f5f85d5b3e81548489d62de14ce7a0f5bfb5319dc57b2daa2792cc7210a78f329afdcf3d1e6b70e207aa54fb58336da4f32c0f7d7
|
7
|
+
data.tar.gz: 212ce596f0b4934b0f3dc9ba77bfbca2e04302adfad5306ba523b97475a647a0bbfc9d123c765d05a09213a5d2d1d3d1ccac535971bc70a154cee4e3d87b6731
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Boxes
|
2
|
+
|
3
|
+
def self.get_vagrant_boxes
|
4
|
+
result = Commands::vagrant_box_list
|
5
|
+
|
6
|
+
boxes = Array.new
|
7
|
+
box_name = nil
|
8
|
+
box_version = nil
|
9
|
+
box_provider = nil
|
10
|
+
|
11
|
+
lines = result.lines.map(&:chomp)
|
12
|
+
lines.each { |line|
|
13
|
+
cols = line.split(/,/)
|
14
|
+
|
15
|
+
if cols[2] == "box-name"
|
16
|
+
box_name = cols[3]
|
17
|
+
end
|
18
|
+
if cols[2] == "box-provider"
|
19
|
+
box_provider = cols[3]
|
20
|
+
end
|
21
|
+
if cols[2] == "box-version"
|
22
|
+
box_version = cols[3]
|
23
|
+
boxes.push VagrantBox.new(box_name, box_version, box_provider,nil)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
boxes
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_by_box_name(box)
|
31
|
+
found = nil
|
32
|
+
boxes = get_vagrant_boxes
|
33
|
+
|
34
|
+
boxes.each { |o|
|
35
|
+
found = o if o.box_name == box.box_name
|
36
|
+
}
|
37
|
+
found
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.install_box_if_missing(box)
|
41
|
+
if find_by_box_name(box) == nil
|
42
|
+
puts "Base box not found importing base box"
|
43
|
+
Commands::vagrant_box_add(box.box_location,box.box_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class VagrantBox
|
48
|
+
|
49
|
+
attr_accessor :box_name, :box_version, :box_provider, :box_location
|
50
|
+
|
51
|
+
def initialize(box_name, box_version, box_provider,box_location)
|
52
|
+
@box_name = box_name
|
53
|
+
@box_version = box_version
|
54
|
+
@box_provider = box_provider
|
55
|
+
@box_location = box_location
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
@box_name + ", " + @box_version + ", " + @box_provider + ", " + @box_location
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Commands
|
2
|
+
def self.vagrant_box_list
|
3
|
+
result = `vagrant box list --machine-readable`
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.vagrant_box_add(box_location,box_name)
|
7
|
+
`vagrant box add \"#{box_location}\" --name #{box_name}`
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.vagrant_plugin_list
|
11
|
+
`vagrant plugin list --machine-readable`
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.vagrant_plugin_install(plugin_name, plugin_version)
|
15
|
+
version = ""
|
16
|
+
if plugin_version != nil
|
17
|
+
version = " --plugin-version #{plugin_version}"
|
18
|
+
end
|
19
|
+
`vagrant plugin install #{plugin_name}#{version}`
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Plugins
|
2
|
+
def self.get_vagrant_plugins
|
3
|
+
result = Commands::vagrant_plugin_list
|
4
|
+
|
5
|
+
plugins = Array.new
|
6
|
+
plugin_name = nil
|
7
|
+
plugin_version = nil
|
8
|
+
plugin_version_constraint = nil
|
9
|
+
|
10
|
+
lines = result.lines.map(&:chomp)
|
11
|
+
lines.each { |line|
|
12
|
+
|
13
|
+
cols = line.split(/,/)
|
14
|
+
|
15
|
+
if cols[2] == "plugin-name"
|
16
|
+
if(plugin_name)
|
17
|
+
#add previously found plugin
|
18
|
+
plugins.push VagrantPlugin.new(plugin_name,plugin_version,plugin_version_constraint)
|
19
|
+
plugin_name = nil
|
20
|
+
plugin_version = nil
|
21
|
+
plugin_version_constraint = nil
|
22
|
+
end
|
23
|
+
plugin_name = cols[3]
|
24
|
+
end
|
25
|
+
if cols[2] == "plugin-version"
|
26
|
+
plugin_version = cols[3]
|
27
|
+
end
|
28
|
+
if cols[2] == "plugin-version-constraint"
|
29
|
+
plugin_version_constraint = cols[3]
|
30
|
+
end
|
31
|
+
}
|
32
|
+
|
33
|
+
if(plugin_name)
|
34
|
+
#add previously found plugin
|
35
|
+
plugins.push VagrantPlugin.new(plugin_name,plugin_version,plugin_version_constraint)
|
36
|
+
plugin_name = nil
|
37
|
+
plugin_version = nil
|
38
|
+
plugin_version_constraint = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
plugins
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.check_plugin_installed(plugin)
|
45
|
+
plugins = get_vagrant_plugins
|
46
|
+
found = nil
|
47
|
+
plugins.each { |p|
|
48
|
+
if p.plugin_name == plugin.plugin_name
|
49
|
+
found = true
|
50
|
+
end
|
51
|
+
}
|
52
|
+
return found
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.check_and_install_plugins(required_plugins)
|
56
|
+
|
57
|
+
plugins = get_vagrant_plugins
|
58
|
+
|
59
|
+
required_plugins.each {|plugin|
|
60
|
+
|
61
|
+
found = nil
|
62
|
+
plugins.each { |p|
|
63
|
+
if p.plugin_name == plugin.plugin_name
|
64
|
+
found = true
|
65
|
+
end
|
66
|
+
}
|
67
|
+
|
68
|
+
if found == nil
|
69
|
+
Commands::vagrant_plugin_install(plugin.plugin_name,plugin.plugin_version)
|
70
|
+
end
|
71
|
+
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
class VagrantPlugin
|
78
|
+
|
79
|
+
attr_accessor :plugin_name, :plugin_version, :plugin_version_constraint
|
80
|
+
|
81
|
+
def initialize(plugin_name, plugin_version, plugin_version_constraint)
|
82
|
+
@plugin_name = plugin_name
|
83
|
+
@plugin_version = plugin_version
|
84
|
+
@plugin_version_constraint = plugin_version_constraint
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_s
|
88
|
+
@plugin_name + ", " + @plugin_version + ", " + @plugin_version_constraint
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Shell
|
2
|
+
def self.execute_command(command,box_name)
|
3
|
+
portNum = get_ssh_details(/(?<=Port ).*/,box_name)
|
4
|
+
keyPath = get_ssh_details(/(?<=IdentityFile ).*/,box_name)
|
5
|
+
hostName = get_ssh_details(/(?<=HostName ).*/,box_name)
|
6
|
+
userName = get_ssh_details(/(?<=User ).*/,box_name)
|
7
|
+
puts "ssh -v -o StrictHostKeyChecking=no #{userName}@#{hostName} -p #{portNum} -i #{keyPath} \"#{command}\""
|
8
|
+
puts `ssh -v -o StrictHostKeyChecking=no #{userName}@#{hostName} -p #{portNum} -i #{keyPath} \"#{command}\"`
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get_ssh_details(regex, box_name)
|
12
|
+
response = `vagrant ssh-config #{box_name}`
|
13
|
+
return response.match(regex)
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant_commands
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nic Jackson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-mocks
|
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: A simple hello world gem
|
42
|
+
email: nicholas.jackson@marks-and-spencer.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/vagrant_commands.rb
|
48
|
+
- lib/vagrant_commands/boxes.rb
|
49
|
+
- lib/vagrant_commands/commands.rb
|
50
|
+
- lib/vagrant_commands/plugins.rb
|
51
|
+
- lib/vagrant_commands/shell.rb
|
52
|
+
- lib/vagrant_commands/version.rb
|
53
|
+
homepage: https://github.com/nicholasjackson/vagrant-commands
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.2.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Simple gem to execute vagrant commands from ruby
|
77
|
+
test_files: []
|