joshuabates-rightscaler 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +3 -0
- data/lib/rightscaler/account.rb +17 -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/design.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/manage.rb +2 -0
- data/lib/rightscaler/resource.rb +38 -0
- data/lib/rightscaler.rb +29 -0
- data/test/test_helper.rb +14 -0
- metadata +87 -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
@@ -0,0 +1,17 @@
|
|
1
|
+
class Rightscaler::Account < Rightscaler::Resource
|
2
|
+
|
3
|
+
def self.authenticate
|
4
|
+
auth_cookie = extract_session_cookie(connection.head(site.to_s + "/login", headers))
|
5
|
+
Rightscaler::Resource.headers['cookie'] = auth_cookie
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.extract_session_cookie(response)
|
11
|
+
response.to_hash["set-cookie"].each do |cookie|
|
12
|
+
cookie = cookie.split("; ").first
|
13
|
+
return cookie if cookie =~ /session_id/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
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/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
|
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,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: joshuabates-rightscaler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Bates
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: active_resource
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: joshuabates@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.markdown
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- README.markdown
|
36
|
+
- lib/rightscaler
|
37
|
+
- lib/rightscaler/account.rb
|
38
|
+
- lib/rightscaler/design
|
39
|
+
- lib/rightscaler/design/credential.rb
|
40
|
+
- lib/rightscaler/design/macro.rb
|
41
|
+
- lib/rightscaler/design/right_script.rb
|
42
|
+
- lib/rightscaler/design/server_template.rb
|
43
|
+
- lib/rightscaler/design.rb
|
44
|
+
- lib/rightscaler/manage
|
45
|
+
- lib/rightscaler/manage/alert_specification.rb
|
46
|
+
- lib/rightscaler/manage/deployment.rb
|
47
|
+
- lib/rightscaler/manage/ec2_ebs_snapshot.rb
|
48
|
+
- lib/rightscaler/manage/ec2_ebs_volume.rb
|
49
|
+
- lib/rightscaler/manage/ec2_elastic_ip.rb
|
50
|
+
- lib/rightscaler/manage/ec2_security_group.rb
|
51
|
+
- lib/rightscaler/manage/ec2_ssh_key.rb
|
52
|
+
- lib/rightscaler/manage/server.rb
|
53
|
+
- lib/rightscaler/manage/status.rb
|
54
|
+
- lib/rightscaler/manage.rb
|
55
|
+
- lib/rightscaler/resource.rb
|
56
|
+
- lib/rightscaler.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
- LICENSE
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/joshuabates/rightscaler
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --inline-source
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 2
|
85
|
+
summary: TODO
|
86
|
+
test_files: []
|
87
|
+
|