[PATCH portal] Add infrastructure for BDD development.
by jason.guiditta
This patch adds Rails integration points for using
cucumber, rspec and webrat, first batch of scenarios/specs
will be in a separate upcoming patch.
Note for fedora that rspec and cucumber are available via
yum, but cucumber currently has an incorrect version for
one of its dependencies, so for the time being it is probably
best to just gem install everything needed besides rspec.
---
src/config/boot.rb | 2 +-
src/config/cucumber.yml | 7 +
src/config/environments/cucumber.rb | 29 +++
src/config/environments/test.rb | 4 +-
src/features/step_definitions/web_steps.rb | 263 ++++++++++++++++++++++++++++
src/features/support/env.rb | 54 ++++++
src/features/support/paths.rb | 27 +++
src/lib/tasks/cucumber.rake | 47 +++++
src/lib/tasks/rspec.rake | 144 +++++++++++++++
src/script/autospec | 6 +
src/script/cucumber | 10 +
src/script/spec | 10 +
src/spec/rcov.opts | 2 +
src/spec/spec.opts | 4 +
src/spec/spec_helper.rb | 54 ++++++
15 files changed, 661 insertions(+), 2 deletions(-)
create mode 100644 src/config/cucumber.yml
create mode 100644 src/config/environments/cucumber.rb
create mode 100644 src/features/step_definitions/web_steps.rb
create mode 100644 src/features/support/env.rb
create mode 100644 src/features/support/paths.rb
create mode 100644 src/lib/tasks/cucumber.rake
create mode 100644 src/lib/tasks/rspec.rake
create mode 100755 src/script/autospec
create mode 100755 src/script/cucumber
create mode 100755 src/script/spec
create mode 100644 src/spec/rcov.opts
create mode 100644 src/spec/spec.opts
create mode 100644 src/spec/spec_helper.rb
diff --git a/src/config/boot.rb b/src/config/boot.rb
index 0ad0f78..dd5e3b6 100644
--- a/src/config/boot.rb
+++ b/src/config/boot.rb
@@ -82,8 +82,8 @@ module Rails
end
def load_rubygems
+ min_version = '1.3.2'
require 'rubygems'
- min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
diff --git a/src/config/cucumber.yml b/src/config/cucumber.yml
new file mode 100644
index 0000000..b7acd38
--- /dev/null
+++ b/src/config/cucumber.yml
@@ -0,0 +1,7 @@
+<%
+rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
+rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
+std_opts = "#{rerun_opts} --format rerun --out rerun.txt --strict --tags ~@wip"
+%>
+default: <%= std_opts %>
+wip: --tags @wip:3 --wip features
diff --git a/src/config/environments/cucumber.rb b/src/config/environments/cucumber.rb
new file mode 100644
index 0000000..98559e1
--- /dev/null
+++ b/src/config/environments/cucumber.rb
@@ -0,0 +1,29 @@
+# Edit at your own peril - it's recommended to regenerate this file
+# in the future when you upgrade to a newer version of Cucumber.
+
+# IMPORTANT: Setting config.cache_classes to false is known to
+# break Cucumber's use_transactional_fixtures method.
+# For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165
+config.cache_classes = true
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell Action Mailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
+
+config.gem 'cucumber-rails', :lib => false, :version => '>=0.2.4' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails'))
+config.gem 'database_cleaner', :lib => false, :version => '>=0.4.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
+config.gem 'webrat', :lib => false, :version => '>=0.6.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
+config.gem 'rspec', :lib => false, :version => '>=1.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
+config.gem 'rspec-rails', :lib => false, :version => '>=1.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
+
diff --git a/src/config/environments/test.rb b/src/config/environments/test.rb
index 9a90783..2d0704e 100644
--- a/src/config/environments/test.rb
+++ b/src/config/environments/test.rb
@@ -35,4 +35,6 @@ config.action_controller.perform_caching = false
# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
-config.action_mailer.delivery_method = :test
\ No newline at end of file
+config.action_mailer.delivery_method = :test
+
+ config.gem 'rspec-rails', :version => '>= 1.3.2', :lib => false unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
diff --git a/src/features/step_definitions/web_steps.rb b/src/features/step_definitions/web_steps.rb
new file mode 100644
index 0000000..ad0a26a
--- /dev/null
+++ b/src/features/step_definitions/web_steps.rb
@@ -0,0 +1,263 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+
+require 'uri'
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+
+# Commonly used webrat steps
+# http://github.com/brynary/webrat
+
+Given /^(?:|I )am on (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )go to (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )press "([^\"]*)"$/ do |button|
+ click_button(button)
+end
+
+When /^(?:|I )follow "([^\"]*)"$/ do |link|
+ click_link(link)
+end
+
+When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
+ click_link_within(parent, link)
+end
+
+When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
+end
+
+When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
+ fill_in(field, :with => value)
+end
+
+# Use this to fill in an entire form with data from a table. Example:
+#
+# When I fill in the following:
+# | Account Number | 5002 |
+# | Expiry date | 2009-11-01 |
+# | Note | Nice guy |
+# | Wants Email? | |
+#
+# TODO: Add support for checkbox, select og option
+# based on naming conventions.
+#
+When /^(?:|I )fill in the following:$/ do |fields|
+ fields.rows_hash.each do |name, value|
+ When %{I fill in "#{name}" with "#{value}"}
+ end
+end
+
+When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
+ select(value, :from => field)
+end
+
+# Use this step in conjunction with Rail's datetime_select helper. For example:
+# When I select "December 25, 2008 10:00" as the date and time
+When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
+ select_datetime(time)
+end
+
+# Use this step when using multiple datetime_select helpers on a page or
+# you want to specify which datetime to select. Given the following view:
+# <%= f.label :preferred %><br />
+# <%= f.datetime_select :preferred %>
+# <%= f.label :alternative %><br />
+# <%= f.datetime_select :alternative %>
+# The following steps would fill out the form:
+# When I select "November 23, 2004 11:20" as the "Preferred" date and time
+# And I select "November 25, 2004 10:30" as the "Alternative" date and time
+When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
+ select_datetime(datetime, :from => datetime_label)
+end
+
+# Use this step in conjunction with Rail's time_select helper. For example:
+# When I select "2:20PM" as the time
+# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
+# will convert the 2:20PM to 14:20 and then select it.
+When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
+ select_time(time)
+end
+
+# Use this step when using multiple time_select helpers on a page or you want to
+# specify the name of the time on the form. For example:
+# When I select "7:30AM" as the "Gym" time
+When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
+ select_time(time, :from => time_label)
+end
+
+# Use this step in conjunction with Rail's date_select helper. For example:
+# When I select "February 20, 1981" as the date
+When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
+ select_date(date)
+end
+
+# Use this step when using multiple date_select helpers on one page or
+# you want to specify the name of the date on the form. For example:
+# When I select "April 26, 1982" as the "Date of Birth" date
+When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
+ select_date(date, :from => date_label)
+end
+
+When /^(?:|I )check "([^\"]*)"$/ do |field|
+ check(field)
+end
+
+When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
+ uncheck(field)
+end
+
+When /^(?:|I )choose "([^\"]*)"$/ do |field|
+ choose(field)
+end
+
+# Adds support for validates_attachment_content_type. Without the mime-type getting
+# passed to attach_file() you will get a "Photo file is not one of the allowed file types."
+# error message
+When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
+ type = path.split(".")[1]
+
+ case type
+ when "jpg"
+ type = "image/jpg"
+ when "jpeg"
+ type = "image/jpeg"
+ when "png"
+ type = "image/png"
+ when "gif"
+ type = "image/gif"
+ end
+
+ attach_file(field, path, type)
+end
+
+Then /^(?:|I )should see "([^\"]*)"$/ do |text|
+ if defined?(Spec::Rails::Matchers)
+ response.should contain(text)
+ else
+ assert_contain text
+ end
+end
+
+Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
+ within(selector) do |content|
+ if defined?(Spec::Rails::Matchers)
+ content.should contain(text)
+ else
+ hc = Webrat::Matchers::HasContent.new(text)
+ assert hc.matches?(content), hc.failure_message
+ end
+ end
+end
+
+Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
+ regexp = Regexp.new(regexp)
+ if defined?(Spec::Rails::Matchers)
+ response.should contain(regexp)
+ else
+ assert_match(regexp, response_body)
+ end
+end
+
+Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
+ within(selector) do |content|
+ regexp = Regexp.new(regexp)
+ if defined?(Spec::Rails::Matchers)
+ content.should contain(regexp)
+ else
+ assert_match(regexp, content)
+ end
+ end
+end
+
+Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
+ if defined?(Spec::Rails::Matchers)
+ response.should_not contain(text)
+ else
+ assert_not_contain(text)
+ end
+end
+
+Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
+ within(selector) do |content|
+ if defined?(Spec::Rails::Matchers)
+ content.should_not contain(text)
+ else
+ hc = Webrat::Matchers::HasContent.new(text)
+ assert !hc.matches?(content), hc.negative_failure_message
+ end
+ end
+end
+
+Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
+ regexp = Regexp.new(regexp)
+ if defined?(Spec::Rails::Matchers)
+ response.should_not contain(regexp)
+ else
+ assert_not_contain(regexp)
+ end
+end
+
+Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
+ within(selector) do |content|
+ regexp = Regexp.new(regexp)
+ if defined?(Spec::Rails::Matchers)
+ content.should_not contain(regexp)
+ else
+ assert_no_match(regexp, content)
+ end
+ end
+end
+
+Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
+ if defined?(Spec::Rails::Matchers)
+ field_labeled(field).value.should =~ /#{value}/
+ else
+ assert_match(/#{value}/, field_labeled(field).value)
+ end
+end
+
+Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
+ if defined?(Spec::Rails::Matchers)
+ field_labeled(field).value.should_not =~ /#{value}/
+ else
+ assert_no_match(/#{value}/, field_labeled(field).value)
+ end
+end
+
+Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
+ if defined?(Spec::Rails::Matchers)
+ field_labeled(label).should be_checked
+ else
+ assert field_labeled(label).checked?
+ end
+end
+
+Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
+ if defined?(Spec::Rails::Matchers)
+ field_labeled(label).should_not be_checked
+ else
+ assert !field_labeled(label).checked?
+ end
+end
+
+Then /^(?:|I )should be on (.+)$/ do |page_name|
+ current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
+ if defined?(Spec::Rails::Matchers)
+ current_path.should == path_to(page_name)
+ else
+ assert_equal path_to(page_name), current_path
+ end
+end
+
+Then /^show me the page$/ do
+ save_and_open_page
+end
\ No newline at end of file
diff --git a/src/features/support/env.rb b/src/features/support/env.rb
new file mode 100644
index 0000000..417a434
--- /dev/null
+++ b/src/features/support/env.rb
@@ -0,0 +1,54 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+ENV["RAILS_ENV"] ||= "cucumber"
+require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
+
+require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
+require 'cucumber/rails/rspec'
+require 'cucumber/rails/world'
+require 'cucumber/rails/active_record'
+require 'cucumber/web/tableish'
+
+require 'webrat'
+require 'webrat/core/matchers'
+
+Webrat.configure do |config|
+ config.mode = :rails
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
+end
+
+
+# If you set this to false, any error raised from within your app will bubble
+# up to your step definition and out to cucumber unless you catch it somewhere
+# on the way. You can make Rails rescue errors and render error pages on a
+# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
+#
+# If you set this to true, Rails will rescue all errors and render error
+# pages, more or less in the same way your application would behave in the
+# default production environment. It's not recommended to do this for all
+# of your scenarios, as this makes it hard to discover errors in your application.
+ActionController::Base.allow_rescue = false
+
+# If you set this to true, each scenario will run in a database transaction.
+# You can still turn off transactions on a per-scenario basis, simply tagging
+# a feature or scenario with the @no-txn tag. If you are using Capybara,
+# tagging with @culerity or @javascript will also turn transactions off.
+#
+# If you set this to false, transactions will be off for all scenarios,
+# regardless of whether you use @no-txn or not.
+#
+# Beware that turning transactions off will leave data in your database
+# after each scenario, which can lead to hard-to-debug failures in
+# subsequent scenarios. If you do this, we recommend you create a Before
+# block that will explicitly put your database in a known state.
+Cucumber::Rails::World.use_transactional_fixtures = true
+
+# How to clean your database when transactions are turned off. See
+# http://github.com/bmabey/database_cleaner for more info.
+require 'database_cleaner'
+DatabaseCleaner.strategy = :truncation
+
diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb
new file mode 100644
index 0000000..c575c07
--- /dev/null
+++ b/src/features/support/paths.rb
@@ -0,0 +1,27 @@
+module NavigationHelpers
+ # Maps a name to a path. Used by the
+ #
+ # When /^I go to (.+)$/ do |page_name|
+ #
+ # step definition in web_steps.rb
+ #
+ def path_to(page_name)
+ case page_name
+
+ when /the home\s?page/
+ '/'
+
+ # Add more mappings here.
+ # Here is an example that pulls values out of the Regexp:
+ #
+ # when /^(.*)'s profile page$/i
+ # user_profile_path(User.find_by_login($1))
+
+ else
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+end
+
+World(NavigationHelpers)
diff --git a/src/lib/tasks/cucumber.rake b/src/lib/tasks/cucumber.rake
new file mode 100644
index 0000000..ab04dc8
--- /dev/null
+++ b/src/lib/tasks/cucumber.rake
@@ -0,0 +1,47 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+
+unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
+
+vendored_cucumber_bin = Dir["#{RAILS_ROOT}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
+
+begin
+ require 'cucumber/rake/task'
+
+ namespace :cucumber do
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'default'
+ end
+
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'wip'
+ end
+
+ desc 'Run all features'
+ task :all => [:ok, :wip]
+ end
+ desc 'Alias for cucumber:ok'
+ task :cucumber => 'cucumber:ok'
+
+ task :default => :cucumber
+
+ task :features => :cucumber do
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
+ end
+rescue LoadError
+ desc 'cucumber rake task not available (cucumber not installed)'
+ task :cucumber do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
+
+end
diff --git a/src/lib/tasks/rspec.rake b/src/lib/tasks/rspec.rake
new file mode 100644
index 0000000..dba3ffc
--- /dev/null
+++ b/src/lib/tasks/rspec.rake
@@ -0,0 +1,144 @@
+gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
+rspec_gem_dir = nil
+Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
+ rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
+end
+rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
+
+if rspec_gem_dir && (test ?d, rspec_plugin_dir)
+ raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
+end
+
+if rspec_gem_dir
+ $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
+elsif File.exist?(rspec_plugin_dir)
+ $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
+end
+
+# Don't load rspec if running "rake gems:*"
+unless ARGV.any? {|a| a =~ /^gems/}
+
+begin
+ require 'spec/rake/spectask'
+rescue MissingSourceFile
+ module Spec
+ module Rake
+ class SpecTask
+ def initialize(name)
+ task name do
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
+ require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment"))
+
+ # ... otherwise, do this:
+ raise <<-MSG
+
+#{"*" * 80}
+* You are trying to run an rspec rake task defined in
+* #{__FILE__},
+* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
+#{"*" * 80}
+MSG
+ end
+ end
+ end
+ end
+ end
+end
+
+Rake.application.instance_variable_get('@tasks').delete('default')
+
+spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
+task :noop do
+end
+
+task :default => :spec
+task :stats => "spec:statsetup"
+
+desc "Run all specs in spec directory (excluding plugin specs)"
+Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+namespace :spec do
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = lambda do
+ IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
+ end
+ end
+
+ desc "Print Specdoc for all specs (excluding plugin specs)"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ desc "Print Specdoc for all plugin examples"
+ Spec::Rake::SpecTask.new(:plugin_doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
+ end
+
+ [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
+ desc "Run the code examples in spec/#{sub}"
+ Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
+ end
+ end
+
+ desc "Run the code examples in vendor/plugins (except RSpec's own)"
+ Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
+ end
+
+ namespace :plugins do
+ desc "Runs the examples for rspec_on_rails"
+ Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
+ end
+ end
+
+ # Setup specs for stats
+ task :statsetup do
+ require 'code_statistics'
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
+ ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
+ ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
+ ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
+ ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
+ ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
+ ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
+ ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
+ ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
+ ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
+ end
+
+ namespace :db do
+ namespace :fixtures do
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
+ task :load => :environment do
+ ActiveRecord::Base.establish_connection(Rails.env)
+ base_dir = File.join(Rails.root, 'spec', 'fixtures')
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
+
+ require 'active_record/fixtures'
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
+ end
+ end
+ end
+ end
+end
+
+end
diff --git a/src/script/autospec b/src/script/autospec
new file mode 100755
index 0000000..837bbd7
--- /dev/null
+++ b/src/script/autospec
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
+ENV['RSPEC'] = 'true' # allows autotest to discover rspec
+ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
+system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
+ $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
diff --git a/src/script/cucumber b/src/script/cucumber
new file mode 100755
index 0000000..7fa5c92
--- /dev/null
+++ b/src/script/cucumber
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+if vendored_cucumber_bin
+ load File.expand_path(vendored_cucumber_bin)
+else
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
+ require 'cucumber'
+ load Cucumber::BINARY
+end
diff --git a/src/script/spec b/src/script/spec
new file mode 100755
index 0000000..46fdbe6
--- /dev/null
+++ b/src/script/spec
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
+else
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
+ ENV["RAILS_ENV"] ||= 'test'
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
+end
+require 'spec/autorun'
+exit ::Spec::Runner::CommandLine.run
diff --git a/src/spec/rcov.opts b/src/spec/rcov.opts
new file mode 100644
index 0000000..274ed51
--- /dev/null
+++ b/src/spec/rcov.opts
@@ -0,0 +1,2 @@
+--exclude "spec/*,gems/*"
+--rails
\ No newline at end of file
diff --git a/src/spec/spec.opts b/src/spec/spec.opts
new file mode 100644
index 0000000..391705b
--- /dev/null
+++ b/src/spec/spec.opts
@@ -0,0 +1,4 @@
+--colour
+--format progress
+--loadby mtime
+--reverse
diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb
new file mode 100644
index 0000000..1f72de0
--- /dev/null
+++ b/src/spec/spec_helper.rb
@@ -0,0 +1,54 @@
+# This file is copied to ~/spec when you run 'ruby script/generate rspec'
+# from the project root directory.
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
+require 'spec/autorun'
+require 'spec/rails'
+
+# Uncomment the next line to use webrat's matchers
+#require 'webrat/integrations/rspec-rails'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
+
+Spec::Runner.configure do |config|
+ # If you're not using ActiveRecord you should remove these
+ # lines, delete config/database.yml and disable :active_record
+ # in your config/boot.rb
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+
+ # == Fixtures
+ #
+ # You can declare fixtures for each example_group like this:
+ # describe "...." do
+ # fixtures :table_a, :table_b
+ #
+ # Alternatively, if you prefer to declare them only once, you can
+ # do so right here. Just uncomment the next line and replace the fixture
+ # names with your fixtures.
+ #
+ # config.global_fixtures = :table_a, :table_b
+ #
+ # If you declare global fixtures, be aware that they will be declared
+ # for all of your examples, even those that don't use them.
+ #
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
+ #
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+ #
+ # == Mock Framework
+ #
+ # RSpec uses its own mocking framework by default. If you prefer to
+ # use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ #
+ # == Notes
+ #
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
+end
--
1.6.6
14 years, 4 months
[PATCH 1/2] initial permission/privilege model for the portal.
by Scott Seago
This is still preliminary, as there are a few things missing:
1) no support for using these permissions in the controllers
2) no UI to manipulate permission records
3) The roles would ideally be loaded via a yml file rather than in the migration, since they are theoretically dynamic values -- changes over time would be allowed without changes to the underlying code.
4) Test fixtures defined for privileges, and roles. Fixtures for permissions will come after we have user and pool, etc fixtures. Those are also needed for permission test cases.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/base_portal_object.rb | 33 +++++
src/app/models/cloud_account.rb | 4 +
src/app/models/permission.rb | 43 +++++++
src/app/models/portal_pool.rb | 4 +
src/app/models/privilege.rb | 76 +++++++++++
src/app/models/provider.rb | 4 +
src/app/models/role.rb | 27 ++++
src/db/migrate/20091008153046_create_privileges.rb | 49 +++++++
src/db/migrate/20091008153058_create_roles.rb | 132 ++++++++++++++++++++
.../migrate/20091008153106_create_permissions.rb | 36 ++++++
.../20091019215838_create_base_portal_objects.rb | 14 ++
src/test/fixtures/base_portal_objects.yml | 9 ++
src/test/fixtures/permissions.yml | 7 +
src/test/fixtures/privileges.yml | 40 ++++++
src/test/fixtures/roles.yml | 47 +++++++
src/test/unit/base_portal_object_test.rb | 8 ++
src/test/unit/permission_test.rb | 8 ++
src/test/unit/privilege_test.rb | 8 ++
src/test/unit/role_test.rb | 8 ++
19 files changed, 557 insertions(+), 0 deletions(-)
create mode 100644 src/app/models/base_portal_object.rb
create mode 100644 src/app/models/permission.rb
create mode 100644 src/app/models/privilege.rb
create mode 100644 src/app/models/role.rb
create mode 100644 src/db/migrate/20091008153046_create_privileges.rb
create mode 100644 src/db/migrate/20091008153058_create_roles.rb
create mode 100644 src/db/migrate/20091008153106_create_permissions.rb
create mode 100644 src/db/migrate/20091019215838_create_base_portal_objects.rb
create mode 100644 src/test/fixtures/base_portal_objects.yml
create mode 100644 src/test/fixtures/permissions.yml
create mode 100644 src/test/fixtures/privileges.yml
create mode 100644 src/test/fixtures/roles.yml
create mode 100644 src/test/unit/base_portal_object_test.rb
create mode 100644 src/test/unit/permission_test.rb
create mode 100644 src/test/unit/privilege_test.rb
create mode 100644 src/test/unit/role_test.rb
diff --git a/src/app/models/base_portal_object.rb b/src/app/models/base_portal_object.rb
new file mode 100644
index 0000000..e96dd44
--- /dev/null
+++ b/src/app/models/base_portal_object.rb
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class BasePortalObject < ActiveRecord::Base
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ GENERAL_PERMISSION_SCOPE = "general_permission_scope"
+
+ def self.general_permission_scope
+ self.find_by_name(GENERAL_PERMISSION_SCOPE)
+ end
+end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index db213b0..afb4623 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -35,6 +35,10 @@ class CloudAccount < ActiveRecord::Base
validates_uniqueness_of :username, :scope => :provider_id
validates_presence_of :password
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def connect
begin
return DeltaCloud.new(username, password, provider.url)
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
new file mode 100644
index 0000000..7c2bd9c
--- /dev/null
+++ b/src/app/models/permission.rb
@@ -0,0 +1,43 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class Permission < ActiveRecord::Base
+ belongs_to :pool
+
+ belongs_to :role
+
+ validates_presence_of :pool_id
+ validates_presence_of :role_id
+
+ validates_presence_of :user_id
+ validates_uniqueness_of :user_id, :scope => [:permission_object_id,
+ :permission_object_type]
+
+ belongs_to :permission_object, :polymorphic => true
+ # type-specific associations
+ belongs_to :portal_pool, :class_name => "PortalPool",
+ :foreign_key => "permission_object_id"
+ belongs_to :provider, :class_name => "Provider",
+ :foreign_key => "permission_object_id"
+ belongs_to :cloud_account, :class_name => "CloudAccount",
+ :foreign_key => "permission_object_id"
+ belongs_to :base_portal_object, :class_name => "BasePortalObject",
+ :foreign_key => "permission_object_id"
+
+end
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
index 6c30a67..6f4084b 100644
--- a/src/app/models/portal_pool.rb
+++ b/src/app/models/portal_pool.rb
@@ -30,6 +30,10 @@ class PortalPool < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :scope => :cloud_account_id
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def populate_realms_and_images
client = cloud_account.connect
realms = client.realms
diff --git a/src/app/models/privilege.rb b/src/app/models/privilege.rb
new file mode 100644
index 0000000..06dd18e
--- /dev/null
+++ b/src/app/models/privilege.rb
@@ -0,0 +1,76 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class Privilege < ActiveRecord::Base
+ has_and_belongs_to_many :roles
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ #default privileges
+ PERM_SET = "set_perms" # can create/modify/delete permission
+ # records on this object
+ PERM_VIEW = "view_perms" # can view permission records on this
+ # object
+
+ # instance privileges normally checked at the pool level, although
+ # instance-specific overrides could be a future enhancement.
+ INSTANCE_MODIFY = "instance_modify" # can create, modify, delete, or
+ # control (start, stop, etc) instances
+ INSTANCE_CONTROL = "instance_control" # can control (start, stop, etc)
+ # instances
+ INSTANCE_VIEW = "instance_view" # can view instance metadata
+ # do we need a separate "connect" privilege?
+
+ # stats privileges normally checked at the pool level, although
+ # instance-specific overrides could be a future enhancement.
+ STATS_VIEW = "stats_view" # can view monitoring data for
+ # instances
+
+ # account privileges normally checked at the provider level, although
+ # account-specific overrides could be a future enhancement.
+ ACCOUNT_MODIFY = "account_modify" # can create or modify cloud accounts
+ ACCOUNT_VIEW = "account_view" # can create or modify cloud accounts
+
+ # pool privileges normally checked at the provider level
+ # (and at the account level for choosing which accounts are visible on the
+ # new pool form), although
+ # pool-specific overrides could be a future enhancement.
+ POOL_MODIFY = "pool_modify" # can create or modify a pool
+ POOL_VIEW = "pool_view" # can view a pool
+
+ # quota privileges normally checked at the pool or account level,
+ # depending on which quota level we're dealing with
+ # (account level for cloud-imposed quota, pool level for portal quota)
+ QUOTA_MODIFY = "quota_modify" # can create or modify a quota
+ QUOTA_VIEW = "quota_view" # can view a quota
+
+ # provider privileges normally checked at the provider level, although
+ # 'new provider' action requires this privilege at the SystemPermission level
+ PROVIDER_MODIFY = "provider_modify" # can create or modify a provider
+ PROVIDER_VIEW = "provider_view" # can view a provider
+
+ # normally checked at the SystemPermission level
+ USER_MODIFY = "user_modify" # can create a new user (other than
+ # self-registration) or modify another
+ # user's metadata (for admin-level
+ # actions)
+ USER_VIEW = "user_view" # can view a user's profile data
+
+end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index b7a071a..dab9fee 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -34,6 +34,10 @@ class Provider < ActiveRecord::Base
validates_presence_of :cloud_type
validates_presence_of :url
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
def connect
begin
return DeltaCloud.new(nil, nil, url)
diff --git a/src/app/models/role.rb b/src/app/models/role.rb
new file mode 100644
index 0000000..db4a9ac
--- /dev/null
+++ b/src/app/models/role.rb
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class Role < ActiveRecord::Base
+ has_many :permissions
+ has_and_belongs_to_many :privileges, :uniq => true
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+end
diff --git a/src/db/migrate/20091008153046_create_privileges.rb b/src/db/migrate/20091008153046_create_privileges.rb
new file mode 100644
index 0000000..74932b0
--- /dev/null
+++ b/src/db/migrate/20091008153046_create_privileges.rb
@@ -0,0 +1,49 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class CreatePrivileges < ActiveRecord::Migration
+ def self.up
+ create_table :privileges do |t|
+ t.string :name, :null => false
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+
+ #create default privileges
+ privileges = ["set_perms", "view_perms",
+ "instance_modify", "instance_control", "instance_view",
+ "stats_view",
+ "account_modify", "account_view",
+ "pool_modify", "pool_view",
+ "quota_modify", "quota_view",
+ "provider_modify", "provider_view",
+ "user_modify", "user_view"]
+ Privilege.transaction do
+ privileges.each do |priv_name|
+ privilege = Privilege.new({:name => priv_name})
+ privilege.save!
+ end
+ end
+ end
+
+ def self.down
+ drop_table :privileges
+ end
+end
diff --git a/src/db/migrate/20091008153058_create_roles.rb b/src/db/migrate/20091008153058_create_roles.rb
new file mode 100644
index 0000000..44c360d
--- /dev/null
+++ b/src/db/migrate/20091008153058_create_roles.rb
@@ -0,0 +1,132 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class CreateRoles < ActiveRecord::Migration
+ def self.up
+ create_table :roles do |t|
+ t.string :name, :null => false
+ t.string :scope, :null => false
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+ create_table :privileges_roles, :id => false do |t|
+ t.integer :privilege_id, :null => false
+ t.integer :role_id, :null => false
+ end
+
+ #create default roles
+ roles = {"Instance Controller" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view"]},
+ "Instance Controller With Monitoring" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view"]},
+ "Instance Creator and User" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view",
+ "instance_modify",
+ "quota_view",
+ "set_perms",
+ "view_perms"]},
+ "Self-service Pool User" =>
+ {:role_scope => "PortalPool",
+ :privileges => ["instance_control",
+ "instance_view",
+ "pool_view",
+ "stats_view",
+ "instance_modify",
+ "quota_view",
+ "set_perms",
+ "view_perms",
+ "account_modify"]},
+ "Pool Creator" =>
+ {:role_scope => "Provider",
+ :privileges => ["provider_view",
+ "pool_modify",
+ "pool_view",
+ "quota_view"]},
+ "Pool Administrator" =>
+ {:role_scope => "Provider",
+ :privileges => ["provider_view",
+ "pool_modify",
+ "pool_view",
+ "quota_view",
+ "quota_modify",
+ "account_view",
+ "account_modify",
+ "set_perms",
+ "view_perms"]},
+ "Account Administrator" =>
+ {:role_scope => "CloudAccount",
+ :privileges => ["set_perms",
+ "view_perms",
+ "account_view",
+ "account_modify"]},
+ "Account User" =>
+ {:role_scope => "CloudAccount",
+ :privileges => ["account_view"]},
+ "Provider Administrator" =>
+ {:role_scope => "BasePortalObject",
+ :privileges => ["provider_modify",
+ "provider_view"]},
+ "Administrator" =>
+ {:role_scope => "BasePortalObject",
+ :privileges => ["provider_modify",
+ "provider_view",
+ "account_modify",
+ "account_view",
+ "user_modify",
+ "user_view",
+ "set_perms",
+ "view_perms",
+ "pool_modify",
+ "pool_view",
+ "quota_modify",
+ "quota_view",
+ "stats_view",
+ "instance_modify",
+ "instance_control",
+ "instance_view"]}
+
+ }
+ Role.transaction do
+ roles.each do |role_name, role_hash|
+ role = Role.new({:name => role_name, :scope => role_hash[:role_scope]})
+ role.save!
+ role.privileges = role_hash[:privileges].collect do |priv_name|
+ Privilege.find_by_name(priv_name)
+ end
+ role.save!
+ end
+ end
+ end
+
+ def self.down
+ drop_table :roles
+ end
+end
diff --git a/src/db/migrate/20091008153106_create_permissions.rb b/src/db/migrate/20091008153106_create_permissions.rb
new file mode 100644
index 0000000..a5f41bd
--- /dev/null
+++ b/src/db/migrate/20091008153106_create_permissions.rb
@@ -0,0 +1,36 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class CreatePermissions < ActiveRecord::Migration
+ def self.up
+ create_table :permissions do |t|
+ t.integer :role_id, :null => false
+ t.integer :user_id, :null => false
+ t.integer :permission_object_id
+ t.string :permission_object_type
+ t.integer :lock_version, :default => 0
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :permissions
+ end
+end
diff --git a/src/db/migrate/20091019215838_create_base_portal_objects.rb b/src/db/migrate/20091019215838_create_base_portal_objects.rb
new file mode 100644
index 0000000..badea5d
--- /dev/null
+++ b/src/db/migrate/20091019215838_create_base_portal_objects.rb
@@ -0,0 +1,14 @@
+class CreateBasePortalObjects < ActiveRecord::Migration
+ def self.up
+ create_table :base_portal_objects do |t|
+ t.string :name, :null => false
+ t.timestamps
+ end
+
+ BasePortalObject.new({:name => "general_permission_scope"}).save!
+ end
+
+ def self.down
+ drop_table :base_portal_objects
+ end
+end
diff --git a/src/test/fixtures/base_portal_objects.yml b/src/test/fixtures/base_portal_objects.yml
new file mode 100644
index 0000000..7e9b357
--- /dev/null
+++ b/src/test/fixtures/base_portal_objects.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+base_portal_object:
+ name: general_permission_scope
\ No newline at end of file
diff --git a/src/test/fixtures/permissions.yml b/src/test/fixtures/permissions.yml
new file mode 100644
index 0000000..5bf0293
--- /dev/null
+++ b/src/test/fixtures/permissions.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/src/test/fixtures/privileges.yml b/src/test/fixtures/privileges.yml
new file mode 100644
index 0000000..6ccb16b
--- /dev/null
+++ b/src/test/fixtures/privileges.yml
@@ -0,0 +1,40 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+set_perms:
+ name: set_perms
+view_perms:
+ name: view_perms
+instance_modify:
+ name: instance_modify
+instance_control:
+ name: instance_control
+instance_view:
+ name: instance_view
+stats_view:
+ name: stats_view
+account_modify:
+ name: account_modify
+account_view:
+ name: account_view
+pool_modify:
+ name: pool_modify
+pool_view:
+ name: pool_view
+quota_modify:
+ name: quota_modify
+quota_view:
+ name: quota_view
+provider_modify:
+ name: provider_modify
+provider_view:
+ name: provider_view
+user_modify:
+ name: user_modify
+user_view:
+ name: user_view
+
diff --git a/src/test/fixtures/roles.yml b/src/test/fixtures/roles.yml
new file mode 100644
index 0000000..2ac7e5f
--- /dev/null
+++ b/src/test/fixtures/roles.yml
@@ -0,0 +1,47 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+instance_controller:
+ name: Instance Controller
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view
+instance_controller_with_monitoring:
+ name: Instance Controller With Monitoring
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view, stats_view
+instance_creator_and_user:
+ name: Instance Creator and User
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms
+self_service_pool_user:
+ name: Self-service Pool User
+ scope: PortalPool
+ privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms, account_modify
+pool_creator:
+ name: Pool Creator
+ scope: Provider
+ privileges: provider_view, pool_modify, pool_view, quota_view
+pool_administrator:
+ name: Pool Administrator
+ scope: Provider
+ privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, account_modify, account_view, stats_view, set_perms, view_perms
+account_administrator:
+ name: Account Administrator
+ scope: CloudAccount
+ privileges: account_modify, account_view, stats_view, set_perms, view_perms
+account_user:
+ name: Account User
+ scope: CloudAccount
+ privileges: account_view
+provider_administrator:
+ name: Provider Administrator
+ scope: BasePortalObject
+ privileges: provider_modify, provider_view, stats_view
+site_administrator:
+ name: Site Administrator
+ scope: BasePortalObject
+ privileges: provider_modify, provider_view, account_modify, account_view, user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, quota_modify, quota_view, stats_view, instance_modify, instance_control, instance_view
diff --git a/src/test/unit/base_portal_object_test.rb b/src/test/unit/base_portal_object_test.rb
new file mode 100644
index 0000000..e6e4b9d
--- /dev/null
+++ b/src/test/unit/base_portal_object_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class BasePortalObjectTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/permission_test.rb b/src/test/unit/permission_test.rb
new file mode 100644
index 0000000..08fcc0b
--- /dev/null
+++ b/src/test/unit/permission_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PermissionTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/privilege_test.rb b/src/test/unit/privilege_test.rb
new file mode 100644
index 0000000..459d805
--- /dev/null
+++ b/src/test/unit/privilege_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class PrivilegeTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/role_test.rb b/src/test/unit/role_test.rb
new file mode 100644
index 0000000..b0374ce
--- /dev/null
+++ b/src/test/unit/role_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class RoleTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
--
1.6.2.5
14 years, 4 months
[PATCH portal] Use deltacloud-client gem instead of plugin.
by jason.guiditta
---
src/config/environment.rb | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/config/environment.rb b/src/config/environment.rb
index d3d2e2f..4277fe7 100644
--- a/src/config/environment.rb
+++ b/src/config/environment.rb
@@ -43,6 +43,7 @@ Rails::Initializer.run do |config|
config.gem "gettext", :lib => "gettext_rails"
config.gem "gettext", :lib => "gettext_activerecord"
config.gem "authlogic"
+ config.gem "deltacloud-client", :lib => "deltacloud"
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
--
1.6.6
14 years, 4 months
Updated version of gemspec patch
by jason.guiditta
This version adds dependency on rest-client so gem will work
in rails with lutter's patchset. To test:
gem build deltacloud-client.gemspec
sudo gem install deltacloud-client-0.0.2.gem
This should install the rest-client dep for you.
14 years, 4 months
[PATCH core] OpenNebula driver, changing Crack to REXML
by Daniel Molina Aranda
Hi,
This is the patch that David ask for, a couple of weeks ago. The main change
is the way we map xml in the OpenNebula driver, changing Crack to REXML. We
have also deleted some methods from the OCCI client that are not necessary
for the deltacloud driver.
Sorry for the late patch. If you have any problem or if you want us to
change anything else, just let us know.
Regards.
--
Daniel Molina, Cloud Technology Engineer/Researcher
DSA Research Group: web http://dsa-research.org and blog
http://blog.dsa-research.org
OpenNebula Open Source Toolkit for Cloud Computing:
http://www.OpenNebula.org
14 years, 4 months
patch format suggestion
by Jason Guiditta
I would like to suggest that for all patches, we update the subject
format to specify with repo the patch applies to, which I think would
make it easier for people testing to know right off what they might be
testing. If no one disagrees, all developer need to do is add the
following to their .git/config file in each repo:
[format]
subjectprefix = PATCH <repo-name-here>
-j
14 years, 4 months
[PATCH core 1/3] Remove trailing whitespace. No functional change.
by David Lutterkort
From: David Lutterkort <lutter(a)redhat.com>
---
client/lib/dcloud/base_model.rb | 6 ++--
client/lib/dcloud/image.rb | 2 +-
client/lib/dcloud/instance.rb | 2 +-
client/lib/dcloud/storage_snapshot.rb | 2 +-
client/lib/dcloud/storage_volume.rb | 2 +-
client/lib/deltacloud.rb | 20 +++++++++---------
client/specs/flavors_spec.rb | 2 +-
client/specs/images_spec.rb | 2 +-
client/specs/initialization_spec.rb | 2 +-
client/specs/instance_states_spec.rb | 2 +-
client/specs/instances_spec.rb | 2 +-
client/specs/realms_spec.rb | 2 +-
.../app/controllers/application_controller.rb | 2 +-
.../libexec/app/controllers/images_controller.rb | 10 ++++----
server/libexec/config/initializers/inflections.rb | 2 +-
.../libexec/config/initializers/session_store.rb | 2 +-
server/libexec/lib/converters/xml_converter.rb | 2 +-
.../lib/deltacloud/drivers/mock/mock_driver.rb | 4 +-
.../deltacloud/drivers/opennebula/cloud_client.rb | 22 ++++++++++----------
.../drivers/rackspace/rackspace_client.rb | 12 +++++-----
.../lib/deltacloud/drivers/rhevm/rhevm_driver.rb | 2 +-
server/libexec/lib/deltacloud/state_machine.rb | 8 +++---
22 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/client/lib/dcloud/base_model.rb b/client/lib/dcloud/base_model.rb
index 8c83fbf..0f210a4 100644
--- a/client/lib/dcloud/base_model.rb
+++ b/client/lib/dcloud/base_model.rb
@@ -20,7 +20,7 @@ module DCloud
class BaseModel
def self.xml_tag_name(name=nil)
- unless ( name.nil? )
+ unless ( name.nil? )
@xml_tag_name = name
end
@xml_tag_name || self.class.name.downcase.to_sym
@@ -54,7 +54,7 @@ module DCloud
@id
end
-
+
protected
attr_reader :client
@@ -68,7 +68,7 @@ module DCloud
def load_payload(xml=nil)
unless ( xml.nil? )
@loaded = true
- @id = xml.text( 'id' )
+ @id = xml.text( 'id' )
end
end
diff --git a/client/lib/dcloud/image.rb b/client/lib/dcloud/image.rb
index cba7fc7..220de21 100644
--- a/client/lib/dcloud/image.rb
+++ b/client/lib/dcloud/image.rb
@@ -37,7 +37,7 @@ module DCloud
unless xml.nil?
@description = xml.text( 'description' )
@owner_id = xml.text( 'owner_id' )
- @name = xml.text( 'name' )
+ @name = xml.text( 'name' )
@architecture = xml.text( 'architecture' )
end
end
diff --git a/client/lib/dcloud/instance.rb b/client/lib/dcloud/instance.rb
index e14dd50..9115e9a 100644
--- a/client/lib/dcloud/instance.rb
+++ b/client/lib/dcloud/instance.rb
@@ -77,7 +77,7 @@ module DCloud
@image = Image.new( @client, image_uri )
flavor_uri = xml.get_elements( 'flavor' )[0].attributes['href']
@flavor = Flavor.new( @client, flavor_uri )
- # Only use realms if they are there
+ # Only use realms if they are there
if (!xml.get_elements( 'realm' ).empty?)
realm_uri = xml.get_elements( 'realm' )[0].attributes['href']
@realm = Realm.new( @client, realm_uri )
diff --git a/client/lib/dcloud/storage_snapshot.rb b/client/lib/dcloud/storage_snapshot.rb
index 9276fb8..ae60771 100644
--- a/client/lib/dcloud/storage_snapshot.rb
+++ b/client/lib/dcloud/storage_snapshot.rb
@@ -40,7 +40,7 @@ module DCloud
if ( ! storage_volumes.empty? )
storage_volume = storage_volumes.first
storage_volume_href = storage_volume.attributes['href']
- if ( storage_volume_href )
+ if ( storage_volume_href )
@storage_volume = StorageVolume.new( @client, storage_volume_href )
end
end
diff --git a/client/lib/dcloud/storage_volume.rb b/client/lib/dcloud/storage_volume.rb
index aec2f57..bdb2e3b 100644
--- a/client/lib/dcloud/storage_volume.rb
+++ b/client/lib/dcloud/storage_volume.rb
@@ -43,7 +43,7 @@ module DCloud
if ( ! instances.empty? )
instance = instances.first
instance_href = instance.attributes['href']
- if ( instance_href )
+ if ( instance_href )
@instance = Instance.new( @client, instance_href )
end
end
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index bae8ff0..5324c79 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -44,12 +44,12 @@ class DeltaCloud
attr_reader :driver_name
def initialize(name, password, api_uri, &block)
- @logger = Logger.new( STDERR )
+ @logger = Logger.new( STDERR )
@name = name
@password = password
@api_uri = URI.parse( api_uri )
@entry_points = {}
- connect( &block )
+ connect( &block )
self
end
@@ -71,7 +71,7 @@ class DeltaCloud
end
end
end
- flavors
+ flavors
end
def flavor(id)
@@ -101,7 +101,7 @@ class DeltaCloud
doc.get_elements( 'states/state' ).each do |state_elem|
state = DCloud::State.new( state_elem.attributes['name'] )
state_elem.get_elements( 'transition' ).each do |transition_elem|
- state.transitions << DCloud::Transition.new(
+ state.transitions << DCloud::Transition.new(
transition_elem.attributes['to'],
transition_elem.attributes['action']
)
@@ -245,7 +245,7 @@ class DeltaCloud
uri = instance.attributes['href']
return DCloud::Instance.new( self, uri, instance )
end
- end
+ end
end
def storage_volumes()
@@ -276,7 +276,7 @@ class DeltaCloud
end
def fetch_storage_volume(uri)
- xml = fetch_resource( :storage_volume, uri )
+ xml = fetch_resource( :storage_volume, uri )
return DCloud::StorageVolume.new( self, uri, xml ) if xml
nil
end
@@ -309,7 +309,7 @@ class DeltaCloud
end
def fetch_storage_snapshot(uri)
- xml = fetch_resource( :storage_snapshot, uri )
+ xml = fetch_resource( :storage_snapshot, uri )
return DCloud::StorageSnapshot.new( self, uri, xml ) if xml
nil
end
@@ -324,7 +324,7 @@ class DeltaCloud
if ( response.is_a?( Net::HTTPSuccess ) )
doc = REXML::Document.new( response.body )
if ( doc.root && ( doc.root.name == type.to_s.gsub( /_/, '-' ) ) )
- return doc.root
+ return doc.root
end
end
end
@@ -374,7 +374,7 @@ class DeltaCloud
end
def request(path='', method=:get, query_args={}, form_data={}, &block)
- if ( path =~ /^http/ )
+ if ( path =~ /^http/ )
request_path = path
else
request_path = "#{api_path}#{path}"
@@ -383,7 +383,7 @@ class DeltaCloud
if ( query_string != '' )
request_path += "?#{query_string}"
end
-
+
logger << "Request [#{method.to_s.upcase} #{request_path}]\n"
request = eval( "Net::HTTP::#{method.to_s.capitalize}" ).new( request_path )
request.basic_auth( @name, @password )
diff --git a/client/specs/flavors_spec.rb b/client/specs/flavors_spec.rb
index 740d7ac..91a063e 100644
--- a/client/specs/flavors_spec.rb
+++ b/client/specs/flavors_spec.rb
@@ -37,7 +37,7 @@ describe "flavors" do
flavor.memory.should be_a(Float)
end
end
- end
+ end
it "should allow filtering of flavors by architecture" do
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
diff --git a/client/specs/images_spec.rb b/client/specs/images_spec.rb
index 5f508db..704c2ae 100644
--- a/client/specs/images_spec.rb
+++ b/client/specs/images_spec.rb
@@ -38,7 +38,7 @@ describe "images" do
image.owner_id.should be_a(String)
end
end
- end
+ end
it "should allow retrieval of my own images" do
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
diff --git a/client/specs/initialization_spec.rb b/client/specs/initialization_spec.rb
index 47449dd..386eb9e 100644
--- a/client/specs/initialization_spec.rb
+++ b/client/specs/initialization_spec.rb
@@ -33,7 +33,7 @@ describe "initializing the client" do
client.entry_points[:instances].should eql( "#{API_URL}/instances" )
client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage/volumes" )
client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage/snapshots" )
- end
+ end
end
it "should provide the current driver name via client" do
diff --git a/client/specs/instance_states_spec.rb b/client/specs/instance_states_spec.rb
index a80d546..667baf6 100644
--- a/client/specs/instance_states_spec.rb
+++ b/client/specs/instance_states_spec.rb
@@ -50,7 +50,7 @@ describe "instance-states" do
includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true
includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true
end
- end
+ end
it "should allow retrieval of a single instance-state blob" do
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
diff --git a/client/specs/instances_spec.rb b/client/specs/instances_spec.rb
index a7d9fdb..b088f74 100644
--- a/client/specs/instances_spec.rb
+++ b/client/specs/instances_spec.rb
@@ -45,7 +45,7 @@ describe "instances" do
instance.private_addresses.should be_a( Array )
end
end
- end
+ end
it "should allow navigation from instance to image" do
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
diff --git a/client/specs/realms_spec.rb b/client/specs/realms_spec.rb
index 8b08649..6f5199f 100644
--- a/client/specs/realms_spec.rb
+++ b/client/specs/realms_spec.rb
@@ -34,7 +34,7 @@ describe "realms" do
realm.name.should be_a(String)
end
end
- end
+ end
it "should allow fetching a realm by id" do
diff --git a/server/libexec/app/controllers/application_controller.rb b/server/libexec/app/controllers/application_controller.rb
index 76641b6..618a833 100644
--- a/server/libexec/app/controllers/application_controller.rb
+++ b/server/libexec/app/controllers/application_controller.rb
@@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base
# filter_parameter_logging :password
- protected
+ protected
def credentials
creds = {}
diff --git a/server/libexec/app/controllers/images_controller.rb b/server/libexec/app/controllers/images_controller.rb
index 382b138..92fe73f 100644
--- a/server/libexec/app/controllers/images_controller.rb
+++ b/server/libexec/app/controllers/images_controller.rb
@@ -29,10 +29,10 @@ class ImagesController < ApplicationController
@images = driver.images( credentials, @filter )
respond_to do |format|
- format.html
+ format.html
format.json
- format.xml {
- render :xml=>convert_to_xml( :image, @images )
+ format.xml {
+ render :xml=>convert_to_xml( :image, @images )
}
end
end
@@ -43,8 +43,8 @@ class ImagesController < ApplicationController
respond_to do |format|
format.html
format.json
- format.xml {
- render :xml=>convert_to_xml( :image, @image )
+ format.xml {
+ render :xml=>convert_to_xml( :image, @image )
}
end
end
diff --git a/server/libexec/config/initializers/inflections.rb b/server/libexec/config/initializers/inflections.rb
index d531b8b..9e8b013 100644
--- a/server/libexec/config/initializers/inflections.rb
+++ b/server/libexec/config/initializers/inflections.rb
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.
-# Add new inflection rules using the following format
+# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
diff --git a/server/libexec/config/initializers/session_store.rb b/server/libexec/config/initializers/session_store.rb
index bdc56be..9450644 100644
--- a/server/libexec/config/initializers/session_store.rb
+++ b/server/libexec/config/initializers/session_store.rb
@@ -2,7 +2,7 @@
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
-# Make sure the secret is at least 30 characters and all random,
+# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
ActionController::Base.session = {
:key => '_deltacloud-framework_session',
diff --git a/server/libexec/lib/converters/xml_converter.rb b/server/libexec/lib/converters/xml_converter.rb
index a353b75..0b11fd7 100644
--- a/server/libexec/lib/converters/xml_converter.rb
+++ b/server/libexec/lib/converters/xml_converter.rb
@@ -82,7 +82,7 @@ module Converters
builder.owner_id( obj.owner_id )
builder.image( :href=>@link_builder.send( :image_url, obj.image_id ) )
builder.flavor( :href=>@link_builder.send( :flavor_url, obj.flavor_id ) )
- builder.realm( :href=>@link_builder.send( :realm_url, obj.realm_id ) ) if obj.realm_id
+ builder.realm( :href=>@link_builder.send( :realm_url, obj.realm_id ) ) if obj.realm_id
builder.state( obj.state )
builder.actions {
if ( obj.actions )
diff --git a/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb b/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
index 61f180a..73cdcc4 100644
--- a/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -192,7 +192,7 @@ class MockDriver < Deltacloud::BaseDriver
instance_yml = YAML.load( File.read( instance_file ) )
instance_yml[:state] = 'RUNNING'
File.open( instance_file, 'w' ) do |f|
- f << YAML.dump( instance_yml )
+ f << YAML.dump( instance_yml )
end
Instance.new( instance_yml )
end
@@ -202,7 +202,7 @@ class MockDriver < Deltacloud::BaseDriver
instance_yml = YAML.load( File.read( instance_file ) )
instance_yml[:state] = 'RUNNING'
File.open( instance_file, 'w' ) do |f|
- f << YAML.dump( instance_yml )
+ f << YAML.dump( instance_yml )
end
Instance.new( instance_yml )
end
diff --git a/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb b/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb
index 10b34d5..19f989d 100644
--- a/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb
+++ b/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb
@@ -35,7 +35,7 @@ rescue LoadError
end
###############################################################################
-# The CloudClient module contains general functionality to implement a
+# The CloudClient module contains general functionality to implement a
# Cloud Client
###############################################################################
module CloudClient
@@ -43,7 +43,7 @@ module CloudClient
# Default location for the authentication file
# #########################################################################
DEFAULT_AUTH_FILE = ENV["HOME"]+"/.one/one_auth"
-
+
# #########################################################################
# Gets authorization credentials from ONE_AUTH or default
# auth file.
@@ -51,7 +51,7 @@ module CloudClient
# Raises an error if authorization is not found
# #########################################################################
def self.get_one_auth
- if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
+ if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
File.file?(ENV["ONE_AUTH"])
one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':')
elsif File.file?(DEFAULT_AUTH_FILE)
@@ -59,12 +59,12 @@ module CloudClient
else
raise "No authorization data present"
end
-
+
raise "Authorization data malformed" if one_auth.length < 2
-
+
one_auth
end
-
+
# #########################################################################
# Starts an http connection and calls the block provided. SSL flag
# is set if needed.
@@ -75,7 +75,7 @@ module CloudClient
http.use_ssl = true
http.verify_mode=OpenSSL::SSL::VERIFY_NONE
end
-
+
begin
http.start do |connection|
block.call(connection)
@@ -83,7 +83,7 @@ module CloudClient
rescue Errno::ECONNREFUSED => e
str = "Error connecting to server (#{e.to_s})."
str << "Server: #{url.host}:#{url.port}"
-
+
return CloudClient::Error.new(str)
end
end
@@ -94,7 +94,7 @@ module CloudClient
# #########################################################################
class Error
attr_reader :message
-
+
# +message+ a description of the error
def initialize(message=nil)
@message=message
@@ -105,7 +105,7 @@ module CloudClient
end
end
- # #########################################################################
+ # #########################################################################
# Returns true if the object returned by a method of the OpenNebula
# library is an Error
# #########################################################################
@@ -113,7 +113,7 @@ module CloudClient
value.class==CloudClient::Error
end
end
-
+
# Command line help functions
module CloudCLI
# Returns the command name
diff --git a/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb b/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb
index 09b71c6..d01d8d3 100644
--- a/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb
+++ b/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb
@@ -31,7 +31,7 @@ module Deltacloud
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
@@ -42,7 +42,7 @@ class RackspaceClient
@service.use_ssl = true
end
- def get(path)
+ def get(path)
@service.get((a)service_uri.path + path, {"Accept" => "application/json", "X-Auth-Token" => @auth_token}).body
end
@@ -50,16 +50,16 @@ class RackspaceClient
JSON.parse(get('/flavors/detail'))['flavors']
end
- def list_images
+ def list_images
JSON.parse(get('/images/detail'))['images']
end
- def list_servers
+ def list_servers
JSON.parse(get('/servers/detail'))['servers']
end
- def load_server_details( server_id )
+ def load_server_details( server_id )
JSON.parse(get("/servers/#{server_id}"))['server']
end
@@ -79,7 +79,7 @@ class RackspaceClient
end
- def headers
+ def headers
{"Accept" => "application/json", "X-Auth-Token" => @auth_token, "Content-Type" => "application/json"}
end
diff --git a/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index eaf008a..d026852 100644
--- a/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -162,7 +162,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
#
# Instances
#
-
+
define_instance_states do
start.to(:stopped) .on( :create )
diff --git a/server/libexec/lib/deltacloud/state_machine.rb b/server/libexec/lib/deltacloud/state_machine.rb
index f624f09..9c4f7ba 100644
--- a/server/libexec/lib/deltacloud/state_machine.rb
+++ b/server/libexec/lib/deltacloud/state_machine.rb
@@ -27,7 +27,7 @@ module Deltacloud
def method_missing(sym,*args)
return state( sym ) if ( args.empty? )
- super( sym, *args )
+ super( sym, *args )
end
class State
@@ -40,13 +40,13 @@ module Deltacloud
@name = name
@transitions = []
end
-
+
def to_s
self.name.to_s
end
def to(destination_name)
- destination = @machine.state(destination_name)
+ destination = @machine.state(destination_name)
transition = Transition.new( @machine, destination )
@transitions << transition
transition
@@ -77,7 +77,7 @@ module Deltacloud
def on(action)
@action = action
end
-
+
end
end
--
1.6.6
14 years, 4 months
[PATCH] Deltacloud command line client
by Michal Fojtik
Hi,
I created a simple command-line client for Deltacloud API.
For basic usage, you just need to export a API_URL variable (format is
described in '--help).
This client is tested against Sinatra version of API. You will need Nokogiri gem
for parsing XMLs (gem install nokogiri || yum install rubygems-nokogiri).
---
client/bin/deltacloudc | 160 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 160 insertions(+), 0 deletions(-)
create mode 100755 client/bin/deltacloudc
diff --git a/client/bin/deltacloudc b/client/bin/deltacloudc
new file mode 100755
index 0000000..8ce9d9b
--- /dev/null
+++ b/client/bin/deltacloudc
@@ -0,0 +1,160 @@
+#!/bin/env ruby
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+require 'rubygems'
+require 'rest_client'
+require 'optparse'
+require 'nokogiri'
+require 'uri'
+
+options = {
+ :format => :plain
+}
+
+@optparse = OptionParser.new do|opts|
+
+opts.banner = <<BANNER
+Usage:
+deltacloudc collection operation [options]
+
+URL format:
+API_URL=http://[user]:[password]@[api_url][port][/uri]
+
+Options:
+BANNER
+ opts.on( '-i', '--id ID', 'ID for operation') { |id| options[:id] = id }
+ opts.on( nil, '--image-id ID', 'Image ID') { |id| options[:image_id] = id }
+ opts.on( nil, '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id }
+ opts.on( nil, '--flavor_id FLAVOR', 'Flavor') { |id| options[:flavor_id] = id }
+ opts.on( '-l', '--list', 'List collections/operations') { |id| options[:list] = true }
+ opts.on( '-u', '--url', 'API url ($API_URL variable)') { |url| options[:api_url] = url }
+ opts.on( nil, '--xml', 'XML output') { |format| options[:format] = :xml }
+ opts.on( '-h', '--help', 'Display this screen' ) { puts opts ; exit }
+ opts.on( '-v', '--version', 'Display API version' ) { options[:version]=true }
+end
+
+def invalid_usage(error_msg='')
+ puts "ERROR: #{error_msg}"
+ exit(1)
+end
+
+def convert_to_plain(xml)
+ doc = Nokogiri::XML(xml)
+ doc.root.traverse do |elem|
+ yield "-----------------------" if elem.children.size>1
+ next unless elem.children.size.eql?(1)
+ if not elem.eql?(doc.root) and not elem.name.eql?('text')
+ yield "#{string_to_width(elem.name, 15)}: #{elem.content.strip}"
+ end
+ end
+ return nil
+end
+
+def string_to_width(string, width, options = {})
+ options.merge!(
+ :pad => ' ', :align => :left
+ )
+ new_string = ""
+ i = 0
+ string.each_char do |c|
+ break if i == width
+ new_string += c
+ i += 1
+ end
+ # add padding
+ if new_string.length < width
+ padding = (options[:pad] * (width - new_string.length))
+ new_string = options[:align] == :left ?
+ new_string + padding : padding + new_string
+ end
+ new_string
+end
+
+(a)optparse.parse!
+
+# First try to get API_URL from environment
+options[:api_url] = ENV['API_URL'] if options[:api_url].nil?
+options[:collection] = ARGV[0]
+options[:operation] = ARGV[1]
+
+invalid_usage("API_URL is not set") if options[:api_url].nil?
+
+options[:list]=true if options[:collection].nil? and options[:operation].nil?
+
+# Default response to XML
+params = { :accept => "application/xml" }
+
+operations = {}
+operations[:get] = [ 'index', 'show', 'new']
+operations[:post] = [ 'save', 'create' ]
+operations[:put] = [ 'update' ]
+operations[:delete] = [ 'delete' ]
+
+rest = RestClient::Resource.new( options[:api_url] , :accept => 'application/xml' )
+
+doc = Nokogiri::XML(rest.get(:accept => "application/xml"))
+version, driver = doc.xpath('/api/@version'), doc.xpath('/api/@driver')
+collections = doc.xpath('/api/link/@rel').collect { |rel| rel.to_s }
+
+if options[:version]
+ puts "API [#{version}] Driver: [#{driver}]"
+ exit
+end
+
+# List available collection for driver
+
+if options[:list] and not options[:collection]
+ puts "Available collections for driver #{driver} [#{version}]:\n\n"
+ collections.collect { |c| puts c }
+elsif options[:list] and options[:collection]
+ # TODO: Place here all available collection operations (through /api/docs)
+else
+ options[:params] = {}
+ options[:params]['image_id'] = options[:image_id] unless options[:image_id].nil?
+ options[:params]['architecture'] = options[:architecture] unless options[:architecture].nil?
+ options[:params]['flavor_id'] = options[:flavor_id] unless options[:flavor_id].nil?
+
+ options[:operation] = 'index' if options[:operation].nil?
+ # First guess HTTP method to use
+ method = operations.keys.select { |k| operations[k].include?(options[:operation]) }.first
+
+ invalid_usage("Unknown operation: #{options[:operation]} ") if method.nil?
+ invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection])
+
+ # 'show' and 'index' is not needed in URI
+ options[:operation] = nil if ['show', 'index'].include?(options[:operation])
+
+ # Resource means Rest URI ['/flavors', '/images/:id']
+ resource = [options[:collection], options[:operation], options[:id]].compact.join('/')
+
+ if method.eql?(:post)
+ puts rest[resource].send(method, params, options[:params])
+ else
+ resource += '?'+URI.escape(options[:params].collect{|k,v| "#{k}=#{v}"}.join('&')) if options[:params]
+ case options[:format]
+ when :xml
+ puts rest[resource].send(method, params)
+ when :plain
+ convert_to_plain(rest[resource].send(method, params)) do |line|
+ puts line
+ end
+ end
+ end
+
+end
+
--
1.6.4.4
--
- Michal
14 years, 4 months
[PATCH] Update gemspec, add license to gem.
by jason.guiditta
---
client/COPYING | 502 +++++++++++++++++++++++++++++++++
client/deltacloud-client-ruby.gemspec | 27 --
client/deltacloud-client.gemspec | 29 ++
3 files changed, 531 insertions(+), 27 deletions(-)
create mode 100644 client/COPYING
delete mode 100644 client/deltacloud-client-ruby.gemspec
create mode 100644 client/deltacloud-client.gemspec
diff --git a/client/COPYING b/client/COPYING
new file mode 100644
index 0000000..551cb4a
--- /dev/null
+++ b/client/COPYING
@@ -0,0 +1,502 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/client/deltacloud-client-ruby.gemspec b/client/deltacloud-client-ruby.gemspec
deleted file mode 100644
index 8e8f6df..0000000
--- a/client/deltacloud-client-ruby.gemspec
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Copyright (C) 2009 Red Hat, Inc.
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-Gem::Specification.new do |s|
- s.author = 'Red Hat, Inc.'
- s.homepage = "http://www.deltacloud.org"
- s.name = 'deltacloud-client-ruby'
- s.description = %q{Deltacloud REST Client}
- s.version = '0.0.1'
- s.summary = %q{Deltacloud Client}
- s.files = Dir['Rakefile', 'credentials.yml', 'lib/**/*.rb', 'init.rb' ]
- s.test_files= Dir.glob("specs/**/**")
-end
diff --git a/client/deltacloud-client.gemspec b/client/deltacloud-client.gemspec
new file mode 100644
index 0000000..4e4efbd
--- /dev/null
+++ b/client/deltacloud-client.gemspec
@@ -0,0 +1,29 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Gem::Specification.new do |s|
+ s.author = 'Red Hat, Inc.'
+ s.homepage = "http://www.deltacloud.org"
+ s.name = 'deltacloud-client'
+ s.description = %q{Deltacloud REST Client}
+ s.version = '0.0.2'
+ s.summary = %q{Deltacloud Client}
+ s.files = Dir['Rakefile', 'credentials.yml', 'lib/**/*.rb', 'init.rb']
+ s.test_files= Dir.glob("specs/**/**")
+ s.extra_rdoc_files = Dir["COPYING"]
+end
--
1.6.6
14 years, 4 months