ggoodale-rackspace_cloud 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/VERSION +1 -1
- data/lib/rackspace_cloud/base.rb +7 -1
- data/lib/rackspace_cloud/image.rb +23 -6
- data/lib/rackspace_cloud/server.rb +15 -0
- data/lib/rackspace_cloud.rb +29 -11
- data/rackspace_cloud.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/rackspace_cloud/base.rb
CHANGED
@@ -10,11 +10,13 @@ module RackspaceCloud
|
|
10
10
|
|
11
11
|
def connect
|
12
12
|
RackspaceCloud.request_authorization(@user, @access_key)
|
13
|
+
RackspaceCloud.check_version_compatibility
|
13
14
|
RackspaceCloud.populate_flavors
|
14
15
|
RackspaceCloud.populate_images
|
16
|
+
RackspaceCloud.get_limits
|
15
17
|
end
|
16
18
|
|
17
|
-
def servers
|
19
|
+
def servers(force_refresh=false)
|
18
20
|
RackspaceCloud.request("/servers/detail")["servers"].collect {|server_json|
|
19
21
|
RackspaceCloud::Server.new(server_json)
|
20
22
|
}
|
@@ -32,6 +34,10 @@ module RackspaceCloud
|
|
32
34
|
RackspaceCloud::Server.new(RackspaceCloud.request("/servers", :method => :post, :data => new_server_data)['server'])
|
33
35
|
end
|
34
36
|
|
37
|
+
def api_version
|
38
|
+
RackspaceCloud::API_VERSION
|
39
|
+
end
|
40
|
+
|
35
41
|
protected
|
36
42
|
|
37
43
|
def validate_config(config)
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module RackspaceCloud
|
2
2
|
class Image
|
3
|
-
|
3
|
+
|
4
|
+
MAX_RACKSPACE_IMAGE_ID = 10 # the highest id in use by a standard rackspace image (vs. a user backup)
|
5
|
+
|
6
|
+
attr_reader :name, :created, :updated, :status, :progress, :rackspace_id
|
4
7
|
|
5
8
|
class << self
|
6
9
|
def lookup_by_id(id)
|
@@ -9,11 +12,12 @@ module RackspaceCloud
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def initialize(image_json)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
15
|
+
populate(image_json)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete
|
19
|
+
raise RuntimeError, "Can't delete Rackspace standar images" if @rackspace_id <= MAX_RACKSPACE_IMAGE_ID
|
20
|
+
RackspaceCloud.request("/images/#{@rackspace_id}", :method => :delete)
|
17
21
|
end
|
18
22
|
|
19
23
|
def to_i
|
@@ -21,6 +25,19 @@ module RackspaceCloud
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def refresh
|
28
|
+
populate(RackspaceCloud.request("/images/#{@rackspace_id}")['image'])
|
29
|
+
RackspaceCloud::IMAGES[@rackspace_id] = self
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def populate(image_json)
|
35
|
+
@rackspace_id = image_json['id']
|
36
|
+
@name = image_json['name']
|
37
|
+
@created = DateTime.parse(image_json['created'])
|
38
|
+
@updated = DateTime.parse(image_json['updated'])
|
39
|
+
@status = image_json['status']
|
40
|
+
@progress = image_json['progress']
|
24
41
|
end
|
25
42
|
end
|
26
43
|
end
|
@@ -42,6 +42,21 @@ module RackspaceCloud
|
|
42
42
|
RackspaceCloud.request("/servers/#{@rackspace_id}", :method => :delete)
|
43
43
|
end
|
44
44
|
|
45
|
+
def update_server_name(new_name)
|
46
|
+
RackspaceCloud.request("/servers/#{@rackspace_id}", :method => :put, :data => {"server" => {"name" => new_name}})
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_admin_password(new_password)
|
50
|
+
RackspaceCloud.request("/servers/#{@rackspace_id}", :method => :put, :data => {"server" => {"adminPass" => new_password}})
|
51
|
+
end
|
52
|
+
|
53
|
+
def save_as_image(name)
|
54
|
+
image_json = RackspaceCloud.request("/images", :method => :post, :data => {'image' => {'name' => name, 'serverId' => @rackspace_id}})['image']
|
55
|
+
new_image = RackspaceCloud::Image.new(image_json)
|
56
|
+
RackspaceCloud::IMAGES[new_image.rackspace_id] = new_image
|
57
|
+
new_image
|
58
|
+
end
|
59
|
+
|
45
60
|
# update this server's status and progress by calling /servers/<id>
|
46
61
|
def refresh
|
47
62
|
populate(RackspaceCloud.request("/servers/#{@rackspace_id}")['server'])
|
data/lib/rackspace_cloud.rb
CHANGED
@@ -9,6 +9,7 @@ Dir[File.join(File.dirname(__FILE__), 'rackspace_cloud/**/*.rb')].sort.each { |l
|
|
9
9
|
|
10
10
|
module RackspaceCloud
|
11
11
|
|
12
|
+
class APIVersionError < StandardError; end
|
12
13
|
class ConfigurationError < StandardError; end
|
13
14
|
class AuthorizationError < StandardError; end
|
14
15
|
|
@@ -21,6 +22,10 @@ module RackspaceCloud
|
|
21
22
|
|
22
23
|
protected
|
23
24
|
|
25
|
+
def RackspaceCloud.check_version_compatibility
|
26
|
+
#This should eventually check the versions and raise an APIVersionError if there's a mismatch.
|
27
|
+
end
|
28
|
+
|
24
29
|
# storage for the lists of flavors and images we request at auth time
|
25
30
|
FLAVORS = {}
|
26
31
|
def RackspaceCloud.populate_flavors
|
@@ -37,6 +42,12 @@ module RackspaceCloud
|
|
37
42
|
end
|
38
43
|
nil
|
39
44
|
end
|
45
|
+
|
46
|
+
LIMITS = {}
|
47
|
+
def RackspaceCloud.get_limits
|
48
|
+
LIMITS.merge!(request("/limits")['limits'])
|
49
|
+
nil
|
50
|
+
end
|
40
51
|
|
41
52
|
def RackspaceCloud.request_authorization(user, access_key)
|
42
53
|
session = Patron::Session.new
|
@@ -55,33 +66,40 @@ module RackspaceCloud
|
|
55
66
|
@auth_token = response.headers['X-Auth-Token']
|
56
67
|
@@authorized = true
|
57
68
|
else
|
58
|
-
raise AuthorizationError, "Error during authorization: #{
|
69
|
+
raise AuthorizationError, "Error during authorization: #{response.status}"
|
59
70
|
end
|
60
71
|
nil
|
61
72
|
end
|
62
73
|
|
63
74
|
def RackspaceCloud.request(path, options={})
|
64
75
|
raise RuntimeError, "Please authorize before using by calling connect()" unless defined?(@@authorized) && @@authorized
|
65
|
-
session
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
76
|
+
@session ||= begin
|
77
|
+
s = Patron::Session.new
|
78
|
+
s.base_url = @server_management_url
|
79
|
+
s.headers['X-Auth-Token'] = @auth_token
|
80
|
+
s.headers["User-Agent"] = "rackspacecloud_ruby_gem"
|
81
|
+
s.timeout = 10
|
82
|
+
s
|
83
|
+
end
|
70
84
|
response = case options[:method]
|
71
85
|
when :post
|
72
|
-
session.headers['Accept'] = "application/json"
|
73
|
-
session.headers['Content-Type'] = "application/json"
|
74
|
-
session.post("#{path}", options[:data].to_json)
|
86
|
+
@session.headers['Accept'] = "application/json"
|
87
|
+
@session.headers['Content-Type'] = "application/json"
|
88
|
+
@session.post("#{path}", options[:data].to_json)
|
89
|
+
when :put
|
90
|
+
@session.headers['Content-Type'] = "application/json"
|
91
|
+
@session.put("#{path}", options[:data].to_json)
|
75
92
|
when :delete
|
76
|
-
session.delete("#{path}")
|
93
|
+
@session.delete("#{path}")
|
77
94
|
else
|
78
|
-
session.get("#{path}.json")
|
95
|
+
@session.get("#{path}.json")
|
79
96
|
end
|
80
97
|
|
81
98
|
case response.status
|
82
99
|
when 200, 202, 204
|
83
100
|
JSON.parse(response.body) unless response.body.empty?
|
84
101
|
else
|
102
|
+
puts response.body
|
85
103
|
raise RuntimeError, "Error fetching #{path}: #{response.status}"
|
86
104
|
end
|
87
105
|
end
|
data/rackspace_cloud.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rackspace_cloud}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Grant Goodale"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-22}
|
10
10
|
s.description = %q{Gem enabling the management of Rackspace Cloud Server instances.}
|
11
11
|
s.email = %q{grant@moreblinktag.com}
|
12
12
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ggoodale-rackspace_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Goodale
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|