vagrant-vrealize 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +16 -0
- data/LICENSE +55 -0
- data/README.md +132 -0
- data/Rakefile +29 -0
- data/example_box/README.md +13 -0
- data/example_box/Vagrantfile +7 -0
- data/example_box/metadata.json +3 -0
- data/example_box/mkbox.sh +3 -0
- data/example_box/vrealize.box +0 -0
- data/lib/vagrant-vrealize/action/connect_vrealize.rb +65 -0
- data/lib/vagrant-vrealize/action/is_created.rb +35 -0
- data/lib/vagrant-vrealize/action/is_stopped.rb +18 -0
- data/lib/vagrant-vrealize/action/message_already_created.rb +18 -0
- data/lib/vagrant-vrealize/action/message_not_created.rb +16 -0
- data/lib/vagrant-vrealize/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-vrealize/action/read_ssh_info.rb +28 -0
- data/lib/vagrant-vrealize/action/read_state.rb +28 -0
- data/lib/vagrant-vrealize/action/run_instance.rb +111 -0
- data/lib/vagrant-vrealize/action/start_instance.rb +25 -0
- data/lib/vagrant-vrealize/action/stop_instance.rb +19 -0
- data/lib/vagrant-vrealize/action/terminate_instance.rb +23 -0
- data/lib/vagrant-vrealize/action/timed_provision.rb +21 -0
- data/lib/vagrant-vrealize/action/wait_for_state.rb +25 -0
- data/lib/vagrant-vrealize/action/warn_networks.rb +19 -0
- data/lib/vagrant-vrealize/action.rb +191 -0
- data/lib/vagrant-vrealize/config.rb +138 -0
- data/lib/vagrant-vrealize/errors.rb +32 -0
- data/lib/vagrant-vrealize/extra-entries.rb +46 -0
- data/lib/vagrant-vrealize/plugin.rb +73 -0
- data/lib/vagrant-vrealize/provider.rb +52 -0
- data/lib/vagrant-vrealize/util/timer.rb +17 -0
- data/lib/vagrant-vrealize/version.rb +5 -0
- data/lib/vagrant-vrealize/vra_client.rb +140 -0
- data/lib/vagrant-vrealize.rb +19 -0
- data/locales/en.yml +148 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad1b04231e2f9e5bef5be02d82619f23c1e58e92
|
4
|
+
data.tar.gz: 6ff3de905eba3c5c8cb89faecf8adad6e16d4590
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb6148f910dd75743a66f56dfcfb1c30dcb619a23392974b21b5c739a80acb3c73832d2e5d91a061a403f0e65456d02da23af5cee3acd060242f4f892a425113
|
7
|
+
data.tar.gz: 3e270ef65ac5aabf2592ea3cdf84c7c346db9a5c122010bab161cead76254c9908a2b3e825c043df6faa82765774a84f138eb12f07e87a02fa7504ff26d02f50
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# How To Contribute
|
2
|
+
|
3
|
+
We want your patches! `vagrant-vrealize` isn't done yet, and anything
|
4
|
+
you've got to contribute will be gratefully received.
|
5
|
+
|
6
|
+
If there's something you want to add:
|
7
|
+
|
8
|
+
1. Make a local branch, give it a meaningful name
|
9
|
+
2. Make your change
|
10
|
+
3. Push the branch to github
|
11
|
+
4. Make a pull request to `master`.
|
12
|
+
5. It'll be reviewed, QA'd, and hopefully merged.
|
13
|
+
|
14
|
+
If you're contributing a complete feature or a bug-fix, this will
|
15
|
+
probably trigger a version bump and a release of the gem, but I'll
|
16
|
+
take care of that.
|
data/LICENSE
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
Copyright (c) 2016 Sky UK Ltd
|
2
|
+
Copyright (c) 2014 Mitchell Hashimoto
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are
|
7
|
+
met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in the
|
14
|
+
documentation and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
32
|
+
This is a derived work, based upon
|
33
|
+
https://github.com/mitchellh/vagrant-aws, which was conveyed under the
|
34
|
+
following license:
|
35
|
+
|
36
|
+
The MIT License (MIT)
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
39
|
+
a copy of this software and associated documentation files (the
|
40
|
+
"Software"), to deal in the Software without restriction, including
|
41
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
42
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
43
|
+
permit persons to whom the Software is furnished to do so, subject to
|
44
|
+
the following conditions:
|
45
|
+
|
46
|
+
The above copyright notice and this permission notice shall be
|
47
|
+
included in all copies or substantial portions of the Software.
|
48
|
+
|
49
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
52
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
53
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
54
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
55
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Vagrant VRealize Provider
|
2
|
+
|
3
|
+
This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds a VDC
|
4
|
+
provider to Vagrant, allowing Vagrant to control and provision machines in
|
5
|
+
VRealize.
|
6
|
+
|
7
|
+
**NOTE:** This plugin requires Vagrant 1.2+,
|
8
|
+
|
9
|
+
**NOTE MORE:** This plugin is a work in progress. The basics work, but it's
|
10
|
+
not as fully-featured as the `vagrant-aws` plugin it's largely based on.
|
11
|
+
|
12
|
+
## What works
|
13
|
+
|
14
|
+
* Boot VRealize instances.
|
15
|
+
* SSH into the instances.
|
16
|
+
* Provision the instances with any built-in Vagrant provisioner.
|
17
|
+
* Minimal synced folder support via `rsync`.
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Install using standard Vagrant 1.1+ plugin installation methods. After
|
22
|
+
installing, `vagrant up` and specify the `vrealize` provider. An
|
23
|
+
example is shown below.
|
24
|
+
|
25
|
+
```
|
26
|
+
$ vagrant plugin install vagrant-vrealize
|
27
|
+
...
|
28
|
+
$ vagrant up --provider=vrealize
|
29
|
+
...
|
30
|
+
```
|
31
|
+
|
32
|
+
Of course, prior to doing this, you'll need to obtain a
|
33
|
+
VRealize-compatible box file for Vagrant.
|
34
|
+
|
35
|
+
## Quick Start
|
36
|
+
|
37
|
+
After installing the plugin (instructions above), the quickest way to get
|
38
|
+
started is to actually use the dummy VRealize box and specify all the details
|
39
|
+
manually within a `config.vm.provider` block. So first, build the box:
|
40
|
+
|
41
|
+
```
|
42
|
+
$ rake box
|
43
|
+
$ vagrant box add --provider vrealize example_box/vrealize.box
|
44
|
+
```
|
45
|
+
|
46
|
+
And then make a Vagrantfile that looks like the following, filling in
|
47
|
+
your information where necessary.
|
48
|
+
|
49
|
+
```
|
50
|
+
Vagrant.configure("2") do |config|
|
51
|
+
config.vm.box = "vrealize"
|
52
|
+
|
53
|
+
config.vm.provider :vrealize do |vrealize, override|
|
54
|
+
# Note: you'll need to make sure your environment variables
|
55
|
+
# are set up correctly for this bit...
|
56
|
+
vrealize.vra_username = ENV['USER']
|
57
|
+
vrealize.vra_password = ENV['PASSWORD']
|
58
|
+
vrealize.vra_tenant = ENV['VRA_TENANT']
|
59
|
+
vrealize.vra_base_url = ENV['VRA_BASE_URL']
|
60
|
+
|
61
|
+
# From here on are configuration settings for the specific VM
|
62
|
+
# we're creating
|
63
|
+
|
64
|
+
vrealize.requested_for = ENV['VRA_AD_USER']
|
65
|
+
|
66
|
+
vrealize.subtenant_id = SOME_GUID
|
67
|
+
vrealize.catalog_item_id = SOME_CATALOG_ID
|
68
|
+
|
69
|
+
vrealize.add_entries do |extras|
|
70
|
+
# This isn't actually needed, it's just here to show how to set custom
|
71
|
+
# request data
|
72
|
+
extras.string('provider-Vrm.DataCenter.Location', '')
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
override.ssh.username = "root"
|
77
|
+
override.ssh.password = SOMETHING_SENSIBLE_HERE
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
And then run `vagrant up --provider=vrealize`.
|
83
|
+
|
84
|
+
## Networks
|
85
|
+
|
86
|
+
Networking features in the form of `config.vm.network` are not
|
87
|
+
supported with `vagrant-vrealize`, currently. If any of these are
|
88
|
+
specified, Vagrant will emit a warning, but will otherwise boot
|
89
|
+
the VRealize machine.
|
90
|
+
|
91
|
+
## Synced Folders
|
92
|
+
|
93
|
+
There is minimal support for synced folders. Upon `vagrant up`,
|
94
|
+
`vagrant reload`, and `vagrant provision`, the Vrealize provider will
|
95
|
+
use `rsync` (if available) to uni-directionally sync the folder to the
|
96
|
+
remote machine over SSH.
|
97
|
+
|
98
|
+
See [Vagrant Synced folders: rsync](https://docs.vagrantup.com/v2/synced-folders/rsync.html)
|
99
|
+
|
100
|
+
|
101
|
+
## Development
|
102
|
+
|
103
|
+
To work on the `vagrant-vrealize` plugin, clone this repository out, and use
|
104
|
+
[Bundler](http://gembundler.com) to get the dependencies:
|
105
|
+
|
106
|
+
```
|
107
|
+
$ bundle
|
108
|
+
```
|
109
|
+
|
110
|
+
If those install, you're ready to start developing the plugin. You can test
|
111
|
+
the plugin without installing it into your Vagrant environment by just
|
112
|
+
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
|
113
|
+
and add the following line to your `Vagrantfile`
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
Vagrant.require_plugin "vagrant-vrealize"
|
117
|
+
```
|
118
|
+
Use bundler to execute Vagrant:
|
119
|
+
```
|
120
|
+
$ bundle exec vagrant up --provider=vrealize
|
121
|
+
```
|
122
|
+
|
123
|
+
## And Finally
|
124
|
+
|
125
|
+
This plugin is an unfinished work-in-progress. It (and large parts of
|
126
|
+
this document) are based on Mitchell Hashimoto's `vagrant-aws` plugin,
|
127
|
+
which can be found here: https://github.com/mitchellh/vagrant-aws.
|
128
|
+
|
129
|
+
## Author
|
130
|
+
|
131
|
+
Alex Young <Alexander.Young@sky.uk>
|
132
|
+
Please get in touch, raise issues, make pull requests, if you're trying to use this and running into problems.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rake/testtask'
|
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
|
+
task :console do
|
18
|
+
require 'irb'
|
19
|
+
require 'irb/completion'
|
20
|
+
require 'vagrant-vrealize'
|
21
|
+
ARGV.clear
|
22
|
+
IRB.start
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Rebuild the boxfile."
|
26
|
+
task :box do
|
27
|
+
sh "cd example_box && bash ./mkbox.sh"
|
28
|
+
puts "Created example_box/vrealize.box"
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Vagrant AWS 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 `aws` provider.
|
5
|
+
To turn this into a box:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ tar cvzf aws.box ./metadata.json ./Vagrantfile
|
9
|
+
```
|
10
|
+
|
11
|
+
This box works by using Vagrant's built-in Vagrantfile merging to setup
|
12
|
+
defaults for AWS. These defaults can easily be overwritten by higher-level
|
13
|
+
Vagrantfiles (such as project root Vagrantfiles).
|
Binary file
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require 'vra'
|
3
|
+
|
4
|
+
require 'vagrant-vrealize/vra_client'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module Vrealize
|
8
|
+
module Action
|
9
|
+
|
10
|
+
# This action connects to VRealize, and sticks a :vra object
|
11
|
+
# into the environment.
|
12
|
+
class ConnectVrealize
|
13
|
+
def initialize(app, env)
|
14
|
+
@app = app
|
15
|
+
@logger = Log4r::Logger.new("vagrant_vrealize::action::connect_vrealize")
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
vra = client(env)
|
21
|
+
|
22
|
+
log_connecting(env)
|
23
|
+
authorized = (vra.authorize!; true) rescue false
|
24
|
+
|
25
|
+
if authorized
|
26
|
+
store(env, vra)
|
27
|
+
else
|
28
|
+
env[:ui].warn("Authorisation failed")
|
29
|
+
end
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def client(env)
|
37
|
+
vra_conf = vra_conf(env)
|
38
|
+
VraClient.build(username: vra_conf.vra_username,
|
39
|
+
password: vra_conf.vra_password,
|
40
|
+
tenant: vra_conf.vra_tenant,
|
41
|
+
base_url: vra_conf.vra_base_url,
|
42
|
+
verify_ssl: true)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def vra_conf(env)
|
47
|
+
env[:machine].provider_config
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def store(env, client)
|
52
|
+
env[:vra] = client
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def log_connecting(env)
|
57
|
+
@logger.info("Connecting to #{env[:machine].provider_config.vra_base_url}")
|
58
|
+
end
|
59
|
+
|
60
|
+
end # class ConnectVrealize
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vrealize
|
3
|
+
module Action
|
4
|
+
|
5
|
+
# This can be used with "Call" built-in to check if the machine
|
6
|
+
# is created and branch in the middleware.
|
7
|
+
class IsCreated
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
NotCreatedStatuses = %i{
|
14
|
+
not_created
|
15
|
+
DELETED
|
16
|
+
}
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
env[:result] = created?(env[:machine])
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def created?(machine)
|
25
|
+
!NotCreatedStatuses.include?(machine.state.id)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
end # class IsCreated
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vrealize
|
3
|
+
module Action
|
4
|
+
# This can be used with "Call" built-in to check if the machine
|
5
|
+
# is stopped and branch in the middleware.
|
6
|
+
class IsStopped
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:result] = env[:machine].state.id == :stopped
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vrealize
|
5
|
+
module Action
|
6
|
+
class MessageAlreadyCreated
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:ui].info(I18n.t("vagrant_vrealize.already_status", status: "created"))
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vrealize
|
3
|
+
module Action
|
4
|
+
class MessageNotCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_vrealize.not_created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vrealize
|
3
|
+
module Action
|
4
|
+
class MessageWillNotDestroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_vrealize.will_not_destroy", name: env[:machine].name))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vrealize
|
5
|
+
module Action
|
6
|
+
# This action reads the SSH info for the machine and puts it into the
|
7
|
+
# `:machine_ssh_info` key in the environment.
|
8
|
+
class ReadSSHInfo
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_vrealize::action::read_ssh_info")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_ssh_info] = read_ssh_info(env[:vra], env[:machine])
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_ssh_info(vra, machine)
|
21
|
+
if machine.id
|
22
|
+
vra.ssh_info(machine.id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vrealize
|
5
|
+
module Action
|
6
|
+
# This action reads the state of the machine and puts it in the
|
7
|
+
# `:machine_state_id` key in the environment.
|
8
|
+
class ReadState
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_vrealize::action::read_state")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state_id] = read_state(env[:vra],env[:machine])
|
16
|
+
end
|
17
|
+
|
18
|
+
def read_state(vra, machine)
|
19
|
+
return :not_created if machine.id.nil?
|
20
|
+
|
21
|
+
resource = vra.resources.by_id(machine.id)
|
22
|
+
|
23
|
+
return resource.status.to_sym
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'vagrant/util/retryable'
|
5
|
+
|
6
|
+
require 'vagrant-vrealize/util/timer'
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module Vrealize
|
10
|
+
module Action
|
11
|
+
# This runs the configured instance.
|
12
|
+
class RunInstance
|
13
|
+
include Vagrant::Util::Retryable
|
14
|
+
|
15
|
+
def initialize(app, env)
|
16
|
+
@app = app
|
17
|
+
@logger = Log4r::Logger.new("vagrant_vrealize::action::run_instance")
|
18
|
+
end
|
19
|
+
|
20
|
+
# There are more literal types than this, but we don't support them yet
|
21
|
+
|
22
|
+
def create_resource(env)
|
23
|
+
env[:ui].info("Creating machine")
|
24
|
+
|
25
|
+
config = env[:machine].provider_config
|
26
|
+
vra = env[:vra]
|
27
|
+
|
28
|
+
EntitledItemsCollection.fetch(env[:vra])
|
29
|
+
.find_by_id(config.catalog_item_id)
|
30
|
+
.request(cpus: config.cpus,
|
31
|
+
memory: config.memory,
|
32
|
+
requested_for: config.requested_for,
|
33
|
+
subtenant_id: config.subtenant_id,
|
34
|
+
lease_days: config.lease_days) { |req|
|
35
|
+
config.extra_entries.types.each do |type|
|
36
|
+
config.extra_entries.of_type(type).each do |k,v|
|
37
|
+
req.set_parameter(k, type, v)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
}
|
41
|
+
.join
|
42
|
+
.machine
|
43
|
+
end
|
44
|
+
|
45
|
+
def wait_for_ssh(env)
|
46
|
+
if !env[:interrupted]
|
47
|
+
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
|
48
|
+
# Wait for SSH to be ready.
|
49
|
+
env[:ui].info(I18n.t("vagrant_vrealize.waiting_for_ssh"))
|
50
|
+
network_ready_retries = 0
|
51
|
+
network_ready_retries_max = 10
|
52
|
+
loop do
|
53
|
+
# If we're interrupted then just back out
|
54
|
+
break if env[:interrupted]
|
55
|
+
begin
|
56
|
+
break if env[:machine].communicate.ready?
|
57
|
+
rescue => e
|
58
|
+
if network_ready_retries < network_ready_retries_max then
|
59
|
+
network_ready_retries += 1
|
60
|
+
@logger.warn(I18n.t("vagrant_vrealize.waiting_for_ssh, retrying"))
|
61
|
+
else
|
62
|
+
raise e
|
63
|
+
end
|
64
|
+
end
|
65
|
+
sleep 2
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def save_ip_address(env, resource)
|
72
|
+
env[:machine].data_dir.join('elastic_ip').open("w+") do |f|
|
73
|
+
f.write({:public_ip => resource.ip_addresses.first}.to_json)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def call(env)
|
78
|
+
vra = env[:vra] or fail "No VRA client instance!"
|
79
|
+
|
80
|
+
# Initialize metrics if they haven't been
|
81
|
+
env[:metrics] ||= {}
|
82
|
+
|
83
|
+
created_resource = create_resource(env)
|
84
|
+
env[:machine].id = created_resource.id
|
85
|
+
save_ip_address(env, created_resource)
|
86
|
+
wait_for_ssh(env)
|
87
|
+
terminate(env) if env[:interrupted]
|
88
|
+
|
89
|
+
@app.call(env)
|
90
|
+
end
|
91
|
+
|
92
|
+
def recover(env)
|
93
|
+
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
|
94
|
+
|
95
|
+
if env[:machine].provider.state.id != :not_created
|
96
|
+
# Undo the import
|
97
|
+
terminate(env)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def terminate(env)
|
102
|
+
destroy_env = env.dup
|
103
|
+
destroy_env.delete(:interrupted)
|
104
|
+
destroy_env[:config_validate] = false
|
105
|
+
destroy_env[:force_confirm_destroy] = true
|
106
|
+
env[:action_runner].run(Action.action_destroy, destroy_env)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
require 'vagrant/util/retryable'
|
4
|
+
|
5
|
+
require 'vagrant-vrealize/util/timer'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module Vrealize
|
9
|
+
module Action
|
10
|
+
# This starts a stopped instance.
|
11
|
+
class StartInstance
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, env)
|
15
|
+
@app = app
|
16
|
+
@logger = Log4r::Logger.new("vagrant_vrealize::action::start_instance")
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
fail NotImplementedError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vrealize
|
5
|
+
module Action
|
6
|
+
# This stops the running instance.
|
7
|
+
class StopInstance
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant_vrealize::action::stop_instance")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
fail NotImplementedError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|