inprovise-vbox 0.2.1
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 +15 -0
- data/.gitignore +4 -0
- data/.travis.yml +28 -0
- data/Gemfile +9 -0
- data/README.md +49 -0
- data/Rakefile.rb +9 -0
- data/inprovise-vbox.gemspec +18 -0
- data/lib/inprovise/vbox.rb +10 -0
- data/lib/inprovise/vbox/vbox.rb +208 -0
- data/lib/inprovise/vbox/version.rb +10 -0
- data/test/fixtures/inprovise.rb +1 -0
- data/test/test_helper.rb +238 -0
- data/test/vbox_test.rb +39 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjQxMmE3NWUxMWNiODNmNGZmMjQ2Nzc0M2NhY2EyN2ZmYTcxOTNmOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzhhZjA1MWVkNDI4ZjAwODEwZGMyMTRjYzM0MjFkNTBmMWJjNzI4ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmMwNzg1NzA4NzlhMThjYWUyMzc2ZWQ1MWMzYjg5MTkzM2MwNDI3MTEyY2Ni
|
10
|
+
YTg4Y2IwYTgyNGRmNmZjZDJiN2ZiNzRkNDIxYTI5ODAzNzNmOWZhNGE2N2I5
|
11
|
+
NTUzMTQ2NWE2YTk0NDE3MjNlOGM5ZmM2ZDExZjI2ZTcwNzE4OTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDE4ZGIyYWZlZmJlMTZmOWQxNjhkOTQxZTY0YmMxMTE4NDUwZTFmOGJhYWQy
|
14
|
+
NmY0ZTcxMDAxNzg1NzdhZmZkMTM5NDRiOWRkMDRjNTBmODNhMjgwNWU0ODc2
|
15
|
+
MTY3ODBlMDUxMjM4OTRjMDRhMjQ4MTk1ODNlNWM3NTlmYWRjYWU=
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem install bundler
|
3
|
+
bundler_args: "--verbose"
|
4
|
+
script: rake test
|
5
|
+
rvm:
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1
|
8
|
+
- 2.2
|
9
|
+
- 2.3.1
|
10
|
+
- ruby-head
|
11
|
+
gemfile:
|
12
|
+
- Gemfile
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
env: CODECLIMATE_REPO_TOKEN=109e18d2cc2d09d4d257bc89b8f80095cc3fd331c698ac2c4d6ebf16344135e0
|
17
|
+
bundle exec rake
|
18
|
+
addons:
|
19
|
+
code_climate:
|
20
|
+
repo_token: 109e18d2cc2d09d4d257bc89b8f80095cc3fd331c698ac2c4d6ebf16344135e0
|
21
|
+
deploy:
|
22
|
+
provider: rubygems
|
23
|
+
api_key:
|
24
|
+
secure: c2FbOO1vcAeHp4hCW/P0XEtfB1jbjS5S1LhnnCSOqM+j37UHqz2pd98CqUdpawA+1o68GtWnqhpJkC5+zx8CM+rE3lNB0SSXk98UqFeCQw/2HlEAn1hkfqxbstNI+wIa7gF7tmZ6ZTtuiPO0JovaknFfu8o2IMZrpf1LOsTrBv+GT3nm32B5b0iJszAwwsPMzvnglHP0lOJjgzxzDK+RtfIujYewJZ/Nr4DEobPDtnTw0gG2Bc1f0GiCWWr38PvNxdH0i7PlVWplAfC/WMRdgdVbxxUNnZBuw0wyRrSmxjWrArhEI6y3qobgduWvYOaddyInViI99wb+M6NV8F86IXnlw2AdK797En5z2ofdvJkUIDAqLJLZ6Q46DfINxH3HtlorVz1C0EOidVEFyP2/SDaMClWbCHGCGTBpUy706BjgDhcpOV6A1uykFjd963hiI7vP6WwgHNtgrW7tZCfK+A+yeh9z8lF/1rW6alS6v1OYfZoqQvfafwLFfCY0Hgheowy0G5azdL7LjP9/aDFkZxohj3UKFfv4//kfcIgTl7BmlbVAxqGMcXhkRq5qL4bcFpdsMzUI1RprJTsmF/fWFFA2En0Oy4aSkkt3IEhgcmCxEGnJmJNNhPadl8Lez7ONi7EhcQm8gUPr5Afz50ywQKSpO6JBVIXe69toLQHYDOg=
|
25
|
+
gemspec: inprovise-vbox.gemspec
|
26
|
+
on:
|
27
|
+
tags: true
|
28
|
+
repo: mcorino/Inprovise-VBox
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
Inprovise Virtual Box
|
3
|
+
=====================
|
4
|
+
|
5
|
+
This project implements an extension for the Inprovise provisioning tool providing `vbox` scripts for installing
|
6
|
+
Libvirt based virtual machine instances.
|
7
|
+
|
8
|
+
This is not a really general purpose plugin nor is it intended to be. This plugin is very much tailored to our particular
|
9
|
+
requirements which are pretty simple in this area. Currently we only use libvirt based virtualization and hvm (fully virtualized)
|
10
|
+
type virtual machines.
|
11
|
+
However, this plugin gives a good example of the ease with which such an Inprovise plugin can be created using mostly the
|
12
|
+
basic functionality provided by Inprovise itself.
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
|
17
|
+
$ gem install inprovise-vbox
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
Add the following to (for example) your Inprovise project's `rigrc` file.
|
23
|
+
|
24
|
+
````ruby
|
25
|
+
require 'inprovise/vbox'
|
26
|
+
````
|
27
|
+
|
28
|
+
Syntax
|
29
|
+
------
|
30
|
+
|
31
|
+
````ruby
|
32
|
+
vbox 'myvm' do
|
33
|
+
|
34
|
+
configuration ({
|
35
|
+
:name => 'MyVM',
|
36
|
+
:image => '/remote/image/path',
|
37
|
+
:memory => 1024,
|
38
|
+
:cpus => 2
|
39
|
+
})
|
40
|
+
|
41
|
+
end
|
42
|
+
````
|
43
|
+
|
44
|
+
When applying this script for a target VM host node it will automatically create a (libvirt based, hvm type) virtual machine instance `MyVM`
|
45
|
+
on the specified host and define a new Inprovise infrastructure node if the installation was successful.
|
46
|
+
|
47
|
+
Optionally user defined `apply`, `revert` and/or `validate` blocks can be added to provide additional (custom)
|
48
|
+
processing.
|
49
|
+
|
data/Rakefile.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib/inprovise/vbox/version')
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Martin Corino"]
|
5
|
+
gem.email = ["mcorino@remedy.nl"]
|
6
|
+
gem.description = %q{VBox script extension for Inprovise}
|
7
|
+
gem.summary = %q{Simple, easy and intuitive virtual machine provisioning}
|
8
|
+
gem.homepage = ""
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "inprovise-vbox"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Inprovise::VBox::VERSION
|
16
|
+
gem.add_dependency('inprovise')
|
17
|
+
gem.post_install_message = ''
|
18
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
# VBox script class for InproviseVBox
|
2
|
+
#
|
3
|
+
# Author:: Martin Corino
|
4
|
+
# License:: Distributes under the same license as Ruby
|
5
|
+
|
6
|
+
module Inprovise::VBox
|
7
|
+
|
8
|
+
# add a common 'vbox' script defining all common actions
|
9
|
+
Inprovise::DSL.script 'vbox' do
|
10
|
+
# add standard actions
|
11
|
+
action('vbox-shutdown') do |vboxname|
|
12
|
+
sudo("virsh shutdown #{vboxname}")
|
13
|
+
end
|
14
|
+
action('vbox-kill') do |vboxname|
|
15
|
+
sudo("virsh destroy #{vboxname}")
|
16
|
+
end
|
17
|
+
action('vbox-start') do |vboxname|
|
18
|
+
sudo("virsh start #{vboxname}")
|
19
|
+
end
|
20
|
+
action('vbox-verify') do |vboxname, autostart=false|
|
21
|
+
vbox_info = sudo("virsh dominfo #{vboxname}").gsub("\n", ' ')
|
22
|
+
vbox_info =~ /name:\s+#{vboxname}\s.*state:\s+running/i &&
|
23
|
+
(!autostart || vbox_info =~ /autostart:\s+enable/i)
|
24
|
+
end
|
25
|
+
action('vbox-delete') do |vboxname|
|
26
|
+
sudo("virsh undefine #{vboxname}")
|
27
|
+
end
|
28
|
+
action 'vbox-ifaddr' do |vboxname|
|
29
|
+
result = []
|
30
|
+
out = sudo("virsh domifaddr #{vboxname}").split("\n").last.strip
|
31
|
+
unless /-+/ =~ out
|
32
|
+
_, mac, _, net = out.split(' ')
|
33
|
+
result << mac << net.split('/').first
|
34
|
+
end
|
35
|
+
result
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class VBoxScript < Inprovise::Script
|
40
|
+
|
41
|
+
# configuration
|
42
|
+
# :name
|
43
|
+
# :image
|
44
|
+
# :format
|
45
|
+
# :diskbus
|
46
|
+
# :memory
|
47
|
+
# :cpus
|
48
|
+
# :os
|
49
|
+
# :network
|
50
|
+
# :netname
|
51
|
+
# :autostart
|
52
|
+
# :install_opts
|
53
|
+
|
54
|
+
def initialize(name)
|
55
|
+
super(name)
|
56
|
+
@vm_script = nil
|
57
|
+
@node_script = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def setup
|
61
|
+
# verify mandatory configuration
|
62
|
+
raise ArgumentError, "Missing required configuration for vbox script #{name}" unless Hash === configuration || OpenStruct === configuration
|
63
|
+
# take care of defaults
|
64
|
+
configuration[:memory] ||= 1024
|
65
|
+
configuration[:cpus] ||= 1
|
66
|
+
configuration[:network] ||= :hostnet
|
67
|
+
# generate name if none set
|
68
|
+
configuration[:name] ||= "#{name}_#{self.hash}_#{Time.now.to_f}"
|
69
|
+
|
70
|
+
vbox_script = self
|
71
|
+
vbox_scrname = self.name
|
72
|
+
# define the scripts that do the actual work as dependencies
|
73
|
+
# 1. install the virtual machine
|
74
|
+
@vm_script = Inprovise::DSL.script "#{name}#vbox_vm" do
|
75
|
+
|
76
|
+
# verify VM
|
77
|
+
validate do
|
78
|
+
vbox_cfg = config[vbox_scrname.to_sym]
|
79
|
+
# look for existing target with VM name on :apply unless node creation is suppressed
|
80
|
+
if command == :apply && !vbox_cfg.no_node
|
81
|
+
if tgt = Inprovise::Infrastructure.find(vbox_cfg.name)
|
82
|
+
type = Inprovise::Infrastructure::Group === tgt ? 'group' : 'node'
|
83
|
+
raise ArgumentError, "VBox #{vbox_cfg.name} clashes with existing #{type}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
trigger 'vbox:vbox-verify', vbox_cfg.name, (command == :apply && vbox_cfg.autostart)
|
87
|
+
end
|
88
|
+
|
89
|
+
# apply : installation
|
90
|
+
apply do
|
91
|
+
vbox_cfg = config[vbox_scrname.to_sym]
|
92
|
+
# 1. verify config
|
93
|
+
raise ArgumentError, "Cannot access VBox image #{vbox_cfg.image}" unless remote(vbox_cfg.image).file?
|
94
|
+
# 2. execute virt-install
|
95
|
+
log("Installing VBox #{vbox_cfg.name}".bold)
|
96
|
+
cmdline = 'virt-install --connect qemu:///system --hvm --virt-type kvm --import --wait 0 '
|
97
|
+
cmdline << '--autostart ' if vbox_cfg.autostart
|
98
|
+
cmdline << "--name #{vbox_cfg.name} --memory #{vbox_cfg.memory} --vcpus #{vbox_cfg.cpus} "
|
99
|
+
cmdline << "--os-variant #{vbox_cfg.os} " if vbox_cfg.os
|
100
|
+
cmdline << case vbox_cfg.network
|
101
|
+
when :hostnet
|
102
|
+
"--network network=#{vbox_cfg.netname || 'default'} "
|
103
|
+
when :bridge
|
104
|
+
"--network bridge=#{vbox_cfg.netname || 'virbr0' } "
|
105
|
+
end
|
106
|
+
cmdline << '--graphics spice '
|
107
|
+
cmdline << "--disk path=#{vbox_cfg.image},device=disk,boot_order=1"
|
108
|
+
cmdline << ",bus=#{vbox_cfg.diskbus}" if vbox_cfg.diskbus
|
109
|
+
cmdline << ",format=#{vbox_cfg.format}" if vbox_cfg.format
|
110
|
+
cmdline << ' --disk device=cdrom,boot_order=2,bus=ide'
|
111
|
+
cmdline << " #{vbox_cfg.install_opts}" if vbox_cfg.install_opts
|
112
|
+
sudo(cmdline)
|
113
|
+
10.times do
|
114
|
+
sleep(1)
|
115
|
+
break if trigger 'vbox:vbox-verify', vbox_cfg.name, vbox_cfg.autostart
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# revert : uninstall
|
120
|
+
revert do
|
121
|
+
vbox_cfg = config[vbox_scrname.to_sym]
|
122
|
+
trigger 'vbox:vbox-shutdown', vbox_cfg.name
|
123
|
+
log.print("Waiting for shutdown of VBox #{vbox_cfg.name}. Please wait ...|".bold)
|
124
|
+
30.times do |n|
|
125
|
+
sleep(1)
|
126
|
+
log.print("\b" + %w{| / - \\}[(n+1) % 4].bold)
|
127
|
+
break unless trigger 'vbox:vbox-verify', vbox_cfg.name
|
128
|
+
end
|
129
|
+
if trigger('vbox:vbox-verify', vbox_cfg.name)
|
130
|
+
trigger('vbox:vbox-kill', vbox_cfg.name)
|
131
|
+
sleep(1)
|
132
|
+
end
|
133
|
+
log.println("\bdone".bold)
|
134
|
+
trigger('vbox:vbox-delete', vbox_cfg.name) unless trigger('vbox:vbox-verify', vbox_cfg.name)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# 2. add an Inprovise node if the VM was installed successfully
|
139
|
+
@node_script = Inprovise::DSL.script "#{name}#vbox_node" do
|
140
|
+
|
141
|
+
# add a node object for the new VM unless suppressed
|
142
|
+
apply do
|
143
|
+
vbox_cfg = config[vbox_scrname.to_sym]
|
144
|
+
unless vbox_cfg.no_node
|
145
|
+
# get MAC and IP for VM
|
146
|
+
log.print("Determining IP address for VBox #{vbox_cfg.name}. Please wait ...|".bold)
|
147
|
+
mac = addr = nil
|
148
|
+
150.times do |n|
|
149
|
+
sleep(2)
|
150
|
+
log.print("\b" + %w{| / - \\}[(n+1) % 4].bold)
|
151
|
+
mac, addr = trigger 'vbox:vbox-ifaddr', vbox_cfg.name
|
152
|
+
if addr
|
153
|
+
break
|
154
|
+
end
|
155
|
+
end
|
156
|
+
log.println("\bdone".bold)
|
157
|
+
raise RuntimeError, "Failed to determin IP address for VBox #{vbox_cfg.name}" unless addr
|
158
|
+
log("VBox #{vbox_cfg.name} : mac=#{mac}, addr=#{addr}") if Inprovise.verbosity > 0
|
159
|
+
vbox_opts = vbox_cfg.to_h
|
160
|
+
vbox_opts.delete(:no_node)
|
161
|
+
vbox_opts.delete(:no_sniff)
|
162
|
+
node = Inprovise::Infrastructure::Node.new(vbox_cfg.name, {:host => addr, :user => vbox_cfg.user, :vbox => vbox_opts})
|
163
|
+
Inprovise::Infrastructure.save
|
164
|
+
unless vbox_cfg.no_sniff
|
165
|
+
# retry on (comm) failure
|
166
|
+
Inprovise::Sniffer.run_sniffers_for(node) rescue Inprovise::Sniffer.run_sniffers_for(node)
|
167
|
+
Inprovise::Infrastructure.save
|
168
|
+
end
|
169
|
+
log("Added new node #{node.to_s}".bold)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# remove the node object for the VM unless node creation suppressed
|
174
|
+
revert do
|
175
|
+
vbox_cfg = config[vbox_scrname.to_sym]
|
176
|
+
unless vbox_cfg.no_node
|
177
|
+
tgt = Inprovise::Infrastructure.find(vbox_cfg.name)
|
178
|
+
if tgt && Inprovise::Infrastructure::Node === tgt
|
179
|
+
Inprovise::Infrastructure.deregister(vbox_cfg.name)
|
180
|
+
Inprovise::Infrastructure.save
|
181
|
+
log("Removed node #{tgt.to_s}".bold)
|
182
|
+
else
|
183
|
+
log("No existing node #{vbox_cfg.name} found!".yellow)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
# add dependencies in correct order
|
191
|
+
# MUST proceed any user defined dependencies
|
192
|
+
dependencies.insert(0, @vm_script.name, @node_script.name)
|
193
|
+
|
194
|
+
self
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
Inprovise::DSL.dsl_define do
|
202
|
+
def vbox(name, &definition)
|
203
|
+
Inprovise.log.local("Adding VBox script #{name}") if Inprovise.verbosity > 1
|
204
|
+
Inprovise.add_script(Inprovise::VBox::VBoxScript.new(name)) do |script|
|
205
|
+
Inprovise::VBox::VBoxScript::DSL.new(script).instance_eval(&definition)
|
206
|
+
end.setup
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# default test scheme
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
# Test helper for InproviseVBox
|
2
|
+
#
|
3
|
+
# Author:: Martin Corino
|
4
|
+
# License:: Distributes under the same license as Ruby
|
5
|
+
require "codeclimate-test-reporter"
|
6
|
+
CodeClimate::TestReporter.start
|
7
|
+
|
8
|
+
gem 'minitest'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
require 'mocha/setup'
|
11
|
+
gem 'inprovise'
|
12
|
+
require_relative '../lib/inprovise/vbox'
|
13
|
+
|
14
|
+
# force root file
|
15
|
+
ENV['INPROVISE_INFRA'] = File.join(File.dirname(__FILE__), 'fixtures', Inprovise::INFRA_FILE)
|
16
|
+
|
17
|
+
def reset_script_index!
|
18
|
+
Inprovise::ScriptIndex.default.clear!
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset_infrastructure!
|
22
|
+
Inprovise::Infrastructure.reset
|
23
|
+
end
|
24
|
+
|
25
|
+
# patch Infrastructure#load and #save to do nothing
|
26
|
+
module Inprovise::Infrastructure
|
27
|
+
class << self
|
28
|
+
def load
|
29
|
+
# noop
|
30
|
+
end
|
31
|
+
def save
|
32
|
+
# noop
|
33
|
+
end
|
34
|
+
|
35
|
+
# add reset
|
36
|
+
def reset
|
37
|
+
targets.synchronize do
|
38
|
+
targets.clear
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# create mock test channel
|
45
|
+
|
46
|
+
Inprovise::CmdChannel.define('test') do
|
47
|
+
|
48
|
+
def initialize(node, user=nil)
|
49
|
+
@node = node
|
50
|
+
@user = user || node.user
|
51
|
+
end
|
52
|
+
|
53
|
+
# command execution
|
54
|
+
|
55
|
+
def run(command, forcelog=false)
|
56
|
+
@node.log.execute("RUN: #{command}") if Inprovise.verbosity > 0
|
57
|
+
"RUN: #{command}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# file management
|
61
|
+
|
62
|
+
def upload(from, to)
|
63
|
+
@node.log.execute("UPLOAD: #{from} => #{to}") if Inprovise.verbosity > 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def download(from, to)
|
67
|
+
@node.log.execute("DOWNLOAD: #{from} => #{to}") if Inprovise.verbosity > 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def mkdir(path)
|
71
|
+
@node.log.execute("MKDIR: #{path}") if Inprovise.verbosity > 0
|
72
|
+
end
|
73
|
+
|
74
|
+
def exists?(path)
|
75
|
+
@node.log.execute("EXISTS?: #{path}") if Inprovise.verbosity > 0
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
def file?(path)
|
80
|
+
@node.log.execute("FILE?: #{path}") if Inprovise.verbosity > 0
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def directory?(path)
|
85
|
+
@node.log.execute("DIRECTORY?: #{path}") if Inprovise.verbosity > 0
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
def content(path)
|
90
|
+
@node.log.execute("READ: #{path}") if Inprovise.verbosity > 0
|
91
|
+
"READ: #{path}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def delete(path)
|
95
|
+
@node.log.execute("DELETE: #{path}") if Inprovise.verbosity > 0
|
96
|
+
end
|
97
|
+
|
98
|
+
def permissions(path)
|
99
|
+
@node.log.execute("PERMISSIONS: #{path}") if Inprovise.verbosity > 0
|
100
|
+
0
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_permissions(path, perm)
|
104
|
+
@node.log.execute("SETPERMISSIONS: #{path} #{perm}") if Inprovise.verbosity > 0
|
105
|
+
end
|
106
|
+
|
107
|
+
def owner(path)
|
108
|
+
@node.log.execute("OWNER: #{path}") if Inprovise.verbosity > 0
|
109
|
+
{:user => @user, :group => 'users'}
|
110
|
+
end
|
111
|
+
|
112
|
+
def set_owner(path, user, group=nil)
|
113
|
+
@node.log.execute("SET_OWNER: #{path} #{user} #{group}") if Inprovise.verbosity > 0
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
# create mock test helper
|
119
|
+
|
120
|
+
Inprovise::CmdHelper.define('test') do
|
121
|
+
|
122
|
+
def initialize(channel, sudo=false)
|
123
|
+
super(channel)
|
124
|
+
end
|
125
|
+
|
126
|
+
# platform properties
|
127
|
+
|
128
|
+
def admin_user
|
129
|
+
'root'
|
130
|
+
end
|
131
|
+
|
132
|
+
def env_reference(varname)
|
133
|
+
"\$#{varname}"
|
134
|
+
end
|
135
|
+
|
136
|
+
# generic command execution
|
137
|
+
|
138
|
+
def sudo
|
139
|
+
return self
|
140
|
+
end
|
141
|
+
|
142
|
+
# basic commands
|
143
|
+
|
144
|
+
def echo(arg)
|
145
|
+
run("echo #{arg}")
|
146
|
+
end
|
147
|
+
|
148
|
+
def cat(path)
|
149
|
+
begin
|
150
|
+
@channel.content(path)
|
151
|
+
rescue
|
152
|
+
run("cat #{path}")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def hash_for(path)
|
157
|
+
Digest::SHA1.hexdigest(run("sha1sum #{path}"))
|
158
|
+
end
|
159
|
+
|
160
|
+
def mkdir(path)
|
161
|
+
run("mkdir -p #{path}")
|
162
|
+
end
|
163
|
+
|
164
|
+
def exists?(path)
|
165
|
+
begin
|
166
|
+
@channel.exists?(path)
|
167
|
+
rescue
|
168
|
+
run(%{if [ -f #{path} ]; then echo "true"; else echo "false"; fi}).strip == 'true'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def file?(path)
|
173
|
+
begin
|
174
|
+
@channel.file?(path)
|
175
|
+
rescue
|
176
|
+
(run("stat --format=%f #{path}").chomp.hex & 0x8000) == 0x8000
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def directory?(path)
|
181
|
+
begin
|
182
|
+
@channel.file?(path)
|
183
|
+
rescue
|
184
|
+
(run("stat --format=%f #{path}").chomp.hex & 0x4000) == 0x4000
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def copy(from, to)
|
189
|
+
run("cp #{from} #{to}")
|
190
|
+
end
|
191
|
+
|
192
|
+
def delete(path)
|
193
|
+
begin
|
194
|
+
@channel.delete(path)
|
195
|
+
rescue
|
196
|
+
run("rm #{path}")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def permissions(path)
|
201
|
+
begin
|
202
|
+
@channel.permissions(path)
|
203
|
+
rescue
|
204
|
+
run("stat --format=%a #{path}").strip.to_i(8)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def set_permissions(path, perm)
|
209
|
+
begin
|
210
|
+
@channel.set_permissions(path, perm)
|
211
|
+
rescue
|
212
|
+
run("chmod -R #{sprintf("%o",perm)} #{path}")
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def owner(path)
|
217
|
+
begin
|
218
|
+
@channel.owner(path)
|
219
|
+
rescue
|
220
|
+
user, group = run("stat --format=%U:%G #{path}").chomp.split(":")
|
221
|
+
{:user => user, :group => group}
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def set_owner(path, user, group=nil)
|
226
|
+
begin
|
227
|
+
@channel.set_owner(path, user, group)
|
228
|
+
rescue
|
229
|
+
run(%{chown -R #{user}#{group ? ":#{group}" : ''} #{path}})
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def binary_exists?(bin)
|
234
|
+
run("which #{bin}") =~ /\/#{bin}/
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
data/test/vbox_test.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# VBox Script tests for Inprovise
|
2
|
+
#
|
3
|
+
# Author:: Martin Corino
|
4
|
+
# License:: Distributes under the same license as Ruby
|
5
|
+
|
6
|
+
require_relative 'test_helper'
|
7
|
+
|
8
|
+
describe Inprovise::VBox do
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
reset_script_index!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Inprovise::DSL do
|
15
|
+
it 'adds a VBox script' do
|
16
|
+
script = Inprovise::DSL.module_eval do
|
17
|
+
vbox 'myVbox' do
|
18
|
+
configuration({
|
19
|
+
:image => '/path/to/disk/image.qcow2',
|
20
|
+
:memory => 512,
|
21
|
+
:cpus => 1,
|
22
|
+
})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
script = Inprovise::ScriptIndex.default.get('myVbox')
|
26
|
+
script.name.must_equal 'myVbox'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'requires a configuration' do
|
30
|
+
assert_raises ArgumentError do
|
31
|
+
script = Inprovise::DSL.module_eval do
|
32
|
+
vbox 'myVbox' do
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inprovise-vbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Corino
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: inprovise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: VBox script extension for Inprovise
|
28
|
+
email:
|
29
|
+
- mcorino@remedy.nl
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- .travis.yml
|
36
|
+
- Gemfile
|
37
|
+
- README.md
|
38
|
+
- Rakefile.rb
|
39
|
+
- inprovise-vbox.gemspec
|
40
|
+
- lib/inprovise/vbox.rb
|
41
|
+
- lib/inprovise/vbox/vbox.rb
|
42
|
+
- lib/inprovise/vbox/version.rb
|
43
|
+
- test/fixtures/inprovise.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
- test/vbox_test.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
metadata: {}
|
49
|
+
post_install_message: ''
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.4.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Simple, easy and intuitive virtual machine provisioning
|
69
|
+
test_files:
|
70
|
+
- test/fixtures/inprovise.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
- test/vbox_test.rb
|