rightscaler 0.0.3
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/LICENSE +20 -0
- data/README.markdown +3 -0
- data/Rakefile +49 -0
- data/VERSION.yml +5 -0
- data/lib/rightscaler.rb +29 -0
- data/lib/rightscaler/account.rb +21 -0
- data/lib/rightscaler/design.rb +2 -0
- data/lib/rightscaler/design/credential.rb +2 -0
- data/lib/rightscaler/design/macro.rb +2 -0
- data/lib/rightscaler/design/right_script.rb +2 -0
- data/lib/rightscaler/design/server_template.rb +2 -0
- data/lib/rightscaler/manage.rb +2 -0
- data/lib/rightscaler/manage/alert_specification.rb +3 -0
- data/lib/rightscaler/manage/deployment.rb +2 -0
- data/lib/rightscaler/manage/ec2_ebs_snapshot.rb +2 -0
- data/lib/rightscaler/manage/ec2_ebs_volume.rb +2 -0
- data/lib/rightscaler/manage/ec2_elastic_ip.rb +2 -0
- data/lib/rightscaler/manage/ec2_security_group.rb +2 -0
- data/lib/rightscaler/manage/ec2_ssh_key.rb +2 -0
- data/lib/rightscaler/manage/server.rb +43 -0
- data/lib/rightscaler/manage/status.rb +12 -0
- data/lib/rightscaler/resource.rb +38 -0
- data/rightscaler.gemspec +66 -0
- data/test/test_helper.rb +14 -0
- metadata +97 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Joshua Bates
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rightscaler"
|
8
|
+
gem.summary = %Q{An ActiveResource interface to the Rightscale API}
|
9
|
+
gem.email = "joshuabates@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/joshuabates/rightscaler"
|
11
|
+
gem.authors = ["Joshua Bates"]
|
12
|
+
gem.add_dependency(%q<activeresource>, [">= 0"])
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/rdoctask'
|
20
|
+
Rake::RDocTask.new do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'rightscaler'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README*')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/*_test.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
task :rcov do
|
44
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
task :default => :test
|
data/VERSION.yml
ADDED
data/lib/rightscaler.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'activesupport'
|
2
|
+
require 'activeresource'
|
3
|
+
require "logger"
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
module Rightscaler
|
7
|
+
VERSION = "0.1"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rightscaler/resource'
|
11
|
+
require 'rightscaler/account'
|
12
|
+
|
13
|
+
require 'rightscaler/design'
|
14
|
+
require 'rightscaler/manage'
|
15
|
+
require 'rightscaler/manage/deployment'
|
16
|
+
require 'rightscaler/manage/server'
|
17
|
+
require 'rightscaler/manage/status'
|
18
|
+
|
19
|
+
# ActiveResource can't manage to do a head request right, this fixes it
|
20
|
+
# https://rails.lighthouseapp.com/projects/8994/tickets/1223-activeresource-head-request-sends-headers-with-a-nil-key#ticket-1223-6
|
21
|
+
module ActiveResource
|
22
|
+
class Connection
|
23
|
+
HTTP_FORMAT_HEADER_NAMES[:head] = 'Content-Type'
|
24
|
+
|
25
|
+
def head(path, headers = {})
|
26
|
+
request(:head, path, build_request_headers(headers, :head))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Rightscaler::Account < Rightscaler::Resource
|
2
|
+
|
3
|
+
def self.set_auth_cookie(cookie)
|
4
|
+
Rightscaler::Resource.headers['cookie'] = cookie
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.authenticate
|
8
|
+
auth_cookie = extract_session_cookie(connection.head(site.to_s + "/login", headers))
|
9
|
+
set_auth_cookie(auth_cookie)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.extract_session_cookie(response)
|
15
|
+
response.to_hash["set-cookie"].each do |cookie|
|
16
|
+
cookie = cookie.split("; ").first
|
17
|
+
return cookie if cookie =~ /session_id/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Rightscaler::Manage::Server < Rightscaler::Resource
|
2
|
+
|
3
|
+
def start
|
4
|
+
post(:start) unless state == "operational"
|
5
|
+
end
|
6
|
+
|
7
|
+
def start_and_wait(scripts=[])
|
8
|
+
watch_until("operational") { start }
|
9
|
+
end
|
10
|
+
|
11
|
+
def stop
|
12
|
+
post(:stop) unless state == "stopped"
|
13
|
+
end
|
14
|
+
|
15
|
+
def stop_and_wait
|
16
|
+
watch_until("stopped") { stop }
|
17
|
+
end
|
18
|
+
|
19
|
+
def reboot
|
20
|
+
post(:reboot)
|
21
|
+
end
|
22
|
+
|
23
|
+
def reboot_and_wait
|
24
|
+
watch_until('operational') { reboot }
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_script(right_script_id)
|
28
|
+
with_status do
|
29
|
+
post(:run_script, :right_script => right_script_id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_script_and_wait(right_script_id)
|
34
|
+
status = run_script(right_script_id)
|
35
|
+
status.watch_until('completed')
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def watch_until(desired_state, &blk)
|
41
|
+
_watch_until(nickname, :state, [desired_state], ['stranded'], &blk)
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Rightscaler::Manage::Status < Rightscaler::Resource
|
2
|
+
|
3
|
+
%w(queued in_progress aborted completed failed).each do |state|
|
4
|
+
define_method "#{state}?" do
|
5
|
+
self.state == state.humanize.downcase
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def watch_until(desired_state, &blk)
|
10
|
+
_watch_until(description, :state, [desired_state], ['failed', 'aborted'], &blk)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Rightscaler::Resource < ActiveResource::Base
|
2
|
+
cattr_accessor :headers
|
3
|
+
|
4
|
+
API_VERSION = "1.0"
|
5
|
+
|
6
|
+
self.site = "https://my.rightscale.com/api/acct/"
|
7
|
+
self.headers = { "X-API-VERSION" => API_VERSION}
|
8
|
+
|
9
|
+
def id
|
10
|
+
href && href.split('/').last
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.account_id=(account_id)
|
14
|
+
self.site = self.site.to_s + account_id.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def with_status
|
20
|
+
response = yield
|
21
|
+
status_id = response.instance_variable_get("@header")["location"].first.split('/').last
|
22
|
+
Rightscaler::Manage::Status.find(status_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def _watch_until(name, state_method, desired_states, failed_states=[], sleep_time=5)
|
26
|
+
yield if block_given?
|
27
|
+
current_status = send(state_method)
|
28
|
+
until desired_states.include?(send(state_method)) || failed_states.include?(send(state_method))
|
29
|
+
sleep(sleep_time)
|
30
|
+
reload
|
31
|
+
unless current_status == send(state_method)
|
32
|
+
current_status = send(state_method)
|
33
|
+
puts "#{name} is now #{send(state_method)}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
desired_states.include? send(state_method)
|
37
|
+
end
|
38
|
+
end
|
data/rightscaler.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rightscaler}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joshua Bates"]
|
12
|
+
s.date = %q{2010-03-24}
|
13
|
+
s.email = %q{joshuabates@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.markdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"LICENSE",
|
20
|
+
"README.markdown",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION.yml",
|
23
|
+
"lib/rightscaler.rb",
|
24
|
+
"lib/rightscaler/account.rb",
|
25
|
+
"lib/rightscaler/design.rb",
|
26
|
+
"lib/rightscaler/design/credential.rb",
|
27
|
+
"lib/rightscaler/design/macro.rb",
|
28
|
+
"lib/rightscaler/design/right_script.rb",
|
29
|
+
"lib/rightscaler/design/server_template.rb",
|
30
|
+
"lib/rightscaler/manage.rb",
|
31
|
+
"lib/rightscaler/manage/alert_specification.rb",
|
32
|
+
"lib/rightscaler/manage/deployment.rb",
|
33
|
+
"lib/rightscaler/manage/ec2_ebs_snapshot.rb",
|
34
|
+
"lib/rightscaler/manage/ec2_ebs_volume.rb",
|
35
|
+
"lib/rightscaler/manage/ec2_elastic_ip.rb",
|
36
|
+
"lib/rightscaler/manage/ec2_security_group.rb",
|
37
|
+
"lib/rightscaler/manage/ec2_ssh_key.rb",
|
38
|
+
"lib/rightscaler/manage/server.rb",
|
39
|
+
"lib/rightscaler/manage/status.rb",
|
40
|
+
"lib/rightscaler/resource.rb",
|
41
|
+
"rightscaler.gemspec",
|
42
|
+
"test/test_helper.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/joshuabates/rightscaler}
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.3.6}
|
48
|
+
s.summary = %q{An ActiveResource interface to the Rightscale API}
|
49
|
+
s.test_files = [
|
50
|
+
"test/test_helper.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<activeresource>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<activeresource>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
require 'rr'
|
5
|
+
require "matchy"
|
6
|
+
require "context"
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
+
require 'rightscale'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
include RR::Adapters::TestUnit
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rightscaler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Joshua Bates
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-24 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activeresource
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
description:
|
33
|
+
email: joshuabates@gmail.com
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.markdown
|
41
|
+
files:
|
42
|
+
- LICENSE
|
43
|
+
- README.markdown
|
44
|
+
- Rakefile
|
45
|
+
- VERSION.yml
|
46
|
+
- lib/rightscaler.rb
|
47
|
+
- lib/rightscaler/account.rb
|
48
|
+
- lib/rightscaler/design.rb
|
49
|
+
- lib/rightscaler/design/credential.rb
|
50
|
+
- lib/rightscaler/design/macro.rb
|
51
|
+
- lib/rightscaler/design/right_script.rb
|
52
|
+
- lib/rightscaler/design/server_template.rb
|
53
|
+
- lib/rightscaler/manage.rb
|
54
|
+
- lib/rightscaler/manage/alert_specification.rb
|
55
|
+
- lib/rightscaler/manage/deployment.rb
|
56
|
+
- lib/rightscaler/manage/ec2_ebs_snapshot.rb
|
57
|
+
- lib/rightscaler/manage/ec2_ebs_volume.rb
|
58
|
+
- lib/rightscaler/manage/ec2_elastic_ip.rb
|
59
|
+
- lib/rightscaler/manage/ec2_security_group.rb
|
60
|
+
- lib/rightscaler/manage/ec2_ssh_key.rb
|
61
|
+
- lib/rightscaler/manage/server.rb
|
62
|
+
- lib/rightscaler/manage/status.rb
|
63
|
+
- lib/rightscaler/resource.rb
|
64
|
+
- rightscaler.gemspec
|
65
|
+
- test/test_helper.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/joshuabates/rightscaler
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: An ActiveResource interface to the Rightscale API
|
96
|
+
test_files:
|
97
|
+
- test/test_helper.rb
|