Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rackspace: pre-pre alpha

  • Loading branch information...
commit 533302b3412f146e5e3776adb860d65e3c9be28a 1 parent 52bc48b
Konstantin Dzreev konstantin-dzreev authored
1  .gitignore
View
@@ -1 +1,2 @@
nbproject
+pkg
1  History.txt
View
@@ -0,0 +1 @@
+== 0.0.0 2009-07-02
9 Manifest.txt
View
@@ -0,0 +1,9 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/benchmark_fix.rb
+lib/right_rackspace.rb
+lib/rackspace_base.rb
+lib/rackspace.rb
+lib/support.rb
9 README.txt
View
@@ -0,0 +1,9 @@
+= RightScale Rackspace Ruby Gems
+
+Published by RightScale, Inc. under the MIT License.
+For information about RightScale, see http://www.rightscale.com
+
+== DESCRIPTION:
+
+== FEATURES:
+
43 Rakefile
View
@@ -0,0 +1,43 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+require "rake/testtask"
+require 'rcov/rcovtask'
+$: << File.dirname(__FILE__)
+require 'lib/right_rackspace.rb'
+
+##testglobs = ["test/ts_right_aws.rb"]
+
+
+# Suppress Hoe's self-inclusion as a dependency for our Gem. This also keeps
+# Rake & rubyforge out of the dependency list. Users must manually install
+# these gems to run tests, etc.
+class Hoe
+ def extra_deps
+ @extra_deps.reject do |x|
+ Array(x).first == 'hoe'
+ end
+ end
+end
+
+Hoe.new('right_rackspace', RightRackspace::VERSION::STRING) do |p|
+ p.rubyforge_name = 'rightrackspace'
+ p.author = 'RightScale, Inc.'
+ p.email = 'support@rightscale.com'
+ p.summary = 'Interface classes for the Rackspace Services'
+## p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
+## p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
+## p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
+## p.remote_rdoc_dir = "/right_rackspace_gem_doc"
+ p.extra_deps = [['right_http_connection','>= 1.2.1']]
+## p.test_globs = testglobs
+end
+
+##desc "Analyze code coverage of the unit tests."
+##Rcov::RcovTask.new do |t|
+## t.test_files = FileList[testglobs]
+## #t.verbose = true # uncomment to see the executed command
+##end
+
+# vim: syntax=Ruby
133 lib/rackspace.rb
View
@@ -33,70 +33,177 @@ def login
# Images
#--------------------------------
+ # List images.
def list_images(opts={})
api_or_cache(:get, detailed_path("/images", opts), opts)
end
- def get_image(id, opts={})
- api(:get, "/images/#{id}", opts)
+ # Get image data.
+ def get_image(image_id, opts={})
+ api(:get, "/images/#{image_id}", opts)
+ end
+
+ # NOT TESTED
+ def create_image(server_id, name, opts={})
+ body = { 'image' => { 'name' => name } }
+ api(:post, "/servers/#{server_id}/actions/create_image", opts.merge(:body => body.to_json))
end
#--------------------------------
# Flavors
#--------------------------------
+ # List flavors.
def list_flavors(opts={})
api_or_cache(:get, detailed_path("/flavors", opts), opts)
end
- def get_flavor(id, opts={})
- api(:get, "/flavors/#{id}", opts)
+ # Get flavor data.
+ def get_flavor(flavor_id, opts={})
+ api(:get, "/flavors/#{flavor_id}", opts)
end
#--------------------------------
# Servers
#--------------------------------
+ # List servers.
def list_servers(opts={})
api_or_cache(:get, detailed_path("/servers", opts), opts)
end
# Launch a new server.
# +Server_data+ is a hash of params params:
- # Mandatory: :name, :image, :flavor
+ # Mandatory: :name, :image_id, :flavor_id
# Optional: :password, :metadata, :files
+ # TODO: A password setting does not seem to be working
def create_server(server_data, opts={} )
personality = server_data[:files].to_a.dup
personality.map! { |file, contents| { 'path'=> file, 'contents' => Base64.encode64(contents).chomp } }
body = {
'server' => {
'name' => server_data[:name],
- 'imageId' => server_data[:image],
- 'flavorId' => server_data[:flavor]
+ 'imageId' => server_data[:image_id],
+ 'flavorId' => server_data[:flavor_id]
}
}
- body['server']['adminPass'] = server_data[:password] unless server_data[:password].blank?
+ body['server']['adminPass'] = server_data[:password] if server_data[:password]
body['server']['metadata'] = server_data[:metadata] unless server_data[:metadata].blank?
body['server']['personality'] = personality unless personality.blank?
api(:post, "/servers", opts.merge(:body => body.to_json))
end
- def get_server(id, opts={})
- api(:get, "/servers/#{id}", opts)
+ # Get a server data.
+ def get_server(server_id, opts={})
+ api(:get, "/servers/#{server_id}", opts)
+ end
+
+ # Change server name and/or password.
+ # NOT TESTED
+ def update_server(server_id, server_data, opts={})
+ body = { 'server' => {} }
+ body['server']['name'] = server_data[:name] if server_data[:name]
+ body['server']['adminPass'] = server_data[:password] if server_data[:password]
+ api(:put, "/servers/#{server_id}", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def reboot_server(server_id, type = :soft, opts={})
+ body = { 'reboot' => { 'type' => type.to_s.upcase } }
+ api(:post, "/servers/#{server_id}/actions/reboot", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def rebuild_server(server_id, image_id, opts={})
+ body = { 'rebuild' => { 'imageId' => image_id } }
+ api(:post, "/servers/#{server_id}/actions/rebuild", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def resize_server(server_id, flavor_id, opts={})
+ body = { 'resize' => { 'flavorId' => flavor_id } }
+ api(:post, "/servers/#{server_id}/actions/resize", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def confirm_resized_server(server_id, opts={})
+ api(:put, "/servers/#{server_id}/actions/resize", opts)
+ end
+
+ # NOT TESTED
+ def revert_resized_server(server_id, opts={})
+ api(:delete, "/servers/#{server_id}/actions/resize", opts)
+ end
+
+ # NOT TESTED
+ def share_ip_address(server_id, shared_ip_group_id, address, opts={})
+ body = {
+ 'shareIp' => {
+ 'sharedIpGroupId' => shared_ip_group_id,
+ 'addr' => address
+ }
+ }
+ api(:post, "/servers/#{server_id}/actions/share_ip", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def unshare_ip_address(server_id, address, opts={})
+ body = { 'unshareIp' => { 'addr' => address } }
+ api(:post, "/servers/#{server_id}/actions/unshare_ip", opts.merge(:body => body.to_json))
end
# Delete a server.
# Returns +true+ on success.
- def delete_server(id, opts={})
- api(:delete, "/servers/#{id}", opts)
+ def delete_server(server_id, opts={})
+ api(:delete, "/servers/#{server_id}", opts)
+ end
+
+ #--------------------------------
+ # Backup Schedules
+ #--------------------------------
+
+ # NOT TESTED
+ def get_backup_schedule(server_id, opts={})
+ api(:get, "/servers/#{server_id}/backup_schedule", opts)
+ end
+
+ # NOT TESTED
+ def update_backup_schedule(server_id, enabled, daily=nil, weekly=nil, opts={})
+ body = { 'backupSchedule' => { 'enabled' => enabled.to_s } }
+ body['backupSchedule']['daily'] = daily unless daily.blank?
+ body['backupSchedule']['weekly'] = weekly unless weekly.blank?
+ api(:post, "/servers/#{server_id}/backup_schedule", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def delete_backup_schedule(server_id, opts={})
+ api(:delete, "/servers/#{server_id}/backup_schedule", opts)
end
#--------------------------------
# Shared IP Groups
#--------------------------------
+ # NOT TESTED
def list_shared_ip_groups(opts={})
- api_or_cache(:get, detailed_path("/list_shared_ip_groups", opts), opts)
+ api_or_cache(:get, detailed_path("/shared_ip_groups", opts), opts)
+ end
+
+ # NOT TESTED
+ def create_shared_ip_groups(name, server_id=nil, opts={})
+ body = { 'sharedIpGroup' => { 'name' => name } }
+ body['sharedIpGroup']['server'] = server_id unless server_id.blank?
+ api(:post, "/shared_ip_groups", opts.merge(:body => body.to_json))
+ end
+
+ # NOT TESTED
+ def get_shared_ip_group(shared_ip_group_id, opts={})
+ api(:get, "/shared_ip_groups/#{shared_ip_group_id}", opts)
+ end
+
+ # NOT TESTED
+ def delete_shared_ip_group(shared_ip_group_id, opts={})
+ api(:delete, "/shared_ip_groups/#{shared_ip_group_id}", opts)
end
end
6 lib/right_rackspace.rb
View
@@ -24,13 +24,7 @@
require 'benchmark'
require 'net/https'
require 'uri'
-#require 'time'
-#require "cgi"
require "base64"
-#require "rexml/document"
-#require "openssl"
-#require "digest/sha1"
-
require 'rubygems'
require 'json'
require 'right_http_connection'
Please sign in to comment.
Something went wrong with that request. Please try again.