You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2011/03/21 23:46:23 UTC
svn commit: r1084006 - in /incubator/deltacloud/trunk/server:
lib/deltacloud/drivers/rackspace/rackspace_driver.rb
views/instances/new.html.haml
Author: lutter
Date: Mon Mar 21 22:46:23 2011
New Revision: 1084006
URL: http://svn.apache.org/viewvc?rev=1084006&view=rev
Log:
rackspace: support feature user_files for instances
Modified:
incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
incubator/deltacloud/trunk/server/views/instances/new.html.haml
Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb?rev=1084006&r1=1084005&r2=1084006&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb Mon Mar 21 22:46:23 2011
@@ -19,6 +19,7 @@
require 'deltacloud/base_driver'
require 'cloudfiles'
require 'cloudservers'
+require 'base64'
module Deltacloud
module Drivers
@@ -28,6 +29,7 @@ class RackspaceDriver < Deltacloud::Base
feature :instances, :user_name
feature :instances, :authentication_password
+ feature :instances, :user_files
def supported_collections
DEFAULT_COLLECTIONS + [ :buckets ] - [ :storage_snapshots, :storage_volumes ]
@@ -82,10 +84,12 @@ class RackspaceDriver < Deltacloud::Base
def create_instance(credentials, image_id, opts)
rs = new_client( credentials )
result = nil
+ params = extract_personality(opts)
+ params[:name] = opts[:name] || Time.now.to_s
+ params[:imageId] = image_id.to_i
+ params[:flavorId] = (opts[:hwp_id] && opts[:hwp_id].length>0) ? opts[:hwp_id].to_i : 1
safely do
- server = rs.create_server(:name => opts[:name] || Time.now.to_s,
- :imageId => image_id.to_i,
- :flavorId => (opts[:hwp_id] && opts[:hwp_id].length>0) ? opts[:hwp_id].to_i : 1)
+ server = rs.create_server(params)
result = convert_instance_after_create(server, credentials.user, server.adminPass)
end
result
@@ -394,6 +398,28 @@ private
end
end
+ private
+
+ def extract_personality(opts)
+ # This relies on an undocumented feature of the cloudservers gem:
+ # create_server allows passing in strings for the file contents
+ # directly if :personality maps to an array of hashes
+ ary = opts.inject([]) do |a, e|
+ k, v = e
+ if k.to_s =~ /^path([0-9]+)/
+ a << {
+ :path => v,
+ :contents => Base64.decode64(opts[:"content#{$1}"])
+ }
+ end
+ a
+ end
+ if ary.empty?
+ {}
+ else
+ { :personality => ary }
+ end
+ end
end
end
Modified: incubator/deltacloud/trunk/server/views/instances/new.html.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/instances/new.html.haml?rev=1084006&r1=1084005&r2=1084006&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/views/instances/new.html.haml (original)
+++ incubator/deltacloud/trunk/server/views/instances/new.html.haml Mon Mar 21 22:46:23 2011
@@ -73,4 +73,20 @@
%br/
%span.radio-group-details
= "#{realm.name}, #{realm.limit}"
+ - if driver_has_feature?(:user_files, :instances)
+ %h2 User-supplied files
+ %table
+ %thead
+ %tr
+ %th
+ %th Path
+ %th Content (must be base64 encoded)
+ %tbody
+ - 1.upto(5) do |i|
+ %tr
+ %td #{i.ordinalize} File:
+ %td
+ %input{ :name => "path#{i}", :size => 20 }
+ %td
+ %input{ :name => "content#{i}", :size => 50 }
%input{ :type => :submit, :name => "commit", :value => "create" }/