vagrant-arubacloud 0.0.2dev
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 +7 -0
- data/.gitignore +19 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +22 -0
- data/Vagrantfile +41 -0
- data/dummy.box +0 -0
- data/example_box/metadata.json +3 -0
- data/gemfiles/vagrant-arubacloud-0.0.1dev.gem +0 -0
- data/gemfiles/vagrant-arubacloud-0.0.2dev.gem +0 -0
- data/lib/vagrant-arubacloud/action/aruba_provision.rb +37 -0
- data/lib/vagrant-arubacloud/action/connect_arubacloud.rb +38 -0
- data/lib/vagrant-arubacloud/action/create_server.rb +105 -0
- data/lib/vagrant-arubacloud/action/delete_server.rb +33 -0
- data/lib/vagrant-arubacloud/action/disable_requiretty.rb +24 -0
- data/lib/vagrant-arubacloud/action/halt_server.rb +55 -0
- data/lib/vagrant-arubacloud/action/is_created.rb +19 -0
- data/lib/vagrant-arubacloud/action/list_servers.rb +23 -0
- data/lib/vagrant-arubacloud/action/list_templates.rb +34 -0
- data/lib/vagrant-arubacloud/action/message_already_created.rb +16 -0
- data/lib/vagrant-arubacloud/action/message_not_created.rb +16 -0
- data/lib/vagrant-arubacloud/action/read_ssh_info.rb +43 -0
- data/lib/vagrant-arubacloud/action/read_state.rb +46 -0
- data/lib/vagrant-arubacloud/action.rb +163 -0
- data/lib/vagrant-arubacloud/cap/disable_requiretty.rb +13 -0
- data/lib/vagrant-arubacloud/command/root.rb +67 -0
- data/lib/vagrant-arubacloud/command/servers.rb +21 -0
- data/lib/vagrant-arubacloud/command/templates.rb +21 -0
- data/lib/vagrant-arubacloud/config.rb +124 -0
- data/lib/vagrant-arubacloud/errors.rb +19 -0
- data/lib/vagrant-arubacloud/plugin.rb +48 -0
- data/lib/vagrant-arubacloud/provider.rb +51 -0
- data/lib/vagrant-arubacloud/version.rb +5 -0
- data/lib/vagrant-arubacloud.rb +53 -0
- data/locales/en.yml +64 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/vagrant-arubacloud/action/connect_arubacloud_spec.rb +36 -0
- data/spec/vagrant-arubacloud/action_spec.rb +25 -0
- data/spec/vagrant-arubacloud/config_spec.rb +192 -0
- data/vagrant-arubacloud.gemspec +28 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c397453e306cc0f71db0fd95c3e3bb38f174a71
|
4
|
+
data.tar.gz: 2132e93f14890b77f1c93cc416e1becf27da6d15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6600f14e8450c63bce01610880c13d23c074138444a60cb0a58cd0f22f0ecf1a3291aece1d82535fd8b9484fb9acaa3fd40631e4056028ef2d2803ce6948fa3a
|
7
|
+
data.tar.gz: 73b6f32013deb16724f4dee072bfb2dd97ecd1b3d807ea90b7a8a0e3a3bdd677bdb31ac7bc6fb8994cd14dcbcc7f2b239dc42bfbc0e47ff4c15c5f7515151c73
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in vagrant-vagrant-arubacloud.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
#gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
8
|
+
gem 'vagrant', path: '/home/alessio.rocchi/RubymineProjects/vagrant'
|
9
|
+
gem 'fog-arubacloud', path: '/home/alessio.rocchi/RubymineProjects/fog-arubacloud'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :plugins do
|
13
|
+
gem 'vagrant-arubacloud', path: '.'
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Alessio Rocchi
|
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,95 @@
|
|
1
|
+
# Vagrant ArubaCloud Provider
|
2
|
+
|
3
|
+
This is a [Vagrant](http://www.vagrantup.com) 1.5+ plugin that adds ArubaCloud provider
|
4
|
+
to Vagrant, allowing Vagrant to control and provision machine in ArubaCloud Smart IaaS Service.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
* Boot ArubaCloud instances.
|
8
|
+
* SSH into instances.
|
9
|
+
* Provision the instances with any built-in Vagrant provisioner.
|
10
|
+
* Specify which datacenter you want to use.
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
Install using standard `vagrant plugin install` method, since the gem is published in[central RubyGemsrepository](https://rubygems.org/gems/vagrant-arubacloud)
|
15
|
+
```
|
16
|
+
$ vagrant plugin install vagrant-arubacloud
|
17
|
+
```
|
18
|
+
|
19
|
+
## Quickstart
|
20
|
+
After installing the plugin (instructions above), the quickest way to get
|
21
|
+
started is to actually use a dummy ArubaCloud box and specify all the details
|
22
|
+
manually within a `config.vm.provider` block. So first, add the dummy
|
23
|
+
box using any name you want:
|
24
|
+
|
25
|
+
```
|
26
|
+
$ vagrant box add dummy https://github.com/arubacloud/vagrant-arubacloud/raw/master/dummy.box
|
27
|
+
...
|
28
|
+
```
|
29
|
+
|
30
|
+
And then make a Vagrantfile that looks like the following, filling in
|
31
|
+
your information where necessary. For now, username and password must be specified as environment variables:
|
32
|
+
```
|
33
|
+
export AC_USERNAME=""
|
34
|
+
export AC_PASSWORD=""
|
35
|
+
```
|
36
|
+
|
37
|
+
```
|
38
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
39
|
+
config.vm.box = "dummy"
|
40
|
+
|
41
|
+
config.vm.define :ubuntu do |ubuntu|
|
42
|
+
ubuntu.ssh.username = 'root'
|
43
|
+
ubuntu.ssh.password = 'yourstrongpassword'
|
44
|
+
ubuntu.vm.provider :arubacloud do |ac|
|
45
|
+
ac.arubacloud_username = ENV['AC_USERNAME']
|
46
|
+
ac.arubacloud_password = ENV['AC_PASSWORD']
|
47
|
+
ac.admin_password = 'yourstrongpassword'
|
48
|
+
ac.template_id = '601'
|
49
|
+
ac.package_id = 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
For now, the root password must be specified in this way, I will change it soon (it's horrible).
|
56
|
+
|
57
|
+
And then run `vagrant up --provider=arubacloud`.
|
58
|
+
|
59
|
+
This will start an Ubuntu 14.04 instance in the second Italian Datacenter (DC2-IT) within
|
60
|
+
your account. And assuming your SSH information was filled in properly
|
61
|
+
within your Vagrantfile, SSH and provisioning will work as well.
|
62
|
+
|
63
|
+
Note that normally a lot of this boilerplate is encoded within the box
|
64
|
+
file, but the box file used for the quick start, the "dummy" box, has
|
65
|
+
no preconfigured defaults.
|
66
|
+
|
67
|
+
If you have issues with SSH connecting, make sure that the instances
|
68
|
+
are being launched with a security group that allows SSH access.
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
To work on the `vagrant-arubacloud` plugin, clone this repository out, and use
|
73
|
+
[Bundler](http://gembundler.com) to get the dependencies:
|
74
|
+
|
75
|
+
```
|
76
|
+
$ bundle
|
77
|
+
```
|
78
|
+
|
79
|
+
Once you have the dependencies, verify the unit tests pass with `rake`:
|
80
|
+
|
81
|
+
```
|
82
|
+
$ bundle exec rake
|
83
|
+
```
|
84
|
+
|
85
|
+
If those pass, you're ready to start developing the plugin. You can test
|
86
|
+
the plugin without installing it into your Vagrant environment by just
|
87
|
+
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
|
88
|
+
and add the following line to your `Vagrantfile`
|
89
|
+
```ruby
|
90
|
+
Vagrant.require_plugin "vagrant-arubacloud"
|
91
|
+
```
|
92
|
+
Use bundler to execute Vagrant:
|
93
|
+
```
|
94
|
+
$ bundle exec vagrant up --provider=arubacloud
|
95
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
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
|
19
|
+
|
20
|
+
# Default task is to run the unit tests
|
21
|
+
task :default => 'spec'
|
22
|
+
|
data/Vagrantfile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = '2'
|
6
|
+
|
7
|
+
%w{AC_USERNAME AC_PASSWORD}.each do |var|
|
8
|
+
abort "Please set the environment variable #{var} in order to run the test" unless ENV.key? var
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'securerandom'
|
12
|
+
rnd_string = SecureRandom.hex(2)
|
13
|
+
|
14
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
15
|
+
|
16
|
+
# All Vagrant configuration is done here. The most common configuration
|
17
|
+
# options are documented and commented below. For a complete reference,
|
18
|
+
# please see the online documentation at vagrantup.com.
|
19
|
+
|
20
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
21
|
+
config.vm.box = "dummy"
|
22
|
+
|
23
|
+
config.vm.define :centos do |centos|
|
24
|
+
centos.ssh.username = 'root'
|
25
|
+
centos.ssh.password = 'g1un71n5.l4m3n74'
|
26
|
+
centos.vm.provider :arubacloud do |ac|
|
27
|
+
ac.arubacloud_username = ENV['AC_USERNAME']
|
28
|
+
ac.arubacloud_password = ENV['AC_PASSWORD']
|
29
|
+
ac.admin_password = 'g1un71n5.l4m3n74'
|
30
|
+
#ac.template_id = '415'
|
31
|
+
ac.template_id = '9'
|
32
|
+
#ac.package_id = 1
|
33
|
+
ac.service_type = 2
|
34
|
+
ac.server_name = "centos-#{rnd_string}"
|
35
|
+
ac.cpu_number = 2
|
36
|
+
ac.ram_qty = 4
|
37
|
+
ac.hds = [{:type => 0, :size => 20}, {:type => 1, :size => 30}]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/dummy.box
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ArubaCloud
|
5
|
+
module Action
|
6
|
+
|
7
|
+
# This override is needed to intercept provisioning action and
|
8
|
+
# call the disable_requiretty capability. This is horrible, but for now
|
9
|
+
# that's it.
|
10
|
+
class ArubaProvision < Vagrant::Action::Builtin::Provision
|
11
|
+
|
12
|
+
def initialize(app, env)
|
13
|
+
@machine = env[:machine]
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@env = env
|
19
|
+
|
20
|
+
if @machine.guest.name.eql? :redhat
|
21
|
+
unless @machine.guest.capability?(:disable_requiretty)
|
22
|
+
@machine.ui.warn(I18n.t('vagrant_arubacloud.disable_require_tty_cap_not_found'))
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
@machine.ui.detail(I18n.t('vagrant_arubacloud.disabling_requiretty'))
|
27
|
+
@machine.guest.capability(:disable_requiretty)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the control to original Provision in middleware stack
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'fog/arubacloud'
|
2
|
+
require 'log4r'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module ArubaCloud
|
6
|
+
module Action
|
7
|
+
|
8
|
+
class ConnectArubaCloud
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new('vagrant_arubacloud::action::connect_arubacloud')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
# Set the datacenter
|
16
|
+
config = env[:machine].provider_config
|
17
|
+
arubacloud_username = config.arubacloud_username
|
18
|
+
arubacloud_password = config.arubacloud_password
|
19
|
+
|
20
|
+
params = {
|
21
|
+
:provider => :arubacloud,
|
22
|
+
:arubacloud_username => arubacloud_username,
|
23
|
+
:arubacloud_password => arubacloud_password,
|
24
|
+
}
|
25
|
+
|
26
|
+
if config.url
|
27
|
+
@logger.info("Connecting to Datacenter: #{config.url}")
|
28
|
+
params[:url] = config.url
|
29
|
+
end
|
30
|
+
|
31
|
+
env[:arubacloud_compute] = Fog::Compute.new params
|
32
|
+
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'fog/arubacloud'
|
2
|
+
require 'log4r'
|
3
|
+
|
4
|
+
require 'vagrant/util/retryable'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module ArubaCloud
|
8
|
+
module Action
|
9
|
+
|
10
|
+
# Create a new server
|
11
|
+
class CreateServer
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, env)
|
15
|
+
@app = app
|
16
|
+
@logger = Log4r::Logger.new('vagrant_arubacloud::action::create_server')
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
config = env[:machine].provider_config
|
21
|
+
|
22
|
+
env[:ui].info('Creating machine...')
|
23
|
+
|
24
|
+
# Set Server Name
|
25
|
+
server_name = config.server_name || env[:machine].name
|
26
|
+
|
27
|
+
# Output the settings we're going to use to the user
|
28
|
+
env[:ui].info('Creating a server with the following settings...')
|
29
|
+
env[:ui].info(" -- Name: #{server_name}")
|
30
|
+
env[:ui].info(" -- Root Password: #{config.admin_password}")
|
31
|
+
env[:ui].info(" -- Package: #{config.package_id}")
|
32
|
+
env[:ui].info(" -- OS Template: #{config.template_id}")
|
33
|
+
env[:ui].info(" -- Service Type: #{config.service_type}")
|
34
|
+
|
35
|
+
# Build the config hash according to the service type
|
36
|
+
if config.service_type.eql? 4
|
37
|
+
options = {
|
38
|
+
:name => server_name,
|
39
|
+
:vm_type => 'smart',
|
40
|
+
:admin_passwd => config.admin_password,
|
41
|
+
:cpu => 1,
|
42
|
+
:memory => 1,
|
43
|
+
:template_id => config.template_id,
|
44
|
+
:package_id => config.package_id
|
45
|
+
}
|
46
|
+
else
|
47
|
+
# Processing hds
|
48
|
+
disks = []
|
49
|
+
config.hds.each do |disk_spec|
|
50
|
+
disks << env[:arubacloud_compute].disks.create({
|
51
|
+
:size => disk_spec[:size],
|
52
|
+
:virtual_disk_type => disk_spec[:type]
|
53
|
+
})
|
54
|
+
.get_hash
|
55
|
+
end
|
56
|
+
options = {
|
57
|
+
:name => server_name,
|
58
|
+
:vm_type => 'pro',
|
59
|
+
:admin_passwd => config.admin_password,
|
60
|
+
:cpu => config.cpu_number,
|
61
|
+
:memory => config.ram_qty,
|
62
|
+
:template_id => config.template_id,
|
63
|
+
:disks => disks
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create the server
|
68
|
+
begin
|
69
|
+
server = env[:arubacloud_compute].servers.create(options)
|
70
|
+
rescue Fog::ArubaCloud::Errors::RequestError => e
|
71
|
+
message = ''
|
72
|
+
error = nil
|
73
|
+
@logger.debug(e.inspect.to_yaml)
|
74
|
+
if e.response['ResultCode'].eql? 16
|
75
|
+
message = "Virtual machine with name: #{options[:name]}, already present. Bailout!"
|
76
|
+
error = Errors::MachineAlreadyPresent
|
77
|
+
elsif e.response['ResultCode'].eql?(-500)
|
78
|
+
message = 'Server returned an unexpected response. Bailout!'
|
79
|
+
error = Errors::BadServerResponse
|
80
|
+
end
|
81
|
+
env[:ui].warn("Response message: #{e.response.to_yaml}")
|
82
|
+
env[:ui].warn(message)
|
83
|
+
raise error
|
84
|
+
end
|
85
|
+
|
86
|
+
# Store id of the machine
|
87
|
+
env[:machine].id = server.id
|
88
|
+
|
89
|
+
# Wait for ssh to be ready
|
90
|
+
env[:ui].info('Waiting for the server to be ready...')
|
91
|
+
|
92
|
+
retryable(:tries => 10, :sleep => 60) do
|
93
|
+
next if env[:interrupted]
|
94
|
+
server.wait_for(5) { ready? }
|
95
|
+
end
|
96
|
+
|
97
|
+
env[:ui].info('The server is ready!')
|
98
|
+
|
99
|
+
@app.call(env)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'fog/arubacloud/error'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module ArubaCloud
|
6
|
+
module Action
|
7
|
+
# This deletes the running server, if there is one.
|
8
|
+
class DeleteServer
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new('vagrant_arubacloud::action::delete_server')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env[:machine].id
|
16
|
+
env[:ui].info(I18n.t('vagrant_arubacloud.deleting_server'))
|
17
|
+
# On fog side, get will call get_service_details, I must be sure
|
18
|
+
# that the returned object has the "id" parameters not nil
|
19
|
+
server = env[:arubacloud_compute].servers.get(env[:machine].id)
|
20
|
+
begin
|
21
|
+
server.delete
|
22
|
+
rescue Fog::ArubaCloud::Errors::VmStatus
|
23
|
+
env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
|
24
|
+
end
|
25
|
+
env[:machine].id = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ArubaCloud
|
3
|
+
module Action
|
4
|
+
class DisableRequireTty
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
unless @machine.guest.capability?(:disable_requiretty)
|
12
|
+
@machine.ui.warn(I18n.t('vagrant_arubacloud.disable_require_tty_cap_not_found'))
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
@machine.ui.detail(I18n.t('vagrant_arubacloud.disabling_requiretty'))
|
17
|
+
@machine.guest.capability(:disable_requiretty)
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'vagrant/util/retryable'
|
3
|
+
require 'fog/arubacloud/error'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ArubaCloud
|
7
|
+
module Action
|
8
|
+
# This stop a server, if it exists
|
9
|
+
class HaltServer
|
10
|
+
include Vagrant::Util::Retryable
|
11
|
+
|
12
|
+
def initialize(app, env)
|
13
|
+
@app = app
|
14
|
+
@env = env
|
15
|
+
@logger = Log4r::Logger.new('vagrant_arubacloud::action::halt_server')
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
if env[:machine].id
|
20
|
+
env[:ui].info(I18n.t('vagrant_arubacloud.halting_server'))
|
21
|
+
server = env[:arubacloud_compute].servers.get(env[:machine].id)
|
22
|
+
|
23
|
+
# Check if the vm is already powered off
|
24
|
+
@logger.debug("VM stopped?: #{server.stopped?}")
|
25
|
+
if server.stopped?
|
26
|
+
# continue the middleware
|
27
|
+
@app.call(env)
|
28
|
+
else
|
29
|
+
# Try to poweroff the VM.
|
30
|
+
begin
|
31
|
+
server.power_off
|
32
|
+
rescue Fog::ArubaCloud::Errors::VmStatus
|
33
|
+
env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state'))
|
34
|
+
return
|
35
|
+
rescue Fog::ArubaCloud::Errors::RequestError => e
|
36
|
+
if e.response['ResultCode'].eql? 17
|
37
|
+
env[:ui].warn(I18n.t('vagrant_arubacloud.operation_already_in_queue'))
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Wait for the server to be proper shut down
|
43
|
+
retryable(:tries => 20, :sleep => 1) do
|
44
|
+
server.wait_for(1) { stopped? }
|
45
|
+
end
|
46
|
+
env[:ui].info(I18n.t('vagrant_arubacloud.server_powered_off'))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
@app.call(env)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ArubaCloud
|
5
|
+
module Action
|
6
|
+
class IsCreated
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new('vagrant_arubacloud::action::is_created')
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env[:result] = env[:machine].id != nil
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ArubaCloud
|
3
|
+
module Action
|
4
|
+
class ListServers
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
compute_service = env[:arubacloud_compute]
|
11
|
+
env[:ui].info ('%-20s %-20s %s' % ['Server Name', 'State', 'IPv4 address'])
|
12
|
+
compute_service.servers.sort_by(&:name).each do |server|
|
13
|
+
# Ask fog for the full details list
|
14
|
+
server.get_server_details
|
15
|
+
# Output the result
|
16
|
+
env[:ui].info ('%-20s %-20s %s' % [server.name, server.state, server.smart_ipv4])
|
17
|
+
end
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ArubaCloud
|
3
|
+
module Action
|
4
|
+
class ListTemplates
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
compute_service = env[:arubacloud_compute]
|
11
|
+
env[:ui].info ('%-40s %-60s %-20s %s' % ['Template Name', 'Description', 'ID', 'Hypervisor ID'])
|
12
|
+
compute_service.templates.sort_by(&:hypervisor).each do |template|
|
13
|
+
env[:ui].info ('%-40s %-60s %-20s %s' % [template.name,
|
14
|
+
template.description,
|
15
|
+
template.id,
|
16
|
+
enum_hypervisor_id(template.hypervisor)])
|
17
|
+
end
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def enum_hypervisor_id(id)
|
22
|
+
case id
|
23
|
+
when 1 then return 'Pro Hyper-V'
|
24
|
+
when 2 then return 'Pro VmWare'
|
25
|
+
when 3 then return 'Pro Hyper-V LowCost'
|
26
|
+
when 4 then return 'Pro Smart'
|
27
|
+
else
|
28
|
+
return 'Not Found'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ArubaCloud
|
3
|
+
module Action
|
4
|
+
class MessageAlreadyCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t('vagrant_arubacloud.already_created'))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ArubaCloud
|
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('Server is not present, assuming not created... Bailout!')
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|