You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2011/03/19 01:03:10 UTC
Add data injection for Rackspace
This series of patches introduces a 'user_files' feature for instances; it
is currently only supported by the Rackspace driver. The feature makes it
possible to inject up to 5 files into an instance before the instance is
launched.
David
Re: Add data injection for Rackspace
Posted by David Lutterkort <lu...@redhat.com>.
On Fri, 2011-03-18 at 17:03 -0700, lutter@redhat.com wrote:
> This series of patches introduces a 'user_files' feature for instances; it
> is currently only supported by the Rackspace driver. The feature makes it
> possible to inject up to 5 files into an instance before the instance is
> launched.
Pushed these
David
Re: [PATCH 3/4] New user_files feature for Rackspace-style file injection
Posted by Michal Fojtik <mi...@mifo.sk>.
On Mar 19, 2011, at 1:03 AM, lutter@redhat.com wrote:
ACK this feature.
-- Michal
> From: David Lutterkort <lu...@redhat.com>
>
> ---
> server/lib/deltacloud/base_driver/features.rb | 12 ++++++++++++
> 1 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
> index 1f07843..c5f9cca 100644
> --- a/server/lib/deltacloud/base_driver/features.rb
> +++ b/server/lib/deltacloud/base_driver/features.rb
> @@ -173,6 +173,18 @@ module Deltacloud
> end
> end
>
> + declare_feature :instances, :user_files do
> + description "Accept up to 5 files to be placed into the instance before launch."
> + operation :create do
> + 1.upto(5) do |i|
> + param :"path#{i}", :string, :optional, nil,
> + "Path where to place the #{i.ordinalize} file, up to 255 characters"
> + param :"content#{i}", :string, :optional, nil,
> + "Contents for the #{i.ordinalize} file, up to 10 kB, Base64 encoded"
> + end
> + end
> + end
> +
> declare_feature :instances, :security_group do
> description "Put instance in one or more security groups on launch"
> operation :create do
> --
> 1.7.4
>
[PATCH 3/4] New user_files feature for Rackspace-style file injection
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/lib/deltacloud/base_driver/features.rb | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index 1f07843..c5f9cca 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -173,6 +173,18 @@ module Deltacloud
end
end
+ declare_feature :instances, :user_files do
+ description "Accept up to 5 files to be placed into the instance before launch."
+ operation :create do
+ 1.upto(5) do |i|
+ param :"path#{i}", :string, :optional, nil,
+ "Path where to place the #{i.ordinalize} file, up to 255 characters"
+ param :"content#{i}", :string, :optional, nil,
+ "Contents for the #{i.ordinalize} file, up to 10 kB, Base64 encoded"
+ end
+ end
+ end
+
declare_feature :instances, :security_group do
description "Put instance in one or more security groups on launch"
operation :create do
--
1.7.4
Re: [PATCH 4/4] rackspace: support feature user_files for instances
Posted by Michal Fojtik <mi...@mifo.sk>.
On Mar 19, 2011, at 1:03 AM, lutter@redhat.com wrote:
ACK. Looks like a nice feaure!
-- Michal
> From: David Lutterkort <lu...@redhat.com>
>
> ---
> .../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
>
[PATCH 4/4] rackspace: support feature user_files for instances
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
.../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
Re: [PATCH 1/4] core_ext: move String enhancements out of rabbit;
add Integer.ordinalize
Posted by David Lutterkort <lu...@redhat.com>.
On Sat, 2011-03-19 at 14:17 +0100, Michal Fojtik wrote:
> On Mar 19, 2011, at 1:03 AM, lutter@redhat.com wrote:
>
> ACK, with small inline comment bellow.
>
> > From: David Lutterkort <lu...@redhat.com>
> >
> > It is much cleaner to keep monkey patches to stock Ruby classes in a
> > separate place. That place is lib/deltacloud/core_ext
> > ---
> > server/deltacloud.rb | 2 +
> > server/lib/deltacloud/core_ext.rb | 20 +++++++++++
> > server/lib/deltacloud/core_ext/integer.rb | 33 ++++++++++++++++++
> > server/lib/deltacloud/core_ext/string.rb | 52 +++++++++++++++++++++++++++++
> > server/lib/sinatra/rabbit.rb | 35 -------------------
> > 5 files changed, 107 insertions(+), 35 deletions(-)
> > create mode 100644 server/lib/deltacloud/core_ext.rb
> > create mode 100644 server/lib/deltacloud/core_ext/integer.rb
> > create mode 100644 server/lib/deltacloud/core_ext/string.rb
> >
> > diff --git a/server/deltacloud.rb b/server/deltacloud.rb
> > index 83f7cfb..cd310ef 100644
> > diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
> > new file mode 100644
> > index 0000000..2beba00
> > --- /dev/null
> > +++ b/server/lib/deltacloud/core_ext/string.rb
> > @@ -0,0 +1,52 @@
> > +
> > +class String
> > + # Rails defines this for a number of other classes, including Object
> > + # see activesupport/lib/active_support/core_ext/object/blank.rb
> > + def blank?
> > + self !~ /\S/
> > + end
> > +
> > + # Title case.
> > + #
> > + # "this is a string".titlecase
> > + # => "This Is A String"
> > + #
> > + # CREDIT: Eliazar Parra
> > + # Copied from facets
> > + def titlecase
> > + gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
> > + end
> > +
> > + def pluralize
> > + self + "s"
> > + end
> > +
> > + def singularize
> > + self.gsub(/s$/, '')
> > + end
>
> There was some special cases when this pluralization/singularization methods
> doesn't work. Collections like 'addresses', etc.
Yes, thre are - but they were not addressed in this code. The above is a
straight cut&paste from rabbit.rb; I'll commit as-is, if the lack of
rules is causing problems, we need to address that separately.
David
Re: [PATCH 1/4] core_ext: move String enhancements out of rabbit; add Integer.ordinalize
Posted by Michal Fojtik <mi...@mifo.sk>.
On Mar 19, 2011, at 1:03 AM, lutter@redhat.com wrote:
ACK, with small inline comment bellow.
-- Michal
> From: David Lutterkort <lu...@redhat.com>
>
> It is much cleaner to keep monkey patches to stock Ruby classes in a
> separate place. That place is lib/deltacloud/core_ext
> ---
> server/deltacloud.rb | 2 +
> server/lib/deltacloud/core_ext.rb | 20 +++++++++++
> server/lib/deltacloud/core_ext/integer.rb | 33 ++++++++++++++++++
> server/lib/deltacloud/core_ext/string.rb | 52 +++++++++++++++++++++++++++++
> server/lib/sinatra/rabbit.rb | 35 -------------------
> 5 files changed, 107 insertions(+), 35 deletions(-)
> create mode 100644 server/lib/deltacloud/core_ext.rb
> create mode 100644 server/lib/deltacloud/core_ext/integer.rb
> create mode 100644 server/lib/deltacloud/core_ext/string.rb
>
> diff --git a/server/deltacloud.rb b/server/deltacloud.rb
> index 83f7cfb..cd310ef 100644
> --- a/server/deltacloud.rb
> +++ b/server/deltacloud.rb
> @@ -20,6 +20,8 @@ $:.unshift File.join(File.dirname(__FILE__), 'lib')
>
> require 'drivers'
>
> +require 'deltacloud/core_ext'
> +
> require 'deltacloud/base_driver'
> require 'deltacloud/hardware_profile'
> require 'deltacloud/state_machine'
> diff --git a/server/lib/deltacloud/core_ext.rb b/server/lib/deltacloud/core_ext.rb
> new file mode 100644
> index 0000000..e3822f2
> --- /dev/null
> +++ b/server/lib/deltacloud/core_ext.rb
> @@ -0,0 +1,20 @@
> +#
> +# Copyright (C) 2011 David Lutterkort
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements. See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership. The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License. You may obtain a copy of the License at
> +#
> +# http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +require 'deltacloud/core_ext/string'
> +require 'deltacloud/core_ext/integer'
> diff --git a/server/lib/deltacloud/core_ext/integer.rb b/server/lib/deltacloud/core_ext/integer.rb
> new file mode 100644
> index 0000000..60b6f68
> --- /dev/null
> +++ b/server/lib/deltacloud/core_ext/integer.rb
> @@ -0,0 +1,33 @@
> +#
> +# Copyright (C) 2011 David Lutterkort
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements. See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership. The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License. You may obtain a copy of the License at
> +#
> +# http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +class Integer
> + # Turn integers into strings +1st+, +2nd+, +3rd+ etc.
> + def ordinalize
> + if (11..13).include?(self % 100)
> + "#{self}th"
> + else
> + case self % 10
> + when 1; "#{self}st"
> + when 2; "#{self}nd"
> + when 3; "#{self}rd"
> + else "#{self}th"
> + end
> + end
> + end
> +end
> diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
> new file mode 100644
> index 0000000..2beba00
> --- /dev/null
> +++ b/server/lib/deltacloud/core_ext/string.rb
> @@ -0,0 +1,52 @@
> +#
> +# Copyright (C) 2011 David Lutterkort
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements. See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership. The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License. You may obtain a copy of the License at
> +#
> +# http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +class String
> + # Rails defines this for a number of other classes, including Object
> + # see activesupport/lib/active_support/core_ext/object/blank.rb
> + def blank?
> + self !~ /\S/
> + end
> +
> + # Title case.
> + #
> + # "this is a string".titlecase
> + # => "This Is A String"
> + #
> + # CREDIT: Eliazar Parra
> + # Copied from facets
> + def titlecase
> + gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
> + end
> +
> + def pluralize
> + self + "s"
> + end
> +
> + def singularize
> + self.gsub(/s$/, '')
> + end
There was some special cases when this pluralization/singularization methods
doesn't work. Collections like 'addresses', etc.
> +
> + def underscore
> + gsub(/::/, '/').
> + gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
> + gsub(/([a-z\d])([A-Z])/,'\1_\2').
> + tr("-", "_").
> + downcase
> + end
> +end
> diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
> index b736b7a..f8d9e3d 100644
> --- a/server/lib/sinatra/rabbit.rb
> +++ b/server/lib/sinatra/rabbit.rb
> @@ -312,41 +312,6 @@ module Sinatra
> helpers RabbitHelper
> end
>
> -class String
> - # Rails defines this for a number of other classes, including Object
> - # see activesupport/lib/active_support/core_ext/object/blank.rb
> - def blank?
> - self !~ /\S/
> - end
> -
> - # Title case.
> - #
> - # "this is a string".titlecase
> - # => "This Is A String"
> - #
> - # CREDIT: Eliazar Parra
> - # Copied from facets
> - def titlecase
> - gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
> - end
> -
> - def pluralize
> - self + "s"
> - end
> -
> - def singularize
> - self.gsub(/s$/, '')
> - end
> -
> - def underscore
> - gsub(/::/, '/').
> - gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
> - gsub(/([a-z\d])([A-Z])/,'\1_\2').
> - tr("-", "_").
> - downcase
> - end
> -end
> -
> configure do
> class << Sinatra::Base
> def options(path, opts={}, &block)
> --
> 1.7.4
>
[PATCH 1/4] core_ext: move String enhancements out of rabbit; add Integer.ordinalize
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
It is much cleaner to keep monkey patches to stock Ruby classes in a
separate place. That place is lib/deltacloud/core_ext
---
server/deltacloud.rb | 2 +
server/lib/deltacloud/core_ext.rb | 20 +++++++++++
server/lib/deltacloud/core_ext/integer.rb | 33 ++++++++++++++++++
server/lib/deltacloud/core_ext/string.rb | 52 +++++++++++++++++++++++++++++
server/lib/sinatra/rabbit.rb | 35 -------------------
5 files changed, 107 insertions(+), 35 deletions(-)
create mode 100644 server/lib/deltacloud/core_ext.rb
create mode 100644 server/lib/deltacloud/core_ext/integer.rb
create mode 100644 server/lib/deltacloud/core_ext/string.rb
diff --git a/server/deltacloud.rb b/server/deltacloud.rb
index 83f7cfb..cd310ef 100644
--- a/server/deltacloud.rb
+++ b/server/deltacloud.rb
@@ -20,6 +20,8 @@ $:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'drivers'
+require 'deltacloud/core_ext'
+
require 'deltacloud/base_driver'
require 'deltacloud/hardware_profile'
require 'deltacloud/state_machine'
diff --git a/server/lib/deltacloud/core_ext.rb b/server/lib/deltacloud/core_ext.rb
new file mode 100644
index 0000000..e3822f2
--- /dev/null
+++ b/server/lib/deltacloud/core_ext.rb
@@ -0,0 +1,20 @@
+#
+# Copyright (C) 2011 David Lutterkort
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require 'deltacloud/core_ext/string'
+require 'deltacloud/core_ext/integer'
diff --git a/server/lib/deltacloud/core_ext/integer.rb b/server/lib/deltacloud/core_ext/integer.rb
new file mode 100644
index 0000000..60b6f68
--- /dev/null
+++ b/server/lib/deltacloud/core_ext/integer.rb
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2011 David Lutterkort
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+class Integer
+ # Turn integers into strings +1st+, +2nd+, +3rd+ etc.
+ def ordinalize
+ if (11..13).include?(self % 100)
+ "#{self}th"
+ else
+ case self % 10
+ when 1; "#{self}st"
+ when 2; "#{self}nd"
+ when 3; "#{self}rd"
+ else "#{self}th"
+ end
+ end
+ end
+end
diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
new file mode 100644
index 0000000..2beba00
--- /dev/null
+++ b/server/lib/deltacloud/core_ext/string.rb
@@ -0,0 +1,52 @@
+#
+# Copyright (C) 2011 David Lutterkort
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+class String
+ # Rails defines this for a number of other classes, including Object
+ # see activesupport/lib/active_support/core_ext/object/blank.rb
+ def blank?
+ self !~ /\S/
+ end
+
+ # Title case.
+ #
+ # "this is a string".titlecase
+ # => "This Is A String"
+ #
+ # CREDIT: Eliazar Parra
+ # Copied from facets
+ def titlecase
+ gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
+ end
+
+ def pluralize
+ self + "s"
+ end
+
+ def singularize
+ self.gsub(/s$/, '')
+ end
+
+ def underscore
+ gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+end
diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
index b736b7a..f8d9e3d 100644
--- a/server/lib/sinatra/rabbit.rb
+++ b/server/lib/sinatra/rabbit.rb
@@ -312,41 +312,6 @@ module Sinatra
helpers RabbitHelper
end
-class String
- # Rails defines this for a number of other classes, including Object
- # see activesupport/lib/active_support/core_ext/object/blank.rb
- def blank?
- self !~ /\S/
- end
-
- # Title case.
- #
- # "this is a string".titlecase
- # => "This Is A String"
- #
- # CREDIT: Eliazar Parra
- # Copied from facets
- def titlecase
- gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
- end
-
- def pluralize
- self + "s"
- end
-
- def singularize
- self.gsub(/s$/, '')
- end
-
- def underscore
- gsub(/::/, '/').
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
- tr("-", "_").
- downcase
- end
-end
-
configure do
class << Sinatra::Base
def options(path, opts={}, &block)
--
1.7.4
Re: [PATCH 2/4] Show parameters added by features in the docs
Posted by Michal Fojtik <mi...@mifo.sk>.
On Mar 19, 2011, at 1:03 AM, lutter@redhat.com wrote:
ACK.
-- Michal
> From: David Lutterkort <lu...@redhat.com>
>
> ---
> server/lib/sinatra/rabbit.rb | 1 +
> server/views/docs/operation.html.haml | 16 +++++++++++++++-
> 2 files changed, 16 insertions(+), 1 deletions(-)
>
> diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
> index f8d9e3d..a465ed6 100644
> --- a/server/lib/sinatra/rabbit.rb
> +++ b/server/lib/sinatra/rabbit.rb
> @@ -74,6 +74,7 @@ module Sinatra
> coll, oper = @collection, self
> ::Sinatra::Application.get("/api/docs/#{@collection.name}/#{@name}") do
> @collection, @operation = coll, oper
> + @features = driver.features_for_operation(coll.name, oper.name)
> respond_to do |format|
> format.html { haml :'docs/operation' }
> format.xml { haml :'docs/operation' }
> diff --git a/server/views/docs/operation.html.haml b/server/views/docs/operation.html.haml
> index b7c3538..927b331 100644
> --- a/server/views/docs/operation.html.haml
> +++ b/server/views/docs/operation.html.haml
> @@ -25,5 +25,19 @@
> %em #{p.name}
> %td{:style => "width:10em"} #{p.type}
> %td #{p.klass}
> - %td{:style => "width:10em"} #{p.options.join(',')}
> + %td{:style => "width:10em"} #{p.options.join(', ')}
> %td #{p.description}
> + - @features.sort { |a,b| a.name.to_s <=> b.name.to_s }.each do |f|
> + %tr
> + %th{:colspan => 4}
> + Feature #{f.name}
> + %th{:colspan => 1}
> + %em= f.description
> + - f.decl.operation(@operation.name).each_param do |p|
> + %tr
> + %td{:style => "width:15em"}
> + %em #{p.name}
> + %td{:style => "width:10em"} #{p.type}
> + %td #{p.klass}
> + %td{:style => "width:10em"} #{p.options.join(', ')}
> + %td #{p.description}
> --
> 1.7.4
>
[PATCH 2/4] Show parameters added by features in the docs
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/lib/sinatra/rabbit.rb | 1 +
server/views/docs/operation.html.haml | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
index f8d9e3d..a465ed6 100644
--- a/server/lib/sinatra/rabbit.rb
+++ b/server/lib/sinatra/rabbit.rb
@@ -74,6 +74,7 @@ module Sinatra
coll, oper = @collection, self
::Sinatra::Application.get("/api/docs/#{@collection.name}/#{@name}") do
@collection, @operation = coll, oper
+ @features = driver.features_for_operation(coll.name, oper.name)
respond_to do |format|
format.html { haml :'docs/operation' }
format.xml { haml :'docs/operation' }
diff --git a/server/views/docs/operation.html.haml b/server/views/docs/operation.html.haml
index b7c3538..927b331 100644
--- a/server/views/docs/operation.html.haml
+++ b/server/views/docs/operation.html.haml
@@ -25,5 +25,19 @@
%em #{p.name}
%td{:style => "width:10em"} #{p.type}
%td #{p.klass}
- %td{:style => "width:10em"} #{p.options.join(',')}
+ %td{:style => "width:10em"} #{p.options.join(', ')}
%td #{p.description}
+ - @features.sort { |a,b| a.name.to_s <=> b.name.to_s }.each do |f|
+ %tr
+ %th{:colspan => 4}
+ Feature #{f.name}
+ %th{:colspan => 1}
+ %em= f.description
+ - f.decl.operation(@operation.name).each_param do |p|
+ %tr
+ %td{:style => "width:15em"}
+ %em #{p.name}
+ %td{:style => "width:10em"} #{p.type}
+ %td #{p.klass}
+ %td{:style => "width:10em"} #{p.options.join(', ')}
+ %td #{p.description}
--
1.7.4