vagrant-scaleway 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd75bdfdd4882cdab032133e1d2fb774aa575e16
4
- data.tar.gz: 19b03b5498e88328ba42a6028e8be1d22a3a3cfb
3
+ metadata.gz: 7193eabc56d0f452064f85e342b7b845557d25b7
4
+ data.tar.gz: 5250b4df9ae07cc85c570480a715949edd45acab
5
5
  SHA512:
6
- metadata.gz: 99bd7fc3bdb655ba213880457fa284db2aca08fee2336beacf0fbf0f86a6c63e1f5ea852285c6beb94b949ef7bf4ad077b385d271a4943927b10af6a07b9a907
7
- data.tar.gz: 40690821c51c739ef925a71d07b72c2ebafdc49c16d1c0510dd2e4e415d16f79059fdd2177453ed1388b05a13f349a03a2c402ce8062f8b59107bc8c2f28d0fa
6
+ metadata.gz: 7d38faaa297dbd510c2ece0380451b9613c2d3cec29b3d7ed258a3843661468c0aa9707d9cf1e34b10718ca923faa8374ea9108ff949af2c4e6b516815a8e7a5
7
+ data.tar.gz: 4b6f758fbddbb7da3c3982d4a8637264b241e62ea36f321d2a0ccb1a7c143b5847ac20eb8f88dcab24dd10801abdb19fd52688a27d6f454eb89f69456ee18a77
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Vagrant Scaleway Provider
2
2
 
3
3
  [![Gem](https://img.shields.io/gem/v/vagrant-scaleway.svg?style=flat-square)](https://rubygems.org/gems/vagrant-scaleway)
4
+ [![Gemnasium](https://img.shields.io/gemnasium/kaorimatz/vagrant-scaleway.svg?style=flat-square)](https://gemnasium.com/kaorimatz/vagrant-scaleway)
4
5
 
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.
6
+ This is a [Vagrant](http://www.vagrantup.com/) plugin that adds a
7
+ [Scaleway](https://www.scaleway.com/) provider to Vagrant, allowing Vagrant to
8
+ control and provision machines in Scaleway.
8
9
 
9
10
  ## Features
10
11
 
@@ -16,7 +17,8 @@ Scaleway.
16
17
  ## Prerequisites
17
18
 
18
19
  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
+ identify your organization ID. Please see the following help pages for
21
+ instructions.
20
22
 
21
23
  - [How to generate an API token](https://www.scaleway.com/docs/generate-an-api-token/)
22
24
  - [How to retrieve my organization ID through the API](https://www.scaleway.com/docs/retrieve-my-organization-id-throught-the-api/)
@@ -46,6 +48,11 @@ And then run `vagrant up` and specify the `scaleway` provider:
46
48
 
47
49
  $ vagrant up --provider=scaleway
48
50
 
51
+ ## Configurations
52
+
53
+ Please see the [RubyDoc](http://www.rubydoc.info/gems/vagrant-scaleway/VagrantPlugins/Scaleway/Config)
54
+ for the list of provider-specific configuration options.
55
+
49
56
  ## Development
50
57
 
51
58
  To work on the `vagrant-scaleway` plugin, clone this repository out, and use
@@ -159,12 +159,40 @@ module VagrantPlugins
159
159
  end
160
160
  end
161
161
 
162
+ # This action is called to list available bootscripts.
163
+ def self.action_list_bootscripts
164
+ Vagrant::Action::Builder.new.tap do |b|
165
+ b.use ConnectScaleway
166
+ b.use ListBootscripts
167
+ end
168
+ end
169
+
170
+ # This action is called to list available images.
171
+ def self.action_list_images
172
+ Vagrant::Action::Builder.new.tap do |b|
173
+ b.use ConnectScaleway
174
+ b.use ListImages
175
+ end
176
+ end
177
+
178
+ # This action is called to list available security groups.
179
+ def self.action_list_security_groups
180
+ Vagrant::Action::Builder.new.tap do |b|
181
+ b.use ConnectScaleway
182
+ b.use ListSecurityGroups
183
+ end
184
+ end
185
+
162
186
  # The autoload farm
163
187
  action_root = Pathname.new(File.expand_path('../action', __FILE__))
164
188
  autoload :ConnectScaleway, action_root.join('connect_scaleway')
165
189
  autoload :CreateServer, action_root.join('create_server')
190
+ autoload :DestroyServer, action_root.join('destroy_server')
166
191
  autoload :IsCreated, action_root.join('is_created')
167
192
  autoload :IsStopped, action_root.join('is_stopped')
193
+ autoload :ListBootscripts, action_root.join('list_bootscripts')
194
+ autoload :ListImages, action_root.join('list_images')
195
+ autoload :ListSecurityGroups, action_root.join('list_security_groups')
168
196
  autoload :MessageAlreadyCreated, action_root.join('message_already_created')
169
197
  autoload :MessageNotCreated, action_root.join('message_not_created')
170
198
  autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
@@ -173,7 +201,6 @@ module VagrantPlugins
173
201
  autoload :StartServer, action_root.join('start_server')
174
202
  autoload :StopServer, action_root.join('stop_server')
175
203
  autoload :WarnNetworks, action_root.join('warn_networks')
176
- autoload :DestroyServer, action_root.join('destroy_server')
177
204
  end
178
205
  end
179
206
  end
@@ -54,20 +54,29 @@ module VagrantPlugins
54
54
  response: e.response.body
55
55
  end
56
56
 
57
+ @logger.info("Machine '#{name}' created.")
58
+
57
59
  # Immediately save the ID since it is created at this point.
58
60
  env[:machine].id = server.id
59
61
 
60
- begin
61
- @app.call(env)
62
- rescue Exception => e
63
- # Delete the server
64
- terminate(env)
62
+ # destroy the server if we were interrupted
63
+ destroy(env) if env[:interrupted]
65
64
 
66
- raise e
67
- end
65
+ @app.call(env)
66
+ end
67
+
68
+ def recover(env)
69
+ return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
70
+
71
+ destroy(env) if env[:machine].provider.state.id != :not_created
72
+ end
68
73
 
69
- # Terminate the server if we were interrupted
70
- terminate(env) if env[:interrupted]
74
+ def destroy(env)
75
+ destroy_env = env.dup
76
+ destroy_env.delete(:interrupted)
77
+ destroy_env[:config_validate] = false
78
+ destroy_env[:force_confirm_destroy] = true
79
+ env[:action_runner].run(Action.action_destroy, destroy_env)
71
80
  end
72
81
  end
73
82
  end
@@ -4,8 +4,7 @@ module VagrantPlugins
4
4
  # This destroys the running server.
5
5
  class DestroyServer
6
6
  def initialize(app, _env)
7
- @app = app
8
- @logger = Log4r::Logger.new('vagrant_scaleway::action::destroy_server')
7
+ @app = app
9
8
  end
10
9
 
11
10
  def call(env)
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Scaleway
3
+ module Action
4
+ class ListBootscripts
5
+ def initialize(app, _env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ compute = env[:scaleway_compute]
11
+
12
+ env[:ui].info('%-37s %-7s %s' % ['Bootscript ID', 'Arch', 'Bootscript Title'], prefix: false)
13
+ compute.bootscripts.sort_by(&:title).each do |bootscript|
14
+ env[:ui].info('%-37s %-7s %s' % [bootscript.id, bootscript.architecture, bootscript.title], prefix: false)
15
+ end
16
+
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module VagrantPlugins
2
+ module Scaleway
3
+ module Action
4
+ class ListImages
5
+ def initialize(app, _env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ compute = env[:scaleway_compute]
11
+
12
+ env[:ui].info('%-37s %-26s %-7s %-36s %s' % ['Image ID', 'Created At', 'Arch', 'Default Bootscript', 'Image Name'], prefix: false)
13
+ compute.images.sort_by(&:name).each do |image|
14
+ created_at = Time.parse(image.creation_date)
15
+ bootscript = image.default_bootscript.title
16
+ env[:ui].info('%-37s %-26s %-7s %-36s %s' % [image.id, created_at, image.arch, bootscript, image.name], prefix: false)
17
+ end
18
+
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Scaleway
3
+ module Action
4
+ class ListSecurityGroups
5
+ def initialize(app, _env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ compute = env[:scaleway_compute]
11
+
12
+ env[:ui].info('%-37s %s' % ['Security Group ID', 'Security Group Name'], prefix: false)
13
+ compute.security_groups.sort_by(&:name).each do |security_group|
14
+ env[:ui].info('%-37s %s' % [security_group.id, security_group.name], prefix: false)
15
+ end
16
+
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -4,8 +4,7 @@ module VagrantPlugins
4
4
  # This stops the running server.
5
5
  class StopServer
6
6
  def initialize(app, _env)
7
- @app = app
8
- @logger = Log4r::Logger.new('vagrant_scaleway::action::stop_server')
7
+ @app = app
9
8
  end
10
9
 
11
10
  def call(env)
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module Scaleway
3
+ module Command
4
+ class Bootscripts < Vagrant.plugin('2', :command)
5
+ def execute
6
+ options = {}
7
+ opts = OptionParser.new do |o|
8
+ o.banner = 'Usage: vagrant scaleway bootscripts [options]'
9
+ end
10
+
11
+ argv = parse_options(opts)
12
+ return unless argv
13
+
14
+ with_target_vms(argv, provider: :scaleway) do |machine|
15
+ machine.action('list_bootscripts')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module Scaleway
3
+ module Command
4
+ class Images < Vagrant.plugin('2', :command)
5
+ def execute
6
+ options = {}
7
+ opts = OptionParser.new do |o|
8
+ o.banner = 'Usage: vagrant scaleway images [options]'
9
+ end
10
+
11
+ argv = parse_options(opts)
12
+ return unless argv
13
+
14
+ with_target_vms(argv, provider: :scaleway) do |machine|
15
+ machine.action('list_images')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ require 'vagrant-scaleway/action'
2
+
3
+ module VagrantPlugins
4
+ module Scaleway
5
+ module Command
6
+ class Root < Vagrant.plugin('2', :command)
7
+ def self.synopsis
8
+ 'queries Scaleway for available resources'
9
+ end
10
+
11
+ def initialize(argv, env)
12
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
13
+
14
+ @subcommands = Vagrant::Registry.new
15
+ @subcommands.register(:bootscripts) do
16
+ require File.expand_path('../bootscripts', __FILE__)
17
+ Bootscripts
18
+ end
19
+ @subcommands.register(:images) do
20
+ require File.expand_path('../images', __FILE__)
21
+ Images
22
+ end
23
+ @subcommands.register(:'security-groups') do
24
+ require File.expand_path('../security_groups', __FILE__)
25
+ SecurityGroups
26
+ end
27
+
28
+ super(argv, env)
29
+ end
30
+
31
+ def execute
32
+ if @main_args.include?('-h') || @main_args.include?('--help')
33
+ # Print the help for all the scaleway commands.
34
+ return help
35
+ end
36
+
37
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
38
+ return help if !command_class || !@sub_command
39
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
40
+
41
+ # Initialize and execute the command class
42
+ command_class.new(@sub_args, @env).execute
43
+ end
44
+
45
+ def help
46
+ opts = OptionParser.new do |opts|
47
+ opts.banner = 'Usage: vagrant scaleway <subcommand> [<args>]'
48
+ opts.separator ''
49
+ opts.separator 'Available subcommands:'
50
+
51
+ # Add the available subcommands as separators in order to print them
52
+ # out as well.
53
+ keys = []
54
+ @subcommands.each { |key, _value| keys << key.to_s }
55
+
56
+ keys.sort.each do |key|
57
+ opts.separator " #{key}"
58
+ end
59
+
60
+ opts.separator ''
61
+ opts.separator 'For help on any individual subcommand run `vagrant scaleway <subcommand> -h`'
62
+ end
63
+
64
+ @env.ui.info(opts.help, prefix: false)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module Scaleway
3
+ module Command
4
+ class SecurityGroups < Vagrant.plugin('2', :command)
5
+ def execute
6
+ options = {}
7
+ opts = OptionParser.new do |o|
8
+ o.banner = 'Usage: vagrant scaleway security-groups [options]'
9
+ end
10
+
11
+ argv = parse_options(opts)
12
+ return unless argv
13
+
14
+ with_target_vms(argv, provider: :scaleway) do |machine|
15
+ machine.action('list_security_groups')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -28,8 +28,8 @@ module VagrantPlugins
28
28
  # @return [String]
29
29
  attr_accessor :organization
30
30
 
31
- # The security group to associate with the server. If nil, organization's
32
- # default security group will be used.
31
+ # The security group ID to associate with the server. If nil,
32
+ # organization's default security group will be used.
33
33
  #
34
34
  # @return [String]
35
35
  attr_accessor :security_group
@@ -101,7 +101,7 @@ module VagrantPlugins
101
101
  end
102
102
  end
103
103
 
104
- def validate(machine)
104
+ def validate(_machine)
105
105
  errors = _detected_errors
106
106
 
107
107
  errors << I18n.t('vagrant_scaleway.config.organization_required') if @organization.nil?
@@ -34,6 +34,11 @@ module VagrantPlugins
34
34
  Provider
35
35
  end
36
36
 
37
+ command(:scaleway, primary: false) do
38
+ require_relative 'command/root'
39
+ Command::Root
40
+ end
41
+
37
42
  # This initializes the internationalization strings.
38
43
  def self.setup_i18n
39
44
  I18n.load_path << File.expand_path('locales/en.yml', Scaleway.source_root)
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Scaleway
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-scaleway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-28 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,7 +79,6 @@ files:
79
79
  - LICENSE.txt
80
80
  - README.md
81
81
  - Rakefile
82
- - dummy.box
83
82
  - example_box/metadata.json
84
83
  - lib/vagrant-scaleway.rb
85
84
  - lib/vagrant-scaleway/action.rb
@@ -88,6 +87,9 @@ files:
88
87
  - lib/vagrant-scaleway/action/destroy_server.rb
89
88
  - lib/vagrant-scaleway/action/is_created.rb
90
89
  - lib/vagrant-scaleway/action/is_stopped.rb
90
+ - lib/vagrant-scaleway/action/list_bootscripts.rb
91
+ - lib/vagrant-scaleway/action/list_images.rb
92
+ - lib/vagrant-scaleway/action/list_security_groups.rb
91
93
  - lib/vagrant-scaleway/action/message_already_created.rb
92
94
  - lib/vagrant-scaleway/action/message_not_created.rb
93
95
  - lib/vagrant-scaleway/action/message_will_not_destroy.rb
@@ -96,6 +98,10 @@ files:
96
98
  - lib/vagrant-scaleway/action/start_server.rb
97
99
  - lib/vagrant-scaleway/action/stop_server.rb
98
100
  - lib/vagrant-scaleway/action/warn_networks.rb
101
+ - lib/vagrant-scaleway/command/bootscripts.rb
102
+ - lib/vagrant-scaleway/command/images.rb
103
+ - lib/vagrant-scaleway/command/root.rb
104
+ - lib/vagrant-scaleway/command/security_groups.rb
99
105
  - lib/vagrant-scaleway/config.rb
100
106
  - lib/vagrant-scaleway/errors.rb
101
107
  - lib/vagrant-scaleway/plugin.rb
@@ -103,6 +109,7 @@ files:
103
109
  - lib/vagrant-scaleway/util/timer.rb
104
110
  - lib/vagrant-scaleway/version.rb
105
111
  - locales/en.yml
112
+ - scaleway.box
106
113
  - vagrant-scaleway.gemspec
107
114
  homepage: https://github.com/kaorimatz/vagrant-scaleway
108
115
  licenses: