vagrant-kubevirt 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +12 -0
- data/LICENSE +13 -0
- data/README.md +109 -0
- data/Rakefile +22 -0
- data/example_box/README.md +9 -0
- data/example_box/Vagrantfile +20 -0
- data/example_box/kubevirt.box +0 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-kubevirt.rb +18 -0
- data/lib/vagrant-kubevirt/action.rb +176 -0
- data/lib/vagrant-kubevirt/action/connect_kubevirt.rb +37 -0
- data/lib/vagrant-kubevirt/action/create_vm.rb +133 -0
- data/lib/vagrant-kubevirt/action/destroy_vm.rb +30 -0
- data/lib/vagrant-kubevirt/action/is_created.rb +18 -0
- data/lib/vagrant-kubevirt/action/is_stopped.rb +18 -0
- data/lib/vagrant-kubevirt/action/read_ssh_info.rb +54 -0
- data/lib/vagrant-kubevirt/action/read_state.rb +44 -0
- data/lib/vagrant-kubevirt/action/set_domain_name.rb +33 -0
- data/lib/vagrant-kubevirt/action/start_vm.rb +35 -0
- data/lib/vagrant-kubevirt/action/stop_vm.rb +37 -0
- data/lib/vagrant-kubevirt/action/wait_for_state.rb +64 -0
- data/lib/vagrant-kubevirt/config.rb +60 -0
- data/lib/vagrant-kubevirt/errors.rb +39 -0
- data/lib/vagrant-kubevirt/plugin.rb +73 -0
- data/lib/vagrant-kubevirt/provider.rb +50 -0
- data/lib/vagrant-kubevirt/version.rb +5 -0
- data/locales/en.yml +69 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/environment_helper.rb +18 -0
- data/spec/support/kubevirt_context.rb +15 -0
- data/spec/support/sharedcontext.rb +33 -0
- data/spec/unit/action/create_vm_spec.rb +122 -0
- data/spec/unit/action/destroy_vm_spec.rb +33 -0
- data/spec/unit/action/read_ssh_info_spec.rb +45 -0
- data/spec/unit/action/read_state_spec.rb +44 -0
- data/spec/unit/action/start_vm_spec.rb +44 -0
- data/spec/unit/action/stop_vm_spec.rb +57 -0
- data/spec/unit/action/wait_for_state_spec.rb +57 -0
- data/spec/unit/config_spec.rb +41 -0
- data/vagrant-kubevirt.gemspec +26 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 13a3b9fb5dbac6f1fbb7774ad9d2a0232bd7a33ee17ab52ea41bf2f7079f1a63
|
4
|
+
data.tar.gz: 3259c02f3b97c69a59ed1bc76db83b07ce4d476eec7977f250d87e13d67efdb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a04ca4cc72aa446a003d9edbe3df6dbde20624ba3d8dbbdd3ee7e3dc113245fb780242c86b610203769dc862ceae0d504237a3e62dae5d682cdb5ee603582ad
|
7
|
+
data.tar.gz: b5a1d70120aa19c1fd311ed623f8f6948d07abe279ef1cddb097672d6a00a8c3e0560004927440e3f1b365c4e539582d70febd1a181c488e6feb1ac1dc6675b3
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
18
|
+
Vagrantfile
|
19
|
+
!example_box/Vagrantfile
|
20
|
+
.vagrant
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
# We depend on Vagrant for development, but we don't add it as a
|
7
|
+
# gem dependency because we expect to be installed within the
|
8
|
+
# Vagrant environment itself using `vagrant plugin`.
|
9
|
+
gem "vagrant", :git => "https://github.com/hashicorp/vagrant.git"
|
10
|
+
|
11
|
+
gem 'vagrant-spec', :github => 'hashicorp/vagrant-spec'
|
12
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2018 Red Hat, Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Vagrant KubeVirt Provider
|
2
|
+
|
3
|
+
|
4
|
+
This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an [KubeVirt](http://kubevirt.io)
|
5
|
+
provider to Vagrant, allowing Vagrant to control and provision virtual machines using Kubernetes add-on.
|
6
|
+
|
7
|
+
**NOTE:** This plugin requires Vagrant 2.2.3+. Due to the issue in net-ssh fixed [here](https://github.com/net-ssh/net-ssh/pull/641).
|
8
|
+
|
9
|
+
## Features
|
10
|
+
* Vagrant `up`, `halt`, `status` and `destroy` commands.
|
11
|
+
* Create and boot virtual machines using templates, registry image or pvc.
|
12
|
+
* Provision the virtual machines with any built-in Vagrant provisioner.
|
13
|
+
* SSH into the VMIs
|
14
|
+
* Synced folder support
|
15
|
+
|
16
|
+
## Future work
|
17
|
+
* Package running virtual machines into new vagrant-kubevirt friendly boxes
|
18
|
+
* Manage networks for virtual machines
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Install using standard Vagrant 1.2+ plugin installation methods. After
|
23
|
+
installing, `vagrant up` and specify the `kubevirt` provider. An example is
|
24
|
+
shown below.
|
25
|
+
|
26
|
+
```
|
27
|
+
$ vagrant plugin install vagrant-kubevirt
|
28
|
+
...
|
29
|
+
$ vagrant up --provider=kubevirt
|
30
|
+
...
|
31
|
+
```
|
32
|
+
|
33
|
+
## Quick Start
|
34
|
+
|
35
|
+
After installing the plugin (instructions above), the quickest way to get
|
36
|
+
started is to actually use a Kubevirt box and specify all the details
|
37
|
+
manually within a `config.vm.provider` block. So first, add the box using
|
38
|
+
any name you want:
|
39
|
+
|
40
|
+
```
|
41
|
+
$ vagrant box add kubevirt https://raw.githubusercontent.com/pkliczewski/vagrant-kubevirt/master/example_box/kubevirt.box
|
42
|
+
...
|
43
|
+
```
|
44
|
+
|
45
|
+
And then make a Vagrantfile that looks like the following, filling in
|
46
|
+
your information where necessary.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Vagrant.configure("2") do |config|
|
50
|
+
config.vm.box = 'kubevirt'
|
51
|
+
config.vm.boot_timeout = 30
|
52
|
+
|
53
|
+
config.vm.provision "shell" do |s|
|
54
|
+
s.inline = "touch example.txt"
|
55
|
+
end
|
56
|
+
|
57
|
+
config.vm.provider :kubevirt do |kubevirt|
|
58
|
+
# kubevirt.template = 'working'
|
59
|
+
kubevirt.cpus = 2
|
60
|
+
kubevirt.memory = 512
|
61
|
+
kubevirt.image = 'kubevirt/fedora-cloud-registry-disk-demo'
|
62
|
+
# kubevirt.pvc = 'my_pvc'
|
63
|
+
|
64
|
+
# kubevirt.hostname = '<kubevirt-host>'
|
65
|
+
# kubevirt.port = '<kubevirt port>'
|
66
|
+
# kubevirt.token = '<token>'
|
67
|
+
end
|
68
|
+
|
69
|
+
config.ssh.username = 'vagrant'
|
70
|
+
config.ssh.password = 'vagrant'
|
71
|
+
config.ssh.private_key_path = ['~/.ssh/id_rsa']
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
And then run `vagrant up --provider=kubevirt`.
|
76
|
+
|
77
|
+
## Box Format
|
78
|
+
|
79
|
+
Every provider in Vagrant must introduce a custom box format. This
|
80
|
+
provider introduces `kubevirt` boxes. You can view an example box in
|
81
|
+
the [example_box/ directory](https://github.com/pkliczewski/vagrant-kubevirt/tree/master/example_box).
|
82
|
+
That directory also contains instructions on how to build a box.
|
83
|
+
|
84
|
+
The box format is basically just the required `metadata.json` file
|
85
|
+
along with a `Vagrantfile` that does default settings for the
|
86
|
+
provider-specific configuration for this provider.
|
87
|
+
|
88
|
+
## Configuration
|
89
|
+
|
90
|
+
There are 2 options to configure provider:
|
91
|
+
|
92
|
+
# Kubevirt provider configuration options:
|
93
|
+
|
94
|
+
* `hostname` - Hostname where Kubevirt is deployed
|
95
|
+
* `port` - Port on which Kubevirt is listening
|
96
|
+
* `token` - Token used to authenticate any requests
|
97
|
+
|
98
|
+
# kubeconfig file
|
99
|
+
|
100
|
+
User can provide path to config file using `KUBECONFIG` environemnt variable or have it in
|
101
|
+
well known location such as `~/.kube/config`.
|
102
|
+
|
103
|
+
### Domain Specific Options
|
104
|
+
|
105
|
+
* `cpus` - Number of virtual cpus. Defaults to 1 if not set.
|
106
|
+
* `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
|
107
|
+
* `template` - Name of template from which new VM will be created.
|
108
|
+
* `image` - Name of image which will be used to create new VM.
|
109
|
+
* `pvc` - Name of persistent volume claim which will be used to create new VM.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
# Immediately sync all stdout so that tools like buildbot can
|
6
|
+
# immediately load in the output.
|
7
|
+
$stdout.sync = true
|
8
|
+
$stderr.sync = true
|
9
|
+
|
10
|
+
# Change to the directory of this file.
|
11
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
12
|
+
|
13
|
+
# This installs the tasks that help with gem creation and
|
14
|
+
# publishing.
|
15
|
+
Bundler::GemHelper.install_tasks
|
16
|
+
|
17
|
+
# Install the `spec` task so that we can run tests.
|
18
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
19
|
+
t.rspec_opts = "--order defined"
|
20
|
+
end
|
21
|
+
# Default task is to run the unit tests
|
22
|
+
task :default => :spec
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Vagrant Kubevirt Example Box
|
2
|
+
|
3
|
+
Vagrant providers each require a custom provider-specific box format.
|
4
|
+
This folder shows the example contents of a box for the `kubevirt` provider.
|
5
|
+
To turn this into a box:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ tar cvzf kubevirt.box ./metadata.json ./Vagrantfile
|
9
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Vagrant.configure("2") do |config|
|
2
|
+
config.vm.box = 'kubevirt'
|
3
|
+
|
4
|
+
# config.vm.synced_folder ".", "/vagrant", disabled: true
|
5
|
+
# config.vm.synced_folder "/home/pkliczewski/git/vagrant-kubevirt/example_box/src", "/srv/website", type: "rsync"
|
6
|
+
|
7
|
+
# config.vm.provision "shell" do |s|
|
8
|
+
# s.inline = "touch example.txt"
|
9
|
+
# end
|
10
|
+
|
11
|
+
config.vm.provider :kubevirt do |kubevirt|
|
12
|
+
kubevirt.cpus = 2
|
13
|
+
kubevirt.memory = 512
|
14
|
+
kubevirt.image = 'kubevirt/fedora-cloud-registry-disk-demo'
|
15
|
+
end
|
16
|
+
|
17
|
+
config.ssh.username = 'vagrant'
|
18
|
+
config.ssh.password = 'vagrant'
|
19
|
+
config.ssh.private_key_path = ['~/.ssh/id_rsa']
|
20
|
+
end
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "vagrant-kubevirt/plugin"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Kubevirt
|
7
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-kubevirt", __FILE__))
|
8
|
+
autoload :Action, lib_path.join("action")
|
9
|
+
autoload :Errors, lib_path.join("errors")
|
10
|
+
|
11
|
+
# This returns the path to the source of this plugin.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
14
|
+
def self.source_root
|
15
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "vagrant/action/builder"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Kubevirt
|
7
|
+
module Action
|
8
|
+
# Include the built-in modules so we can use them as top-level things.
|
9
|
+
include Vagrant::Action::Builtin
|
10
|
+
|
11
|
+
# This action is called to bring the box up from nothing.
|
12
|
+
def self.action_up
|
13
|
+
Vagrant::Action::Builder.new.tap do |b|
|
14
|
+
b.use ConfigValidate
|
15
|
+
b.use ConnectKubevirt
|
16
|
+
b.use Call, IsCreated do |env1, b1|
|
17
|
+
b1.use SetDomainName
|
18
|
+
|
19
|
+
if env1[:result]
|
20
|
+
b1.use Message,
|
21
|
+
I18n.t("vagrant_kubevirt.already_status", :status => "created")
|
22
|
+
else
|
23
|
+
b1.use CreateVM
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
b.use Provision
|
28
|
+
b.use SyncedFolders
|
29
|
+
|
30
|
+
b.use Call, IsStopped do |env2, b2|
|
31
|
+
if env2[:result]
|
32
|
+
b2.use StartVM
|
33
|
+
b2.use Call, WaitForState, :running, 120 do |env3, b3|
|
34
|
+
unless env3[:result]
|
35
|
+
b3.use Message,
|
36
|
+
I18n.t("vagrant_kubevirt.action_failed", :action => 'Up')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# This action is called to halt the remote machine.
|
45
|
+
def self.action_halt
|
46
|
+
Vagrant::Action::Builder.new.tap do |b|
|
47
|
+
b.use ConfigValidate
|
48
|
+
b.use Call, IsCreated do |env, b2|
|
49
|
+
unless env[:result]
|
50
|
+
b2.use Message,
|
51
|
+
I18n.t("vagrant_kubevirt.not_created")
|
52
|
+
next
|
53
|
+
end
|
54
|
+
|
55
|
+
b2.use ConnectKubevirt
|
56
|
+
b2.use SetDomainName
|
57
|
+
b2.use StopVM
|
58
|
+
b2.use Call, WaitForState, :stopped, 120 do |env2, b3|
|
59
|
+
unless env2[:result]
|
60
|
+
b2.use Message,
|
61
|
+
I18n.t("vagrant_kubevirt.action_failed", :action => 'Halt')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# This action is called to terminate the remote machine.
|
69
|
+
def self.action_destroy
|
70
|
+
Vagrant::Action::Builder.new.tap do |b|
|
71
|
+
b.use ConfigValidate
|
72
|
+
b.use Call, IsCreated do |env, b2|
|
73
|
+
unless env[:result]
|
74
|
+
b2.use Message,
|
75
|
+
I18n.t("vagrant_kubevirt.not_created")
|
76
|
+
next
|
77
|
+
end
|
78
|
+
|
79
|
+
b2.use ConnectKubevirt
|
80
|
+
b2.use DestroyVM
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# This action is called to read the state of the machine. The
|
86
|
+
# resulting state is expected to be put into the `:machine_state_id`
|
87
|
+
# key.
|
88
|
+
def self.action_read_state
|
89
|
+
Vagrant::Action::Builder.new.tap do |b|
|
90
|
+
b.use ConfigValidate
|
91
|
+
b.use ConnectKubevirt
|
92
|
+
b.use ReadState
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# This action is called to read the SSH info of the machine. The
|
97
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
98
|
+
# key.
|
99
|
+
def self.action_read_ssh_info
|
100
|
+
Vagrant::Action::Builder.new.tap do |b|
|
101
|
+
b.use ConfigValidate
|
102
|
+
b.use ConnectKubevirt
|
103
|
+
b.use ReadSSHInfo
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# This action is called to SSH into the machine.
|
109
|
+
def self.action_ssh
|
110
|
+
Vagrant::Action::Builder.new.tap do |b|
|
111
|
+
b.use ConfigValidate
|
112
|
+
b.use Call, IsCreated do |env, b2|
|
113
|
+
unless env[:result]
|
114
|
+
b2.use Message,
|
115
|
+
I18n.t("vagrant_kubevirt.not_created")
|
116
|
+
next
|
117
|
+
end
|
118
|
+
|
119
|
+
b2.use SSHExec
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.action_ssh_run
|
125
|
+
Vagrant::Action::Builder.new.tap do |b|
|
126
|
+
b.use ConfigValidate
|
127
|
+
b.use Call, IsCreated do |env, b2|
|
128
|
+
unless env[:result]
|
129
|
+
b2.use Message,
|
130
|
+
I18n.t("vagrant_kubevirt.not_created")
|
131
|
+
next
|
132
|
+
end
|
133
|
+
|
134
|
+
b2.use SSHRun
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.action_provision
|
140
|
+
Vagrant::Action::Builder.new.tap do |b|
|
141
|
+
b.use ConfigValidate
|
142
|
+
b.use Call, IsCreated do |env, b2|
|
143
|
+
unless env[:result]
|
144
|
+
b2.use Message,
|
145
|
+
I18n.t("vagrant_kubevirt.not_created")
|
146
|
+
next
|
147
|
+
end
|
148
|
+
|
149
|
+
b2.use Call, IsStopped do |env2, b3|
|
150
|
+
if env2[:result]
|
151
|
+
I18n.t("vagrant_kubevirt.not_running")
|
152
|
+
next
|
153
|
+
end
|
154
|
+
|
155
|
+
b3.use Provision
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# The autoload farm
|
162
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
163
|
+
autoload :ConnectKubevirt, action_root.join("connect_kubevirt")
|
164
|
+
autoload :CreateVM, action_root.join("create_vm")
|
165
|
+
autoload :DestroyVM, action_root.join("destroy_vm")
|
166
|
+
autoload :IsCreated, action_root.join("is_created")
|
167
|
+
autoload :IsStopped, action_root.join("is_stopped")
|
168
|
+
autoload :ReadState, action_root.join("read_state")
|
169
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
170
|
+
autoload :SetDomainName, action_root.join("set_domain_name")
|
171
|
+
autoload :StartVM, action_root.join("start_vm")
|
172
|
+
autoload :StopVM, action_root.join("stop_vm")
|
173
|
+
autoload :WaitForState, action_root.join("wait_for_state")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'fog/kubevirt'
|
2
|
+
|
3
|
+
require "log4r"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Kubevirt
|
7
|
+
module Action
|
8
|
+
class ConnectKubevirt
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_kubevirt::action::connect_kubevirt")
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
# Get config options for kubevirt provider.
|
18
|
+
config = env[:machine].provider_config
|
19
|
+
|
20
|
+
# Build the fog config
|
21
|
+
fog_config = {
|
22
|
+
:kubevirt_hostname => config.hostname,
|
23
|
+
:kubevirt_port => config.port,
|
24
|
+
:kubevirt_token => config.token,
|
25
|
+
:kubevirt_namespace => config.namespace,
|
26
|
+
:kubevirt_log => @logger
|
27
|
+
}
|
28
|
+
|
29
|
+
@logger.info("Connecting to Kubevirt...")
|
30
|
+
env[:kubevirt_compute] = Fog::Kubevirt::Compute.new(fog_config)
|
31
|
+
|
32
|
+
@app.call(env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|