vagrant-vmck 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c48a2944fd255f1686bd41ecddfe03a0c169909ef0766932ef65a8ad6fbcdcd3
4
+ data.tar.gz: 1770e7e5d169b14bdd1909c8537a09000a5f3245ddd021b3e9efadc69441b93b
5
+ SHA512:
6
+ metadata.gz: af4574a138fd402c69dfbbf05dc3c978fe334191440d610aa04f28ed3e24f0bfb59c9bbfc98a407bd836ff167c6618bf7f0ec80aa736b0a02b0594a503737422
7
+ data.tar.gz: a17e3e60b8fc2de7db9ca22a9e80e25a70660ce618afe3813ece8df6d335fb5ebfaadb76479d58242e388873719a9b7cd7c910bfc7d4f5ac56870e013c7364ac
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ .vagrant
4
+ Vagrantfile
5
+ !example_box/Vagrantfile
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', git: 'https://github.com/hashicorp/vagrant.git'
5
+ end
6
+
7
+ group :plugins do
8
+ gem 'vagrant-vmck', path: '.'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Alex Morega
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Readme.md ADDED
@@ -0,0 +1,28 @@
1
+ # Vagrant Vmck Provider
2
+
3
+ [Vagrant][] provider form [Vmck][].
4
+
5
+ [Vagrant]: https://www.vagrantup.com
6
+ [Vmck]: https://github.com/mgax/vmck
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```shell
14
+ $ vagrant plugin install vagrant-vmck
15
+ ```
16
+
17
+
18
+ ## Usage
19
+
20
+ See `example_box/Vagrantfile` for an example configuration.
21
+
22
+ ```shell
23
+ $ vagrant up --provider=vmck
24
+ ```
25
+
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+
6
+ config.vm.box = "base"
7
+
8
+ config.vm.provider :vmck do |provider|
9
+ provider.vmck_url = 'http://127.0.0.1:8000'
10
+ end
11
+
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'log4r'
2
+ require 'vagrant-vmck/client'
3
+
4
+ module VagrantPlugins
5
+ module Vmck
6
+ module Action
7
+ class ConnectVmck
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_vmck::action::connect")
12
+ end
13
+
14
+ def call(env)
15
+ url = env[:machine].provider_config.vmck_url
16
+ env[:vmck] = Vmck::Client.new(url)
17
+ @app.call(env)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module Vmck
5
+ module Action
6
+ class Create
7
+ include Vagrant::Util::Retryable
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_vmck::action::start_instance")
12
+ end
13
+
14
+ def call(env)
15
+ client = env[:vmck]
16
+
17
+ env[:ui].info("Vmck starting job ...")
18
+ id = client.create()['id'].to_s
19
+ env[:machine].id = id
20
+
21
+ env[:ui].info("Vmck waiting for job #{id} to be ready ...")
22
+ retryable(:tries => 120, :sleep => 1) do
23
+ next if env[:interrupted]
24
+ raise 'not ready' unless client.get(id)['ssh']
25
+ end
26
+
27
+ env[:ui].info("Vmck job #{id} is ready, waiting for ssh ...")
28
+ retryable(:tries => 120, :sleep => 1) do
29
+ break if env[:interrupted]
30
+ break if env[:machine].communicate.ready?
31
+ sleep 2
32
+ end
33
+
34
+ env[:ui].info("Vmck got ssh access to job #{id}")
35
+ @app.call(env)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module Vmck
5
+ module Action
6
+ class Destroy
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_vmck::action::start_instance")
11
+ end
12
+
13
+ def call(env)
14
+ id = env[:machine].id
15
+ env[:ui].info("Vmck destroying job #{id} ...")
16
+
17
+ env[:vmck].stop(id)
18
+ env[:machine].id = nil
19
+ env[:ui].info("Vmck job #{id} destroyed successfully")
20
+
21
+ @app.call(env)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module Vmck
5
+ module Action
6
+ class ReadJob
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_vmck::action::start_instance")
11
+ end
12
+
13
+ def call(env)
14
+ env[:vmck_job] = read_job(env[:vmck], env[:machine].id)
15
+ @app.call(env)
16
+ end
17
+
18
+ def read_job(client, job_id)
19
+ return {'state': nil} if job_id.nil?
20
+ job_state = client.get(job_id)
21
+ job_state['ready_for_ssh'] = !! job_state['ssh']
22
+ return job_state
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ require 'vagrant-vmck/action/connect_vmck'
2
+ require 'vagrant-vmck/action/read_job'
3
+ require 'vagrant-vmck/action/create'
4
+ require 'vagrant-vmck/action/destroy'
5
+
6
+ module VagrantPlugins
7
+ module Vmck
8
+ module Action
9
+ include Vagrant::Action::Builtin
10
+
11
+ def self.read_job
12
+ return Vagrant::Action::Builder.new.tap do |builder|
13
+ builder.use ConfigValidate
14
+ builder.use ConnectVmck
15
+ builder.use ReadJob
16
+ end
17
+ end
18
+
19
+ def self.up
20
+ return Vagrant::Action::Builder.new.tap do |builder|
21
+ builder.use ConfigValidate
22
+ builder.use ConnectVmck
23
+ builder.use Create
24
+ end
25
+ end
26
+
27
+ def self.ssh
28
+ return Vagrant::Action::Builder.new.tap do |builder|
29
+ builder.use ConfigValidate
30
+ builder.use ConnectVmck
31
+ builder.use SSHExec
32
+ end
33
+ end
34
+
35
+ def self.destroy
36
+ return Vagrant::Action::Builder.new.tap do |builder|
37
+ builder.use ConfigValidate
38
+ builder.use ConnectVmck
39
+ builder.use Destroy
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module VagrantPlugins
5
+ module Vmck
6
+ class Client
7
+
8
+ def initialize(url)
9
+ @logger = Log4r::Logger.new('vmck::client')
10
+ @client = Faraday.new({ :url => url })
11
+ end
12
+
13
+ def request(method, path)
14
+ @logger.info "Request: #{path}"
15
+
16
+ result = @client.send(method) do |req|
17
+ req.url(path)
18
+ end
19
+
20
+ if method == :delete
21
+ body = nil
22
+ else
23
+ body = JSON.parse(result.body)
24
+ @logger.info "Response: #{body}"
25
+ return body
26
+ end
27
+
28
+ if result.status < 200 or result.status >= 300
29
+ raise({
30
+ :path => path,
31
+ :status => result.status,
32
+ :response => body.inspect,
33
+ })
34
+ end
35
+
36
+ end
37
+
38
+ def create
39
+ request(:post, "/v0/jobs")
40
+ end
41
+
42
+ def get(id)
43
+ request(:get, "/v0/jobs/#{id}")
44
+ end
45
+
46
+ def stop(id)
47
+ request(:delete, "/v0/jobs/#{id}")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Vmck
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :vmck_url
5
+ attr_accessor :private_key_path
6
+
7
+ def initialize
8
+ @vmck_url = UNSET_VALUE
9
+ @private_key_path = UNSET_VALUE
10
+ end
11
+
12
+ def finalize!
13
+ @vmck_url = nil if @vmck_url == UNSET_VALUE
14
+ @private_key_path = nil if @private_key_path == UNSET_VALUE
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module Vmck
3
+ class Plugin < Vagrant.plugin('2')
4
+ name "Vmck"
5
+
6
+ config :vmck, :provider do
7
+ require_relative 'config'
8
+ Config
9
+ end
10
+
11
+ provider :vmck do
12
+ require_relative 'provider'
13
+ Provider
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ require 'log4r'
2
+ require 'vagrant-vmck/action'
3
+
4
+ module VagrantPlugins
5
+ module Vmck
6
+ class Provider < Vagrant.plugin('2', :provider)
7
+
8
+ def initialize(machine)
9
+ @machine = machine
10
+ @logger = Log4r::Logger.new("vagrant_vmck::provider")
11
+ end
12
+
13
+ def action(name)
14
+ return Action.send(name) if Action.respond_to?(name)
15
+ nil
16
+ end
17
+
18
+ def ssh_info
19
+ env = @machine.action('read_job', lock: false)
20
+ job = env[:vmck_job]
21
+
22
+ return nil unless job['ready_for_ssh']
23
+
24
+ return {
25
+ :host => job['ssh']['host'],
26
+ :port => job['ssh']['port'],
27
+ :username => job['ssh']['username'],
28
+ :private_key_path => @machine.provider_config.private_key_path,
29
+ }
30
+ end
31
+
32
+ def state
33
+ env = @machine.action('read_job', lock: false)
34
+ state = env[:vmck_job]['state']
35
+ long = short = state.to_s
36
+ Vagrant::MachineState.new(state, short, long)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Vmck
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'vagrant-vmck/version'
2
+ require 'vagrant-vmck/plugin'
3
+
4
+ module VagrantPlugins
5
+ module Vmck
6
+
7
+ lib_path = Pathname.new(File.expand_path('../vagrant-vmck', __FILE__))
8
+
9
+ autoload :Action, lib_path.join('action')
10
+
11
+ def self.source_root
12
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-vmck/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "vagrant-vmck"
6
+ spec.version = VagrantPlugins::Vmck::VERSION
7
+ spec.authors = ["Alex Morega"]
8
+ spec.email = ["alex@grep.ro"]
9
+ spec.summary = "Vagrant provider plugin for Vmck."
10
+ spec.description = "Enables Vagrant to use Vmck jobs."
11
+ spec.homepage = "https://github.com/mgax/vagrant-vmck"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.require_path = "lib"
18
+
19
+ spec.add_dependency "faraday"
20
+ spec.add_dependency "json"
21
+ spec.add_dependency "log4r"
22
+
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-vmck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Morega
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: log4r
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Enables Vagrant to use Vmck jobs.
84
+ email:
85
+ - alex@grep.ro
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - Readme.md
94
+ - example_box/Vagrantfile
95
+ - lib/vagrant-vmck.rb
96
+ - lib/vagrant-vmck/action.rb
97
+ - lib/vagrant-vmck/action/connect_vmck.rb
98
+ - lib/vagrant-vmck/action/create.rb
99
+ - lib/vagrant-vmck/action/destroy.rb
100
+ - lib/vagrant-vmck/action/read_job.rb
101
+ - lib/vagrant-vmck/client.rb
102
+ - lib/vagrant-vmck/config.rb
103
+ - lib/vagrant-vmck/plugin.rb
104
+ - lib/vagrant-vmck/provider.rb
105
+ - lib/vagrant-vmck/version.rb
106
+ - vagrant-vmck.gemspec
107
+ homepage: https://github.com/mgax/vagrant-vmck
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Vagrant provider plugin for Vmck.
130
+ test_files: []