vagrant-openvz 0.0.2

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.
Files changed (37) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +39 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +54 -0
  6. data/Rakefile +1 -0
  7. data/Vagrantfile +30 -0
  8. data/box/centos-6-x86_64/VagrantFile +10 -0
  9. data/box/centos-6-x86_64/centos-6-x86_64.box +0 -0
  10. data/box/centos-6-x86_64/make_box.sh +1 -0
  11. data/box/centos-6-x86_64/metadata.json +3 -0
  12. data/lib/vagrant-openvz.rb +9 -0
  13. data/lib/vagrant-openvz/action.rb +165 -0
  14. data/lib/vagrant-openvz/action/boot.rb +21 -0
  15. data/lib/vagrant-openvz/action/check_created.rb +19 -0
  16. data/lib/vagrant-openvz/action/check_running.rb +19 -0
  17. data/lib/vagrant-openvz/action/create.rb +36 -0
  18. data/lib/vagrant-openvz/action/created.rb +20 -0
  19. data/lib/vagrant-openvz/action/destroy.rb +21 -0
  20. data/lib/vagrant-openvz/action/destroy_confirm.rb +15 -0
  21. data/lib/vagrant-openvz/action/fetch_ip.rb +19 -0
  22. data/lib/vagrant-openvz/action/forced_halt.rb +21 -0
  23. data/lib/vagrant-openvz/action/is_running.rb +18 -0
  24. data/lib/vagrant-openvz/action/message.rb +22 -0
  25. data/lib/vagrant-openvz/action/share_folders.rb +56 -0
  26. data/lib/vagrant-openvz/command/version.rb +11 -0
  27. data/lib/vagrant-openvz/config.rb +56 -0
  28. data/lib/vagrant-openvz/driver.rb +90 -0
  29. data/lib/vagrant-openvz/driver/cli.rb +81 -0
  30. data/lib/vagrant-openvz/errors.rb +29 -0
  31. data/lib/vagrant-openvz/plugin.rb +32 -0
  32. data/lib/vagrant-openvz/provider.rb +108 -0
  33. data/lib/vagrant-openvz/sudo_wrapper.rb +80 -0
  34. data/lib/vagrant-openvz/version.rb +5 -0
  35. data/vagrant-openvz.gemspec +23 -0
  36. data/vg.sh +4 -0
  37. metadata +114 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .vagrant/
2
+ pkg/
3
+ solo-setup.sh
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-openvz.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GIT
2
+ remote: git://github.com/mitchellh/vagrant.git
3
+ revision: 2c8cc95e7928f8d25fb76dbbd9e9132ef08b7649
4
+ specs:
5
+ vagrant (1.3.4.dev)
6
+ childprocess (~> 0.3.7)
7
+ erubis (~> 2.7.0)
8
+ i18n (~> 0.6.0)
9
+ log4r (~> 1.1.9)
10
+ net-scp (~> 1.1.0)
11
+ net-ssh (~> 2.6.6)
12
+
13
+ PATH
14
+ remote: .
15
+ specs:
16
+ vagrant-openvz (0.0.2)
17
+
18
+ GEM
19
+ remote: https://rubygems.org/
20
+ specs:
21
+ childprocess (0.3.9)
22
+ ffi (~> 1.0, >= 1.0.11)
23
+ erubis (2.7.0)
24
+ ffi (1.9.0)
25
+ i18n (0.6.5)
26
+ log4r (1.1.10)
27
+ net-scp (1.1.2)
28
+ net-ssh (>= 2.6.5)
29
+ net-ssh (2.6.8)
30
+ rake (10.1.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.3)
37
+ rake
38
+ vagrant!
39
+ vagrant-openvz!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aslan Brooke
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,54 @@
1
+ # Vagrant::Openvz
2
+
3
+ LINUX ONLY TECHNOLOGY.
4
+
5
+ This is primarily a provider plugin for vagrant. The provider integrates openvz with the normal actions associated with vagrant including: up, ssh, halt, destroy.
6
+
7
+ Successfully used in combination with the following vagrant plugins:
8
+
9
+ vagrant-omnibus
10
+ vagrant-berkshelf
11
+
12
+ ## Credits
13
+
14
+ Two other code bases contributed to the work involved in creating this plugin: vagrant-lxc, and vagrant itself.
15
+
16
+ ## Platforms
17
+
18
+ Centos 6.4
19
+ Others may work, though usability unknown as of now.
20
+
21
+ ## Installation without building
22
+
23
+ The plugin requires that you openvz and vagrant be installed. Then run the following from the command line which will install it from rubygems.org:
24
+
25
+ vagrant plugin install vagrant-openvz.
26
+
27
+ ## Boxes
28
+
29
+ Boxes are bare bones and currently depend on the templates provided by OpenVZ. You can download the one tested box from "box/centos-6-x86_64/centos-6-x86_64.box" in this source repository, however on first usage the actualy template for the box will be downloaded through openvz.
30
+
31
+ ## Building the plugin
32
+
33
+ 1. Download the source code (if your going to contribute see next section)
34
+ 2. Install bundler
35
+ 3. Navigate to the downloaded source code, and within the same folder as the "Gemfile" file run "bundle" to get depedencies.
36
+
37
+ Reference
38
+ * Book: Vagrant, up and running; Chapter 7; Section "Plugi-In Development Basics"
39
+
40
+ ## Contributing
41
+
42
+ During development on Centos 6(.4), in order to use: "bundle exec vagrant box add" I had to download the latest version of vagrant. Track down "bsdtar" and put it in a new folder, then add the folder path to the PATH. Then export it. This way the functionality would work properly.
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
50
+ ## ROADMAP (Features not yet added).
51
+
52
+ * Port Forwarding.
53
+ * Improve usage of env[:ui] logging.
54
+ * Tokenize all hardcoded text.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Vagrantfile ADDED
@@ -0,0 +1,30 @@
1
+ Vagrant.require_plugin "vagrant-openvz"
2
+
3
+ $script = <<SCRIPT
4
+ echo I am provisioning...
5
+ date > /etc/vagrant_provisioned_at
6
+ SCRIPT
7
+
8
+ Vagrant.configure('2') do |config|
9
+
10
+ config.vm.box = "centos-6-x86_64"
11
+
12
+ config.vm.define "vz1" do |vm_vz1|
13
+ vm_vz1.vm.provider :openvz do |openvz|
14
+ openvz.vzctid="1"
15
+ openvz.physpages="0:1G"
16
+ openvz.hostname="vz1"
17
+ openvz.ipadd="192.168.101.1"
18
+ openvz.nameserver="8.8.8.8"
19
+ openvz.diskspace="1000000:1100000"
20
+ openvz.diskinodes="100000:101000"
21
+ openvz.quotatime="600"
22
+ openvz.pubkey="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
23
+ end
24
+
25
+ vm_vz1.vm.provision "shell", inline: $script
26
+
27
+ end
28
+
29
+
30
+ end
@@ -0,0 +1,10 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.provider :openvz do |ovz|
3
+ ovz.template = "centos-6-x86_64.tar.gz"
4
+ ovz.physpages = "0:512MB"
5
+ ovz.nameserver = "8.8.8.8"
6
+ ovz.diskspace = "2000000:2100000"
7
+ ovz.diskinodes = "150000:1510000"
8
+ ovz.quotatime = "600"
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ tar czf centos-6-x86_64.box VagrantFile metadata.json
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "openvz"
3
+ }
@@ -0,0 +1,9 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "This plugin must run within Vagrant."
5
+ end
6
+
7
+ require "vagrant-openvz/version"
8
+ require "vagrant-openvz/plugin"
9
+
@@ -0,0 +1,165 @@
1
+ require 'vagrant-openvz/action/boot'
2
+ require 'vagrant-openvz/action/created'
3
+ require 'vagrant-openvz/action/create'
4
+ require 'vagrant-openvz/action/is_running.rb'
5
+ require 'vagrant-openvz/action/destroy'
6
+ require 'vagrant-openvz/action/destroy_confirm.rb'
7
+ require 'vagrant-openvz/action/forced_halt.rb'
8
+ require 'vagrant-openvz/action/message.rb'
9
+ require 'vagrant-openvz/action/fetch_ip.rb'
10
+ require 'vagrant-openvz/action/check_running.rb'
11
+ require 'vagrant-openvz/action/check_created.rb'
12
+ require 'vagrant-openvz/action/share_folders.rb'
13
+
14
+ require "log4r"
15
+
16
+ begin
17
+ require "vagrant/action/builder"
18
+ rescue LoadError
19
+ raise "This plugin must run within Vagrant."
20
+ end
21
+
22
+ module VagrantPlugins
23
+ module Openvz
24
+ module Action
25
+
26
+ # This action brings the machine up from nothing, including creating the
27
+ # container, and booting.
28
+ def self.action_up
29
+ Vagrant::Action::Builder.new.tap do |bldr|
30
+ bldr.use Vagrant::Action::Builtin::ConfigValidate
31
+ bldr.use Vagrant::Action::Builtin::Call, Created do |env, intern_bldr|
32
+ # If the VM is NOT created yet, then do the setup steps
33
+ if !env[:result]
34
+ intern_bldr.use Vagrant::Action::Builtin::HandleBoxUrl
35
+ intern_bldr.use Create
36
+ end
37
+ end
38
+ bldr.use action_start
39
+ end
40
+ end
41
+
42
+ # This action starts a container, assuming it is already created and exists.
43
+ # A precondition of this action is that the container exists.
44
+ def self.action_start
45
+ Vagrant::Action::Builder.new.tap do |bldr|
46
+ bldr.use Vagrant::Action::Builtin::ConfigValidate
47
+ bldr.use Vagrant::Action::Builtin::Call, IsRunning do |env, intern_bldr|
48
+ # If the VM is running, then our work here is done, exit
49
+ next if env[:result]
50
+ intern_bldr.use action_boot
51
+ end
52
+ end
53
+ end
54
+
55
+ # This action boots the VM, assuming the VM is in a state that requires
56
+ # a bootup (i.e. not saved).
57
+ def self.action_boot
58
+ Vagrant::Action::Builder.new.tap do |bldr|
59
+ bldr.use Vagrant::Action::Builtin::Provision
60
+ bldr.use Vagrant::Action::Builtin::EnvSet, :port_collision_repair => true
61
+ bldr.use Vagrant::Action::Builtin::HandleForwardedPortCollisions
62
+ bldr.use ShareFolders
63
+ bldr.use Vagrant::Action::Builtin::SetHostname
64
+ #TODO: Port forwarding.
65
+ bldr.use Boot
66
+ bldr.use Vagrant::Action::Builtin::WaitForCommunicator
67
+ end
68
+ end
69
+
70
+ # This is the action that is primarily responsible for halting
71
+ # the virtual machine, gracefully or by force.
72
+ def self.action_halt
73
+ logger = Log4r::Logger.new("vagrant::provider::openvz")
74
+ Vagrant::Action::Builder.new.tap do |bldr|
75
+ bldr.use Vagrant::Action::Builtin::Call, Created do |env, intern_bldr|
76
+ logger.debug("In Action::action_halt, env[:result]=#{env[:result]}")
77
+ if env[:result]
78
+ #TODO: Clear forwarded ports.
79
+ #TODO: Remove Temporary Files
80
+ #TODO: Graceful halt
81
+ intern_bldr.use ForcedHalt
82
+ else
83
+ intern_bldr.use Message, :not_created
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ # This is the action that is primarily responsible for completely
90
+ # freeing the resources of the underlying virtual machine.
91
+ def self.action_destroy
92
+ Vagrant::Action::Builder.new.tap do |bldr|
93
+ bldr.use Vagrant::Action::Builtin::Call, Created do |env1, intern_bldr|
94
+ if !env1[:result]
95
+ intern_bldr.use Message, :not_created
96
+ next
97
+ end
98
+
99
+ intern_bldr.use Vagrant::Action::Builtin::Call, DestroyConfirm do |env2, intern2_bldr|
100
+ if env2[:result]
101
+ intern2_bldr.use Vagrant::Action::Builtin::ConfigValidate
102
+ intern2_bldr.use Vagrant::Action::Builtin::EnvSet, :force_halt => true
103
+ intern2_bldr.use action_halt
104
+ intern2_bldr.use Destroy
105
+ #TODO: Use Vagrant::Action::Builtin::ProvisionerCleanup (vagrant 1.3+)
106
+ else
107
+ intern2_bldr.use Message, :will_not_destroy
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ # This action is called to read the IP of the container. The IP found
115
+ # is expected to be put into the `:machine_ip` key.
116
+ def self.action_fetch_ip
117
+ Vagrant::Action::Builder.new.tap do |bldr|
118
+ bldr.use Vagrant::Action::Builtin::ConfigValidate
119
+ bldr.use FetchIp
120
+ end
121
+ end
122
+
123
+ # This is the action that will exec into an SSH shell.
124
+ def self.action_ssh
125
+ Vagrant::Action::Builder.new.tap do |bldr|
126
+ bldr.use CheckCreated
127
+ bldr.use CheckRunning
128
+ bldr.use Vagrant::Action::Builtin::SSHExec
129
+ end
130
+ end
131
+
132
+ # This is the action that will run a single SSH command.
133
+ def self.action_ssh_run
134
+ Vagrant::Action::Builder.new.tap do |bldr|
135
+ bldr.use CheckCreated
136
+ bldr.use CheckRunning
137
+ bldr.use Vagrant::Action::Builtin::SSHRun
138
+ end
139
+ end
140
+
141
+ # This action just runs the provisioners on the machine.
142
+ def self.action_provision
143
+ Vagrant::Action::Builder.new.tap do |bldr|
144
+ bldr.use Vagrant::Action::Builtin::ConfigValidate
145
+ bldr.use Vagrant::Action::Builtin::Call, Created do |env1, intern_bldr|
146
+ if !env1[:result]
147
+ intern_bldr.use Message, :not_created
148
+ next
149
+ end
150
+
151
+ b2.use Vagrant::Action::Builtin::Call, IsRunning do |env2, intern2_bldr|
152
+ if !env2[:result]
153
+ intern2_bldr.use Message, :not_running
154
+ next
155
+ end
156
+
157
+ intern2_bldr.use Vagrant::Action::Builtin::Provision
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module Openvz
3
+ module Action
4
+ class Boot
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ @env = env
11
+
12
+ config = env[:machine].provider_config
13
+
14
+ env[:machine].provider.driver.start(config.vzctid,config.pubkey)
15
+
16
+ @app.call env
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Openvz
3
+ module Action
4
+ class CheckCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env[:machine].state.id == :not_created
11
+ raise Vagrant::Errors::VMNotCreatedError
12
+ end
13
+
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Openvz
3
+ module Action
4
+ class CheckRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env[:machine].state.id != :exist_mounted_running
11
+ raise Vagrant::Errors::VMNotRunningError
12
+ end
13
+
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ module VagrantPlugins
2
+ module Openvz
3
+ module Action
4
+ class Create
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ config = env[:machine].provider_config
11
+ box = env[:machine].box
12
+
13
+ container_name = "vz#{config.vzctid}"
14
+
15
+ settings={}
16
+ settings.merge!(:physpages => config.physpages)
17
+ settings.merge!(:hostname => container_name)
18
+ settings.merge!(:ipadd => config.ipadd)
19
+ settings.merge!(:nameserver => config.nameserver)
20
+ settings.merge!(:diskspace => config.diskspace)
21
+ settings.merge!(:diskinodes => config.diskinodes)
22
+ settings.merge!(:quotatime => config.quotatime)
23
+ settings.merge!(:template_name => "#{box.name}")
24
+
25
+ env[:machine].provider.driver.create(
26
+ container_name,config.vzctid,settings
27
+ )
28
+
29
+ env[:machine].id = container_name
30
+
31
+ @app.call env
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end