On Mar 19, 2011, at 1:03 AM, [email protected] wrote: ACK. Looks like a nice feaure!
-- Michal > From: David Lutterkort <[email protected]> > > --- > .../drivers/rackspace/rackspace_driver.rb | 32 ++++++++++++++++++-- > server/views/instances/new.html.haml | 16 ++++++++++ > 2 files changed, 45 insertions(+), 3 deletions(-) > > diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb > b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb > index a4272e1..4363580 100644 > --- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb > +++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb > @@ -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::BaseDriver > > 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::BaseDriver > 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 > diff --git a/server/views/instances/new.html.haml > b/server/views/instances/new.html.haml > index 5d075a6..647bf63 100644 > --- a/server/views/instances/new.html.haml > +++ b/server/views/instances/new.html.haml > @@ -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" }/ > -- > 1.7.4 >
