These patches implement part of what's needed for user data/file injection. The main change is that the toplevel entry point now advertises user-data for EC2 and user-files for Rackspace in the XML, and lists optional features in the HTML. Patch 4/4 also adds support for user-data to the EC2 driver.
The main point of posting these is to get some discussion on the proposed XML format for optional features.
There's still a whole bunch of things that need to happen before this is ready: * Update the client to accept user-data/user-files when appropriate * Add validation of request parameters, e.g., so that you get an error when you try to create an instance with user-data on Rimu. I might put that off for another patch series, since we need more validation across the board * Add user-files support to Rackspace driver
In any event, the api.xml for EC2 now contains
<link href='http://localhost:3000/api/instances' rel='instances'> <feature name='user-data'> <constraint name='size' unit='kB'>16</constraint> </feature> </link>
and that for Rackspace has
<link href='http://localhost:3000/api/instances' rel='instances'> <feature name='user-files'> <constraint name='number' unit='count'>5</constraint> <constraint name='size' unit='kB'>10</constraint> <constraint name='pathlen' unit='byte'>255</constraint> </feature> </link>
The idea is that features are per-collection; it is implied that having the user-data feature means that you can include a corresponding parameter in a create instance request. AFAICT, you don't get that back from a DescribeInstances, and there is therefore no way to display this in the instance view.
David
From: David Lutterkort lutter@redhat.com
* new class Feature * base_driver: add features and support for defining them in drivers * views (xml): list features for each collection in api.xml * views (html): produce table with all features for a driver --- server/libexec/app/views/api/show.html.haml | 21 ++++++++++++++++- server/libexec/app/views/api/show.xml.haml | 4 +++ server/libexec/lib/deltacloud/base_driver.rb | 14 +++++++++++ server/libexec/lib/deltacloud/feature.rb | 31 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletions(-) create mode 100644 server/libexec/lib/deltacloud/feature.rb
diff --git a/server/libexec/app/views/api/show.html.haml b/server/libexec/app/views/api/show.html.haml index 95bb744..f6712c5 100644 --- a/server/libexec/app/views/api/show.html.haml +++ b/server/libexec/app/views/api/show.html.haml @@ -3,5 +3,24 @@
%ul - for entry_point in @entry_points - %li + %li = link_to entry_point[0].to_s.titlecase, entry_point[1] + +%h2 Optional Features + +%table + %tr + %th Collection + %th Name + %th Constraints + - for coll in driver.class.features.keys.sort + - for feature in driver.features(coll) + %tr + %td= coll + %td= feature.name + %td + - first = true + - for constr in feature.constraints + = " and " unless first + - first = false + #{constr.name} <= #{constr.human_value} diff --git a/server/libexec/app/views/api/show.xml.haml b/server/libexec/app/views/api/show.xml.haml index a41acb8..5520fe9 100644 --- a/server/libexec/app/views/api/show.xml.haml +++ b/server/libexec/app/views/api/show.xml.haml @@ -1,3 +1,7 @@ %api{ :version=>@version, :driver=>DRIVER } - for entry_point in @entry_points %link{ :rel=>entry_point[0], :href=>entry_point[1] } + - for feature in driver.features(entry_point[0]) + %feature{ :name=>feature.name } + - for constr in feature.constraints + %constraint{ :name => constr.name, :unit => constr.unit } #{constr.value} diff --git a/server/libexec/lib/deltacloud/base_driver.rb b/server/libexec/lib/deltacloud/base_driver.rb index 5add111..03d3d5b 100644 --- a/server/libexec/lib/deltacloud/base_driver.rb +++ b/server/libexec/lib/deltacloud/base_driver.rb @@ -45,6 +45,20 @@ module Deltacloud self.class.hardware_profiles.find{|e| e.name == name } end
+ def self.features + @features ||= {} + end + + def self.feature(collection, name, &block) + features[collection] ||= [] + return if features[collection].find { |f| f.name == name } + features[collection] << Feature.new(name, &block) + end + + def features(collection) + self.class.features[collection] || [] + end + def self.define_instance_states(&block) machine = ::Deltacloud::StateMachine.new(&block) @instance_state_machine = machine diff --git a/server/libexec/lib/deltacloud/feature.rb b/server/libexec/lib/deltacloud/feature.rb new file mode 100644 index 0000000..5e20ba3 --- /dev/null +++ b/server/libexec/lib/deltacloud/feature.rb @@ -0,0 +1,31 @@ +class Deltacloud::Feature + attr_reader :name, :constraints + + class Constraint + attr_reader :name, :value, :unit + + def initialize(name, value, opts) + @name = name + @value = value + @unit = opts[:unit] || "count" + end + + def human_value + if unit == "count" + value.to_s + else + "#{value} #{unit}" + end + end + end + + def initialize(name, &block) + @name = name + instance_eval &block + end + + def constraint(name, value, opts = {}) + @constraints ||= [] + @constraints << Constraint.new(name, value, opts) + end +end
From: David Lutterkort lutter@redhat.com
--- .../lib/deltacloud/drivers/ec2/ec2_driver.rb | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb index 93e798a..474aae7 100644 --- a/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -60,6 +60,10 @@ class EC2Driver < Deltacloud::BaseDriver } ), ]
+ feature(:instances, "user-data") do + constraint "size", 16, :unit => "kB" + end + define_hardware_profile('m1-small') do cpu 1 memory 1.7
From: David Lutterkort lutter@redhat.com
--- .../drivers/rackspace/rackspace_driver.rb | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_driver.rb index 3bb1714..fb0deef 100644 --- a/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +++ b/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_driver.rb @@ -24,6 +24,12 @@ module Deltacloud
class RackspaceDriver < Deltacloud::BaseDriver
+ feature(:instances, "user-files") do + constraint "number", 5 + constraint "size", 10, :unit => "kB" + constraint "pathlen", 255, :unit => "byte" + end + def flavors(credentials, opts=nil) racks = new_client( credentials ) results = racks.list_flavors.map do |flav|
From: David Lutterkort lutter@redhat.com
--- .../lib/deltacloud/drivers/ec2/ec2_driver.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb index 474aae7..7f3eb5a 100644 --- a/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb +++ b/server/libexec/lib/deltacloud/drivers/ec2/ec2_driver.rb @@ -201,7 +201,7 @@ class EC2Driver < Deltacloud::BaseDriver 1,1, [], nil, - '', + params[:"user-data"], 'public', flavor_id, nil,
deltacloud-devel@lists.fedorahosted.org