vagrant-scaleway 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd75bdfdd4882cdab032133e1d2fb774aa575e16
4
+ data.tar.gz: 19b03b5498e88328ba42a6028e8be1d22a3a3cfb
5
+ SHA512:
6
+ metadata.gz: 99bd7fc3bdb655ba213880457fa284db2aca08fee2336beacf0fbf0f86a6c63e1f5ea852285c6beb94b949ef7bf4ad077b385d271a4943927b10af6a07b9a907
7
+ data.tar.gz: 40690821c51c739ef925a71d07b72c2ebafdc49c16d1c0510dd2e4e415d16f79059fdd2177453ed1388b05a13f349a03a2c402ce8062f8b59107bc8c2f28d0fa
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /Vagrantfile
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.5
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-scaleway.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
8
+ end
9
+
10
+ group :plugins do
11
+ gem 'vagrant-scaleway', path: '.'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Satoshi Matsumoto
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Vagrant Scaleway Provider
2
+
3
+ [![Gem](https://img.shields.io/gem/v/vagrant-scaleway.svg?style=flat-square)](https://rubygems.org/gems/vagrant-scaleway)
4
+
5
+ This is a [Vagrant](http://www.vagrantup.com/) plugin that adds a Scaleway
6
+ provider to Vagrant, allowing Vagrant to control and provision machines in
7
+ Scaleway.
8
+
9
+ ## Features
10
+
11
+ - Boot Scaleway servers.
12
+ - SSH into the servers.
13
+ - Provision the servers with any built-in Vagrant provisioner.
14
+ - Minimal synced folder support via rsync.
15
+
16
+ ## Prerequisites
17
+
18
+ Prior to using this plugin, you will first need to create an API token and
19
+ identify your organization ID. Please see the following help for instructions.
20
+
21
+ - [How to generate an API token](https://www.scaleway.com/docs/generate-an-api-token/)
22
+ - [How to retrieve my organization ID through the API](https://www.scaleway.com/docs/retrieve-my-organization-id-throught-the-api/)
23
+
24
+ ## Installation
25
+
26
+ Install using standard Vagrant plugin installation methods.
27
+
28
+ $ vagrant plugin install vagrant-scaleway
29
+
30
+ ## Usage
31
+
32
+ First, make a Vagrantfile that looks like the following:
33
+
34
+ ```ruby
35
+ Vagrant.configure('2') do |config|
36
+ config.vm.provider :scaleway do |scaleway, override|
37
+ scaleway.organization = 'YOUR_ORGANIZATION_UUID'
38
+ scaleway.token = 'YOUR_TOKEN'
39
+
40
+ override.ssh.private_key_path = '~/.ssh/id_rsa'
41
+ end
42
+ end
43
+ ```
44
+
45
+ And then run `vagrant up` and specify the `scaleway` provider:
46
+
47
+ $ vagrant up --provider=scaleway
48
+
49
+ ## Development
50
+
51
+ To work on the `vagrant-scaleway` plugin, clone this repository out, and use
52
+ [Bundler](http://gembundler.com) to get the dependencies:
53
+
54
+ $ bundle
55
+
56
+ If those pass, you're ready to start developing the plugin. You can test
57
+ the plugin without installing it into your Vagrant environment by just
58
+ creating a `Vagrantfile` in the top level of this directory (it is gitignored)
59
+ that uses it, and uses bundler to execute Vagrant:
60
+
61
+ $ bundle exec vagrant up --provider=scaleway
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kaorimatz/vagrant-scaleway.
66
+
67
+ ## License
68
+
69
+ The plugin is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ end
8
+
9
+ task default: :test
data/dummy.box ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "scaleway"
3
+ }
@@ -0,0 +1,17 @@
1
+ require 'pathname'
2
+ require 'vagrant-scaleway/plugin'
3
+
4
+ module VagrantPlugins
5
+ module Scaleway
6
+ lib_path = Pathname.new(File.expand_path('../vagrant-scaleway', __FILE__))
7
+ autoload :Action, lib_path.join('action')
8
+ autoload :Errors, lib_path.join('errors')
9
+
10
+ # This returns the path to the source of this plugin.
11
+ #
12
+ # @return [Pathname]
13
+ def self.source_root
14
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,179 @@
1
+ require 'vagrant/action/builder'
2
+
3
+ module VagrantPlugins
4
+ module Scaleway
5
+ module Action
6
+ # Include the built-in modules so we can use them as top-level things.
7
+ include Vagrant::Action::Builtin
8
+
9
+ # This action is called to terminate the remote machine.
10
+ def self.action_destroy
11
+ Vagrant::Action::Builder.new.tap do |b|
12
+ b.use Call, DestroyConfirm do |env, b2|
13
+ if env[:result]
14
+ b2.use ConfigValidate
15
+ b2.use Call, IsCreated do |env2, b3|
16
+ unless env2[:result]
17
+ b3.use MessageNotCreated
18
+ next
19
+ end
20
+
21
+ b3.use ConnectScaleway
22
+ b3.use ProvisionerCleanup, :before if defined?(ProvisionerCleanup)
23
+ b3.use DestroyServer
24
+ end
25
+ else
26
+ b2.use MessageWillNotDestroy
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ # This action is called to halt the remote machine.
33
+ def self.action_halt
34
+ Vagrant::Action::Builder.new.tap do |b|
35
+ b.use ConfigValidate
36
+ b.use Call, IsCreated do |env, b2|
37
+ unless env[:result]
38
+ b2.use MessageNotCreated
39
+ next
40
+ end
41
+
42
+ b2.use ConnectScaleway
43
+ b2.use StopServer
44
+ end
45
+ end
46
+ end
47
+
48
+ # This action is called when `vagrant provision` is called.
49
+ def self.action_provision
50
+ Vagrant::Action::Builder.new.tap do |b|
51
+ b.use ConfigValidate
52
+ b.use Call, IsCreated do |env, b2|
53
+ unless env[:result]
54
+ b2.use MessageNotCreated
55
+ next
56
+ end
57
+
58
+ b2.use Provision
59
+ end
60
+ end
61
+ end
62
+
63
+ # This action is called to read the SSH info of the machine. The
64
+ # resulting state is expected to be put into the `:machine_ssh_info`
65
+ # key.
66
+ def self.action_read_ssh_info
67
+ Vagrant::Action::Builder.new.tap do |b|
68
+ b.use ConfigValidate
69
+ b.use ConnectScaleway
70
+ b.use ReadSSHInfo
71
+ end
72
+ end
73
+
74
+ # This action is called to read the state of the machine. The
75
+ # resulting state is expected to be put into the `:machine_state_id`
76
+ # key.
77
+ def self.action_read_state
78
+ Vagrant::Action::Builder.new.tap do |b|
79
+ b.use ConfigValidate
80
+ b.use ConnectScaleway
81
+ b.use ReadState
82
+ end
83
+ end
84
+
85
+ # This action is called to restart the remote machine.
86
+ def self.action_reload
87
+ Vagrant::Action::Builder.new.tap do |b|
88
+ b.use ConfigValidate
89
+ b.use ConnectScaleway
90
+ b.use Call, IsCreated do |env1, b1|
91
+ unless env1[:result]
92
+ b1.use MessageNotCreated
93
+ next
94
+ end
95
+
96
+ b1.use action_halt
97
+ b1.use action_up
98
+ end
99
+ end
100
+ end
101
+
102
+ # This action is called to SSH into the machine.
103
+ def self.action_ssh
104
+ Vagrant::Action::Builder.new.tap do |b|
105
+ b.use ConfigValidate
106
+ b.use Call, IsCreated do |env, b2|
107
+ unless env[:result]
108
+ b2.use MessageNotCreated
109
+ next
110
+ end
111
+
112
+ b2.use SSHExec
113
+ end
114
+ end
115
+ end
116
+
117
+ # This action is called to execute a command on the machine via SSH.
118
+ def self.action_ssh_run
119
+ Vagrant::Action::Builder.new.tap do |b|
120
+ b.use ConfigValidate
121
+ b.use Call, IsCreated do |env, b2|
122
+ unless env[:result]
123
+ b2.use MessageNotCreated
124
+ next
125
+ end
126
+
127
+ b2.use SSHRun
128
+ end
129
+ end
130
+ end
131
+
132
+ # This action is called to bring the box up from nothing.
133
+ def self.action_up
134
+ Vagrant::Action::Builder.new.tap do |b|
135
+ b.use HandleBox
136
+ b.use ConfigValidate
137
+ b.use BoxCheckOutdated
138
+ b.use ConnectScaleway
139
+ b.use Call, IsCreated do |env1, b1|
140
+ if env1[:result]
141
+ b1.use Call, IsStopped do |env2, b2|
142
+ if env2[:result]
143
+ b2.use Provision
144
+ b2.use SyncedFolders
145
+ b2.use WarnNetworks
146
+ b2.use StartServer
147
+ else
148
+ b2.use MessageAlreadyCreated
149
+ end
150
+ end
151
+ else
152
+ b1.use Provision
153
+ b1.use SyncedFolders
154
+ b1.use WarnNetworks
155
+ b1.use CreateServer
156
+ b1.use StartServer
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ # The autoload farm
163
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
164
+ autoload :ConnectScaleway, action_root.join('connect_scaleway')
165
+ autoload :CreateServer, action_root.join('create_server')
166
+ autoload :IsCreated, action_root.join('is_created')
167
+ autoload :IsStopped, action_root.join('is_stopped')
168
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
169
+ autoload :MessageNotCreated, action_root.join('message_not_created')
170
+ autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
171
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
172
+ autoload :ReadState, action_root.join('read_state')
173
+ autoload :StartServer, action_root.join('start_server')
174
+ autoload :StopServer, action_root.join('stop_server')
175
+ autoload :WarnNetworks, action_root.join('warn_networks')
176
+ autoload :DestroyServer, action_root.join('destroy_server')
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,34 @@
1
+ require 'fog/scaleway'
2
+
3
+ module VagrantPlugins
4
+ module Scaleway
5
+ module Action
6
+ # This action connects to Scaleway, verifies credentials work, and
7
+ # puts the Scaleway connection object into the `:scaleway_compute` key
8
+ # in the environment.
9
+ class ConnectScaleway
10
+ def initialize(app, _env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new('vagrant_scaleway::action::connect_scaleway')
13
+ end
14
+
15
+ def call(env)
16
+ # Get the configs
17
+ provider_config = env[:machine].provider_config
18
+
19
+ # Build the fog config
20
+ fog_config = {
21
+ provider: :scaleway,
22
+ scaleway_organization: provider_config.organization,
23
+ scaleway_token: provider_config.token
24
+ }
25
+
26
+ @logger.info('Connecting to Scaleway...')
27
+ env[:scaleway_compute] = Fog::Compute.new(fog_config)
28
+
29
+ @app.call(env)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,75 @@
1
+ require 'vagrant/util/retryable'
2
+ require 'vagrant-scaleway/util/timer'
3
+
4
+ module VagrantPlugins
5
+ module Scaleway
6
+ module Action
7
+ # This creates the configured server.
8
+ class CreateServer
9
+ include Vagrant::Util::Retryable
10
+
11
+ def initialize(app, _env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new('vagrant_scaleway::action::create_server')
14
+ end
15
+
16
+ def call(env)
17
+ # Initialize metrics if they haven't been
18
+ env[:metrics] ||= {}
19
+
20
+ config = env[:machine].provider_config
21
+
22
+ bootscript = config.bootscript
23
+ commercial_type = config.commercial_type
24
+ image = config.image
25
+ name = config.name
26
+ security_group = config.security_group
27
+ tags = config.tags
28
+
29
+ env[:ui].info(I18n.t('vagrant_scaleway.creating_server'))
30
+ env[:ui].info(" -- Bootscript: #{bootscript}") if bootscript
31
+ env[:ui].info(" -- Commercial Type: #{commercial_type}")
32
+ env[:ui].info(" -- Image: #{image}")
33
+ env[:ui].info(" -- Name: #{name}")
34
+ env[:ui].info(" -- Security Group: #{security_group}") if security_group
35
+ env[:ui].info(" -- Tags: #{tags}") unless tags.empty?
36
+
37
+ options = {
38
+ name: name,
39
+ image: image,
40
+ commercial_type: commercial_type,
41
+ tags: tags
42
+ }
43
+
44
+ options[:bootscript] = bootscript if bootscript
45
+ options[:security_group] = security_group if security_group
46
+
47
+ begin
48
+ server = env[:scaleway_compute].servers.create(options)
49
+ rescue Fog::Scaleway::Compute::Error => e
50
+ raise Errors::FogError, message: e.message
51
+ rescue Excon::Errors::HTTPStatusError => e
52
+ raise Errors::InternalFogError,
53
+ error: e.message,
54
+ response: e.response.body
55
+ end
56
+
57
+ # Immediately save the ID since it is created at this point.
58
+ env[:machine].id = server.id
59
+
60
+ begin
61
+ @app.call(env)
62
+ rescue Exception => e
63
+ # Delete the server
64
+ terminate(env)
65
+
66
+ raise e
67
+ end
68
+
69
+ # Terminate the server if we were interrupted
70
+ terminate(env) if env[:interrupted]
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end