capistrano-rack 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: 7d066e18263d780bab15ff95203f2b3a38abe981
4
- data.tar.gz: 2d9a77c0398e9b1c2dcf4f580039f5fa1098f7cf
3
+ metadata.gz: 3e6f3618f6ffe51d2586c8bf09c98039c984acd2
4
+ data.tar.gz: 6cc80001f2afaf300a60e198b9466ab786921c5b
5
5
  SHA512:
6
- metadata.gz: 80f9422987ec6385f054536536a1905b301048dcfadb1f66590a1fe2b6883771537e30b449e957c435f153f216001dbec32008b11d888e6f0d2f1e082488e13e
7
- data.tar.gz: 0e669b7195804499fa26e5e9f549a404fed7fb39a9d912925d0852a371cda36a0fe9078f14f9210b5d5d5b9e4ab0c3f8d6b60413a87cdb19a5fe0c65753cf21a
6
+ metadata.gz: 6655301c242d37ac5ab2fcb22bd839592161a16c379f8eee9837e643c6473ccc22556b049ba80721080e96737d59df045601f17078aebadeec9d484dcaac118e
7
+ data.tar.gz: 3a1a98c0052f14a75fa0a7d687160e8a0c1780045b55f26b828b7d7695dc72a4045117c1e2ee659128d8d52c697d72316c5a65bc2682d0b9921edc43ef64e523
data/Gemfile CHANGED
@@ -5,4 +5,3 @@ gemspec
5
5
 
6
6
  gem 'capistrano'
7
7
  gem 'fog'
8
-
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-rack (0.1.0)
4
+ capistrano-rack (0.2.0)
5
5
  capistrano (~> 3.4, >= 3.0.0)
6
6
  fog (~> 1.35)
7
7
 
@@ -45,7 +45,7 @@ GEM
45
45
  fog-xml (~> 0.1.1)
46
46
  ipaddress (~> 0.5)
47
47
  nokogiri
48
- fog-aliyun (0.0.10)
48
+ fog-aliyun (0.1.0)
49
49
  fog-core (~> 1.27)
50
50
  fog-json (~> 1.0)
51
51
  ipaddress (~> 0.8)
data/README.md CHANGED
@@ -18,7 +18,7 @@ require 'capistrano/rack'
18
18
 
19
19
  And then execute:
20
20
 
21
- $ bundle && bundle exec rake
21
+ $ bundle && bundle exec rake
22
22
 
23
23
  Make sure to have a `~/.rack/config` in your `$HOME` directory with these properties:
24
24
 
@@ -32,25 +32,75 @@ If you are already a [**Rackspace CLI**](https://developer.rackspace.com/docs/ra
32
32
 
33
33
  ## Usage
34
34
 
35
- You can use `capistrano-rack` recipe in your deployment script like this:
35
+ `capistrano-rack` recipe supports two Rackspace Cloud services:
36
+
37
+ ### Next Generation Cloud Servers™
38
+
39
+ To deploy to your Next Gen Cloud servers:
36
40
 
37
41
  ```ruby
38
- rackspace_servers(:roles, '^regex')
42
+ rackspace_servers(roles=[], regex_str='^myservers-', addr_type=:private, config_file=nil, connection_options={})
39
43
  ```
40
44
 
41
- where `regex` is a regular expression to filter throught the names of your servers.
45
+ Where:
46
+ * `roles`: your [Capistrano Roles](http://capistranorb.com/).
47
+ * `regex_str`: a regular expression to filter throught your Next Gen Cloud servers.
48
+ * `addr_type`: type of IP addresses (`:public` or `:private`).
49
+ * `config_file`: Rackspace configuration file.
50
+ * `connection_options`: Optional connection parameters.
51
+
52
+ ### Auto Scale
42
53
 
43
- If you want to use a different configuration file for Rackspace, `rackspace_servers()` have an additional parameter:
54
+ To deploy to your Scaling Group:
44
55
 
45
56
  ```ruby
46
- rackspace_servers(:roles, '^regex', '/path/to/my/config/file')
57
+ rackspace_autoscale(roles=[], group_name='', addr_type=:private, config_file=nil, connection_options={})
47
58
  ```
48
59
 
60
+ Where:
61
+ * `roles`: your [Capistrano Roles](http://capistranorb.com/).
62
+ * `group_name`: Name of your Scaling Group.
63
+ * `addr_type`: type of IP addresses (`:public` or `:private`).
64
+ * `config_file`: Rackspace configuration file.
65
+ * `connection_options`: Optional connection parameters.
66
+
67
+ ### Optional Connection Parameters
68
+
69
+ <table>
70
+ <tr><th>Key</th><th>Description</th></tr>
71
+ <tr>
72
+ <td>:connect_timeout</td>
73
+ <td>Connection timeout (default: 60 seconds)</td>
74
+ </tr>
75
+ <tr>
76
+ <td>:read_timeout</td>
77
+ <td>Read timeout for connection (default: 60 seconds)</td> </tr>
78
+ <tr>
79
+ <td>:write_timeout</td>
80
+ <td>Write timeout for connection (default: 60 seconds)</td>
81
+ </tr>
82
+ <tr>
83
+ <td>:proxy</td>
84
+ <td>Proxy for HTTP and HTTPS connections</td>
85
+ </tr>
86
+ <tr>
87
+ <td>:ssl_ca_path</td>
88
+ <td>Path to SSL certificate authorities</td>
89
+ </tr>
90
+ <tr>
91
+ <td>:ssl_ca_file</td>
92
+ <td>SSL certificate authority file</td>
93
+ </tr>
94
+ <tr>
95
+ <td>:ssl_verify_peer</td>
96
+ <td>SSL verify peer (default: true)</td>
97
+ </tr>
98
+ </table>
99
+
49
100
  ## Contributing
50
101
 
51
102
  Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
52
103
 
53
-
54
104
  ## License
55
105
 
56
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
106
+ This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -3,9 +3,6 @@ require 'fog'
3
3
  require 'capistrano'
4
4
  require 'capistrano/rack/version'
5
5
 
6
- #
7
- # Properties Reader
8
- #
9
6
  class PropertiesReader
10
7
  def initialize(file)
11
8
  @file = file
@@ -27,35 +24,56 @@ class PropertiesReader
27
24
 
28
25
  end
29
26
 
27
+ class RackspaceOptions
28
+ def self.get(config_file=nil)
29
+ props_reader = PropertiesReader.new(config_file || "#{ENV['HOME']}/.rack/config")
30
+ return {
31
+ :rackspace_api_key => props_reader.get("api-key"),
32
+ :rackspace_username => props_reader.get("username"),
33
+ :rackspace_region => props_reader.get("region")
34
+ }
35
+ end
36
+ end
37
+
30
38
  module Capistrano
31
39
  module Rack
32
- #
33
- # Retrieves a list of Rackspace instances containing a tag list
34
- # which matches a supplied hash. Matching instances are applied
35
- # to the Cap server list.
36
- #
37
- # Usage: servers {'app' => 'zumba', 'stack' => 'web'}
38
- #
39
- def rackspace_servers(role=nil, regex_string='', config_file=nil)
40
- props_reader = PropertiesReader.new(config_file || "#{ENV['HOME']}/.rack/config")
41
- rackspace = Fog::Compute.new(
42
- {
43
- :provider => 'Rackspace',
44
- :rackspace_api_key => props_reader.get("api-key"),
45
- :rackspace_username => props_reader.get("username"),
46
- :rackspace_region => props_reader.get("region"),
47
- :version => :v2,
48
- :connection_options => {}
49
- })
50
- response = rackspace.list_servers
51
- response.body['servers'].select do |rackspace_server|
52
- if !rackspace_server["name"].match(/#{regex_string}/).nil?
53
- # Iterate over the list of private IP addresses
54
- rackspace_server['addresses']['private'].select do |private_addr|
55
- server (private_addr['addr']), %w{role || :app}
56
- end
57
- end
40
+ def rackspace_servers(roles=[], regex_str='', addr_type=:private, config_file=nil, connection_options={})
41
+ @compute_service = Fog::Compute.new(RackspaceOptions.get(config_file)
42
+ .merge({
43
+ :provider => 'Rackspace',
44
+ :version => :v2,
45
+ :connection_options => connection_options
46
+ }))
47
+ # List all servers and filter them based on the passed 'regex_str' parameter
48
+ @compute_service.list_servers.body['servers']
49
+ .select { |server| !server['name'].match(/#{regex_str}/).nil? }
50
+ .flat_map { |s| s["addresses"][addr_type.to_s] }
51
+ .select { |iface| iface['version'] == 4 }
52
+ .map { |iface| iface['addr'] }
53
+ .each { |server_addr| server (server_addr), roles || %w{:app} }
54
+ end
55
+
56
+ def rackspace_autoscale(roles=[], group_name='', addr_type=:private, config_file=nil, connection_options={})
57
+ rackspace_options = RackspaceOptions.get(config_file)
58
+
59
+ if !connection_options.empty? then
60
+ rackspace_options.merge!({:connection_options => connection_options})
58
61
  end
62
+
63
+ @compute_service = Fog::Compute.new(rackspace_options.merge({
64
+ :provider => 'Rackspace',
65
+ :version => :v2
66
+ }))
67
+ @autoscale_service = Fog::Rackspace::AutoScale.new(rackspace_options)
68
+
69
+ # Get the servers Ids inside the specified group name
70
+ @autoscale_service.groups.find { |g| g.group_config.name == group_name }.state['active']
71
+ .map { |server| server['id'] }
72
+ .map { |id| @compute_service.servers.get id }
73
+ .flat_map { |h| h.addresses[addr_type.to_s] }
74
+ .select { |iface| iface['version'] == 4 }
75
+ .map { |iface| iface['addr'] }
76
+ .each { |server_addr| server (server_addr), roles || %w{:app} }
59
77
  end
60
78
 
61
79
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Rack
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-rack
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
  - Faissal Elamraoui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano