opennebula-provider 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +57 -0
  6. data/Rakefile +3 -0
  7. data/boxes/dummy/README.md +11 -0
  8. data/boxes/dummy/dummy.box +0 -0
  9. data/boxes/dummy/metadata.json +3 -0
  10. data/gist.sh +25 -0
  11. data/github.sh +25 -0
  12. data/lib/opennebula-provider/action/check_state.rb +28 -0
  13. data/lib/opennebula-provider/action/connect_opennebula.rb +24 -0
  14. data/lib/opennebula-provider/action/create.rb +20 -0
  15. data/lib/opennebula-provider/action/destroy.rb +19 -0
  16. data/lib/opennebula-provider/action/read_ssh_info.rb +24 -0
  17. data/lib/opennebula-provider/action/sync_folders.rb +97 -0
  18. data/lib/opennebula-provider/action.rb +75 -0
  19. data/lib/opennebula-provider/config.rb +40 -0
  20. data/lib/opennebula-provider/helpers/rocci.rb +91 -0
  21. data/lib/opennebula-provider/plugin.rb +21 -0
  22. data/lib/opennebula-provider/provider.rb +30 -0
  23. data/lib/opennebula-provider/version.rb +5 -0
  24. data/lib/opennebula-provider.rb +12 -0
  25. data/locales/en.yml +44 -0
  26. data/opennebula-provider.gemspec +52 -0
  27. data/rubocop-todo.yml +119 -0
  28. data/rubocop.yml +27 -0
  29. data/test/rsyncme/1.file +0 -0
  30. data/test/rsyncme/10.file +0 -0
  31. data/test/rsyncme/2.file +0 -0
  32. data/test/rsyncme/3.file +0 -0
  33. data/test/rsyncme/4.file +0 -0
  34. data/test/rsyncme/5.file +0 -0
  35. data/test/rsyncme/6.file +0 -0
  36. data/test/rsyncme/7.file +0 -0
  37. data/test/rsyncme/8.file +0 -0
  38. data/test/rsyncme/9.file +0 -0
  39. data/test/test_rsa +27 -0
  40. data/to_github.sh +4 -0
  41. data/to_gitlab.sh +4 -0
  42. metadata +151 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 779d5d81948ae21453f701452543fae1f62e5cfa
4
+ data.tar.gz: 0e8536b41b05d86f5d97ec8c5ef34c69b1b02f09
5
+ SHA512:
6
+ metadata.gz: da9a502cf68a5df238e4ee9e4c33478d1f580ed8d3fc9dfe2b868710f3d8bab4745c4f430b49dd75427f0e7567b8d9193aa179fd0782bba15e8ce776fcbade81
7
+ data.tar.gz: 7e396c173cb436084c6092f736e6a7b29b7f430a3af797eb17caaff9c4e253c4b4660d6645a5f72d5ede493006c6fdd2f7b70cc1c2e5a25870ded02e68835f0c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'occi-api'
4
+
5
+ group :development do
6
+ gem 'vagrant', :git => 'https://github.com/mitchellh/vagrant.git'
7
+ gem 'vagrant-spec', :git => 'https://github.com/mitchellh/vagrant-spec.git'
8
+ end
9
+
10
+ group :plugins do
11
+ gem 'opennebula-provider', path: '.'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 eucher
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,57 @@
1
+ # OpenNebula::Provider
2
+
3
+ This is a Vagrant 1.5 plugin that add an OpenNebula provider to Vagrant.
4
+
5
+ **NOTE:** This plugin requires occi-api gem and works with rOCCI-server.
6
+
7
+ ## Features
8
+
9
+ * Boot OpenNebula instances
10
+ * SSH into instances
11
+ * Provision the instances with any built-in Vagrant provisioner
12
+ * Minimal synced folder support via `rsync`
13
+
14
+ ## Installation
15
+
16
+ ```
17
+ $ vagrant plugin install opennebula-provider
18
+ ...
19
+ $ vagrant up --provider=opennebula
20
+ ...
21
+ ```
22
+
23
+ ## Box Format
24
+
25
+ TODO: Write box format creation instruction here.
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ Vagrant.configure("2") do |config|
31
+ config.vm.box = "dummy"
32
+
33
+ config.vm.provider :opennebula do |one, override|
34
+ one.endpoint = 'http://rOCCI-server:PORT'
35
+ one.username = 'YOUR NAME'
36
+ one.password = 'YOUR PASSWORD'
37
+ one.os_tpl = 'OS template'
38
+ end
39
+ end
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ * `endpoint` - rOCCI server url
45
+ * `username` - OpenNebula username
46
+ * `password` - OpenNebula password
47
+ * `auth` - OpenNebula authorization method, default: basic
48
+ * `os_tpl` - OpenNebula os template
49
+ * `resource_tpl` - OpenNebula resource template, default: small
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( http://github.com/<my-github-username>/opennebula-provider/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ # Dummy box
2
+
3
+ Vagrant providers each require a custom provider-specific box format. This folder
4
+ contains a "dummy" box that allows you to use the plugin without the need to create
5
+ a custom base box.
6
+
7
+ To turn this into a "box", run:
8
+
9
+ ```
10
+ tar cvzf dummy.box ./metadata.json
11
+ ```
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "opennebula"
3
+ }
data/gist.sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+
3
+ git filter-branch --env-filter '
4
+
5
+ an="$GIT_AUTHOR_NAME"
6
+ am="$GIT_AUTHOR_EMAIL"
7
+ cn="$GIT_COMMITTER_NAME"
8
+ cm="$GIT_COMMITTER_EMAIL"
9
+
10
+ if [ "$GIT_COMMITTER_EMAIL" = "cyber@sibnet.ru" ]
11
+ then
12
+ cn="Cherdancev Evgeni"
13
+ cm="joe@netpost.ru"
14
+ fi
15
+ if [ "$GIT_AUTHOR_EMAIL" = "cyber@sibnet.ru" ]
16
+ then
17
+ an="Cherdancev Evgeni"
18
+ am="joe@netpost.ru"
19
+ fi
20
+
21
+ export GIT_AUTHOR_NAME="$an"
22
+ export GIT_AUTHOR_EMAIL="$am"
23
+ export GIT_COMMITTER_NAME="$cn"
24
+ export GIT_COMMITTER_EMAIL="$cm"
25
+ '
data/github.sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+
3
+ git filter-branch -f --env-filter '
4
+
5
+ an="$GIT_AUTHOR_NAME"
6
+ am="$GIT_AUTHOR_EMAIL"
7
+ cn="$GIT_COMMITTER_NAME"
8
+ cm="$GIT_COMMITTER_EMAIL"
9
+
10
+ if [ "$GIT_COMMITTER_EMAIL" = "joe@netpost.ru" ]
11
+ then
12
+ cn="eucher"
13
+ cm="cyber@sibnet.ru"
14
+ fi
15
+ if [ "$GIT_AUTHOR_EMAIL" = "joe@netpost.ru" ]
16
+ then
17
+ an="eucher"
18
+ am="cyber@sibnet.ru"
19
+ fi
20
+
21
+ export GIT_AUTHOR_NAME="$an"
22
+ export GIT_AUTHOR_EMAIL="$am"
23
+ export GIT_COMMITTER_NAME="$cn"
24
+ export GIT_COMMITTER_EMAIL="$cm"
25
+ '
@@ -0,0 +1,28 @@
1
+ require 'opennebula-provider/helpers/rocci'
2
+
3
+ module VagrantPlugins
4
+ module OpenNebulaProvider
5
+ module Action
6
+ class CheckState
7
+ include Helpers::Rocci
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::check_state')
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_state] = check_state(env[:rocci], env[:machine])
16
+ @logger.info I18n.t('opennebula_provider.info.state', state: env[:machine_state])
17
+ @app.call(env)
18
+ end
19
+
20
+ def check_state(rocci, machine)
21
+ return :not_created if machine.id.nil?
22
+ state = rocci.machine_state(machine.id)
23
+ state.to_sym
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'opennebula-provider/helpers/rocci'
2
+
3
+ module VagrantPlugins
4
+ module OpenNebulaProvider
5
+ module Action
6
+ class ConnectOpenNebula
7
+ include Helpers::Rocci
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::connect_opennebula')
12
+ end
13
+
14
+ def call(env)
15
+ @logger.info('Connecting to OpenNebula')
16
+ rocci = rocci(env[:machine].provider_config)
17
+ env[:rocci] = rocci
18
+
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module OpenNebulaProvider
3
+ module Action
4
+ class Create
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::create')
8
+ end
9
+
10
+ def call(env)
11
+ @logger.info I18n.t('opennebula_provider.info.creating')
12
+ result = env[:rocci].compute
13
+ env[:rocci].wait_for_event(env, result)
14
+ env[:machine].id = result
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module OpenNebulaProvider
3
+ module Action
4
+ class Destroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::create')
8
+ end
9
+
10
+ def call(env)
11
+ @logger.info I18n.t('opennebula_provider.info.destroying', machine: env[:machine].id)
12
+ env[:rocci].delete(env[:machine].id)
13
+ env[:machine].id = nil
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module VagrantPlugins
2
+ module OpenNebulaProvider
3
+ module Action
4
+ class ReadSSHInfo
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::read_ssh_info')
8
+ end
9
+
10
+ def call(env)
11
+ env[:machine_ssh_info] = read_ssh_info(env[:rocci], env[:machine])
12
+ @app.call(env)
13
+ end
14
+
15
+ def read_ssh_info(rocci, machine)
16
+ return nil if machine.id.nil?
17
+
18
+ host = rocci.ssh_info(machine.id)
19
+ { host: host, port: 22 }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,97 @@
1
+ require 'vagrant/util/subprocess'
2
+ require 'vagrant/util/which'
3
+
4
+ module VagrantPlugins
5
+ module OpenNebulaProvider
6
+ module Action
7
+ class SyncFolders
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::sync_folders')
11
+ end
12
+
13
+ def call(env)
14
+ @app.call(env)
15
+
16
+ ssh_info = env[:machine].ssh_info
17
+
18
+ unless Vagrant::Util::Which.which('rsync')
19
+ env[:ui].warn(I18n.t('opennebula_provider.info.rsync_not_found_warning', side: 'host'))
20
+ return
21
+ end
22
+
23
+ if env[:machine].communicate.execute('which rsync', error_check: false) != 0
24
+ env[:ui].warn(I18n.t('opennebula_provider.info.rsync_not_found_warning', side: 'guest'))
25
+ return
26
+ end
27
+
28
+ env[:machine].config.vm.synced_folders.each do |id, data|
29
+ # Ignore disabled shared folders
30
+ next if data[:disabled]
31
+
32
+ hostpath = File.expand_path(data[:hostpath], env[:root_path])
33
+ guestpath = data[:guestpath]
34
+
35
+ # Make sure there is a trailing slash on the host path to
36
+ # avoid creating an additional directory with rsync
37
+ hostpath = "#{hostpath}/" if hostpath !~ /\/$/
38
+
39
+ # on windows rsync.exe requires cygdrive-style paths
40
+ if Vagrant::Util::Platform.windows?
41
+ hostpath = hostpath.gsub(/^(?<disk>\w):/) { "/cygdrive/#{:disk}" }
42
+ end
43
+ env[:ui].info(I18n.t('opennebula_provider.info.rsyncing', hostpath: hostpath, guestpath: guestpath))
44
+
45
+ # Create the host path if it doesn't exist and option flag is set
46
+ if data[:create]
47
+ begin
48
+ FileUtils.mkdir_p(hostpath)
49
+ rescue => err
50
+ raise Errors::MkdirError,
51
+ hostpath: hostpath,
52
+ err: err
53
+ end
54
+ end
55
+
56
+ # Create the guest path
57
+ env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
58
+ env[:machine].communicate.sudo(
59
+ "chown -R #{ssh_info[:username]} '#{guestpath}'")
60
+
61
+ # collect rsync excludes specified :rsync_excludes=>['path1',...] in synced_folder options
62
+ excludes = ['.vagrant/', 'Vagrantfile', *Array(data[:rsync_excludes])].uniq
63
+
64
+ # Rsync over to the guest path using the SSH info
65
+ command = [
66
+ 'rsync', '--verbose', '--archive', '-z',
67
+ *excludes.map { |e| ['--exclude', e] }.flatten,
68
+ '-e', "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no #{ssh_key_options(ssh_info)}",
69
+ hostpath,
70
+ "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
71
+
72
+ # we need to fix permissions when using rsync.exe on windows, see
73
+ # http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
74
+ if Vagrant::Util::Platform.windows?
75
+ command.insert(1, '--chmod', 'ugo=rwX')
76
+ end
77
+
78
+ r = Vagrant::Util::Subprocess.execute(*command)
79
+ if r.exit_code != 0
80
+ fail Errors::RsyncError,
81
+ guestpath: guestpath,
82
+ hostpath: hostpath,
83
+ stderr: r.stderr
84
+ end
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def ssh_key_options(ssh_info)
91
+ # Ensure that `private_key_path` is an Array (for Vagrant < 1.4)
92
+ Array(ssh_info[:private_key_path]).map { |path| "-i '#{path}' " }.join
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,75 @@
1
+ require_relative 'action/check_state'
2
+ require_relative 'action/connect_opennebula'
3
+ require_relative 'action/create'
4
+ require_relative 'action/destroy'
5
+ require_relative 'action/read_ssh_info'
6
+ require_relative 'action/sync_folders'
7
+
8
+ module VagrantPlugins
9
+ module OpenNebulaProvider
10
+ module Action
11
+ include Vagrant::Action::Builtin
12
+
13
+ def self.destroy
14
+ Vagrant::Action::Builder.new.tap do |b|
15
+ b.use Call, DestroyConfirm do |env, b1|
16
+ b1.use ConfigValidate
17
+ b1.use ConnectOpenNebula
18
+ b1.use Call, CheckState do |env2, b2|
19
+ case env2[:machine_state]
20
+ when :active
21
+ b2.use Destroy
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.up
29
+ Vagrant::Action::Builder.new.tap do |b|
30
+ b.use ConfigValidate
31
+ b.use ConnectOpenNebula
32
+ b.use Call, CheckState do |env, b1|
33
+ case env[:machine_state]
34
+ when :active
35
+ p 'active' # TODO, use logger
36
+ when :not_created
37
+ b1.use Create
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.check_state
44
+ Vagrant::Action::Builder.new.tap do |b|
45
+ b.use ConfigValidate
46
+ b.use ConnectOpenNebula
47
+ b.use CheckState
48
+ end
49
+ end
50
+
51
+ def self.provision
52
+ Vagrant::Action::Builder.new.tap do |b|
53
+ b.use ConfigValidate
54
+ b.use Provision
55
+ b.use SyncFolders
56
+ end
57
+ end
58
+
59
+ def self.read_ssh_info
60
+ Vagrant::Action::Builder.new.tap do |b|
61
+ b.use ConfigValidate
62
+ b.use ConnectOpenNebula
63
+ b.use ReadSSHInfo
64
+ end
65
+ end
66
+
67
+ def self.ssh
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use SSHExec
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,40 @@
1
+ module VagrantPlugins
2
+ module OpenNebulaProvider
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :endpoint
5
+ attr_accessor :auth
6
+ attr_accessor :username
7
+ attr_accessor :password
8
+ attr_accessor :os_tpl
9
+ attr_accessor :resource_tpl
10
+
11
+ def initialize
12
+ @endpoint = UNSET_VALUE
13
+ @auth = UNSET_VALUE
14
+ @username = UNSET_VALUE
15
+ @password = UNSET_VALUE
16
+ @os_tpl = UNSET_VALUE
17
+ @resource_tpl = UNSET_VALUE
18
+ end
19
+
20
+ def finalize!
21
+ @endpoint = nil if @endpoint == UNSET_VALUE
22
+ @auth = 'basic' if @auth == UNSET_VALUE
23
+ @username = nil if @username == UNSET_VALUE
24
+ @password = nil if @password == UNSET_VALUE
25
+ @os_tpl = nil if @os_tpl == UNSET_VALUE
26
+ @resource_tpl = 'small' if @resource_tpl == UNSET_VALUE
27
+ end
28
+
29
+ def validate(machine)
30
+ errors = []
31
+ errors << I18n.t('opennebula_provider.config.endpoint') unless @endpoint
32
+ errors << I18n.t('opennebula_provider.config.username') unless @username
33
+ errors << I18n.t('opennebula_provider.config.password') unless @password
34
+ errors << I18n.t('opennebula_provider.config.resource_tpl') unless @resource_tpl
35
+
36
+ { 'OpenNebula provider' => errors }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,91 @@
1
+ require 'occi-api'
2
+
3
+ module VagrantPlugins
4
+ module OpenNebulaProvider
5
+ module Helpers
6
+ module Rocci
7
+ def rocci(provider_config)
8
+ @rocci ||= RocciApi.new(@machine, provider_config)
9
+ end
10
+ end
11
+
12
+ class RocciApi
13
+ include Vagrant::Util::Retryable
14
+
15
+ def initialize(machine, provider_config)
16
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula::helpers::rocciapi')
17
+ @config = provider_config
18
+ options = {
19
+ endpoint: @config.endpoint,
20
+ auth: {
21
+ type: @config.auth,
22
+ username: @config.username,
23
+ password: @config.password
24
+ }
25
+ # :log => {
26
+ #:out => STDERR,
27
+ #:level => Occi::Api::Log::DEBUG
28
+ # }
29
+ }
30
+ @rocci = Occi::Api::Client::ClientHttp.new(options)
31
+ end
32
+
33
+ def compute
34
+ @logger.info 'compute!'
35
+ cmpt = @rocci.get_resource 'compute'
36
+ os = @rocci.get_mixin @config.os_tpl, 'os_tpl'
37
+ size = @rocci.get_mixin @config.resource_tpl, 'resource_tpl'
38
+ cmpt.mixins << os << size
39
+ cmpt.title = 'testROCCIvagrant'
40
+ cmpt_loc = @rocci.create cmpt
41
+ @logger.info "Location of new compute resource: #{cmpt_loc}"
42
+ cmpt_loc
43
+ end
44
+
45
+ def delete(id)
46
+ @logger.info 'delete!'
47
+ @rocci.delete id
48
+ end
49
+
50
+ def describe_resource(resource)
51
+ @rocci.describe resource
52
+ end
53
+
54
+ def machine_state(id)
55
+ if id
56
+ desc = @rocci.describe id
57
+ return :not_created if desc.empty?
58
+ return desc.first.attributes.occi.compute.state
59
+ else
60
+ return :not_created
61
+ end
62
+ end
63
+
64
+ def ssh_info(id)
65
+ desc = describe_resource(id)
66
+ networkinterface = desc.first.links.map do |link|
67
+ if link.attributes.occi.key?(:networkinterface)
68
+ link.attributes.occi.networkinterface
69
+ else
70
+ nil
71
+ end
72
+ end.reject! { |n| n.nil? }.first
73
+ networkinterface[:address]
74
+ end
75
+
76
+ def wait_for_event(env, id)
77
+ retryable(tries: 120, sleep: 10) do
78
+ # stop waiting if interrupted
79
+ next if env[:interrupted]
80
+
81
+ # check event status
82
+ result = machine_state(id)
83
+
84
+ yield result if block_given?
85
+ fail 'not ready' if result != 'active'
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'version'
2
+
3
+ require 'vagrant'
4
+
5
+ module VagrantPlugins
6
+ module OpenNebulaProvider
7
+ class Plugin < Vagrant.plugin('2')
8
+ name 'opennebula-provider'
9
+
10
+ provider(:opennebula) do
11
+ require_relative 'provider'
12
+ Provider
13
+ end
14
+
15
+ config(:opennebula, :provider) do
16
+ require_relative 'config'
17
+ Config
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'action'
2
+
3
+ module VagrantPlugins
4
+ module OpenNebulaProvider
5
+ class Provider < Vagrant.plugin('2', :provider)
6
+ def initialize(machine)
7
+ @logger = Log4r::Logger.new('vagrant::provider::opennebula')
8
+ @machine = machine
9
+ end
10
+
11
+ def action(name)
12
+ return Action.send(name) if Action.respond_to?(name)
13
+ nil
14
+ end
15
+
16
+ def ssh_info
17
+ env = @machine.action('read_ssh_info')
18
+ env[:machine_ssh_info]
19
+ end
20
+
21
+ def state
22
+ env = @machine.action('check_state')
23
+ state = env[:machine_state]
24
+ short = I18n.t("opennebula_provider.states.short_#{state}")
25
+ long = I18n.t("opennebula_provider.states.long_#{state}")
26
+ Vagrant::MachineState.new(state, short, long)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module OpenNebulaProvider
3
+ VERSION = '0.1.4'
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'opennebula-provider/plugin'
2
+
3
+ module VagrantPlugins
4
+ module OpenNebulaProvider
5
+ def self.source_root
6
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
7
+ end
8
+
9
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
10
+ I18n.reload!
11
+ end
12
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,44 @@
1
+ en:
2
+ opennebula_provider:
3
+ info:
4
+ connecting: |-
5
+ Connecting to OpenNebula
6
+ creating: |-
7
+ Creating a new instance...
8
+ not_created: |-
9
+ Instance is not created
10
+ destroying: |-
11
+ Machine %{machine} is destroying...
12
+ state: |-
13
+ Machine state is %{state}
14
+ rsyncing: |-
15
+ Rsyncing folder: %{hostpath} => %{guestpath}...
16
+ rsync_not_found_warning: |-
17
+ Warning! Folder sync disabled because the rsync binary is missing in the %{side}.
18
+ Make sure rsync is installed and the binary can be found in the PATH.
19
+
20
+ states:
21
+ short_not_created: |-
22
+ not created
23
+ long_not_created: |-
24
+ The OpenNebula instance is not created
25
+
26
+ short_active: |-
27
+ active
28
+ long_active: |-
29
+ Instance is active
30
+
31
+ short_running: |-
32
+ running
33
+ long_running: |-
34
+ The OpenNebula instance is running
35
+
36
+ config:
37
+ endpoint: |-
38
+ rOCCI-server endpoint is not set
39
+ username: |-
40
+ Username is not set
41
+ password: |-
42
+ Password is not set
43
+ resource_tpl: |-
44
+ A resource template must defined via "resource_tpl"
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+ $:.unshift File.expand_path('../lib', __FILE__)
3
+ require 'opennebula-provider/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'opennebula-provider'
7
+ spec.version = VagrantPlugins::OpenNebulaProvider::VERSION
8
+ spec.authors = ['eucher']
9
+ spec.email = ['cyber@sibnet.ru']
10
+ spec.description = %q{OpenNebula provider for Vagrant}
11
+ spec.summary = spec.description
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ root_path = File.dirname(__FILE__)
16
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
17
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
18
+ gitignore_path = File.join(root_path, ".gitignore")
19
+ gitignore = File.readlines(gitignore_path)
20
+ gitignore.map! { |line| line.chomp.strip }
21
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
22
+
23
+ unignored_files = all_files.reject do |file|
24
+ # Ignore any directories, the gemspec only cares about files
25
+ next true if File.directory?(file)
26
+
27
+ # Ignore any paths that match anything in the gitignore. We do
28
+ # two tests here:
29
+ #
30
+ # - First, test to see if the entire path matches the gitignore.
31
+ # - Second, match if the basename does, this makes it so that things
32
+ # like '.DS_Store' will match sub-directories too (same behavior
33
+ # as git).
34
+ #
35
+ gitignore.any? do |ignore|
36
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
37
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
38
+ end
39
+ end
40
+
41
+ spec.files = unignored_files
42
+
43
+ spec.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
44
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
45
+ spec.require_paths = ["lib"]
46
+
47
+ spec.add_runtime_dependency 'occi-api', '~> 4.2'
48
+
49
+ spec.add_development_dependency 'bundler', '~> 1.3'
50
+ spec.add_development_dependency 'rake'
51
+ spec.add_development_dependency 'rspec'
52
+ end
data/rubocop-todo.yml ADDED
@@ -0,0 +1,119 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-04-21 12:09:58 +0700 using RuboCop version 0.20.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ # Cop supports --auto-correct.
10
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
11
+ AlignParameters:
12
+ Enabled: false
13
+
14
+ # Offense count: 1
15
+ # Cop supports --auto-correct.
16
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
17
+ BracesAroundHashParameters:
18
+ Enabled: false
19
+
20
+ # Offense count: 2
21
+ CyclomaticComplexity:
22
+ Max: 8
23
+
24
+ # Offense count: 1
25
+ # Cop supports --auto-correct.
26
+ DeprecatedHashMethods:
27
+ Enabled: false
28
+
29
+ # Offense count: 14
30
+ Documentation:
31
+ Enabled: false
32
+
33
+ # Offense count: 5
34
+ # Cop supports --auto-correct.
35
+ EmptyLinesAroundBody:
36
+ Enabled: false
37
+
38
+ # Offense count: 1
39
+ # Configuration parameters: Exclude.
40
+ FileName:
41
+ Enabled: false
42
+
43
+ # Offense count: 14
44
+ # Cop supports --auto-correct.
45
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
46
+ HashSyntax:
47
+ Enabled: false
48
+
49
+ # Offense count: 7
50
+ # Cop supports --auto-correct.
51
+ LeadingCommentSpace:
52
+ Enabled: false
53
+
54
+ # Offense count: 17
55
+ LineLength:
56
+ Max: 122
57
+
58
+ # Offense count: 4
59
+ # Configuration parameters: CountComments.
60
+ MethodLength:
61
+ Max: 40
62
+
63
+ # Offense count: 1
64
+ MultilineBlockChain:
65
+ Enabled: false
66
+
67
+ # Offense count: 4
68
+ # Cop supports --auto-correct.
69
+ NegatedIf:
70
+ Enabled: false
71
+
72
+ # Offense count: 1
73
+ # Cop supports --auto-correct.
74
+ NilComparison:
75
+ Enabled: false
76
+
77
+ # Offense count: 1
78
+ # Cop supports --auto-correct.
79
+ PerlBackrefs:
80
+ Enabled: false
81
+
82
+ # Offense count: 6
83
+ # Cop supports --auto-correct.
84
+ # Configuration parameters: AllowMultipleReturnValues.
85
+ RedundantReturn:
86
+ Enabled: false
87
+
88
+ # Offense count: 2
89
+ # Cop supports --auto-correct.
90
+ RedundantSelf:
91
+ Enabled: false
92
+
93
+ # Offense count: 2
94
+ # Cop supports --auto-correct.
95
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
96
+ SignalException:
97
+ Enabled: false
98
+
99
+ # Offense count: 1
100
+ # Cop supports --auto-correct.
101
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
102
+ SpaceBeforeBlockBraces:
103
+ Enabled: false
104
+
105
+ # Offense count: 3
106
+ # Cop supports --auto-correct.
107
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
108
+ SpaceInsideBlockBraces:
109
+ Enabled: false
110
+
111
+ # Offense count: 15
112
+ # Cop supports --auto-correct.
113
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
114
+ StringLiterals:
115
+ Enabled: false
116
+
117
+ # Offense count: 1
118
+ UselessAssignment:
119
+ Enabled: false
data/rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-04-21 12:09:58 +0700 using RuboCop version 0.20.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 2
9
+ CyclomaticComplexity:
10
+ Max: 10
11
+
12
+ # Offense count: 14
13
+ Documentation:
14
+ Enabled: false
15
+
16
+ # Offense count: 17
17
+ LineLength:
18
+ Max: 122
19
+
20
+ # Offense count: 4
21
+ # Configuration parameters: CountComments.
22
+ MethodLength:
23
+ Max: 50
24
+
25
+ # Offense count: 1
26
+ MultilineBlockChain:
27
+ Enabled: false
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/test_rsa ADDED
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpQIBAAKCAQEA7PbUG3ZnKywbc031GWQjzxnqBYHgOy78cEoMccC1oiuX1+1o
3
+ tKkGtADuAnDOrd3bPOQNr0vNxJpizHM+Jdj/Osno8gW1G01rGTQG/CZ6uA20bd4b
4
+ ob1yPjrmo/PaFmG18xgK/P7hP8h9ME9pXHWiQAewQs1OW/QM9REowFrxyFIEAZXp
5
+ /MKXP96Yr59cdFRY+5k0uchOH5zT1HR5VEIaS1bouF2IYSUjdHbDbX8LRU5z4h4R
6
+ 1rf1f6ANAsZfANi+G0wJqZwOCf8vz397AzAEMfhCHCYwrD68qpl9Olf9HWgnF1WT
7
+ U5yX0+bakZWl0VmJGsBlD9y8q+A2tZo+VMLBNQIDAQABAoIBAQDJ8w4PnZgNThjS
8
+ 6tSA4Dw4a0BrkyUzqzaOyDzU0US6weY1quo6VXcV/1jYkaVCvjnzKfSTucnSzTR4
9
+ Q5rqjIXwZ1V0tfKEIzWsFBAD4xNhOqTToZ/w9tCfQnl/rvnlaz6yv4HV3a7AOjCe
10
+ 9H65wrMVWLgaJniqm1JTpV0Smi9G5SMCs3S+r3JMeTDkGiaMOuRxt0jWF6tQqKvW
11
+ UquE9uRZkqXnvZUZYe38AjZ/grbhIJHUFqDxidAGX4ouhnIuqZy971oel6C3ZPWu
12
+ 4Px5Ex58+HqRdjvOnLhSVVgBEtE8LdMMjYf3RFTPszdMtAXpU+zh2Jzkswha+pKT
13
+ +99gYshdAoGBAPvxVgxNZsRZWnpDPAEm5R5I0pD7vP9oCtr4QlQPTHCt6GYXtS+J
14
+ rHCUomNH98+kVbQuWqaOFX2FfIIw9C/GO/r8X51sSAp7Ah0HKW6WeLKMk+jfgruH
15
+ jJy5MS2gMmdVAgoAr8OXMMFJAyuvgyeVpXpJiEdOIV4U8oCB4dPLSEcHAoGBAPDH
16
+ vdhLUItEE3XWeghalkXPeWa1EBc7l53dXxr/4DXk63/AgFIGt7g5OEwZjPqSZ0Pz
17
+ SbuOxGzIj8FVwfSvFWbOsbe03IRgaIltGWq6pVzpa3uJASNAWZh10z3UhJuj9vWG
18
+ 4oMvGkZoBK8eAjgQPAxVhemZotoxEhaNkDQtDorjAoGBANTtVmf3Uo9HZSxHfoMK
19
+ uEEsEqnt2AGTkPkXMBeTBmuEzxDZoIuYs2BCfiuiO1IF9VjehEaXdporItt1PCrU
20
+ QwUQHk8RoKEa7OJTlzSbf06HeMorfHW5TaF28pU4+uBR+/MwOVv4f4AbkM5u+02N
21
+ L9l2I/L/mTvGQF1TZ+RzvZYpAoGABMPfNPWgnXD2daGN/rZUPQNzIp44uEz8niow
22
+ ZKdlt4tVQcz8fSMW5bV0MMVcreTR2F1rOyQDLSf2+FuLIB2K7eLvT3Rr3M7PotCe
23
+ 7SbOeP1BnEtE037Fhyfly1Z2XWIsVAWcW/5FpdkPJqwQXS2tEo1qvgnFWE4aTon0
24
+ raOqowMCgYEAy2I3mslOA9lylapShkydPRraBow9rTtpGi8K85HTdyz3wzfR5t7Y
25
+ Aoad1jJ77U2nXnHTe+s1X7FusyX8SF6Wl9jb/Wjf9K/LbMZQqCmzDqsAA6Rwguds
26
+ OD2kABU5dyf6X8BJ3vpv4JR57nOowwkKFKJNZmkNPiwolF9kCk0YQFM=
27
+ -----END RSA PRIVATE KEY-----
data/to_github.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ git config user.name 'eucher'
4
+ git config user.email 'cyber@sibnet.ru'
data/to_gitlab.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ git config user.name 'Cherdancev Evgeni'
4
+ git config user.email 'joe@netpost.ru'
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opennebula-provider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - eucher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: occi-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: OpenNebula provider for Vagrant
70
+ email:
71
+ - cyber@sibnet.ru
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - locales/en.yml
78
+ - README.md
79
+ - to_github.sh
80
+ - gist.sh
81
+ - Gemfile
82
+ - boxes/dummy/dummy.box
83
+ - boxes/dummy/metadata.json
84
+ - boxes/dummy/README.md
85
+ - to_gitlab.sh
86
+ - rubocop-todo.yml
87
+ - lib/opennebula-provider/version.rb
88
+ - lib/opennebula-provider/plugin.rb
89
+ - lib/opennebula-provider/helpers/rocci.rb
90
+ - lib/opennebula-provider/action/destroy.rb
91
+ - lib/opennebula-provider/action/check_state.rb
92
+ - lib/opennebula-provider/action/read_ssh_info.rb
93
+ - lib/opennebula-provider/action/connect_opennebula.rb
94
+ - lib/opennebula-provider/action/create.rb
95
+ - lib/opennebula-provider/action/sync_folders.rb
96
+ - lib/opennebula-provider/action.rb
97
+ - lib/opennebula-provider/config.rb
98
+ - lib/opennebula-provider/provider.rb
99
+ - lib/opennebula-provider.rb
100
+ - opennebula-provider.gemspec
101
+ - github.sh
102
+ - rubocop.yml
103
+ - test/rsyncme/10.file
104
+ - test/rsyncme/1.file
105
+ - test/rsyncme/6.file
106
+ - test/rsyncme/4.file
107
+ - test/rsyncme/5.file
108
+ - test/rsyncme/8.file
109
+ - test/rsyncme/9.file
110
+ - test/rsyncme/7.file
111
+ - test/rsyncme/3.file
112
+ - test/rsyncme/2.file
113
+ - test/test_rsa
114
+ - Rakefile
115
+ - .gitignore
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.1.11
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: OpenNebula provider for Vagrant
140
+ test_files:
141
+ - test/rsyncme/10.file
142
+ - test/rsyncme/1.file
143
+ - test/rsyncme/6.file
144
+ - test/rsyncme/4.file
145
+ - test/rsyncme/5.file
146
+ - test/rsyncme/8.file
147
+ - test/rsyncme/9.file
148
+ - test/rsyncme/7.file
149
+ - test/rsyncme/3.file
150
+ - test/rsyncme/2.file
151
+ - test/test_rsa