capistrano-rightscale 0.2.0 → 0.3.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.
- data/README.markdown +3 -2
- data/Rakefile +13 -13
- data/VERSION +1 -1
- data/lib/capistrano/rightscale.rb +61 -37
- metadata +4 -4
data/README.markdown
CHANGED
@@ -9,7 +9,8 @@ Introduction
|
|
9
9
|
[RightScale](http://www.rightscale.com) provides a service for managing deployments of servers in various clouds. Servers can be tagged with
|
10
10
|
machine tags. This plugin allows for specific tags in specific deployments to be mapped to Capistrano roles.
|
11
11
|
|
12
|
-
At present these mappings require several api calls, which are slow.
|
12
|
+
At present these mappings require several api calls, which are slow. On the first call, a cache file is written in the users
|
13
|
+
home directory. This can be disabled with an ENV variable RIGHTSCALE_CACHE=false.
|
13
14
|
|
14
15
|
Installation
|
15
16
|
============
|
@@ -24,7 +25,7 @@ Usage
|
|
24
25
|
|
25
26
|
In order to use the `capistrano-rightscale` plugin, you must require it in your Capfile:
|
26
27
|
|
27
|
-
require 'capistrano
|
28
|
+
require 'capistrano/rightscale'
|
28
29
|
|
29
30
|
Then you must specify your Rightscale API credentials:
|
30
31
|
|
data/Rakefile
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
begin
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "capistrano-rightscale"
|
5
|
+
gemspec.summary = "An extension for capistrano for integrating roles with RightScale server tags"
|
6
|
+
gemspec.description = "An extension for capistrano for integrating roles with RightScale server tags"
|
7
|
+
gemspec.email = "lachlan@ljd.cc"
|
8
|
+
gemspec.homepage = "http://github.com/99designs/capistrano-rightscale"
|
9
|
+
gemspec.authors = ["Lachlan Donald"]
|
10
|
+
gemspec.add_dependency('capistrano', '>= 2.1.0')
|
11
|
+
gemspec.add_dependency('rightscale-api')
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
14
|
rescue LoadError
|
15
|
-
|
15
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
16
16
|
end
|
17
17
|
|
18
18
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -1,40 +1,64 @@
|
|
1
1
|
require 'rightscale-api'
|
2
|
+
require 'json'
|
3
|
+
require 'fileutils'
|
2
4
|
|
3
5
|
module Capistrano
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
6
|
+
class Configuration
|
7
|
+
module Tags
|
8
|
+
|
9
|
+
def deployment(deployment)
|
10
|
+
logger.info "querying rightscale for deployment %s" % deployment
|
11
|
+
deployment = rightscale.deployments.index.find { |d| d['href'] == rightscale_url("/deployments/%d" % deployment) }
|
12
|
+
servers = []
|
13
|
+
deployment['servers'].each do |server|
|
14
|
+
if server['state'] == 'operational'
|
15
|
+
settings = rightscale.servers.settings(server['href'])
|
16
|
+
servers.push << {
|
17
|
+
'dns_name' => settings['dns_name'],
|
18
|
+
'tags' => tags_for_server(server)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
servers
|
23
|
+
end
|
24
|
+
|
25
|
+
# associate a tag in a specific deployment with a role
|
26
|
+
# e.g:
|
27
|
+
# tag "x99:role=app", :app, :deployment => 45678
|
28
|
+
def tag(which, *args)
|
29
|
+
cache_file = '%s/.rightscale%d' % [ ENV['HOME'], args[1][:deployment] ]
|
30
|
+
|
31
|
+
if File.exist?(cache_file) and ENV.fetch('RIGHTSCALE_CACHE', 'true') == 'true'
|
32
|
+
logger.info("cache file found for deployment %d" % args[1][:deployment]);
|
33
|
+
servers = JSON.parse(File.open(cache_file, "r").read)
|
34
|
+
else
|
35
|
+
servers = deployment(args[1][:deployment])
|
36
|
+
File.open(cache_file, 'w') {|f| f.write(servers.to_json) }
|
37
|
+
end
|
38
|
+
|
39
|
+
servers.each do |server|
|
40
|
+
server(server['dns_name'], *args) if server['tags'].include?(which)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# query rightscale for tags for a running instance
|
45
|
+
def tags_for_server(server)
|
46
|
+
instance_id = server["current_instance_href"].split('/').last
|
47
|
+
tags = rightscale.get(rightscale_url("/tags/search.js?resource_href=/ec2_instances/%d" % instance_id))
|
48
|
+
tags.collect { |x| x["name"] }
|
49
|
+
end
|
50
|
+
|
51
|
+
# rightscale client
|
52
|
+
def rightscale
|
53
|
+
@rightscale ||= RightScale::Client.new(
|
54
|
+
fetch(:rightscale_account), fetch(:rightscale_username), fetch(:rightscale_password))
|
55
|
+
end
|
56
|
+
|
57
|
+
def rightscale_url(path)
|
58
|
+
"https://my.rightscale.com/api/acct/%d%s" % [ fetch(:rightscale_account), path ]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
include Tags
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-rightscale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lachlan Donald
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-18 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|