incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962127 - in /incubator/deltacloud/trunk/drivers/rackspace: ./ lib/ lib/rackspace_client.rb lib/sample.rb
Date Thu, 08 Jul 2010 23:24:31 GMT
Author: lutter
Date: Thu Jul  8 23:24:31 2010
New Revision: 962127

URL: http://svn.apache.org/viewvc?rev=962127&view=rev
Log:
Initial monkey scratchings

Added:
    incubator/deltacloud/trunk/drivers/rackspace/
    incubator/deltacloud/trunk/drivers/rackspace/lib/
    incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb
    incubator/deltacloud/trunk/drivers/rackspace/lib/sample.rb

Added: incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb?rev=962127&view=auto
==============================================================================
--- incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb (added)
+++ incubator/deltacloud/trunk/drivers/rackspace/lib/rackspace_client.rb Thu Jul  8 23:24:31
2010
@@ -0,0 +1,52 @@
+require "net/http"
+require "net/https"
+require 'rubygems'
+require 'json'
+
+
+class RackspaceClient
+
+  @@AUTH_API = URI.parse('https://auth.api.rackspacecloud.com/v1.0')
+  
+  def initialize(username, auth_key)
+    http = Net::HTTP.new(@@AUTH_API.host,@@AUTH_API.port)
+    http.use_ssl = true
+    authed = http.get(@@AUTH_API.path, {'X-Auth-User' => username, 'X-Auth-Key' =>
auth_key})
+    @auth_token  = authed.header['X-Auth-Token']
+    @service_uri = URI.parse(authed.header['X-Server-Management-Url'])
+    @service = Net::HTTP.new(@service_uri.host, @service_uri.port)
+    @service.use_ssl = true
+  end
+
+  def get(path) 
+    @service.get(@service_uri.path + path, {"Accept" => "application/json", "X-Auth-Token"
=> @auth_token}).body
+  end
+
+  def list_flavors
+    JSON.parse(get('/flavors/detail'))['flavors']
+  end
+
+  def list_images 
+    JSON.parse(get('/images/detail'))['images']
+  end
+
+  def list_instances
+    JSON.parse(get('/servers/detail'))['servers']
+  end
+
+  def start_server(image_id, flavor_id, name)
+    json = { :server => { :name => name, :imageId => image_id, :flavorId => flavor_id
}}.to_json
+    resp = @service.post(@service_uri.path + "/servers", json, {"Accept" => "application/json",
"X-Auth-Token" => @auth_token, "Content-Type" => "application/json"}).body
+    JSON.parse(resp)
+  end
+
+
+
+
+
+
+end
+
+
+
+

Added: incubator/deltacloud/trunk/drivers/rackspace/lib/sample.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rackspace/lib/sample.rb?rev=962127&view=auto
==============================================================================
--- incubator/deltacloud/trunk/drivers/rackspace/lib/sample.rb (added)
+++ incubator/deltacloud/trunk/drivers/rackspace/lib/sample.rb Thu Jul  8 23:24:31 2010
@@ -0,0 +1,33 @@
+#
+# Author: Michael Neale
+# Monkey scratchings to manipulate rackspace cloud
+#
+
+require 'rackspace_client'
+rs_client = RackspaceClient.new(ARGV[0], ARGV[1])
+rs_client.list_flavors.each { |e| puts e['name']  + " --> " + e['id'].to_s}
+
+rs_client.list_images.each { |e| puts e['name'] + " --> " + e['status'] + " --> " +
e['id'].to_s }
+
+instances = rs_client.list_instances
+if (instances.size > 0) then
+  instances.each { |e| puts e['id'].to_s  + " ---> " + e['name'] + " ---> " + e['status']
}
+else
+  puts "we should start something up"
+  #resp = rs_client.start_server(13, 1, "mike01") 
+  #puts resp.to_s
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+



Mime
View raw message