vagrant-lightsail 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82b6fc2ea5e0e5fd4c462a2e74516426060ca956
4
- data.tar.gz: 3a9418b432a35da4848f966695fa40b0ef2b5b2e
3
+ metadata.gz: ba1f77ceffe556ec6fd1a0ce5ae63caa9f62864b
4
+ data.tar.gz: d5740a3fd4889b718aa970f947599adb15a59865
5
5
  SHA512:
6
- metadata.gz: 51b0c4ba1515e68cf9cfa559e51f57708f4576d4a145f4875e3b8d4c9992ff0a1978a98ebf3bfdd49ab678ac02c728dea224021237f044d49dfd05c155c5afd6
7
- data.tar.gz: 6b13ed86e7e12095f3dc5ab2961f8f6fbec18be9095ba8f27c65d352d1ca89ede07bb3ef566bf23a5eed1d834da71b71f1cd386b7933732ce7d839c14c62f5f7
6
+ metadata.gz: f0262c3f1677c1bd933a7d8115429aea232f05cbbdb2fd193e56cd32e1129e7dc5dc88d9593d981b73e96525db457ddf04f0ff34d3a0fb0ebdc6d94417b54929
7
+ data.tar.gz: aa18a305de6327a944a6b789dcb6c350b31ef154ea480bbd5a4edc0cef9d765c15263aacb5bd3e963e278a58791d25b7e421b0e2bc7ea82b566cb8c5be0e9cbf
data/.gitignore CHANGED
@@ -4,7 +4,7 @@
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
7
- /pkg/
7
+ *.gem
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /test/.vagrant/
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2017-01-24
10
+ ### Added
11
+ - Translation information for vagrant states
12
+ - New action, configure_ports, allows for opening of public firewall
13
+ ports
14
+
15
+ ### Changed
16
+ - Simplify API calls when starting, stopping, and terminating
17
+ instances
18
+
19
+ ## [0.1.0] - 2017-01-17
20
+ ### Added
21
+ - Initial release
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Lightsail Vagrant Provider
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/vagrant-lightsail.svg)](https://badge.fury.io/rb/vagrant-lightsail)
4
+
3
5
  `vagrant-lightsail` is a [Vagrant](https://www.vagrantup.com/) 1.2+
4
6
  plugin that support managing [Lightsail](https://amazonlightsail.com/)
5
7
  instances.
@@ -9,6 +11,7 @@ It can:
9
11
  - Power on and off instances
10
12
  - Provision an instance
11
13
  - Setup an SSH public key for authentication
14
+ - Open public firewall ports on instance
12
15
 
13
16
  It is based heavily
14
17
  on [vagrant-aws](https://github.com/mitchellh/vagrant-aws)
@@ -37,6 +40,7 @@ Vagrant.configure('2') do |config|
37
40
  provider.access_key_id = 'YOUR KEY'
38
41
  provider.secret_access_key = 'YOUR SECRET KEY'
39
42
  provider.keypair_name = 'KEYPAIR NAME'
43
+ provider.port_info = [{ from_port: 443, to_port: 443, protocol: 'tcp' }]
40
44
  end
41
45
  end
42
46
  ```
@@ -84,6 +88,8 @@ The following attributes are available to configure the provider:
84
88
  - `keypair_name`
85
89
  * The name to use when creating an SSH key for
86
90
  authentication. Defaults to *vagrant*.
91
+ - `port_info`
92
+ * Array of ports to open. See below.
87
93
  - `region`
88
94
  * The region to start the instance in. Defaults to *us-east-1*.
89
95
  - `secret_access_key`
@@ -93,6 +99,36 @@ The following attributes are available to configure the provider:
93
99
  - `user_data`
94
100
  * Plain text user data for the instance being booted.
95
101
 
102
+ ## Public Firewall Ports
103
+ The plugin supports opening firewall ports via the `port_info`
104
+ configuration parmater. Any number of port hashes can be specified in the
105
+ array but they must contain only the following keys:
106
+
107
+ - `from_port`
108
+ * Type: *Integer* The first port in the range. Valid Range: Minimum
109
+ value of 0. Maximum value of 65535.
110
+ - `protocol`
111
+ * Type: *String* The protocol. Valid Values: `tcp | all | udp`
112
+ - `to_port`
113
+ * Type: *Integer* The last port in the range. Valid Range: Minimum
114
+ value of 0. Maximum value of 65535.
115
+
116
+ ### Examples
117
+ Open port `TCP:443`
118
+
119
+ ```
120
+ provider.port_info = [{ from_port: 443, to_port: 443, protocol: 'tcp' }]
121
+ ```
122
+
123
+ Open ports `TCP:3306` and `UDP:161`
124
+
125
+ ```
126
+ provider.port_info = [
127
+ { from_port: 3306, to_port: 3306, protocol: 'tcp' },
128
+ { from_port: 161, to_port: 161, protocol: 'udp' },
129
+ ]
130
+ ```
131
+
96
132
  ## Contributing
97
133
 
98
134
  - Fork and clone repo
@@ -110,6 +146,7 @@ bundle exec rake test
110
146
  ```
111
147
  - Make code changes
112
148
  - Run tests again
149
+ - Update *README.md* and *CHANGELOG.md*
113
150
  - Create a Pull Request!
114
151
 
115
152
  ## License
@@ -38,6 +38,7 @@ module VagrantPlugins
38
38
  if env2[:result]
39
39
  b2.use prepare_boot
40
40
  b2.use StartInstance # restart this instance
41
+ b2.use ConfigurePorts
41
42
  else
42
43
  b2.use MessageAlreadyCreated # TODO: write a better message
43
44
  end
@@ -46,6 +47,7 @@ module VagrantPlugins
46
47
  b1.use SetupKey
47
48
  b1.use prepare_boot
48
49
  b1.use RunInstance # launch a new instance
50
+ b1.use ConfigurePorts
49
51
  end
50
52
  end
51
53
  end
@@ -146,6 +148,7 @@ module VagrantPlugins
146
148
 
147
149
  # The autload farm
148
150
  action_root = Pathname.new(File.expand_path('../action', __FILE__))
151
+ autoload :ConfigurePorts, action_root.join('configure_ports')
149
152
  autoload :ConnectLightsail, action_root.join('connect_lightsail')
150
153
  autoload :IsCreated, action_root.join('is_created')
151
154
  autoload :IsStopped, action_root.join('is_stopped')
@@ -0,0 +1,43 @@
1
+ require 'log4r'
2
+
3
+ module VagrantPlugins
4
+ module Lightsail
5
+ module Action
6
+ # This configures ports on instance
7
+ class ConfigurePorts
8
+ def initialize(app, _)
9
+ @app = app
10
+ @logger = Log4r::Logger.new('vagrant_lightsail::action::configure_ports')
11
+ end
12
+
13
+ def call(env)
14
+ port_info = env[:machine].provider_config.port_info
15
+
16
+ port_info.each do |pi|
17
+ begin
18
+ env[:lightsail_client].open_instance_public_ports(
19
+ port_info: pi,
20
+ instance_name: env[:machine].id
21
+ )
22
+
23
+ env[:ui].info I18n.t 'vagrant_lightsail.port_open',
24
+ proto: pi[:protocol],
25
+ port_no_from: pi[:from_port],
26
+ port_no_to: pi[:to_port]
27
+ rescue Aws::Lightsail::Errors::InvalidInputException => e
28
+ env[:ui].info I18n.t 'vagrant_lightsail.port_open_fail',
29
+ proto: pi[:protocol],
30
+ port_no_from: pi[:from_port],
31
+ port_no_to: pi[:to_port],
32
+ error: e.to_s
33
+ rescue Aws::Lightsail::Errors => e
34
+ raise Errors::LightailError, message: e
35
+ end
36
+ end
37
+
38
+ @app.call(env)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -14,12 +14,10 @@ module VagrantPlugins
14
14
  end
15
15
 
16
16
  def call(env)
17
- server = env[:lightsail_client].get_instance(instance_name: env[:machine].id).instance
18
-
19
17
  env[:ui].info I18n.t 'vagrant_lightsail.starting'
20
18
 
21
19
  begin
22
- env[:lightsail_client].start_instance(instance_name: server.name).operations[0]
20
+ env[:lightsail_client].start_instance(instance_name: env[:machine].id).operations[0]
23
21
  rescue Aws::Lightsail::Errors => e
24
22
  raise Errors::LightailError, message: e
25
23
  end
@@ -11,13 +11,11 @@ module VagrantPlugins
11
11
  end
12
12
 
13
13
  def call(env)
14
- server = env[:lightsail_client].get_instance(instance_name: env[:machine].id).instance
15
-
16
14
  if env[:machine].state.id == :stopped
17
15
  env[:ui].info I18n.t('vagrant_lightsail.already_status', status: env[:machine].state.id)
18
16
  else
19
17
  env[:ui].info(I18n.t('vagrant_lightsail.stopping'))
20
- env[:lightsail_client].stop_instance(instance_name: server.name)
18
+ env[:lightsail_client].stop_instance(instance_name: env[:machine].id)
21
19
  end
22
20
 
23
21
  @app.call(env)
@@ -10,13 +10,11 @@ module VagrantPlugins
10
10
  @logger = Log4r::Logger.new('vagrant_lightsail::action::terminate_instance')
11
11
  end
12
12
 
13
+ # Destroy the server and remove the tracking ID
13
14
  def call(env)
14
- server = env[:lightsail_client].get_instance(instance_name: env[:machine].id).instance
15
-
16
- # Destroy the server and remove the tracking ID
17
15
  env[:ui].info(I18n.t('vagrant_lightsail.terminating'))
18
16
  begin
19
- env[:lightsail_client].delete_instance(instance_name: server.name)
17
+ env[:lightsail_client].delete_instance(instance_name: env[:machine].id)
20
18
  rescue Aws::Lightsail::Errors => e
21
19
  raise Errors::LightailError, message: e
22
20
  end
@@ -11,6 +11,7 @@ module VagrantPlugins
11
11
  attr_accessor :bundle_id
12
12
  attr_accessor :endpoint
13
13
  attr_accessor :keypair_name
14
+ attr_accessor :port_info
14
15
  attr_accessor :region
15
16
  attr_accessor :secret_access_key
16
17
  attr_accessor :session_token
@@ -25,6 +26,7 @@ module VagrantPlugins
25
26
  @bundle_id = UNSET_VALUE
26
27
  @endpoint = UNSET_VALUE
27
28
  @keypair_name = UNSET_VALUE
29
+ @port_info = [UNSET_VALUE]
28
30
  @region = UNSET_VALUE
29
31
  @secret_access_key = UNSET_VALUE
30
32
  @session_token = UNSET_VALUE
@@ -47,6 +49,7 @@ module VagrantPlugins
47
49
  @bundle_id = 'nano_1_0' if @bundle_id == UNSET_VALUE
48
50
  @endpoint = nil if @endpoint == UNSET_VALUE
49
51
  @keypair_name = 'vagrant' if @keypair_name == UNSET_VALUE
52
+ @port_info = [] if @port_info == [UNSET_VALUE]
50
53
  @region = 'us-east-1' if @region == UNSET_VALUE
51
54
  @availability_zone = "#{@region}a" if @availability_zone == UNSET_VALUE
52
55
  @session_token = nil if @session_token == UNSET_VALUE
@@ -61,6 +64,8 @@ module VagrantPlugins
61
64
  profile: @aws_profile, location: @aws_dir)
62
65
  end
63
66
 
67
+ errors << I18n.t('vagrant_lightsail.config.port_info_array') unless @port_info.is_a? Array
68
+
64
69
  errors << I18n.t('vagrant_lightsail.config.region_required') if @region.nil?
65
70
 
66
71
  { 'Lightsail Provider' => errors }
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Lightsail
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -6,6 +6,8 @@ en:
6
6
  One or more of the needed AWS credentials are missing. No
7
7
  environment variables are set nor profile '%{profile}' exists
8
8
  at '%{location}'
9
+ port_info_array: |-
10
+ Port info must be an array. See plugin documentation.
9
11
  region_required: |-
10
12
  A region must be specified via "region"
11
13
 
@@ -33,6 +35,10 @@ en:
33
35
  This can sometimes result in not being able to access your instance.
34
36
  not_created: |-
35
37
  Instance is not created. Please run `vagrant up` first.
38
+ port_open: |-
39
+ Opened ports %{proto}:%{port_no_from} - %{proto}:%{port_no_to}
40
+ port_open_fail: |-
41
+ Unable to open ports %{proto}:%{port_no_from} - %{proto}:%{port_no_to}: %{error}
36
42
  ready: |-
37
43
  Machine is booted and ready for use!
38
44
  starting: |-
@@ -48,3 +54,40 @@ en:
48
54
  will_not_destroy: |-
49
55
  The instance '%{name}' will not be destroyed, since the
50
56
  confirmation was declined.
57
+
58
+ states:
59
+ short_not_created: |-
60
+ not created
61
+ long_not_created: |-
62
+ The Lightsail instance is not created. Run `vagrant up` to
63
+ create it.
64
+
65
+ short_stopped: |-
66
+ stopped
67
+ long_stopped: |-
68
+ The Lightsail instance is stopped. Run `vagrant up` to start it.
69
+
70
+ short_stopping: |-
71
+ stopping
72
+ long_stopping: |-
73
+ The Lightsail instance is stopping. Wait until is completely
74
+ stopped to run `vagrant up` and start it.
75
+
76
+ short_pending: |-
77
+ pending
78
+ long_pending: |-
79
+ The Lightsail instance is pending a start (i.e. this is a
80
+ transition state).
81
+
82
+ short_running: |-
83
+ running
84
+ long_running: |-
85
+ The Lightsail instance is running. To stop this machine, you can
86
+ run `vagrant halt`. To destroy the machine, you can run `vagrant
87
+ destroy`.
88
+
89
+ short_pending: |-
90
+ pending
91
+ long_pending: |-
92
+ The Lightsail instance is still being initialized. To destroy
93
+ this machine, you can run `vagrant destroy`.
data/test/Vagrantfile CHANGED
@@ -9,7 +9,19 @@ Vagrant.configure('2') do |config|
9
9
  override.vm.box = 'lightsail'
10
10
  override.vm.box_url = 'https://github.com/thejandroman/vagrant-lightsail/raw/master/box/lightsail.box'
11
11
  override.ssh.username = 'ubuntu'
12
+
12
13
  provider.keypair_name = 'Test-Key'
14
+ provider.port_info = [
15
+ { from_port: 22,
16
+ to_port: 22,
17
+ protocol: 'tcp' },
18
+ { from_port: 80,
19
+ to_port: 80,
20
+ protocol: 'udp' },
21
+ { from_port: 443,
22
+ to_port: 443,
23
+ protocol: 'tcp' }
24
+ ]
13
25
  end
14
26
 
15
27
  config.vm.provision :shell, path: 'scripts/provision.sh'
data/test/test.sh CHANGED
@@ -25,7 +25,6 @@ bundle exec vagrant halt
25
25
  bundle exec vagrant up
26
26
  destroy 'N'
27
27
  bundle exec vagrant destroy --force
28
- exit
29
28
  destroy 'N'
30
29
  destroy 'y'
31
30
  bundle exec vagrant destroy --force
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lightsail
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
  - Alejandro Figueroa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -92,6 +92,7 @@ files:
92
92
  - ".rubocop.yml"
93
93
  - ".ruby-version"
94
94
  - ".travis.yml"
95
+ - CHANGELOG.md
95
96
  - Gemfile
96
97
  - LICENSE.txt
97
98
  - README.md
@@ -100,6 +101,7 @@ files:
100
101
  - box/metadata.json
101
102
  - lib/vagrant-lightsail.rb
102
103
  - lib/vagrant-lightsail/action.rb
104
+ - lib/vagrant-lightsail/action/configure_ports.rb
103
105
  - lib/vagrant-lightsail/action/connect_lightsail.rb
104
106
  - lib/vagrant-lightsail/action/is_created.rb
105
107
  - lib/vagrant-lightsail/action/is_stopped.rb