vagrant_filoo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +61 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE +22 -0
  5. data/README.md +207 -0
  6. data/Rakefile +5 -0
  7. data/doc/img_res/filoo_logo.png +0 -0
  8. data/doc/img_res/filoo_wolke.png +0 -0
  9. data/example_box/README.md +13 -0
  10. data/example_box/metadata.json +3 -0
  11. data/filoo.box +0 -0
  12. data/lib/vagrant_filoo/action/create_server.rb +51 -0
  13. data/lib/vagrant_filoo/action/get_images.rb +21 -0
  14. data/lib/vagrant_filoo/action/is_created.rb +22 -0
  15. data/lib/vagrant_filoo/action/is_stopped.rb +18 -0
  16. data/lib/vagrant_filoo/action/message_already_created.rb +16 -0
  17. data/lib/vagrant_filoo/action/message_not_created.rb +16 -0
  18. data/lib/vagrant_filoo/action/read_ssh_info.rb +40 -0
  19. data/lib/vagrant_filoo/action/read_state.rb +65 -0
  20. data/lib/vagrant_filoo/action/start_instance.rb +48 -0
  21. data/lib/vagrant_filoo/action/stop_instance.rb +31 -0
  22. data/lib/vagrant_filoo/action/terminate_instance.rb +24 -0
  23. data/lib/vagrant_filoo/action/test.rb +2 -0
  24. data/lib/vagrant_filoo/action.rb +184 -0
  25. data/lib/vagrant_filoo/cloud_compute.rb +629 -0
  26. data/lib/vagrant_filoo/config.rb +54 -0
  27. data/lib/vagrant_filoo/errors.rb +81 -0
  28. data/lib/vagrant_filoo/plugin.rb +73 -0
  29. data/lib/vagrant_filoo/provider.rb +52 -0
  30. data/lib/vagrant_filoo/util/timer.rb +17 -0
  31. data/lib/vagrant_filoo/version.rb +5 -0
  32. data/lib/vagrant_filoo.rb +17 -0
  33. data/locales/en.yml +122 -0
  34. data/sample_config/Vagrantfile_example +23 -0
  35. data/spec/spec_helper.rb +0 -0
  36. data/spec/vagrant_filoo/config_spec.rb +70 -0
  37. data/templates/metadata.json.erb +3 -0
  38. data/templates/vagrant-filoo_package_Vagrantfile.erb +5 -0
  39. data/vagrant_filoo.gemspec +58 -0
  40. metadata +178 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9b0385a665c31b877a060d18231e12bc264b1a9
4
+ data.tar.gz: 5d9de96e77ef02d20f5736c816099d10ee669bd0
5
+ SHA512:
6
+ metadata.gz: 61964f5d18997c8ecd44ea7d4c7e53c325e8cdec0506dcdeeef55d028d5a6d7fd7c4d87771a8a71806dde8ac8356cc49c2f7fefb5f91f45f7967d6c71dbb35bd
7
+ data.tar.gz: f5e5a0125cddf965b1ba302e1fed58cc74027a009ca09c1000cdf2ef56634d6e0d494ceaa4a9ddc34be21d3221416e2ef3f2058af5f787fafccccc21d452ac0c
data/.gitignore ADDED
@@ -0,0 +1,61 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .bundle
5
+ pkg/*
6
+ tags
7
+ Gemfile.lock
8
+
9
+ .buildpath
10
+ .project
11
+
12
+ /.config
13
+ /coverage/
14
+ /InstalledFiles
15
+ /pkg/
16
+ /spec/reports/
17
+ /test/tmp/
18
+ /test/version_tmp/
19
+ /tmp/
20
+
21
+ ## Specific to RubyMotion:
22
+ .dat*
23
+ .repl_history
24
+ build/
25
+
26
+ # RVM files for gemset/ruby setting
27
+ .ruby-*
28
+ .rvmrc
29
+
30
+ ## Documentation cache and generated files:
31
+ /.yardoc/
32
+ /_yardoc/
33
+ /doc/
34
+ /rdoc/
35
+
36
+ ## Environment normalisation:
37
+ /.bundle/
38
+ /vendor/bundle
39
+ /lib/bundler/man/
40
+
41
+ # for a library or gem, you might want to ignore these files since the code is
42
+ # intended to run in multiple environments; otherwise, check them in:
43
+ # Gemfile.lock
44
+ # .ruby-version
45
+ # .ruby-gemset
46
+
47
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
48
+ .rvmrc
49
+
50
+ tmp
51
+ *.bundle
52
+ *.so
53
+ *.o
54
+ *.a
55
+ mkmf.log
56
+ .idea
57
+
58
+ # Vagrant
59
+ .vagrant
60
+ Vagrantfile
61
+ !example_box/Vagrantfile
data/Gemfile ADDED
@@ -0,0 +1,14 @@
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/mitchellh/vagrant.git"
10
+ end
11
+
12
+ group :plugins do
13
+ gem 'vagrant_filoo', path: "."
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Huf Secure Mobile
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # vagrant_filoo 0.0.2
2
+ Vagrant filoo provisioner
3
+
4
+ This is a Vagrant 1.7x plugin that adds an provider for filoo hosting to Vagrant, allowing Vagrant to control and provision machines within the filoo public and private cloud.
5
+
6
+
7
+ ![htps://www.filoo.de/vserver.html](/doc/img_res/filoo_logo.png?raw=true )
8
+
9
+ htps://www.filoo.de/vserver.html
10
+
11
+ **NOTE:** This plugin requires Vagrant 1.7x
12
+
13
+ #TODO
14
+ - set servername 4.1.16 vserver/setcustomname
15
+ - Publish to public gem repository
16
+
17
+ ## Usage
18
+
19
+ Install using standard Vagrant 1.1+ plugin installation methods. After installing, `vagrant up` and specify the `filoo` provider. An example is shown below. dummy
20
+
21
+ ```
22
+ $ vagrant plugin install vagrant-filoo
23
+ ...
24
+ $ vagrant up --provider=filoo
25
+ ...
26
+ ```
27
+
28
+ Of course prior to doing this, you'll need to obtain an Filoo-compatible box file for Vagrant.
29
+
30
+ ## Quick Start
31
+
32
+ After installing the plugin (instructions above), the quickest way to get started is to actually use a dummy Filoo box and specify all the details manually within a `config.vm.provider` block. So first, add the dummy box using any name you want:
33
+
34
+ ```
35
+ $ vagrant box add filoo <url to filoo box>
36
+ ...
37
+ ```
38
+
39
+ And then make a Vagrantfile that looks like the following, filling in your information where necessary.
40
+
41
+ It is good practice to access the filoo api key via system environment variable. To use environment variable FILOO_API_KEY add following line in the Vagrantfile
42
+ ```
43
+ filoo.filoo_api_key = ENV['FILOO_API_KEY']
44
+ ```
45
+
46
+ as seen in the commented line of config beneath.
47
+
48
+ ```
49
+ Vagrant.configure("2") do |config|
50
+ config.vm.box = "filoo"
51
+
52
+ config.vm.provider :filoo do |filoo, override|
53
+ filoo.filoo_api_key = "your filoo api access key"
54
+ # or to use environment variable uncomment this
55
+ #filoo.filoo_api_key = ENV['FILOO_API_KEY']
56
+
57
+ filoo.filoo_api_entry_point = "https://api.filoo.de/api/v1"
58
+ filoo.cd_image_name = "Debian 7.7 - 64bit"
59
+ filoo.type = "dynamic"
60
+ filoo.cpu = 1
61
+ filoo.ram = 128
62
+ filoo.hdd = 10
63
+ filoo.additional_nic = true # defaults to false
64
+ end
65
+ end
66
+ ```
67
+
68
+ And then run 'vagrant up --provider=filoo'.
69
+
70
+ This will start an Debian 6.0 - 64bit instance in the Filoo infrastructure
71
+
72
+ Note that normally a lot of this boilerplate is encoded within the box
73
+ file, but the box file used for the quick start, the "dummy" box, has
74
+ no preconfigured defaults.
75
+
76
+
77
+ ## Box Format
78
+
79
+ Every provider in Vagrant must introduce a custom box format. This
80
+ provider introduces `filoo` boxes. You can view an example box in
81
+ the [example_box/ directory](<path to repository>/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
+ This provider exposes quite a few provider-specific configuration options:
91
+
92
+ * `filoo_api_key` - The api key for accessing Filoo
93
+ * `cd_image_name` - The Filoo omage name to boot, such as ""Debian 6.0 - 64bit"
94
+ * `filoo_api_entry_point` - The base url to the api "https://api.filoo.de/api/v1"
95
+
96
+ These can be set like typical provider-specific configuration:
97
+
98
+ ```ruby
99
+ Vagrant.configure("2") do |config|
100
+ # ... other stuff
101
+
102
+ config.vm.provider :filoo do |filoo|
103
+ filoo.filoo_api_key = "foo"
104
+ filoo.filoo_api_entry_point = "bar"
105
+ filoo.cd_image_name = "foo-bar"
106
+ end
107
+ end
108
+ ```
109
+
110
+ ## Networks
111
+
112
+ Networking features in the form of `config.vm.network` are not
113
+ supported with `vagrant-filoo`, currently. If any of these are
114
+ specified, Vagrant will emit a warning, but will otherwise boot
115
+ the filoo machine.
116
+
117
+ ## Synced Folders
118
+
119
+ Shared folders are not supported at the current state.
120
+
121
+ Linux and Windows clients optionally can use sshfs to mount a folder on the network or to connect a network drive. While the Linux implementation via fuse is quite stable the windows variant is not. We have successfully tested under Windows 7. Under Windows the re-connect after a network cut-off sometimes fails.
122
+
123
+ General Information: https://de.wikipedia.org/wiki/SSHFS
124
+ Windows build: https://code.google.com/p/win-sshfs/
125
+
126
+ See [Vagrant Synced folders: rsync](https://docs.vagrantup.com/v2/synced-folders/rsync.html)
127
+
128
+
129
+ ## Other Examples
130
+
131
+
132
+
133
+ ## Development
134
+
135
+ The easiest way to setup the environment is to install ruby with the Rails Installer (http://railsinstaller.org). Also you have to install vagrant on your machine to develop the plugin
136
+
137
+ To work on the `vagrant-filoo` plugin, clone this repository out, and use
138
+ [Bundler](http://gembundler.com) to get the dependencies:
139
+
140
+ or run from your "command prompt with ruby and rails"
141
+
142
+ ```
143
+ $ gem install bundler
144
+ ```
145
+
146
+ in the project folder run from your "command prompt with ruby and rails"
147
+
148
+ ```
149
+ $ bundle
150
+ ```
151
+
152
+ If you get an ssl error follow instructions on https://gist.github.com/luislavena/f064211759ee0f806c88
153
+
154
+ Once you have the dependencies, verify the unit tests pass with `rake`:
155
+
156
+ ```
157
+ $ bundle exec rake
158
+ ```
159
+
160
+ If those pass, you're ready to start developing the plugin. You can test
161
+ the plugin without installing it into your Vagrant environment by just
162
+ creating a `Vagrantfile` in the top level of this directory (it is gitignored)
163
+ and add the following line to your `Vagrantfile`
164
+ ```ruby
165
+ Vagrant.require_plugin "vagrant_filoo"
166
+ ```
167
+
168
+ create a box
169
+
170
+ ```
171
+ $ cd example_box
172
+ $ tar cvzf filoo.box ./metadata.json ./Vagrantfile
173
+ $ mv filoo.box ../filoo.box
174
+ $ cd ..
175
+ ```
176
+
177
+ Use vagrant to add the box
178
+
179
+ ```
180
+ $ vagrant box add filoo.box
181
+ ```
182
+
183
+ Copy the example Vagrantfile
184
+
185
+ ```
186
+ cp example_config/Vagrantfile_example Vagrantfile
187
+ ```
188
+
189
+ Edit your filoo api key in Vagrantfile or access Api Key via Environment Variable
190
+
191
+ ```
192
+ filoo.filoo_api_key = "your filoo api access key"
193
+ # or to use environment variable uncomment this
194
+ #filoo.filoo_api_key = ENV['FILOO_API_KEY']
195
+ ```
196
+
197
+ Use bundler to execute Vagrant:
198
+ ```
199
+ $ bundle exec vagrant up --provider=filoo
200
+ ```
201
+
202
+ Package and publish the plugin (see https://www.noppanit.com/create-simple-vagrant-plugin/)
203
+
204
+ ```
205
+ $ rake build
206
+ $ gem push pkg/vagrant_filoo-0.0.1.gem
207
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ Bundler::GemHelper.install_tasks
5
+
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant FILOO 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 `filoo` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf filoo.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for Filoo. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "filoo"
3
+ }
data/filoo.box ADDED
Binary file
@@ -0,0 +1,51 @@
1
+ require_relative "../cloud_compute"
2
+ require_relative '../errors'
3
+ require 'vagrant_filoo/util/timer'
4
+
5
+ module VagrantPlugins
6
+ module Filoo
7
+ module Action
8
+ class CreateServer
9
+ def initialize(app, env)
10
+ @app = app
11
+ @baseUrl =env[:machine].provider_config.filoo_api_entry_point
12
+ @apiKey = env[:machine].provider_config.filoo_api_key
13
+ end
14
+
15
+ def call(env)
16
+
17
+ if (env[:images].nil?)
18
+ raise Errors::ImagesNotLoaded
19
+ end
20
+ config = env[:machine].provider_config
21
+ if env[:images][config.cd_image_name].nil?
22
+ raise VagrantPlugins::Filoo::Errors::ConfigError,
23
+ message: "Filoo Configuration parameter 'cd_image_name' with value #{config.cd_image_name} references not a filoo image that has autoinstall flag set. Please use one of the folowing image names #{env[:images].keys.join(' | ')}"
24
+ end
25
+
26
+ imageId = "#{env[:images][config.cd_image_name]}".to_i
27
+
28
+ params = {
29
+ :type => config.type,
30
+ :cpu => config.cpu,
31
+ :ram => config.ram,
32
+ :hdd => config.hdd,
33
+ :cd_imageid => imageId
34
+ }
35
+
36
+ env[:ui].info("vagrant_filoo creating_instance")
37
+ env[:ui].info(" -- Type: #{config.type}")
38
+ env[:ui].info(" -- CPUs: #{config.cpu}")
39
+ env[:ui].info(" -- Ram: #{config.ram}")
40
+ env[:ui].info(" -- Image Id: #{imageId}")
41
+ env[:ui].info(" -- Image Name: #{config.cd_image_name}")
42
+ env[:result] = VagrantPlugins::Filoo::CloudCompute::createServer(params, @baseUrl, @apiKey)
43
+ env[:machine].id = env[:result]["vmid"]
44
+ #env[:machine].name = env[:result]["custom_vmname"]
45
+ env[:ui].info(" -- Server created, server state #{env[:result]}")
46
+ @app.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../errors'
2
+
3
+ module VagrantPlugins
4
+ module Filoo
5
+ module Action
6
+ class GetImages
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @baseUrl =env[:machine].provider_config.filoo_api_entry_point()
11
+ @apiKey = env[:machine].provider_config.filoo_api_key()
12
+ end
13
+ def call(env)
14
+ env[:images]= VagrantPlugins::Filoo::CloudCompute::getAutoInstallImages(@baseUrl, @apiKey)
15
+ env[:result] = env[:images]
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Filoo
3
+ module Action
4
+ class IsCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:result] = true
11
+ if env[:machine].state.id == :not_created
12
+ env[:result] = false
13
+ end
14
+ if env[:machine].state.id == :deleted
15
+ env[:result] = false
16
+ end
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module Filoo
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,16 @@
1
+ module VagrantPlugins
2
+ module Filoo
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_filoo.already_created", :id => env[:machine].id))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module Filoo
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_filoo.not_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+ require_relative "../cloud_compute"
3
+
4
+
5
+ module VagrantPlugins
6
+ module Filoo
7
+ module Action
8
+ class ReadSSHInfo
9
+ def initialize(app, env)
10
+ @app = app
11
+ @baseUrl =env[:machine].provider_config.filoo_api_entry_point()
12
+ @apiKey = env[:machine].provider_config.filoo_api_key()
13
+ end
14
+ def call(env)
15
+ vmid = vmid = env[:machine].id
16
+ serverStatus = VagrantPlugins::Filoo::CloudCompute::getServerStatus(vmid, @baseUrl, @apiKey)
17
+ if serverStatus["network_settings"].nil?
18
+ raise VagrantPlugins::Filoo::Errors::UnexpectedStateError,
19
+ resource: VagrantPlugins::Filoo::CloudCompute::SERVERSTATUS_RESOURCE,
20
+ state: serverStatus,
21
+ message: "Unexpected State of server status " + serverList.to_json,
22
+ description: "Server with vmid #{vmid} should have server status with field network_settings present"
23
+ end
24
+
25
+ if serverStatus["network_settings"].length < 1 or serverStatus["network_settings"][0]["ipadress"].nil?
26
+ raise VagrantPlugins::Filoo::Errors::UnexpectedStateError,
27
+ resource: VagrantPlugins::Filoo::CloudCompute::SERVERSTATUS_RESOURCE,
28
+ state: serverStatus,
29
+ description: "Server with vmid #{vmid} should have server status with subfield field ipadress network_settings present"
30
+ end
31
+ env[:machine_ssh_info] = { :host => serverStatus["network_settings"][0]["ipadress"],
32
+ :port => 22 ,
33
+ :username => "root"
34
+ }
35
+ @app.call(env)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,65 @@
1
+ require_relative "../cloud_compute"
2
+ require "vagrant/machine_state"
3
+ require 'json'
4
+
5
+ module VagrantPlugins
6
+ module Filoo
7
+ module Action
8
+ class ReadState
9
+ include VagrantPlugins::Filoo::CloudCompute
10
+ SERVERSTATUS_RESOURCE = '/vserver/status'
11
+ def initialize(app, env)
12
+ @app = app
13
+ @baseUrl ="#{env[:machine].provider_config.filoo_api_entry_point}"
14
+ @apiKey = env[:machine].provider_config.filoo_api_key()
15
+ end
16
+
17
+ def call(env)
18
+ if env[:machine].nil? or env[:machine].id.nil?
19
+ env[:machine_state_id] = :not_created
20
+ else
21
+ vmid = env[:machine].id
22
+ begin
23
+ serverStatus = VagrantPlugins::Filoo::CloudCompute::getServerStatus(vmid, @baseUrl, @apiKey)
24
+ env[:machine_state_id] = machineStateIdFromState(serverStatus)
25
+ rescue VagrantPlugins::Filoo::Errors::FilooApiError => e
26
+ errorCode = nil;
27
+ begin
28
+ errorCode = JSON.parse(e.message)["code"]
29
+ rescue JSON::ParserError => jsonErr
30
+ raise e
31
+ end
32
+ if errorCode == 403
33
+ env[:machine_state_id] = :not_created
34
+ else
35
+ raise e
36
+ end
37
+ en
38
+ end
39
+ end
40
+ @app.call(env)
41
+ end
42
+
43
+ def machineStateIdFromState(serverStatus)
44
+ case serverStatus["vmstatus"]
45
+ when "running"
46
+ return :running
47
+ when "stopped"
48
+ return :stopped
49
+ when "processing_autoinstall"
50
+ return :processing_autoinstall
51
+ when "disabled"
52
+ return :disabled
53
+ when "activated"
54
+ return :activated
55
+ when "deleted"
56
+ return :deleted
57
+ when "unknown"
58
+ return :unknown
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,48 @@
1
+ require "log4r"
2
+ require_relative "../cloud_compute"
3
+ require 'vagrant_filoo/util/timer'
4
+
5
+ module VagrantPlugins
6
+ module Filoo
7
+ module Action
8
+ class StartInstance
9
+ include VagrantPlugins::Filoo::CloudCompute
10
+
11
+ def initialize(app, env)
12
+ @app = app
13
+ @baseUrl =env[:machine].provider_config.filoo_api_entry_point
14
+ @apiKey = env[:machine].provider_config.filoo_api_key
15
+ @filooConfig = env[:machine].provider_config
16
+ @logger = Log4r::Logger.new("vagrant_filoo::action::start_instance")
17
+ end
18
+
19
+ def call(env)
20
+ env[:metrics] ||= {}
21
+ vmid = env[:machine].id
22
+ env[:result] = VagrantPlugins::Filoo::CloudCompute::startInstance(vmid, @baseUrl, @apiKey, @filooConfig)
23
+ env[:ui].info("Machine #{vmid} successfully started, state #{env[:result].to_json}")
24
+ @logger.info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
25
+
26
+ if !env[:interrupted]
27
+ env[:metrics]["instance_ssh_time"] = Util::Timer.time do
28
+ # Wait for SSH to be ready.
29
+ env[:ui].info(I18n.t("vagrant_filoo.waiting_for_ssh"))
30
+ while true
31
+ # If we're interrupted then just back out
32
+ break if env[:interrupted]
33
+ break if env[:machine].communicate.ready?
34
+ sleep 2
35
+ end
36
+ end
37
+
38
+ @logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
39
+
40
+ # Ready and booted!
41
+ env[:ui].info(I18n.t("vagrant_filoo.ready"))
42
+ end
43
+ @app.call(env)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../cloud_compute"
2
+
3
+ module VagrantPlugins
4
+ module Filoo
5
+ module Action
6
+ # This starts a stopped instance.
7
+ class StopInstance
8
+ STOP_RESOURCE = "/vserver/stop"
9
+ STOP_INSTANCE_TIMEOUT = 60
10
+ def initialize(app, env)
11
+ @app = app
12
+ @baseUrl =env[:machine].provider_config.filoo_api_entry_point
13
+ @apiKey = env[:machine].provider_config.filoo_api_key
14
+ end
15
+
16
+ def call(env)
17
+ if env[:machine].state.id == :stopped
18
+ env[:ui].info(I18n.t("vagrant_filoo.already_status", :status => env[:machine].state.id))
19
+ else
20
+ vmid = env[:machine].id
21
+ env[:ui].info("Halt machine #{vmid}")
22
+ env[:result] = VagrantPlugins::Filoo::CloudCompute::stopInstance vmid, @baseUrl, @apiKey
23
+ env[:ui].info("Machine #{vmid} successfully halted, state #{env[:result].to_json}")
24
+ end
25
+ @app.call(env)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end