[PATCH 1/3] BZ# 768507: aeolus-cli needs syntax to be more flexible
by Jason Guiditta
https://bugzilla.redhat.com/show_bug.cgi?id=768507
Refactor cli usage to always require a command.
---
bin/aeolus-cli | 4 +-
lib/aeolus_cli.rb | 1 +
lib/aeolus_cli/command/cli_parser.rb | 72 +++++++++++++++++++++++++++++++
lib/aeolus_cli/command/config_parser.rb | 6 +-
spec/command/cli_parser.rb | 50 +++++++++++++++++++++
spec/spec_helper.rb | 18 +-------
6 files changed, 129 insertions(+), 22 deletions(-)
create mode 100644 lib/aeolus_cli/command/cli_parser.rb
create mode 100644 spec/command/cli_parser.rb
diff --git a/bin/aeolus-cli b/bin/aeolus-cli
index f3af29b..9f9a1aa 100755
--- a/bin/aeolus-cli
+++ b/bin/aeolus-cli
@@ -16,5 +16,5 @@
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'aeolus_cli'
-parser = Aeolus::CLI::ConfigParser.new(ARGV)
-puts parser.process
+parser = Aeolus::CLI::CLIParser.new(ARGV)
+parser.process
diff --git a/lib/aeolus_cli.rb b/lib/aeolus_cli.rb
index a5a6bce..851d8da 100644
--- a/lib/aeolus_cli.rb
+++ b/lib/aeolus_cli.rb
@@ -22,6 +22,7 @@ require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'import_command'
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'delete_command')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'status_command')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'config_parser')
+require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'cli_parser')
require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'base')
require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'image')
diff --git a/lib/aeolus_cli/command/cli_parser.rb b/lib/aeolus_cli/command/cli_parser.rb
new file mode 100644
index 0000000..2aedef0
--- /dev/null
+++ b/lib/aeolus_cli/command/cli_parser.rb
@@ -0,0 +1,72 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'optparse'
+
+module Aeolus
+ module CLI
+ class CLIParser
+ COMMANDS = %w(image)
+ attr_accessor :options, :command, :args
+
+ def initialize(argv=[], out=STDOUT )
+ @args = argv
+ @out = out
+ @options = {}
+ end
+
+ def process
+ # Check for command, then call appropriate Optionparser and initiate
+ # call to that class.
+ @command = @args.shift
+ if COMMANDS.include?(@command)
+ parse() unless @args.include?('-h')
+ self.send((a)command.to_sym)
+ else
+ @args << "-h" unless @args.include?('-h')
+ parse()
+ end
+ end
+
+ private
+ def parse()
+ @optparse ||= OptionParser.new do|opts|
+ opts.banner = "Usage: aeolus-cli [#{COMMANDS.join('|')}] [subcommand] [general options] [command options]"
+ opts.separator ""
+ opts.on( '-h', '--help', 'Get usage information for this tool') do
+ @out.puts opts
+ end
+ opts.separator ""
+ opts.separator "URL with credentials to Conductor are set in ~/.aeolus-cli"
+ opts.separator "Conductor URL should point to https://<host_where_conductor_runs>/conductor/api"
+ end
+
+ begin
+ @optparse.parse(@args)
+ rescue OptionParser::InvalidOption => e
+ #This is just a wrapper, let the actual commands handle bad options later
+ return true
+ rescue OptionParser::MissingArgument => e
+ @out.puts "Warning, #{e.message}"
+ exit(1)
+ end
+ end
+
+ def image
+ parser = Aeolus::CLI::ConfigParser.new(@args)
+ parser.process
+ end
+ end
+ end
+end
diff --git a/lib/aeolus_cli/command/config_parser.rb b/lib/aeolus_cli/command/config_parser.rb
index 2be3e61..438bb70 100644
--- a/lib/aeolus_cli/command/config_parser.rb
+++ b/lib/aeolus_cli/command/config_parser.rb
@@ -35,7 +35,7 @@ module Aeolus
# File.expand_path("~")
if COMMANDS.include?(@command)
parse(@command)
- self.send((a)command.to_sym)
+ self.send((a)command.to_sym) unless @args.include?('-h')
else
@args << "-h"
puts "Valid command required: \n\n"
@@ -48,7 +48,7 @@ module Aeolus
subcommand = subcommand.to_sym if subcommand
@optparse ||= OptionParser.new do|opts|
- opts.banner = "Usage: aeolus-cli [#{COMMANDS.join('|')}] [general options] [command options]"
+ opts.banner = "Usage: aeolus-cli image [#{COMMANDS.join('|')}] [general options] [command options]"
opts.separator ""
opts.separator "General options:"
@@ -221,7 +221,7 @@ module Aeolus
end
begin
- @optparse.parse!(@args)
+ @optparse.parse(@args)
rescue OptionParser::InvalidOption
puts "Warning: Invalid option"
exit(1)
diff --git a/spec/command/cli_parser.rb b/spec/command/cli_parser.rb
new file mode 100644
index 0000000..7efbc06
--- /dev/null
+++ b/spec/command/cli_parser.rb
@@ -0,0 +1,50 @@
+# Copyright 2011 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'spec_helper'
+
+module Aeolus
+ module CLI
+ describe CLIParser do
+ it "should parse the specified command" do
+ ConfigParser.any_instance.should_receive(:process).with(any_args()).and_return(true)
+ parser = CLIParser.new(%w(image list --images))
+ parser.process
+ parser.command.should == 'image'
+ end
+
+ context "output help" do
+ before(:each) do
+ @out = double("out")
+ @out.should_receive(:puts).with(instance_of(OptionParser)).once
+ end
+
+ it "should output help if no params passed" do
+ parser = CLIParser.new([], @out)
+ parser.process
+ end
+
+ it "should output help if -h passed" do
+ parser = CLIParser.new(%w(-h), @out)
+ parser.process
+ end
+
+ it "should output help if --help passed" do
+ parser = CLIParser.new(%w(--help), @out)
+ parser.process
+ end
+ end
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2c3ccd7..d198732 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -15,24 +15,8 @@
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib/aeolus_cli/command/"))
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib/aeolus_cli/model/"))
-require 'rubygems'
-require 'base'
-require 'image'
-require 'build'
-require 'target_image'
-require 'provider_image'
-require 'provider'
-require 'provider_type'
-require 'provider_account'
-require 'config_parser'
+require 'aeolus_cli'
require 'stringio'
-require 'base_command'
-require 'list_command'
-require 'build_command'
-require 'push_command'
-require 'import_command'
-require 'delete_command'
-require 'status_command'
require 'vcr_setup'
--
1.7.7.4
12 years, 4 months
[PATCH 0/2] BZ 768509
by Jason Guiditta
Note, this relies on patch:
BZ-768507-aeolus-cli-needs-syntax-to-be-more-flexibl.patch
12 years, 4 months
[PATCH conductor] Rake task to insert ldap users.
by Scott Seago
This is a barebones rake task to insert ldap users into the conductor user database. This is only needed if the admin wants to pre-configure non-default permissions for the user before the user logs in. If the user is being set up with the default permissions (on the default pool, etc) this isn't needed, as the user is automatically created upon initial login.
We're not doing any validation of the users other than the standard model validation on the login field. We don't have the user's password, so we can't test login here. I'm not sure what additional validation is required here, if any, but an invalid user is fairly safe - the user can't log in if it's not a valid ldap username, so the only harm is cluttering iup the database with extra users that aren't useful for anything.
At the moment, this script does not set default permissions for the users. I'm not sure whether we want that or not -- currently create_ldap_user! does not do this, even for ldap users created via user logins, so if we want this, we should probably modify create_ldap_user! to use RegistrationService.
Syntax to create ldap users is as follows:
rake dc:create_ldap_users[username1:username2:username3:...]
---
src/lib/tasks/dc_tasks.rake | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/lib/tasks/dc_tasks.rake b/src/lib/tasks/dc_tasks.rake
index 28653cd..84637bb 100644
--- a/src/lib/tasks/dc_tasks.rake
+++ b/src/lib/tasks/dc_tasks.rake
@@ -28,6 +28,30 @@ namespace :dc do
end
+ desc 'Create and register a list of ldap users, separated by ":"'
+ task :create_ldap_users, [:logins] => :environment do |t, args|
+ unless args.logins
+ puts "Usage: rake 'dc:create_ldap_users[login1:login2:...]'"
+ exit(1)
+ end
+
+ args.logins.split(":").each do |login|
+ user = User.find_by_login(args.login)
+
+ if user
+ puts "User already exists: #{login}"
+ end
+
+ begin
+ user = User.create_ldap_user!(login)
+ puts "User #{login} registered"
+ rescue Exception => e
+ puts "User registration failed: #{e}"
+ end
+ end
+ end
+
+
desc 'Grant administrator privileges to registred user'
task :site_admin, [:login] => :environment do |t, args|
unless args.login
--
1.7.6.4
12 years, 4 months
[PATCH conductor] fix for bz #765901: fix pools_in_use calculation
by Scott Seago
---
src/app/controllers/pools_controller.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 7e4503a..f0a0e35 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -294,7 +294,7 @@ class PoolsController < ApplicationController
instances = current_user.owned_instances
@failed_instances = instances.select {|instance| instance.state == Instance::STATE_CREATE_FAILED || instance.state == Instance::STATE_ERROR}
@statistics = {
- :pools_in_use => @user_pools.collect { |pool| pool.instances.pending.count > 0 || pool.instances.deployed.count > 0 }.count,
+ :pools_in_use => @user_pools.select { |pool| pool.instances.pending.count > 0 || pool.instances.deployed.count > 0 }.count,
:deployments => current_user.deployments.count,
:instances => instances.count,
:instances_pending => instances.select {|instance| instance.state == Instance::STATE_NEW || instance.state == Instance::STATE_PENDING}.count,
--
1.7.6.4
12 years, 4 months
[PATCH aeolus-cli] BZ#767074 Fix print_provider_content method for delete with no provider content
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_cli/command/delete_command.rb | 42 ++++++++++---------
spec/command/delete_command_spec.rb | 41 +++++++++++++++++++
.../delete_build_no_provider_content.yml | 42 ++++++++++++++++++++
.../delete_image_no_provider_content.yml | 42 ++++++++++++++++++++
.../delete_target_image_no_provider_content.yml | 42 ++++++++++++++++++++
5 files changed, 189 insertions(+), 20 deletions(-)
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
create mode 100644 spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml
diff --git a/lib/aeolus_cli/command/delete_command.rb b/lib/aeolus_cli/command/delete_command.rb
index 54de83f..7343262 100644
--- a/lib/aeolus_cli/command/delete_command.rb
+++ b/lib/aeolus_cli/command/delete_command.rb
@@ -70,36 +70,38 @@ module Aeolus
print_provider_content(response.body)
exit(0)
end
+
rescue => e
- handle_exception(e)
+ exit(1)
end
end
private
def print_provider_content(content_xml)
h = Hash.from_xml(content_xml)
- provider_content = h[h.keys.first]["content"]["provider_content"]
- content = provider_content.instance_of?(Array) ? provider_content : [provider_content]
- if content.size > 0
- widths = calculate_widths(content)
- puts "N.B. The following provider content must be manually removed"
- puts ""
-
- # Print Headers
- printf("%-#{widths[:provider] + 5}s", "Provider")
- printf("%-#{widths[:id] + 5}s", "ID")
- puts ""
+ if provider_content = h[h.keys.first]["content"]["provider_content"]
+ content = provider_content.instance_of?(Array) ? provider_content : [provider_content]
+ if content.size > 0
+ widths = calculate_widths(content)
+ puts "N.B. The following provider content must be manually removed"
+ puts ""
- # Print Column Lines
- printf("%-#{widths[:provider] + 5}s", "-" * widths[:provider])
- printf("%-#{widths[:id] + 5}s", "-" * widths[:id])
- puts ""
+ # Print Headers
+ printf("%-#{widths[:provider] + 5}s", "Provider")
+ printf("%-#{widths[:id] + 5}s", "ID")
+ puts ""
- # Print Content
- content.each do |pc|
- printf("%-#{widths[:provider] + 5}s", pc["provider"])
- printf("%-#{widths[:id] + 5}s", pc["target_identifier"])
+ # Print Column Lines
+ printf("%-#{widths[:provider] + 5}s", "-" * widths[:provider])
+ printf("%-#{widths[:id] + 5}s", "-" * widths[:id])
puts ""
+
+ # Print Content
+ content.each do |pc|
+ printf("%-#{widths[:provider] + 5}s", pc["provider"])
+ printf("%-#{widths[:id] + 5}s", pc["target_identifier"])
+ puts ""
+ end
end
end
end
diff --git a/spec/command/delete_command_spec.rb b/spec/command/delete_command_spec.rb
index 7325161..a15ac39 100644
--- a/spec/command/delete_command_spec.rb
+++ b/spec/command/delete_command_spec.rb
@@ -73,6 +73,47 @@ module Aeolus
end
end
+ context "Delete with no Provider Content" do
+ it "should correctly return when deleting an image with no Provider Images" do
+ VCR.use_cassette('command/delete_command/delete_image_no_provider_content') do
+ @options = {:image => "af1b3773-b229-406a-b59c-f5f96ebc2d0b"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Image: af1b3773-b229-406a-b59c-f5f96ebc2d0b Deleted Successfully")
+ end
+ end
+
+ it "should correctly return when deleting build with no Provider Images" do
+ VCR.use_cassette('command/delete_command/delete_build_no_provider_content') do
+ @options = {:build => "85e1efd5-890a-422f-adfa-d340ddcae187"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.build
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Build: 85e1efd5-890a-422f-adfa-d340ddcae187 Deleted Successfully")
+ end
+ end
+
+ it "should correctly return when deleting a target image with no Provider Images" do
+ VCR.use_cassette('command/delete_command/delete_target_image_no_provider_content') do
+ @options = {:targetimage => "93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b"}
+ dc = DeleteCommand.new(@options)
+ begin
+ dc.target_image
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Target Image: 93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b Deleted Successfully")
+ end
+ end
+ end
+
context "Delete Failed Not Found" do
it "should display an appropriate message when the given image is not found" do
VCR.use_cassette('command/delete_command/delete_image_not_found') do
diff --git a/spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml
new file mode 100644
index 0000000..854f6ef
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_build_no_provider_content.yml
@@ -0,0 +1,42 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/builds/85e1efd5-890a-4...
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ etag:
+ - "\"d27ce6cf60644af5736fff88e6d73dda\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Tue, 20 Dec 2011 14:35:06 GMT
+ x-runtime:
+ - "0.258616"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZDJkYWI3NDcwZGRlNjdiMTM3ODhjYzJhNjMwMmVjMTgiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--cdf1db4ad503e7a2177a113543adc7d62c73cd51; path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ transfer-encoding:
+ - chunked
+ body: |
+ <build href='https://localhost/conductor/api/images/85e1efd5-890a-422f-adfa-d340ddcae187' id='85e1efd5-890a-422f-adfa-d340ddcae187'>
+ <status>DELETED</status>
+ <content>
+ </content>
+ </build>
+
+ http_version: "1.1
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
new file mode 100644
index 0000000..c9f7b16
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
@@ -0,0 +1,42 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/images/af1b3773-b229-4...
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ etag:
+ - "\"5d1bc3e7c96eba873098df89f4af1ee2\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Tue, 20 Dec 2011 14:30:22 GMT
+ x-runtime:
+ - "0.309692"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZTJjNTVhZDliMTljMzUyOTZiMDFiOWZlYWVlNTU2OTgiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--7db888b26ee555c9d51cad92eec0f20f725fd6f3; path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ transfer-encoding:
+ - chunked
+ body: |
+ <image href='https://localhost/conductor/api/images/af1b3773-b229-406a-b59c-f5f96ebc2d0b' id='af1b3773-b229-406a-b59c-f5f96ebc2d0b'>
+ <status>DELETED</status>
+ <content>
+ </content>
+ </image>
+
+ http_version: "1.1"
\ No newline at end of file
diff --git a/spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml
new file mode 100644
index 0000000..717757b
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_target_image_no_provider_content.yml
@@ -0,0 +1,42 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri: https://admin:password@localhost:443/conductor/api/target_images/93bc6d11...
+ body:
+ headers:
+ accept-language:
+ - en
+ accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ etag:
+ - "\"641448cca5a5780b18b324c7308ff65a\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ date:
+ - Tue, 20 Dec 2011 14:39:50 GMT
+ x-runtime:
+ - "0.204005"
+ set-cookie:
+ - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlNTNkZGFmNGNkOGZhNjQxZmI1Nzc5MTM3OTQxN2VjNTYiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--b59985e00d69a7903bc134a51a9f1cd00edc276d; path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ transfer-encoding:
+ - chunked
+ body: |
+ <target_image href='https://localhost/conductor/api/images/93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b' id='93bc6d11-6b09-4b1c-92a3-c580ca4f6f3b'>
+ <status>DELETED</status>
+ <content>
+ </content>
+ </target_image>
+
+ http_version: "1.1"
\ No newline at end of file
--
1.7.6.4
12 years, 4 months
[PATCH conductor 1/3] BZ 768089: Refactor provider account matching to facilitate stubbing
by Scott Seago
Instance.match was one long 70 line method, which wasn't conducive to stubbing out parts of it for rspec tests.
---
src/app/models/instance.rb | 51 +++++++-----------------------------
src/app/models/provider_account.rb | 31 ++++++++++++++++++++++
src/app/util/taskomatic.rb | 11 +++++---
3 files changed, 48 insertions(+), 45 deletions(-)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 08aa3b6..083c01f 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -184,6 +184,15 @@ class Instance < ActiveRecord::Base
Aeolus::Image::Warehouse::ImageBuild.find(image_build_uuid) if image_build_uuid
end
+ def build
+ image_build || (image.nil? ? nil : image.latest_pushed_build)
+ end
+
+ # defined as class method to facilitate stubbing out for testing
+ def self.provider_images_for_match(image, provider)
+ (image.build ? image.build.provider_images : []).select {|pi| pi.provider_name == provider.name}
+ end
+
def assembly_xml
@assembly_xml ||= AssemblyXML.new(self[:assembly_xml].to_s)
end
@@ -346,50 +355,10 @@ class Instance < ActiveRecord::Base
errors << I18n.t('instances.errors.image_not_found', :b_uuid=> image_build_uuid, :i_uuid => image_uuid) if image_build.nil? and image.nil?
return [[], errors] unless errors.empty?
- build = image_build || image.latest_pushed_build
- provider_images = build ? build.provider_images : []
matched = []
pool.pool_family.provider_accounts.each do |account|
- unless account.provider.enabled?
- errors << I18n.t('instances.errors.must_be_enabled', :account_name => account.name)
- next
- end
+ account.instance_matches(self, matched, errors)
- # match_provider_hardware_profile returns a single provider
- # hardware_profile that can satisfy the input hardware_profile
- hwp = HardwareProfile.match_provider_hardware_profile(account.provider,
- hardware_profile)
- unless hwp
- errors << I18n.t('instances.errors.hw_profile_match_not_found', :account_name => account.name)
- next
- end
- account_images = provider_images.select {|pi| pi.provider_name == account.provider.name}
- if account_images.empty?
- errors << I18n.t('instances.errors.image_not_pushed_to_provider', :account_name => account.name)
- next
- end
- if account.quota.reached?
- errors << I18n.t('instances.errors.provider_account_quota_reached', :account_name => account.name)
- next
- end
- if requires_config_server? and account.config_server.nil?
- errors << I18n.t('instances.errors.no_config_server_available', :account_name => account.name)
- next
- end
- account_images.each do |pi|
- if not frontend_realm.nil?
- brealms = frontend_realm.realm_backend_targets.select {|brealm_target| brealm_target.target_provider == account.provider}
- if brealms.empty?
- errors << I18n.t('instances.errors.realm_not_mapped', :frontend_realm_name => frontend_realm.name)
- next
- end
- brealms.each do |brealm_target|
- matched << Match.new(pool.pool_family, account, hwp, pi, brealm_target.target_realm)
- end
- else
- matched << Match.new(pool.pool_family, account, hwp, pi, nil)
- end
- end
end
[matched, errors]
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
index 88ac8d4..0ba423b 100644
--- a/src/app/models/provider_account.rb
+++ b/src/app/models/provider_account.rb
@@ -338,6 +338,37 @@ class ProviderAccount < ActiveRecord::Base
end
end
+ def instance_matches(instance, matched, errors)
+ if !provider.enabled?
+ errors << I18n.t('instances.errors.must_be_enabled', :account_name => name)
+ elsif quota.reached?
+ errors << I18n.t('instances.errors.provider_account_quota_reached', :account_name => name)
+ # match_provider_hardware_profile returns a single provider
+ # hardware_profile that can satisfy the input hardware_profile
+ elsif !(hwp = HardwareProfile.match_provider_hardware_profile(provider, instance.hardware_profile))
+ errors << I18n.t('instances.errors.hw_profile_match_not_found', :account_name => name)
+ elsif (account_images = Instance.provider_images_for_match(instance,provider)).empty?
+ errors << I18n.t('instances.errors.image_not_pushed_to_provider', :account_name => name)
+ elsif instance.requires_config_server? and config_server.nil?
+ errors << I18n.t('instances.errors.no_config_server_available', :account_name => name)
+ else
+ account_images.each do |pi|
+ if not instance.frontend_realm.nil?
+ brealms = instance.frontend_realm.realm_backend_targets.select {|brealm_target| brealm_target.target_provider == provider}
+ if brealms.empty?
+ errors << I18n.t('instances.errors.realm_not_mapped', :frontend_realm_name => instance.frontend_realm.name)
+ next
+ end
+ brealms.each do |brealm_target|
+ matched << Instance::Match.new(instance.pool.pool_family, self, hwp, pi, brealm_target.target_realm)
+ end
+ else
+ matched << Instance::Match.new(instance.pool.pool_family, self, hwp, pi, nil)
+ end
+ end
+ end
+ end
+
private
def self.apply_search_filter(search)
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb
index 9750873..3629706 100644
--- a/src/app/util/taskomatic.rb
+++ b/src/app/util/taskomatic.rb
@@ -32,10 +32,7 @@ module Taskomatic
task.state = Task::STATE_RUNNING
task.save!
-
- Rails.logger.info "Task instance create completed with key #{dcloud_instance.id} and state #{dcloud_instance.state}"
- task.instance.external_key = dcloud_instance.id
- task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ handle_instance_state(task.instance,dcloud_instance)
task.instance.save!
rescue HttpException => ex
task.failure_code = Task::FAILURE_PROVIDER_CONTACT_FAILED
@@ -48,6 +45,12 @@ module Taskomatic
end
end
+ def self.handle_instance_state(instance, dcloud_instance)
+ Rails.logger.info "Task instance create completed with key #{dcloud_instance.id} and state #{dcloud_instance.state}"
+ instance.external_key = dcloud_instance.id
+ instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ end
+
def self.do_action(task, action)
task.time_started = Time.now
--
1.7.6.4
12 years, 4 months
aeolus-image-rubygem .gemspec file
by Petr Blaho
Hi,
when working on some patches or reviews I often needs to build
rubygem-aeolus-image and manually install it as a rpm to system to
use conductor against new not packaged code.
I tried to use bundler to load aeolus-image rubygem from my modified
code - using gem 'aeolus-image', :path =>
'/home/pblaho/workspace/aeolus-image-rubygem'
it failed.
I found that it needs .gemspec file to work.
I have just refactored Gem::Specification.new block from Rakefile to
aeolus-image.gemspec and it works.
I can send a patch with that simple change - but it will need to be
properly tested if something in Rakefile is not broken (a succeded in
building rpm from it) by someone else.
What do you thing about introducing this .gemspec file to our repo?
It will let us to use bundler to load that gem from directory (or git repo)
instead of building and installing rpm package every time.
--
With regards
Petr Blaho
12 years, 4 months