vagrant-ganeti 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +12 -0
  3. data/LICENSE +8 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +137 -0
  6. data/Rakefile +23 -0
  7. data/example_box/README.md +13 -0
  8. data/example_box/Vagrantfile +8 -0
  9. data/example_box/ganeti.box +0 -0
  10. data/example_box/metadata.json +3 -0
  11. data/lib/vagrant-plugin-ganeti/action/connect_ganeti.rb +70 -0
  12. data/lib/vagrant-plugin-ganeti/action/is_created.rb +18 -0
  13. data/lib/vagrant-plugin-ganeti/action/is_reachable.rb +18 -0
  14. data/lib/vagrant-plugin-ganeti/action/message_already_created.rb +16 -0
  15. data/lib/vagrant-plugin-ganeti/action/message_not_created.rb +16 -0
  16. data/lib/vagrant-plugin-ganeti/action/message_not_reachable.rb +16 -0
  17. data/lib/vagrant-plugin-ganeti/action/message_will_not_destroy.rb +16 -0
  18. data/lib/vagrant-plugin-ganeti/action/read_ssh_info.rb +32 -0
  19. data/lib/vagrant-plugin-ganeti/action/read_state.rb +84 -0
  20. data/lib/vagrant-plugin-ganeti/action/remove_instance.rb +26 -0
  21. data/lib/vagrant-plugin-ganeti/action/run_instance.rb +76 -0
  22. data/lib/vagrant-plugin-ganeti/action/sync_folders.rb +85 -0
  23. data/lib/vagrant-plugin-ganeti/action/timed_provision.rb +22 -0
  24. data/lib/vagrant-plugin-ganeti/action/unlink_server.rb +30 -0
  25. data/lib/vagrant-plugin-ganeti/action/warn_networks.rb +19 -0
  26. data/lib/vagrant-plugin-ganeti/action.rb +137 -0
  27. data/lib/vagrant-plugin-ganeti/config.rb +308 -0
  28. data/lib/vagrant-plugin-ganeti/errors.rb +19 -0
  29. data/lib/vagrant-plugin-ganeti/plugin.rb +73 -0
  30. data/lib/vagrant-plugin-ganeti/provider.rb +50 -0
  31. data/lib/vagrant-plugin-ganeti/util/ganeti_client.rb +142 -0
  32. data/lib/vagrant-plugin-ganeti/util/timer.rb +17 -0
  33. data/lib/vagrant-plugin-ganeti/version.rb +5 -0
  34. data/lib/vagrant-plugin-ganeti.rb +19 -0
  35. data/locales/en.yml +81 -0
  36. data/vagrant-plugin-ganeti.gemspec +57 -0
  37. metadata +163 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-plugin-ganeti.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ # We depend on Vagrant for development, but we don't add it as a
8
+ # gem dependency because we expect to be installed within the
9
+ # Vagrant environment itself using `vagrant plugin`.
10
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
11
+ end
12
+
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2013 Mitchell Hashimoto
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
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,137 @@
1
+ # Vagrant Ganeti Provider
2
+ This is a Vagrant 1.2+ plugin that adds an Ganeti provider to Vagrant, allowing Vagrant to control and provision
3
+ machines in Ganeti.
4
+
5
+ NOTE: This plugin requires Vagrant 1.2
6
+ NOTE: This project is work in progress, there are lot of things which might not work yet.
7
+
8
+ ## Installation
9
+
10
+ Build the Gem:
11
+
12
+ $ gem build 'vagrant-plugin-ganeti.gemspec'
13
+
14
+
15
+
16
+ Install using standard Vagrant 1.1+ plugin installation methods. After installing, vagrant up and specify the ganeti provider. An example is shown below.
17
+
18
+ $ vagrant plugin install vagrant-plugin-ganeti-0.0.1.gem
19
+
20
+ ## Usage
21
+
22
+ $ vagrant up --provider=ganeti
23
+ ...
24
+ Of course prior to doing this, you'll need to obtain an Ganeti-compatible box file for Vagrant.
25
+
26
+
27
+ ##Quick Start
28
+
29
+ After installing the plugin (instructions above), the quickest way to get started is to actually use a "ganeti" Ganeti box and specify all the details manually within a config.vm.provider block. So first, add the "ganeti" box using any name you want:
30
+
31
+ $ vagrant box add ganeti https://raw.github.com/osuosl/vagrant-plugin-ganeti/master/example_box/ganeti.box
32
+ ...
33
+ And then make a Vagrantfile that looks like the following, filling in your information where necessary.
34
+
35
+ Vagrant.configure("2") do |config|
36
+ config.vm.box = "ganeti"
37
+ config.vm.provider :ganeti do |ganeti, override|
38
+ ganeti.rapi_user = "#rapiuser"
39
+ ganeti.rapi_pass = "#password"
40
+ ganeti.cluster = "https://10.10.10.10:5080/"
41
+ ganeti.os_type = "image+debian-squeeze"
42
+ ganeti.instance_name = "gimager3.organisation.org"
43
+ ganeti.pnode = "gnode.organisation.org"
44
+ ganeti.nics = [{"ip"=>"10.10.10.100"}]
45
+ ganeti.disks =[{"size"=>"8000"}]
46
+ ganeti.disk_template = "plain"
47
+ override.ssh.username = "User name of the default user "
48
+ override.ssh.private_key_path = "Path to your private key"
49
+ end
50
+ end
51
+
52
+
53
+ And then run vagrant up --provider=ganeti.
54
+
55
+ This will start an instance in the Ganeti Cluster. And assuming your SSH information was filled in properly within your Vagrantfile, SSH and provisioning will work as well.
56
+
57
+ If you have issues with SSH connecting, make sure that the instances are being launched with a security group that allows SSH access.
58
+
59
+ ## Box Format
60
+
61
+ Every provider in Vagrant must introduce a custom box format. This
62
+ provider introduces `aws` boxes. You can view an example box in
63
+ the [example_box/ directory](https://github.com/osuosl/vagrant-plugin-ganeti/master/example_box/).
64
+ That directory also contains instructions on how to build a box.
65
+
66
+ The box format is basically just the required `metadata.json` file
67
+ along with a `Vagrantfile` that does default settings for the
68
+ provider-specific configuration for this provider.
69
+
70
+ ## Configuration
71
+
72
+ This provider exposes quite a few provider-specific configuration options:
73
+
74
+ * `rapi_user` - The username for accessing the RAPI. REQUIRED
75
+ * `rapi_pass` - The password for the corrensponding user. REQUIRED
76
+ * `cluster` - The host address of the master Ganeti Node. REQUIRED
77
+ * `os_type` - The OS that needs to be booted up. Note : This will override the default box . OPTIONAL
78
+ * `mode` - Mode of creation. Defaults to create. OPTIONAL
79
+ * `instance_name` - The name of the instance. REQUIRED
80
+ * `pnode` - The primary node where instance needs to be created. Defaults to None. OPTIONAL
81
+ * `snode` - The Secondary node in case of drbd is used. Defaults to None. OPTIONAL
82
+ * `nics` - Network configuration. REQUIRED
83
+ * `disks` - The Size of the Disks . Defaults to 8 G . OPTIONAL
84
+ * `disk_template` - The type of the disk template. Defaults to plain . OPTIONAL
85
+ * `iallocator` - The name of the iallocator policy. Defaults to cluster default . OPTIONAL
86
+ * `memory` - The size of the memory. Defaults to plain . OPTIONAL
87
+ * `vcpus` - The No of VCPUS . Defaults to None . OPTIONAL
88
+ * `ip_check` - Either 'true' or 'false' (Without quotes). Defaults to true . OPTIONAL
89
+ * `name_check` - Either 'true' or 'false' (Without quotes) . Defaults to true . OPTIONAL
90
+
91
+
92
+ hvparams settings
93
+ * `boot_order` - Defaults to None . OPTIONAL
94
+ * `cdrom_image_path` - Defaults to None . OPTIONAL
95
+ * `nic_type` - Defaults to None . OPTIONAL
96
+ * `disk_type` - Defaults to None . OPTIONAL
97
+ * `cpu_type` - Defaults to None . OPTIONAL
98
+ * `kernel_path` - Defaults to None . OPTIONAL
99
+ * `kernel_args` - Defaults to None . OPTIONAL
100
+ * `initrd_path` - Defaults to None . OPTIONAL
101
+ * `root_path` - Defaults to None . OPTIONAL
102
+ * `serial_console` - Defaults to None . OPTIONAL
103
+ * `kvm_flag` - Defaults to None . OPTIONAL
104
+
105
+
106
+ ## Networks
107
+
108
+ Networking features in the form of `config.vm.network` are not
109
+ supported with `vagrant-ganeti`, currently. If any of these are
110
+ specified, Vagrant will emit a warning, but will otherwise boot
111
+ the Ganeti machine.
112
+
113
+ ## Synced Folders
114
+
115
+ There is minimal support for synced folders. Upon `vagrant provision`, the Ganeti provider will use
116
+ `rsync` (if available) to uni-directionally sync the folder to
117
+ the remote machine over SSH.
118
+
119
+ This is good enough for all built-in Vagrant provisioners (shell,
120
+ chef, and puppet) to work!
121
+
122
+
123
+ ## TODO
124
+
125
+ 1. Add more Features supported by RAPI
126
+
127
+ ## Contributing
128
+
129
+ 1. Fork it
130
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
131
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
132
+ 4. Push to the branch (`git push origin my-new-feature`)
133
+ 5. Create new Pull Request
134
+
135
+ ## About the Project
136
+ Author : Ahmed Shabib
137
+ This project is done as part of GSOC -2013 ,and is mentored by Lance Albertson(Ramereth) and Ken Lett
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'rspec/core/rake_task'
5
+
6
+ # Immediately sync all stdout so that tools like buildbot can
7
+ # immediately load in the output.
8
+ $stdout.sync = true
9
+ $stderr.sync = true
10
+
11
+ # Change to the directory of this file.
12
+ Dir.chdir(File.expand_path("../", __FILE__))
13
+
14
+ # This installs the tasks that help with gem creation and
15
+ # publishing.
16
+ Bundler::GemHelper.install_tasks
17
+
18
+ # Install the `spec` task so that we can run tests.
19
+ RSpec::Core::RakeTask.new
20
+
21
+ # Default task is to run the unit tests
22
+ task :default => "spec"
23
+
@@ -0,0 +1,13 @@
1
+ # Vagrant Ganeti 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 `ganeti` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf ganeti.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for Ganeti. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,8 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.provider :ganeti do |ganeti|
6
+ ganeti.os_name = "image+debian-squeeze"
7
+ end
8
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "ganeti"
3
+ }
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'base64'
6
+ require 'json'
7
+ require 'log4r'
8
+
9
+ module VagrantPlugins
10
+ module GANETI
11
+ module Action
12
+ # This action connects to Ganeti, verifies credentials start the instance.
13
+ class ConnectGANETI
14
+ def initialize(app, env)
15
+ @app = app
16
+ @logger = Log4r::Logger.new("vagrant_ganeti::action::connect_ganeti")
17
+ end
18
+
19
+ def call(env)
20
+
21
+ config = env[:machine].provider_config.get_config()
22
+ client = VagrantPlugins::GANETI::Util::GanetiClient.new(config.cluster,config.rapi_user,config.rapi_pass)
23
+ info = {}
24
+ info['__version__'] = 1
25
+ info['os_type'] = config.os_type
26
+ info['disk_template'] = config.disk_template
27
+ info['disks'] = config.disks
28
+ info['instance_name'] = config.instance_name
29
+ info['mode'] = config.mode
30
+ info['nics'] = config.nics
31
+
32
+ if config.iallocator == "__DEFAULT__" and config.pnode.nil?
33
+ config.iallocator = client.set_default_iallocator
34
+ info['iallocator'] = config.iallocator
35
+ elsif not config.iallocator.nil? and config.pnode.nil?
36
+ info['iallocator'] = config.iallocator
37
+ end
38
+
39
+ # Adding optional parameters
40
+ info['ip_check'] =false if not config.ip_check.nil? and config.ip_check ==false
41
+ info['name_check'] =false if not config.name_check.nil? and config.name_check ==false
42
+ info['pnode'] = config.pnode if not config.pnode.nil?
43
+ info['snode'] = config.snode if not config.snode.nil?
44
+ info['beparams'] = {} #Key value pairs
45
+ info['beparams']['memory'] = config.memory if not config.memory.nil?
46
+ info['beparams']['vcpus'] = config.vcpus if not config.vcpus.nil?
47
+ info['hvparams'] = {} #key value pairs
48
+ info['hvparams']['boot_order'] = config.boot_order if not config.boot_order.nil?
49
+ info['hvparams']['cdrom_image_path'] = config.cdrom_image_path if not config.cdrom_image_path.nil?
50
+ info['hvparams']['nic_type'] = config.nic_type if not config.nic_type.nil?
51
+ info['hvparams']['disk_type'] = config.disk_type if not config.disk_type.nil?
52
+ info['hvparams']['cpu_type'] = config.cpu_type if not config.cpu_type.nil?
53
+ info['hvparams']['kernel_path'] = config.kernel_path if not config.kernel_path.nil?
54
+ info['hvparams']['kernel_args'] = config.kernel_args if not config.kernel_args.nil?
55
+ info['hvparams']['initrd_path'] = config.initrd_path if not config.initrd_path.nil?
56
+ info['hvparams']['root_path'] = config.root_path if not config.root_path.nil?
57
+ info['hvparams']['serial_console'] = config.serial_console if not config.serial_console.nil?
58
+ info['hvparams']['kvm_flag'] = config.kvm_flag if not config.kvm_flag.nil?
59
+
60
+
61
+ client.set_config(info)
62
+ @logger.info("Connecting to GANETI...")
63
+ #Call ganeti_client ruby wrapper
64
+ env[:ganeti_compute] = client
65
+ @app.call(env)
66
+ end
67
+ end
68
+ end #Action
69
+ end #ganeti
70
+ end #VagrantPlugin
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module GANETI
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id != :not_created
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module GANETI
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsReachable
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = true
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module GANETI
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_ganeti.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 GANETI
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_ganeti.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 GANETI
3
+ module Action
4
+ class MessageNotReachable
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_ganeti.host_not_reachable"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module GANETI
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_ganeti.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module GANETI
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_ganeti::action::read_ssh_info")
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_ssh_info] = read_ssh_info(env[:ganeti_compute], env[:machine])
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_ssh_info(ganeti, machine)
21
+ return nil if machine.id.nil?
22
+ puts "Ganeti is #{machine.id}"
23
+ # Read the DNS info
24
+ return {
25
+ :host => machine.id,
26
+ :port => 22
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,84 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module GANETI
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_ganeti::action::read_state")
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_state_id] = read_state(env[:machine])
16
+ env[:ui].info "Read the machine state id #{env[:machine].id}"
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_state(machine)
21
+ return :not_created if machine.id.nil?
22
+
23
+ ip_address = machine.id
24
+ if machine.communicate.ready?
25
+ @logger.info "#{ip_address} is reachable and SSH login OK"
26
+ return :reachable
27
+ else
28
+ if ssh_port_open? ip_address
29
+ @logger.info "#{ip_address} is reachable, SSH port open (but login failed)"
30
+ return :reachable
31
+ else
32
+ if is_pingable? ip_address
33
+ @logger.info "#{ip_address} is pingable (but SSH failed)"
34
+ return :reachable
35
+ end
36
+ end
37
+ end
38
+
39
+ # host is not reachable at all...
40
+ return :not_reachable
41
+
42
+
43
+ #return machine.communicate.ready? ? :running : :not_reachable
44
+ end
45
+
46
+
47
+ def is_pingable?(ip)
48
+ if Vagrant::Util::Platform.windows?
49
+ system("ping -n 1 #{ip}")
50
+ else
51
+ system("ping -q -c 1 #{ip}")
52
+ end
53
+ end
54
+
55
+ def ssh_port_open?(ip)
56
+ is_port_open?(ip, 22)
57
+ end
58
+
59
+ #
60
+ # borrowed from http://stackoverflow.com/a/3473208/2388971
61
+ #
62
+ def is_port_open?(ip, port)
63
+ require 'socket'
64
+ s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
65
+ sa = Socket.sockaddr_in(port, ip)
66
+ begin
67
+ s.connect_nonblock(sa)
68
+ rescue Errno::EINPROGRESS
69
+ if IO.select(nil, [s], nil, 1)
70
+ begin
71
+ s.connect_nonblock(sa)
72
+ rescue Errno::EISCONN
73
+ return true
74
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
75
+ return false
76
+ end
77
+ end
78
+ end
79
+ return false
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,26 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module GANETI
5
+ module Action
6
+ # "unlink" vagrant and the managed server
7
+ class RemoveInstance
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_ganeti::action::remove_instance")
12
+ end
13
+
14
+ def call(env)
15
+ server = env[:ganeti_compute]
16
+ env[:ui].info("Removing the instance#{server.info['instance_name']}")
17
+ server.instance_terminate
18
+ # set machine id to nil
19
+ env[:machine].id = nil
20
+
21
+ @app.call(env)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,76 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module GANETI
5
+ module Action
6
+ # "unlink" vagrant and the managed server
7
+ class RunInstance
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_ganeti::action::remove_instance")
12
+ end
13
+
14
+ def call(env)
15
+ config = env[:machine].provider_config.get_config()
16
+ client = env[:ganeti_compute]
17
+ # Launch!
18
+ env[:ui].info(I18n.t("vagrant_ganeti.launching_instance"))
19
+ env[:ui].info(" -- Rapi User: #{config.rapi_user}")
20
+ env[:ui].info(" -- OS Type: #{config.os_type}")
21
+ env[:ui].info(" -- Instance NAME: #{config.instance_name}")
22
+ env[:ui].info(" -- Cluster: #{config.cluster}")
23
+ env[:ui].info(" -- Primary Node #{config.pnode}") if not config.pnode.nil?
24
+ env[:ui].info(" -- Disk Template: #{config.disk_template}")
25
+ env[:ui].info(" -- Disks #{config.disks}")
26
+ env[:ui].info(" -- Network Configurations: #{config.nics}")
27
+ env[:ui].info(" -- Memory : #{config.memory }") if not config.memory.nil?
28
+ env[:ui].info(" -- VCPUs : #{config.vcpus }") if not config.vcpus.nil?
29
+ env[:ui].info(" -- Iallocator Policy : #{config.iallocator }") if not config.iallocator == "__DEFAULT__"
30
+ env[:ui].info(" -- Version : #{config.version }") if config.version
31
+ env[:ui].info(" -- ip_check : #{config.ip_check }") if not config.ip_check.nil?
32
+ env[:ui].info(" -- name_check : #{config.name_check }") if not config.name_check.nil?
33
+
34
+ createjob = client.instance_create()
35
+ env[:ui].info( "New Job Created #{createjob}.")
36
+ env[:ui].info( "Preparing to Create Instance")
37
+ env[:ui].info( "This might take few minutes.....")
38
+ puts env[:ganeti_compute]
39
+
40
+
41
+ while true
42
+ status = client.is_job_ready(createjob)
43
+
44
+ if status == "error"
45
+ env[:ui].info("Error Creating instance")
46
+ break
47
+ elsif status == "running"
48
+ #Waiting for the message to succeed
49
+ sleep(15)
50
+ elsif status == "success"
51
+ env[:ui].info( "Instance sucessfully Created.")
52
+ env[:ui].info( "Booting up the Instance.")
53
+ bootinstancejob = client.start_instance()
54
+ sleep(3)
55
+ if client.is_job_ready(bootinstancejob) == "success"
56
+ env[:machine].id = client.info['nics'][0]['ip']
57
+ env[:ui].info( "#{ env[:machine].id}")
58
+ env[:ui].info("Instance Started Successfully")
59
+ else
60
+ env[:ui].info("Error Staring Instance")
61
+ end
62
+ break
63
+ elsif status == "already_exists"
64
+ env[:ui].info( "Instance already Exists. Use Vagrant SSH to login .\nUse 'vagrant destroy' and 'vagrant up' again to create instance afresh")
65
+ env[:machine].id = client.info['nics'][0]['ip']
66
+ break
67
+ end
68
+
69
+ end
70
+
71
+ @app.call(env)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end