vagrant-abiquo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38864b2ac0132ec39bc8ad85c49af85cf8b3ced4
4
+ data.tar.gz: 5371bf394611a016465041a475dc220716a172e8
5
+ SHA512:
6
+ metadata.gz: 785aab0851790885c4376c71454f09be252c936b2d8e07cdac72821904d9c5b40dc1d42331dc3da04e05b000a2818e94210a3957f3da1e0dd83826343dafe574
7
+ data.tar.gz: 2d9f200d45754a690028e77e519b82bad966ede1017e9e5ae5ea1d74cfa9edfb1cc668f262021f2e72c13b277f21093fae26658b8d40e0bacc05f6daca415239
@@ -0,0 +1,6 @@
1
+ Changelog
2
+ =========
3
+
4
+ 0.0.1
5
+ -----
6
+ - Working to make this work
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.6.3'
4
+ gem 'rest-client'
5
+ gem 'rake'
6
+
7
+ group :plugins do
8
+ gem "vagrant-abiquo", path: "."
9
+ end
10
+
11
+ gemspec
12
+
@@ -0,0 +1,106 @@
1
+ GIT
2
+ remote: git://github.com/mitchellh/vagrant.git
3
+ revision: 85d63a91f7aff7c16afee1dbc8bccc11cc6faa5e
4
+ tag: v1.6.3
5
+ specs:
6
+ vagrant (1.6.3)
7
+ bundler (>= 1.5.2, < 1.7.0)
8
+ childprocess (~> 0.5.0)
9
+ erubis (~> 2.7.0)
10
+ i18n (~> 0.6.0)
11
+ listen (~> 2.7.1)
12
+ log4r (~> 1.1.9, < 1.1.11)
13
+ net-scp (~> 1.1.0)
14
+ net-ssh (>= 2.6.6, < 2.10.0)
15
+ rb-kqueue (~> 0.2.0)
16
+ wdm (~> 0.1.0)
17
+ winrm (~> 1.1.3)
18
+
19
+ PATH
20
+ remote: .
21
+ specs:
22
+ vagrant-abiquo (0.0.1)
23
+ json
24
+ log4r
25
+ rest-client (>= 1.6.7)
26
+
27
+ GEM
28
+ remote: https://rubygems.org/
29
+ specs:
30
+ akami (1.2.2)
31
+ gyoku (>= 0.4.0)
32
+ nokogiri
33
+ builder (3.2.2)
34
+ celluloid (0.15.2)
35
+ timers (~> 1.1.0)
36
+ childprocess (0.5.3)
37
+ ffi (~> 1.0, >= 1.0.11)
38
+ erubis (2.7.0)
39
+ ffi (1.9.3)
40
+ gssapi (1.0.3)
41
+ ffi (>= 1.0.1)
42
+ gyoku (1.1.1)
43
+ builder (>= 2.1.2)
44
+ httpclient (2.3.4.1)
45
+ httpi (0.9.7)
46
+ rack
47
+ i18n (0.6.9)
48
+ json (1.8.1)
49
+ listen (2.7.6)
50
+ celluloid (>= 0.15.2)
51
+ rb-fsevent (>= 0.9.3)
52
+ rb-inotify (>= 0.9)
53
+ little-plugger (1.1.3)
54
+ log4r (1.1.10)
55
+ logging (1.8.2)
56
+ little-plugger (>= 1.1.3)
57
+ multi_json (>= 1.8.4)
58
+ mime-types (2.3)
59
+ mini_portile (0.6.0)
60
+ multi_json (1.10.1)
61
+ net-scp (1.1.2)
62
+ net-ssh (>= 2.6.5)
63
+ net-ssh (2.9.1)
64
+ nokogiri (1.6.2.1)
65
+ mini_portile (= 0.6.0)
66
+ nori (1.1.5)
67
+ rack (1.5.2)
68
+ rake (10.3.2)
69
+ rb-fsevent (0.9.4)
70
+ rb-inotify (0.9.4)
71
+ ffi (>= 0.5.0)
72
+ rb-kqueue (0.2.3)
73
+ ffi (>= 0.5.0)
74
+ rest-client (1.6.7)
75
+ mime-types (>= 1.16)
76
+ rubyntlm (0.1.1)
77
+ savon (0.9.5)
78
+ akami (~> 1.0)
79
+ builder (>= 2.1.2)
80
+ gyoku (>= 0.4.0)
81
+ httpi (~> 0.9)
82
+ nokogiri (>= 1.4.0)
83
+ nori (~> 1.0)
84
+ wasabi (~> 1.0)
85
+ timers (1.1.0)
86
+ uuidtools (2.1.4)
87
+ wasabi (1.0.0)
88
+ nokogiri (>= 1.4.0)
89
+ wdm (0.1.0)
90
+ winrm (1.1.3)
91
+ gssapi (~> 1.0.0)
92
+ httpclient (~> 2.2, >= 2.2.0.2)
93
+ logging (~> 1.6, >= 1.6.1)
94
+ nokogiri (~> 1.5)
95
+ rubyntlm (~> 0.1.1)
96
+ savon (= 0.9.5)
97
+ uuidtools (~> 2.1.2)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ rake
104
+ rest-client
105
+ vagrant!
106
+ vagrant-abiquo!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Daniel Beneyto
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.
@@ -0,0 +1,106 @@
1
+ Abiquo Vagrant Provider
2
+ ==============================
3
+ `vagrant-abiquo` is a provider plugin for Vagrant that supports the
4
+ management of [Abiquo](https://www.abiquo.com/) virtual machines
5
+
6
+ Current features include:
7
+ - create and destroy virtualmachines
8
+ - power on and off virtualmachines
9
+
10
+ The provider has been tested with Vagrant 1.4.x using Ubuntu 12.04 and
11
+ CentOS 6.3 guest operating systems.
12
+
13
+ Install
14
+ -------
15
+ Installation of the provider requires two steps:
16
+
17
+ 1. Install the provider plugin using the Vagrant command-line interface:
18
+
19
+ $ vagrant plugin install vagrant-abiquo
20
+
21
+
22
+ Configure
23
+ ---------
24
+ Once the provider has been installed, you will need to configure your project
25
+ to use it. The most basic `Vagrantfile` to create a droplet on Digital Ocean
26
+ is shown below:
27
+
28
+ ```ruby
29
+ Vagrantfile content goes here
30
+ ```
31
+
32
+ Please note the following:
33
+ - You *must* specify the `override.ssh.private_key_path` to enable authentication
34
+ with the droplet. The provider will create a new Digital Ocean SSH key using
35
+ your public key which is assumed to be the `private_key_path` with a *.pub*
36
+ extension.
37
+ - You *must* specify your Digital Ocean Client and API keys. These may be
38
+ found on the control panel within the *My Settings > API Access* section.
39
+
40
+ **Supported Configuration Attributes**
41
+
42
+ The following attributes are available to further configure the provider:
43
+ - `provider.image` - A string representing the image to use when creating a
44
+ new droplet (e.g. `Debian 6.0 x64`). The available options may
45
+ be found on Digital Ocean's new droplet [form](https://www.digitalocean.com/droplets/new).
46
+ It defaults to `Ubuntu 14.04.3 x64`.
47
+ - `provider.region` - A string representing the region to create the new
48
+ droplet in. It defaults to `New York 2`.
49
+ - `provider.size` - A string representing the size to use when creating a
50
+ new droplet (e.g. `1GB`). It defaults to `512MB`.
51
+ - `provider.private_networking` - A boolean flag indicating whether to enable
52
+ a private network interface (if the region supports private networking). It
53
+ defaults to `false`.
54
+ - `provider.backups_enabled` - A boolean flag indicating whether to enable backups for
55
+ the droplet. It defaults to `false`.
56
+ - `provider.ssh_key_name` - A string representing the name to use when creating
57
+ a Digital Ocean SSH key for droplet authentication. It defaults to `Vagrant`.
58
+ - `provider.setup` - A boolean flag indicating whether to setup a new user
59
+ account and modify sudo to disable tty requirement. It defaults to `true`.
60
+ If you are using a tool like [packer](https://packer.io) to create
61
+ reusable snapshots with user accounts already provisioned, set to `false`.
62
+
63
+ The provider will create a new user account with the specified SSH key for
64
+ authorization if `config.ssh.username` is set and the `provider.setup`
65
+ attribute is `true`.
66
+
67
+ Run
68
+ ---
69
+ After creating your project's `Vagrantfile` with the required configuration
70
+ attributes described above, you may create a new droplet with the following
71
+ command:
72
+
73
+ $ vagrant up --provider=digital_ocean
74
+
75
+ This command will create a new droplet, setup your SSH key for authentication,
76
+ create a new user account, and run the provisioners you have configured.
77
+
78
+ **Supported Commands**
79
+
80
+ The provider supports the following Vagrant sub-commands:
81
+ - `vagrant destroy` - Destroys the droplet instance.
82
+ - `vagrant ssh` - Logs into the droplet instance using the configured user
83
+ account.
84
+ - `vagrant halt` - Powers off the droplet instance.
85
+ - `vagrant provision` - Runs the configured provisioners and rsyncs any
86
+ specified `config.vm.synced_folder`.
87
+ - `vagrant reload` - Reboots the droplet instance.
88
+ - `vagrant rebuild` - Destroys the droplet instance and recreates it with the
89
+ same IP address is was assigned to previously.
90
+ - `vagrant status` - Outputs the status (active, off, not created) for the
91
+ droplet instance.
92
+
93
+ Contribute
94
+ ----------
95
+ To contribute, clone the repository, and use [Bundler](http://gembundler.com)
96
+ to install dependencies:
97
+
98
+ $ bundle
99
+
100
+ To run the provider's tests:
101
+
102
+ $ bundle exec rake test
103
+
104
+ You can now make modifications. Running `vagrant` within the Bundler
105
+ environment will ensure that plugins installed in your Vagrant
106
+ environment are not loaded.
@@ -0,0 +1,22 @@
1
+ require 'bundler/gem_helper'
2
+
3
+ namespace :gem do
4
+ Bundler::GemHelper.install_tasks
5
+ end
6
+
7
+ task :test do
8
+ result = sh 'bash test/test.sh'
9
+
10
+ if result
11
+ puts 'Success!'
12
+ else
13
+ puts 'Failure!'
14
+ exit 1
15
+ end
16
+ end
17
+
18
+ def env
19
+ ['ABIQUO_API_USER', 'ABIQUO_API_PASSWORD', 'VAGRANT_LOG'].inject('') do |acc, key|
20
+ acc += "#{key}=#{ENV[key] || 'error'} "
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ VAGRANTFILE_API_VERSION = "2"
2
+
3
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
4
+ config.vm.define 'abiquotesting' do |t|
5
+ end
6
+ config.vm.provider :abiquo do |provider, override|
7
+ override.vm.box = 'abiquo'
8
+ override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
9
+ override.vm.hostname = 'abiquotesting'
10
+
11
+ provider.abiquo_api_user = 'admin'
12
+ provider.abiquo_api_password = 'xabiquo'
13
+ provider.abiquo_api_uri = 'https://preproduction.bcn.abiquo.com:443/api'
14
+ provider.virtualdatacenter = 'testVDC'
15
+ provider.virtualappliance = 'testing'
16
+ provider.label = 'MyVagrantVM'
17
+ # Nic which is exposed for SSH access
18
+ provider.exposed_nic = 'nic0'
19
+ provider.template = 'CoreVMDK'
20
+ end
21
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "abiquo"
3
+ }
@@ -0,0 +1,14 @@
1
+ require 'vagrant-abiquo/version'
2
+ require 'vagrant-abiquo/plugin'
3
+ require 'vagrant-abiquo/errors'
4
+
5
+ module VagrantPlugins
6
+ module Abiquo
7
+ def self.source_root
8
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
9
+ end
10
+
11
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
12
+ I18n.reload!
13
+ end
14
+ end
@@ -0,0 +1,86 @@
1
+ require 'vagrant-abiquo/actions/check_state'
2
+ require 'vagrant-abiquo/actions/create'
3
+ require 'vagrant-abiquo/actions/destroy'
4
+ require 'vagrant-abiquo/actions/power_off'
5
+ require 'vagrant-abiquo/actions/power_on'
6
+
7
+ module VagrantPlugins
8
+ module Abiquo
9
+ module Actions
10
+ include Vagrant::Action::Builtin
11
+
12
+ def self.destroy
13
+ return Vagrant::Action::Builder.new.tap do |builder|
14
+ builder.use ConfigValidate
15
+ builder.use Call, CheckState do |env, b|
16
+ case env[:machine_state]
17
+ when :not_created
18
+ env[:ui].info I18n.t('vagrant_abiquo.info.not_created')
19
+ else
20
+ b.use Call, DestroyConfirm do |env2, b2|
21
+ if env2[:result]
22
+ b2.use Destroy
23
+ b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.provision
32
+ return Vagrant::Action::Builder.new.tap do |builder|
33
+ builder.use ConfigValidate
34
+ builder.use Call, CheckState do |env, b|
35
+ case env[:machine_state]
36
+ when :active
37
+ b.use Provision
38
+ b.use ModifyProvisionPath
39
+ b.use SyncFolders
40
+ when :off
41
+ env[:ui].info I18n.t('vagrant_abiquo.info.off')
42
+ when :not_created
43
+ env[:ui].info I18n.t('vagrant_abiquo.info.not_created')
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def self.up
50
+ return Vagrant::Action::Builder.new.tap do |builder|
51
+ builder.use ConfigValidate
52
+ builder.use Call, CheckState do |env, b|
53
+ case env[:machine_state]
54
+ when :active
55
+ env[:ui].info I18n.t('vagrant_abiquo.info.already_active')
56
+ when :off
57
+ b.use PowerOn
58
+ b.use provision
59
+ when :not_created
60
+ b.use Create
61
+ b.use provision
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.halt
68
+ return Vagrant::Action::Builder.new.tap do |builder|
69
+ builder.use ConfigValidate
70
+ builder.use Call, CheckState do |env, b|
71
+ case env[:machine_state]
72
+ when :active
73
+ b.use PowerOff
74
+ when :off
75
+ env[:ui].info I18n.t('vagrant_abiquo.info.already_off')
76
+ when :not_created
77
+ env[:ui].info I18n.t('vagrant_abiquo.info.not_created')
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Abiquo
3
+ module Actions
4
+ class CheckState
5
+ def initialize(app, env)
6
+ @app = app
7
+ @machine = env[:machine]
8
+ @logger = Log4r::Logger.new('vagrant::abiquo::check_state')
9
+ end
10
+
11
+ def call(env)
12
+ env[:machine_state] = @machine.state.id
13
+ @logger.info "Machine state is '#{@machine.state.id}'"
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,113 @@
1
+ require 'vagrant-abiquo/helpers/client'
2
+
3
+ module VagrantPlugins
4
+ module Abiquo
5
+ module Actions
6
+ class Create
7
+ include Helpers::Client
8
+ include Vagrant::Util::Retryable
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @machine = env[:machine]
13
+ @client = client
14
+ @logger = Log4r::Logger.new('vagrant::abiquo::create')
15
+ end
16
+
17
+ def call(env)
18
+ # Find for selected virtual datacenter
19
+ vdcs_accept = {:accept => "application/vnd.abiquo.virtualdatacenters+json" }
20
+ virtualdatacenters = @client.http_request(@machine.provider_config.abiquo_api_uri+"/cloud/virtualdatacenters?limit=0","GET", vdcs_accept)
21
+ virtualdatacenter_id = @client.find_id("VirtualDatacener",virtualdatacenters, @machine.provider_config.virtualdatacenter)
22
+ # Find for selected virtual appliance
23
+ vapps_accept = {:accept => "application/vnd.abiquo.virtualappliances+json" }
24
+ virtualappliances = @client.http_request(@machine.provider_config.abiquo_api_uri+"/cloud/virtualdatacenters/#{virtualdatacenter_id}/virtualappliances?limit=0","GET",vapps_accept)
25
+ virtualappliance_id = @client.find_id("VirtualAppliance",virtualappliances, @machine.provider_config.virtualappliance)
26
+ # Find for selected vm template
27
+ templates_accept = {:accept => "application/vnd.abiquo.virtualmachinetemplates+json"}
28
+ templates = @client.http_request(@machine.provider_config.abiquo_api_uri+"/cloud/virtualdatacenters/#{virtualdatacenter_id}/action/templates?limit=0","GET",templates_accept)
29
+ template_href = @client.find_template("Template",templates, @machine.provider_config.template)
30
+
31
+ # If everything is OK we can proceed to create the VM
32
+ # VM Template link
33
+ link = {}
34
+ link['title'] = @machine.provider_config.template
35
+ link['rel'] = "virtualmachinetemplate"
36
+ link['type'] = "application/vnd.abiquo.virtualmachinetemplate+json"
37
+ link['href'] = template_href
38
+
39
+ # VM entity
40
+ vm_definition = {}
41
+ vm_definition['label'] = @machine.provider_config.label
42
+ vm_definition['vdrpEnabled'] = true
43
+ vm_definition['links'] = Array.new
44
+ vm_definition['links'][0] = link
45
+
46
+ # POST Headers
47
+ vm_post_headers = { :content_type => "application/vnd.abiquo.virtualmachine+json", :accept => "application/vnd.abiquo.virtualmachine+json" }
48
+
49
+ # Creating VM in Abiquo
50
+ env[:ui].info I18n.t('vagrant_abiquo.info.creating')
51
+ @vm = JSON.parse(@client.http_request(@machine.provider_config.abiquo_api_uri+"/cloud/virtualdatacenters/#{virtualdatacenter_id}/virtualappliances/#{virtualappliance_id}/virtualmachines","POST",vm_post_headers,vm_definition.to_json))
52
+
53
+ # Deploying VM
54
+ env[:ui].info I18n.t('vagrant_abiquo.info.deploying')
55
+ @vm['links'].each do |link|
56
+ if link['rel'].eql? "deploy"
57
+ @task = JSON.parse(@client.http_request(link['href'],"POST",:accept => link['type']))
58
+ end
59
+ end
60
+
61
+ # Check when deploy finishes. This may take a while
62
+ retryable(:tries => 120, :sleep => 10) do
63
+ # TO-DO: Add content-type headers to GET request
64
+ @task_state = JSON.parse(@client.http_request(@task['links'][0]['href'],"GET"))
65
+ raise 'DeployInProgress' if @task_state['state'] == 'STARTED'
66
+ end
67
+
68
+ if @task_state['state'] == 'FINISHED_SUCCESSFULLY'
69
+ # Deploy successfully completed
70
+ env[:ui].info I18n.t('vagrant_abiquo.info.deploycompleted')
71
+ @vm['links'].each do |link|
72
+ if link['rel'].eql? "edit"
73
+ @vm = JSON.parse(@client.http_request(link['href'],"GET"))
74
+ end
75
+ end
76
+ @vm['links'].each do |link|
77
+ if link['rel'].eql? @machine.provider_config.exposed_nic
78
+ # Refresh vm state with provider and output ip address
79
+ virtualmachine = Provider.virtualmachine(@machine)
80
+ env[:ui].info I18n.t('vagrant_abiquo.info.vm_ip', {:ip => link['title']})
81
+ # Assign the machine id for reference in other commands
82
+ @machine.id = @vm['id'].to_s
83
+ end
84
+ end
85
+ else
86
+ # Deploy failed
87
+ env[:ui].info I18n.t('vagrant_abiquo.info.deployfailed')
88
+ end
89
+
90
+ @app.call(env)
91
+ end
92
+
93
+ # Both the recover and terminate are stolen almost verbatim from
94
+ # the Vagrant AWS provider up action
95
+ def recover(env)
96
+ return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
97
+
98
+ if @machine.state.id != :not_created
99
+ terminate(env)
100
+ end
101
+ end
102
+
103
+ def terminate(env)
104
+ destroy_env = env.dup
105
+ destroy_env.delete(:interrupted)
106
+ destroy_env[:config_validate] = false
107
+ destroy_env[:force_confirm_destroy] = true
108
+ env[:action_runner].run(Actions.destroy, destroy_env)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end