Error build template
by Julio Alberto Carrillo
Hi,
I have errors whit i try run this command for build a template.
aeolus-image build --target rhev --template f14.xml
f14.xml
<template>
<name>f14jeos</name>
<os>
<name>Fedora</name>
<version>14</version>
<arch>x86_64</arch>
<install type='url'>
<url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fedora
/x86_64/os/</url>
</install>
</os>
<description>Fedora 14</description>
</template>
Error i get is :
2011-09-28 17:21:54,200 DEBUG imagefactory.ImageWarehouse.ImageWarehouse
pid(2176) Message: Created Image Warehouse instance
http://localhost:9090 - buckets(target_images, templates, icicles,
provider_images)
2011-09-28 17:21:54,208 INFO imagefactory.ImageWarehouse.ImageWarehouse
pid(2176) Message: Creating a bucket returned status 500.
2011-09-28 17:21:54,214 DEBUG imagefactory.ImageWarehouse.ImageWarehouse
pid(2176) Message: Setting metadata ({'object_type': 'image', 'uuid':
'96d588f7-817d-43eb-bcc1-e116d443b727'}) for
http://localhost:9090/images/96d588f7-817d-43eb-bcc1-e116d443b727
2011-09-28 17:21:54,261 INFO imagefactory.ImageWarehouse.ImageWarehouse
pid(2176) Message: Creating a bucket returned status 500.
2011-09-28 17:21:54,264 DEBUG imagefactory.ImageWarehouse.ImageWarehouse
pid(2176) Message: Setting metadata ({'image':
'96d588f7-817d-43eb-bcc1-e116d443b727', 'object_type': 'build', 'uuid':
'92917154-a3e3-4e35-8a3c-85f85ab4ec4e'}) for
http://localhost:9090/builds/92917154-a3e3-4e35-8a3c-85f85ab4ec4e
2011-09-28 17:21:54,355 DEBUG imagefactory.ImageWarehouse.ImageWarehouse
pid(2176) Message: Created Image Warehouse instance
http://localhost:9090 - buckets(target_images, templates, icicles,
provider_images)
2011-09-28 17:21:54,359 DEBUG
imagefactory.builders.BaseBuilder.FedoraBuilder pid(2176) Message:
Exception caught in ImageFactory
2011-09-28 17:21:54,360 DEBUG
imagefactory.builders.BaseBuilder.FedoraBuilder pid(2176) Message:
Traceback (most recent call last):
File
"/usr/lib/python2.6/site-packages/imagefactory/builders/FedoraBuilder.py",
line 129, in build_image
raise ImageFactoryException("Invalid build target (%s) passed to
build_image()" % (self.target))
ImageFactoryException: Invalid build target (rhev) passed to build_image()
2011-09-28 17:21:54,363 DEBUG imagefactory.BuildJob.BuildAdaptor
pid(2176) Message: Raising event with agent handler
(<ImageFactoryAgent(Thread-1, initial)>), changed status from NEW to FAILED
12 years, 6 months
[PATCH configure 1/2] Move ec2 and mock out of default configure and into their own profiles v3
by Richard Su
v3 - rebased
v2 - removed nil cpu from hwp1, was not compatible with rhev
Their profiles are activated by running "aeolus-configure -p ec2" and
"aeolus-configure -p mock".
Ensure all provider profiles create a default bucket.
Remove whitespaces.
---
conf/ec2 | 13 ++++++
conf/mock | 12 ++++++
recipes/aeolus/manifests/profiles/default.pp | 41 +-------------------
recipes/aeolus/manifests/profiles/ec2.pp | 52 ++++++++++++++++++++++++++
recipes/aeolus/manifests/profiles/mock.pp | 51 +++++++++++++++++++++++++
recipes/aeolus/manifests/profiles/rhevm.pp | 4 +-
recipes/aeolus/manifests/profiles/vsphere.pp | 4 +-
7 files changed, 135 insertions(+), 42 deletions(-)
create mode 100644 conf/ec2
create mode 100644 conf/mock
create mode 100644 recipes/aeolus/manifests/profiles/ec2.pp
create mode 100644 recipes/aeolus/manifests/profiles/mock.pp
diff --git a/conf/ec2 b/conf/ec2
new file mode 100644
index 0000000..142887f
--- /dev/null
+++ b/conf/ec2
@@ -0,0 +1,13 @@
+# ec2 setup configuration.
+---
+parameters:
+ enable_https: true
+ enable_security: false
+ package_provider: rpm
+classes:
+- aeolus::conductor
+- aeolus::image-factory
+- aeolus::iwhd
+- aeolus::deltacloud::core
+- aeolus::deltacloud::ec2
+- aeolus::profiles::ec2
diff --git a/conf/mock b/conf/mock
new file mode 100644
index 0000000..087c329
--- /dev/null
+++ b/conf/mock
@@ -0,0 +1,12 @@
+# mock setup configuration.
+---
+parameters:
+ enable_https: true
+ enable_security: false
+ package_provider: rpm
+classes:
+- aeolus::conductor
+- aeolus::image-factory
+- aeolus::iwhd
+- aeolus::deltacloud::core
+- aeolus::profiles::mock
diff --git a/recipes/aeolus/manifests/profiles/default.pp b/recipes/aeolus/manifests/profiles/default.pp
index 8bbfb7f..c3a58cd 100644
--- a/recipes/aeolus/manifests/profiles/default.pp
+++ b/recipes/aeolus/manifests/profiles/default.pp
@@ -13,7 +13,6 @@
# limitations under the License.
class aeolus::profiles::default {
- include aeolus::deltacloud::ec2
aeolus::create_bucket{"aeolus":}
@@ -25,31 +24,7 @@ class aeolus::profiles::default {
aeolus::conductor::login{"admin": password => "password",
require => Aeolus::Conductor::Site_admin['admin']}
-
- aeolus::conductor::provider{"mock":
- deltacloud_driver => 'mock',
- url => 'http://localhost:3002/api',
- require => Aeolus::Conductor::Login["admin"] }
-
- aeolus::conductor::provider::account{"mockuser":
- provider => 'mock',
- type => 'mock',
- username => 'mockuser',
- password => 'mockpassword',
- require => Aeolus::Conductor::Provider["mock"] }
-
- aeolus::conductor::provider{"ec2-us-east-1":
- deltacloud_driver => 'ec2',
- deltacloud_provider => 'us-east-1',
- url => 'http://localhost:3002/api',
- require => Aeolus::Conductor::Login["admin"] }
-
- aeolus::conductor::provider{"ec2-us-west-1":
- deltacloud_driver => 'ec2',
- deltacloud_provider => 'us-west-1',
- url => 'http://localhost:3002/api',
- require => Aeolus::Conductor::Login["admin"] }
-
+
aeolus::conductor::hwp{"hwp1":
memory => "512",
cpu => "1",
@@ -57,17 +32,7 @@ class aeolus::profiles::default {
architecture => "x86_64",
require => Aeolus::Conductor::Login["admin"] }
- aeolus::conductor::hwp{"hwp2":
- memory => "1",
- cpu => "",
- storage => "1",
- architecture => "x86_64",
- require => Aeolus::Conductor::Login["admin"] }
-
aeolus::conductor::logout{"admin":
- require => [Aeolus::Conductor::Provider['mock'],
- Aeolus::Conductor::Provider::Account['mockuser'],
- Aeolus::Conductor::Provider['ec2-us-east-1'],
- Aeolus::Conductor::Provider['ec2-us-west-1'],
- Aeolus::Conductor::Hwp['hwp1', 'hwp2']] }
+ require => Aeolus::Conductor::Hwp['hwp1']}
+
}
diff --git a/recipes/aeolus/manifests/profiles/ec2.pp b/recipes/aeolus/manifests/profiles/ec2.pp
new file mode 100644
index 0000000..3dd96e0
--- /dev/null
+++ b/recipes/aeolus/manifests/profiles/ec2.pp
@@ -0,0 +1,52 @@
+# 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.
+
+class aeolus::profiles::ec2 {
+ include aeolus::deltacloud::ec2
+
+ aeolus::create_bucket{"aeolus":}
+
+ aeolus::conductor::site_admin{"admin":
+ email => 'dcuser(a)aeolusproject.org',
+ password => "password",
+ first_name => 'aeolus',
+ last_name => 'user'}
+
+ aeolus::conductor::login{"admin": password => "password",
+ require => Aeolus::Conductor::Site_admin['admin']}
+
+ aeolus::conductor::provider{"ec2-us-east-1":
+ deltacloud_driver => 'ec2',
+ deltacloud_provider => 'us-east-1',
+ url => 'http://localhost:3002/api',
+ require => Aeolus::Conductor::Login["admin"] }
+
+ aeolus::conductor::provider{"ec2-us-west-1":
+ deltacloud_driver => 'ec2',
+ deltacloud_provider => 'us-west-1',
+ url => 'http://localhost:3002/api',
+ require => Aeolus::Conductor::Login["admin"] }
+
+ aeolus::conductor::hwp{"hwp1":
+ memory => "512",
+ cpu => "1",
+ storage => "",
+ architecture => "x86_64",
+ require => Aeolus::Conductor::Login["admin"] }
+
+ aeolus::conductor::logout{"admin":
+ require => [Aeolus::Conductor::Provider['ec2-us-east-1'],
+ Aeolus::Conductor::Provider['ec2-us-west-1'],
+ Aeolus::Conductor::Hwp['hwp1']] }
+}
diff --git a/recipes/aeolus/manifests/profiles/mock.pp b/recipes/aeolus/manifests/profiles/mock.pp
new file mode 100644
index 0000000..1656815
--- /dev/null
+++ b/recipes/aeolus/manifests/profiles/mock.pp
@@ -0,0 +1,51 @@
+# 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.
+
+class aeolus::profiles::mock {
+
+ aeolus::create_bucket{"aeolus":}
+
+ aeolus::conductor::site_admin{"admin":
+ email => 'dcuser(a)aeolusproject.org',
+ password => "password",
+ first_name => 'aeolus',
+ last_name => 'user'}
+
+ aeolus::conductor::login{"admin": password => "password",
+ require => Aeolus::Conductor::Site_admin['admin']}
+
+ aeolus::conductor::provider{"mock":
+ deltacloud_driver => 'mock',
+ url => 'http://localhost:3002/api',
+ require => Aeolus::Conductor::Login["admin"] }
+
+ aeolus::conductor::provider::account{"mockuser":
+ provider => 'mock',
+ type => 'mock',
+ username => 'mockuser',
+ password => 'mockpassword',
+ require => Aeolus::Conductor::Provider["mock"] }
+
+ aeolus::conductor::hwp{"hwp1":
+ memory => "512",
+ cpu => "1",
+ storage => "",
+ architecture => "x86_64",
+ require => Aeolus::Conductor::Login["admin"] }
+
+ aeolus::conductor::logout{"admin":
+ require => [Aeolus::Conductor::Provider['mock'],
+ Aeolus::Conductor::Provider::Account['mockuser'],
+ Aeolus::Conductor::Hwp['hwp1']] }
+}
diff --git a/recipes/aeolus/manifests/profiles/rhevm.pp b/recipes/aeolus/manifests/profiles/rhevm.pp
index 03fef5b..93d8bad 100644
--- a/recipes/aeolus/manifests/profiles/rhevm.pp
+++ b/recipes/aeolus/manifests/profiles/rhevm.pp
@@ -57,14 +57,14 @@ class aeolus::profiles::rhevm {
url => "http://localhost:3002/api",
deltacloud_provider => "$rhevm_deltacloud_provider",
require => Aeolus::Conductor::Login["admin"] }
-
+
aeolus::conductor::provider::account{"rhevm":
provider => 'rhevm',
type => 'rhevm',
username => '$rhevm_deltacloud_username',
password => '$rhevm_deltacloud_password',
require => Aeolus::Conductor::Provider["rhevm"] }
-
+
aeolus::conductor::hwp{"hwp1":
memory => "512",
cpu => "1",
diff --git a/recipes/aeolus/manifests/profiles/vsphere.pp b/recipes/aeolus/manifests/profiles/vsphere.pp
index 72a3e59..1715181 100644
--- a/recipes/aeolus/manifests/profiles/vsphere.pp
+++ b/recipes/aeolus/manifests/profiles/vsphere.pp
@@ -34,14 +34,14 @@ class aeolus::profiles::vsphere {
url => "http://localhost:3002/api",
deltacloud_provider => "$vsphere_deltacloud_provider",
require => [Aeolus::Conductor::Login["admin"]] }
-
+
aeolus::conductor::provider::account{"vsphere":
provider => 'vsphere',
type => 'vsphere',
username => '$vsphere_username',
password => '$vsphere_password',
require => Aeolus::Conductor::Provider["vsphere"] }
-
+
aeolus::conductor::hwp{"hwp1":
memory => "512",
cpu => "1",
--
1.7.6.2
12 years, 6 months
ImageFactory REST API support
by Martyn Taylor
This patch set will allow building and importing images in factory via the rest api.
To build:
i = Aeolus::Image::Factory::Image.new(:targets => targets, :template => template)
i.save!
To import:
i = Aeolus::Image::Factory::Image.new(:target_identifier => "ami-1234567", :provider_name => "ec2-us-east-1", :target_name => "ec2", :image_descriptor => "<image><name>MyImage</name><image>")
i.save!
12 years, 6 months
[PATCH aeolus-image-rubygem] Added imagefactory REST API support
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_image/model/factory/base.rb | 63 ++++++++++++++++++++++
lib/aeolus_image/model/factory/build.rb | 8 +++
lib/aeolus_image/model/factory/builder.rb | 8 +++
lib/aeolus_image/model/factory/image.rb | 8 +++
lib/aeolus_image/model/factory/provider_image.rb | 11 ++++
lib/aeolus_image/model/factory/target_image.rb | 11 ++++
6 files changed, 109 insertions(+), 0 deletions(-)
create mode 100644 lib/aeolus_image/model/factory/base.rb
create mode 100644 lib/aeolus_image/model/factory/build.rb
create mode 100644 lib/aeolus_image/model/factory/builder.rb
create mode 100644 lib/aeolus_image/model/factory/image.rb
create mode 100644 lib/aeolus_image/model/factory/provider_image.rb
create mode 100644 lib/aeolus_image/model/factory/target_image.rb
diff --git a/lib/aeolus_image/model/factory/base.rb b/lib/aeolus_image/model/factory/base.rb
new file mode 100644
index 0000000..614a25f
--- /dev/null
+++ b/lib/aeolus_image/model/factory/base.rb
@@ -0,0 +1,63 @@
+module Aeolus
+ module Image
+ module Factory
+ class Base < ActiveResource::Base
+ self.format = :json
+
+ class << self
+ ## Remove format from the url for resources
+ def element_path(id, prefix_options = {}, query_options = nil)
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
+ "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
+ end
+
+ ## Remove format from the url for collections
+ def collection_path(prefix_options = {}, query_options = nil)
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
+ end
+
+ ## For a collection call, ActiveResource formatting is not
+ ## compliant with Factory's output.
+ def instantiate_collection(collection, prefix_options = {})
+ unless collection.kind_of? Array
+ [instantiate_record(collection, prefix_options)]
+ else
+ collection.collect! { |record| instantiate_record(record, prefix_options) }
+ end
+ end
+
+ ## The objects returned from this method are not automatically converted into ActiveResource instances - they are ordinary Hashes.
+ ## Modifications below ensures that you get ActiveResource instances.
+ def get(method_name, options = {})
+ object_array = connection.get(custom_method_collection_url(method_name, options), headers)
+ if object_array.class.to_s=="Array"
+ object_array.collect! {|record| self.class.new.load(record)}
+ else
+ self.class.new.load(object_array)
+ end
+ end
+ end
+
+ ## Instance Methods: (modifying the ActiveRecord::CustomMethods).
+ ## This modification is same as defined in above method
+ def get(method_name, options = {})
+ self.class.new.load(connection.get(custom_method_element_url(method_name, options), self.class.headers))
+ end
+
+ # Modifying the url formations to make them Factory compliant
+ def custom_method_element_url(method_name, options = {})
+ "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/" +
+ "#{method_name}#{self.class.send!(:query_string, options)}"
+ end
+
+ # Modifying the url formations to make them Factory compliant
+ def self.custom_method_collection_url(method_name, options = {})
+ prefix_options, query_options = split_options(options)
+ url = "#{prefix(prefix_options)}#{collection_name}/#{method_name}#{query_string(query_options)}"
+ url
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/factory/build.rb b/lib/aeolus_image/model/factory/build.rb
new file mode 100644
index 0000000..b238cea
--- /dev/null
+++ b/lib/aeolus_image/model/factory/build.rb
@@ -0,0 +1,8 @@
+module Aeolus
+ module Image
+ module Factory
+ class Build < Base
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/factory/builder.rb b/lib/aeolus_image/model/factory/builder.rb
new file mode 100644
index 0000000..5476456
--- /dev/null
+++ b/lib/aeolus_image/model/factory/builder.rb
@@ -0,0 +1,8 @@
+module Aeolus
+ module Image
+ module Factory
+ class Builder < Base
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/factory/image.rb b/lib/aeolus_image/model/factory/image.rb
new file mode 100644
index 0000000..712457f
--- /dev/null
+++ b/lib/aeolus_image/model/factory/image.rb
@@ -0,0 +1,8 @@
+module Aeolus
+ module Image
+ module Factory
+ class Image < Base
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/factory/provider_image.rb b/lib/aeolus_image/model/factory/provider_image.rb
new file mode 100644
index 0000000..9022c06
--- /dev/null
+++ b/lib/aeolus_image/model/factory/provider_image.rb
@@ -0,0 +1,11 @@
+module Aeolus
+ module Image
+ module Factory
+ class ProviderImage < Base
+ def self.status(id)
+ Aeolus::Image::Factory::Builder.find(id).status
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/factory/target_image.rb b/lib/aeolus_image/model/factory/target_image.rb
new file mode 100644
index 0000000..4c87006
--- /dev/null
+++ b/lib/aeolus_image/model/factory/target_image.rb
@@ -0,0 +1,11 @@
+module Aeolus
+ module Image
+ module Factory
+ class TargetImage < Base
+ def self.status(id)
+ Aeolus::Image::Factory::Builder.find(id).status
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
--
1.7.6.2
12 years, 6 months
[PATCH aeolus-image-rubygem] Moved warehouse models in Warehouse Module
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
This will help separate the warehouse and factory models
---
lib/aeolus_image.rb | 21 +--
lib/aeolus_image/model/image.rb | 91 ----------
lib/aeolus_image/model/image_build.rb | 68 --------
lib/aeolus_image/model/provider_image.rb | 46 -----
lib/aeolus_image/model/target_image.rb | 56 ------
lib/aeolus_image/model/template.rb | 29 ---
lib/aeolus_image/model/warehouse/image.rb | 93 ++++++++++
lib/aeolus_image/model/warehouse/image_build.rb | 70 ++++++++
lib/aeolus_image/model/warehouse/provider_image.rb | 48 +++++
lib/aeolus_image/model/warehouse/target_image.rb | 58 +++++++
lib/aeolus_image/model/warehouse/template.rb | 31 ++++
.../model/warehouse/warehouse_client.rb | 178 +++++++++++++++++++
.../model/warehouse/warehouse_model.rb | 162 ++++++++++++++++++
lib/aeolus_image/model/warehouse_client.rb | 180 --------------------
lib/aeolus_image/model/warehouse_model.rb | 162 ------------------
15 files changed, 647 insertions(+), 646 deletions(-)
delete mode 100644 lib/aeolus_image/model/image.rb
delete mode 100644 lib/aeolus_image/model/image_build.rb
delete mode 100644 lib/aeolus_image/model/provider_image.rb
delete mode 100644 lib/aeolus_image/model/target_image.rb
delete mode 100644 lib/aeolus_image/model/template.rb
create mode 100644 lib/aeolus_image/model/warehouse/image.rb
create mode 100644 lib/aeolus_image/model/warehouse/image_build.rb
create mode 100644 lib/aeolus_image/model/warehouse/provider_image.rb
create mode 100644 lib/aeolus_image/model/warehouse/target_image.rb
create mode 100644 lib/aeolus_image/model/warehouse/template.rb
create mode 100644 lib/aeolus_image/model/warehouse/warehouse_client.rb
create mode 100644 lib/aeolus_image/model/warehouse/warehouse_model.rb
delete mode 100644 lib/aeolus_image/model/warehouse_client.rb
delete mode 100644 lib/aeolus_image/model/warehouse_model.rb
diff --git a/lib/aeolus_image.rb b/lib/aeolus_image.rb
index f17ed66..ce23933 100644
--- a/lib/aeolus_image.rb
+++ b/lib/aeolus_image.rb
@@ -14,17 +14,10 @@
require 'optparse'
require 'logger'
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'base_command')
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'list_command')
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'build_command')
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'push_command')
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'import_command')
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'delete_command')
-require File.join(File.dirname(__FILE__), 'aeolus_image/command', 'config_parser')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'warehouse_client') # Not sure we need this
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'warehouse_model') # We may be able to factor this out?
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'image')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'image_build')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'provider_image')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'target_image')
-require File.join(File.dirname(__FILE__), 'aeolus_image/model', 'template')
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'warehouse_client') # Not sure we need this
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'warehouse_model') # We may be able to factor this out?
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'image')
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'image_build')
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'provider_image')
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'target_image')
+require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'template')
diff --git a/lib/aeolus_image/model/image.rb b/lib/aeolus_image/model/image.rb
deleted file mode 100644
index 73b004e..0000000
--- a/lib/aeolus_image/model/image.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-# 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.
-
-module Aeolus
- module Image
- class Image < WarehouseModel
- OS = Struct.new(:name, :version, :arch)
-
- @bucket_name = 'images'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :latest_build
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- @xml_body = Nokogiri::XML @body
- end
-
- def template_xml
- unless @template_xml
- begin
- @template_xml = Nokogiri::XML image_builds.first.target_images.first.target_template.body
- rescue
- @template_xml = Nokogiri::XML "<template></template>"
- end
- end
- @template_xml
- end
-
- def latest_pushed_build
- ImageBuild.find(@latest_build) if @latest_build
- end
-
- def image_builds
- ImageBuild.find_all_by_image_uuid(@uuid)
- end
-
- #TODO: We should get the image fields from the object body once we have it defined.
- def name
- unless @name
- @name = @xml_body.xpath("/image/name").text
- if @name.empty?
- @name = template_xml.xpath("/template/name").text
- end
- end
- @name
- end
-
- def os
- unless @os
- @os = OS.new(template_xml.xpath("/template/os/name").text, template_xml.xpath("/template/os/version").text, template_xml.xpath("/template/os/arch").text)
- end
- @os
- end
-
- def description
- unless @description
- @description = template_xml.xpath("/template/description").text
- end
- @description
- end
-
- # Delete this image and all child objects
- def delete!
- begin
- image_builds.each do |build|
- build.delete!
- end
- rescue NoMethodError
- end
- Image.delete(@uuid)
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/image_build.rb b/lib/aeolus_image/model/image_build.rb
deleted file mode 100644
index b751117..0000000
--- a/lib/aeolus_image/model/image_build.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-# 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.
-
-module Aeolus
- module Image
- class ImageBuild < WarehouseModel
- @bucket_name = 'builds'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :image
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
- def self.find_all_by_image_uuid(uuid)
- self.set_warehouse_and_bucket if self.bucket.nil?
- self.bucket.objects.map do |wh_object|
- if wh_object.attr('image') == uuid
- ImageBuild.new(wh_object.attrs(wh_object.attr_list))
- end
- end.compact
- end
-
- def image
- Image.find(@image) if @image
- end
-
- def target_images
- TargetImage.all.select {|ti| ti.build and (ti.build.uuid == self.uuid)}
- end
-
- def provider_images
- targets = target_images
- ProviderImage.all.select do |pi|
- targets.include?(pi.target_image)
- end
- end
-
- # Deletes this image and all child objects
- def delete!
- begin
- target_images.each do |ti|
- ti.delete!
- end
- rescue NoMethodError
- end
- ImageBuild.delete(@uuid)
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/provider_image.rb b/lib/aeolus_image/model/provider_image.rb
deleted file mode 100644
index a5f319d..0000000
--- a/lib/aeolus_image/model/provider_image.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-# 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.
-
-module Aeolus
- module Image
- class ProviderImage < WarehouseModel
- @bucket_name = 'provider_images'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if [:provider, :target_image].include?(k.to_sym)
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
- def target_image
- TargetImage.find(@target_image) if @target_image
- end
-
- def provider_name
- @provider
- end
-
- # Deletes this provider image
- def delete!
- ProviderImage.delete(@uuid)
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/target_image.rb b/lib/aeolus_image/model/target_image.rb
deleted file mode 100644
index c029430..0000000
--- a/lib/aeolus_image/model/target_image.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# 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.
-
-module Aeolus
- module Image
- class TargetImage < WarehouseModel
- @bucket_name = 'target_images'
-
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :build
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
- def build
- ImageBuild.find(@build) if @build
- end
-
- def provider_images
- ProviderImage.all.select{|pi| pi.target_image and (pi.target_image.uuid == self.uuid)}
- end
-
- def target_template
- Template.find(@template) if @template
- end
-
- # Deletes this targetimage and all child objects
- def delete!
- begin
- provider_images.each do |pi|
- pi.delete!
- end
- rescue NoMethodError
- end
- TargetImage.delete(@uuid)
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/template.rb b/lib/aeolus_image/model/template.rb
deleted file mode 100644
index e1ac3cb..0000000
--- a/lib/aeolus_image/model/template.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# 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.
-
-module Aeolus
- module Image
- class Template < WarehouseModel
- @bucket_name = 'templates'
-
- def initialize(attrs)
- attrs.each do |k,v|
- sym = :attr_accessor
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
- end
- end
-end
diff --git a/lib/aeolus_image/model/warehouse/image.rb b/lib/aeolus_image/model/warehouse/image.rb
new file mode 100644
index 0000000..7a7a4f3
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/image.rb
@@ -0,0 +1,93 @@
+# 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.
+
+module Aeolus
+ module Image
+ module Warehouse
+ class Image < WarehouseModel
+ OS = Struct.new(:name, :version, :arch)
+
+ @bucket_name = 'images'
+
+ def initialize(attrs)
+ attrs.each do |k,v|
+ if k.to_sym == :latest_build
+ sym = :attr_writer
+ else
+ sym = :attr_accessor
+ end
+ self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
+ send(:"#{k}=", v)
+ end
+ @xml_body = Nokogiri::XML @body
+ end
+
+ def template_xml
+ unless @template_xml
+ begin
+ @template_xml = Nokogiri::XML image_builds.first.target_images.first.target_template.body
+ rescue
+ @template_xml = Nokogiri::XML "<template></template>"
+ end
+ end
+ @template_xml
+ end
+
+ def latest_pushed_build
+ ImageBuild.find(@latest_build) if @latest_build
+ end
+
+ def image_builds
+ ImageBuild.find_all_by_image_uuid(@uuid)
+ end
+
+ #TODO: We should get the image fields from the object body once we have it defined.
+ def name
+ unless @name
+ @name = @xml_body.xpath("/image/name").text
+ if @name.empty?
+ @name = template_xml.xpath("/template/name").text
+ end
+ end
+ @name
+ end
+
+ def os
+ unless @os
+ @os = OS.new(template_xml.xpath("/template/os/name").text, template_xml.xpath("/template/os/version").text, template_xml.xpath("/template/os/arch").text)
+ end
+ @os
+ end
+
+ def description
+ unless @description
+ @description = template_xml.xpath("/template/description").text
+ end
+ @description
+ end
+
+ # Delete this image and all child objects
+ def delete!
+ begin
+ image_builds.each do |build|
+ build.delete!
+ end
+ rescue NoMethodError
+ end
+ Image.delete(@uuid)
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/warehouse/image_build.rb b/lib/aeolus_image/model/warehouse/image_build.rb
new file mode 100644
index 0000000..d99069d
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/image_build.rb
@@ -0,0 +1,70 @@
+# 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.
+
+module Aeolus
+ module Image
+ module Warehouse
+ class ImageBuild < WarehouseModel
+ @bucket_name = 'builds'
+
+ def initialize(attrs)
+ attrs.each do |k,v|
+ if k.to_sym == :image
+ sym = :attr_writer
+ else
+ sym = :attr_accessor
+ end
+ self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
+ send(:"#{k}=", v)
+ end
+ end
+
+ def self.find_all_by_image_uuid(uuid)
+ self.set_warehouse_and_bucket if self.bucket.nil?
+ self.bucket.objects.map do |wh_object|
+ if wh_object.attr('image') == uuid
+ ImageBuild.new(wh_object.attrs(wh_object.attr_list))
+ end
+ end.compact
+ end
+
+ def image
+ Image.find(@image) if @image
+ end
+
+ def target_images
+ TargetImage.all.select {|ti| ti.build and (ti.build.uuid == self.uuid)}
+ end
+
+ def provider_images
+ targets = target_images
+ ProviderImage.all.select do |pi|
+ targets.include?(pi.target_image)
+ end
+ end
+
+ # Deletes this image and all child objects
+ def delete!
+ begin
+ target_images.each do |ti|
+ ti.delete!
+ end
+ rescue NoMethodError
+ end
+ ImageBuild.delete(@uuid)
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/warehouse/provider_image.rb b/lib/aeolus_image/model/warehouse/provider_image.rb
new file mode 100644
index 0000000..acd0386
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/provider_image.rb
@@ -0,0 +1,48 @@
+# 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.
+
+module Aeolus
+ module Image
+ module Warehouse
+ class ProviderImage < WarehouseModel
+ @bucket_name = 'provider_images'
+
+ def initialize(attrs)
+ attrs.each do |k,v|
+ if [:provider, :target_image].include?(k.to_sym)
+ sym = :attr_writer
+ else
+ sym = :attr_accessor
+ end
+ self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
+ send(:"#{k}=", v)
+ end
+ end
+
+ def target_image
+ TargetImage.find(@target_image) if @target_image
+ end
+
+ def provider_name
+ @provider
+ end
+
+ # Deletes this provider image
+ def delete!
+ ProviderImage.delete(@uuid)
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/warehouse/target_image.rb b/lib/aeolus_image/model/warehouse/target_image.rb
new file mode 100644
index 0000000..8636694
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/target_image.rb
@@ -0,0 +1,58 @@
+# 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.
+
+module Aeolus
+ module Image
+ module Warehouse
+ class TargetImage < WarehouseModel
+ @bucket_name = 'target_images'
+
+ def initialize(attrs)
+ attrs.each do |k,v|
+ if k.to_sym == :build
+ sym = :attr_writer
+ else
+ sym = :attr_accessor
+ end
+ self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
+ send(:"#{k}=", v)
+ end
+ end
+
+ def build
+ ImageBuild.find(@build) if @build
+ end
+
+ def provider_images
+ ProviderImage.all.select{|pi| pi.target_image and (pi.target_image.uuid == self.uuid)}
+ end
+
+ def target_template
+ Template.find(@template) if @template
+ end
+
+ # Deletes this targetimage and all child objects
+ def delete!
+ begin
+ provider_images.each do |pi|
+ pi.delete!
+ end
+ rescue NoMethodError
+ end
+ TargetImage.delete(@uuid)
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/warehouse/template.rb b/lib/aeolus_image/model/warehouse/template.rb
new file mode 100644
index 0000000..a3b9ec5
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/template.rb
@@ -0,0 +1,31 @@
+# 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.
+
+module Aeolus
+ module Image
+ module Warehouse
+ class Template < WarehouseModel
+ @bucket_name = 'templates'
+
+ def initialize(attrs)
+ attrs.each do |k,v|
+ sym = :attr_accessor
+ self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
+ send(:"#{k}=", v)
+ end
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/warehouse/warehouse_client.rb b/lib/aeolus_image/model/warehouse/warehouse_client.rb
new file mode 100644
index 0000000..4df83a1
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/warehouse_client.rb
@@ -0,0 +1,178 @@
+# 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 'rubygems'
+
+require 'rest-client'
+require 'nokogiri'
+
+#TODO: perform iwhd version-dependent URI mapping
+module Aeolus
+ module Image
+ module Warehouse
+ class BucketObject
+ attr_reader :key
+
+ def initialize(connection, key, bucket)
+ @connection = connection
+ @key = key
+ @bucket = bucket
+ @path = "/#{@bucket.name}/#{(a)key}"
+ end
+
+ def self.create(connection, key, bucket, body, attrs = {})
+ obj = new(connection, key, bucket)
+ obj.set_body(body)
+ obj.set_attrs(attrs)
+ obj
+ end
+
+ def body
+ @connection.do_request @path, :plain => true
+ end
+
+ def set_body(body)
+ @connection.do_request @path, :content => body, :method => :put
+ end
+
+ def attr_list
+ result = @connection.do_request @path, :content => 'op=parts', :method => :post
+ return result.xpath('/object/object_attr/@name').to_a.map {|item| item.value}
+ end
+
+ def attrs(list)
+ attrs = {}
+ list.each do |att|
+ next if att.match('-')
+ attrs[att] = (@connection.do_request("#{@path}/#{att}", :plain => true) rescue nil)
+ end
+ attrs[:body] = body
+ attrs
+ end
+
+ def attr(name)
+ attrs([name])[name]
+ end
+
+ def set_attrs(hash)
+ hash.each do |name, content|
+ set_attr(name, content)
+ end
+ end
+
+ def set_attr(name, content)
+ path = "#{@path}/#{name}"
+ @connection.do_request path, :content => content, :method => :put
+ end
+
+ def delete!
+ @connection.do_request @path, :method => :delete
+ true
+ end
+
+ end
+
+ class Bucket
+ attr_accessor :name
+
+ def initialize(name, connection)
+ @name = name
+ @connection = connection
+ end
+
+ def to_s
+ "Bucket: #{@name}"
+ end
+
+ def object_names
+ result = @connection.do_request "/#{@name}"
+ result.xpath('/objects/object').map do |obj|
+ obj.at_xpath('./key/text()').to_s
+ end
+ end
+
+ def objects
+ object_names.map do |name|
+ object(name)
+ end
+ end
+
+ def object(key)
+ BucketObject.new @connection, key, self
+ end
+
+ def create_object(key, body, attrs)
+ BucketObject.create(@connection, key, self, body, attrs)
+ end
+
+ def include?(key)
+ object_names.include?(key)
+ end
+ end
+
+ class Connection
+ attr_accessor :uri
+
+ def initialize(uri)
+ @uri = uri
+ end
+
+ def do_request(path = '', opts={})
+ opts[:method] ||= :get
+ opts[:content] ||= ''
+ opts[:plain] ||= false
+ opts[:headers] ||= {}
+
+ result = RestClient::Request.execute :method => opts[:method], :url => @uri + path, :payload => opts[:content], :headers => opts[:headers]
+
+ return Nokogiri::XML result unless opts[:plain]
+ return result
+ end
+
+ end
+
+ class Client
+
+ def initialize(uri)
+ @connection = Connection.new(uri)
+ end
+
+ def create_bucket(bucket)
+ @connection.do_request "/#{bucket}", :method => :put rescue RestClient::InternalServerError
+ Bucket.new(bucket, @connection)
+ end
+
+ def bucket(bucket)
+ Bucket.new bucket, @connection
+ end
+
+ def buckets
+ @connection.do_request.xpath('/api/link[@rel="bucket"]').map do |obj|
+ obj.at_xpath('./@href').to_s.gsub(/.*\//, '')
+ end
+ end
+
+ def get_iwhd_version
+ result = @connection.do_request.at_xpath('/api[@service="image_warehouse"]/@version')
+ raise "Response does not contain <api> tag or version information" if result == nil
+ return result.value
+ end
+
+ def query(bucket_name, query_string)
+ @connection.do_request "/#{bucket_name}/_query", {:method => :post, :content => query_string}
+ end
+ end
+ end
+ end
+end
diff --git a/lib/aeolus_image/model/warehouse/warehouse_model.rb b/lib/aeolus_image/model/warehouse/warehouse_model.rb
new file mode 100644
index 0000000..3a07230
--- /dev/null
+++ b/lib/aeolus_image/model/warehouse/warehouse_model.rb
@@ -0,0 +1,162 @@
+# 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.
+
+module Aeolus
+ module Image
+ module Warehouse
+ class BucketObjectNotFound < Exception;end
+ class BucketNotFound < Exception;end
+
+ class WarehouseModel < ActiveResource::Base
+
+ def ==(other_obj)
+ # If the objects have different instance variables defined, they're definitely not ==
+ return false unless instance_variables.sort == other_obj.instance_variables.sort
+ # Otherwise, ensure that they're all the same
+ instance_variables.each do |iv|
+ return false unless other_obj.instance_variable_get(iv) == instance_variable_get(iv)
+ end
+ # They have the same instance variables and values, so they're equal
+ true
+ end
+
+ class << self
+ attr_accessor :warehouse, :bucket, :bucket_name
+
+ def set_warehouse_and_bucket
+ begin
+ @@config ||= load_config
+ self.warehouse = Warehouse::Client.new(@@config[:iwhd][:url])
+ self.bucket = self.warehouse.bucket(@bucket_name)
+ rescue
+ raise BucketNotFound
+ end
+ end
+
+ def bucket_objects
+ self.set_warehouse_and_bucket if self.bucket.nil?
+
+ begin
+ self.bucket.objects
+ rescue RestClient::ResourceNotFound
+ []
+ end
+ end
+
+ def first
+ obj = bucket_objects.first
+ obj ? self.new(obj.attrs(obj.attr_list)) : nil
+ end
+
+ def last
+ obj = bucket_objects.last
+ obj ? self.new(obj.attrs(obj.attr_list)) : nil
+ end
+
+ def all
+ bucket_objects.map do |wh_object|
+ self.new(wh_object.attrs(wh_object.attr_list))
+ end
+ end
+
+ def find(uuid)
+ self.set_warehouse_and_bucket if self.bucket.nil?
+ begin
+ if self.bucket.include?(uuid)
+ self.new(self.bucket.object(uuid).attrs(self.bucket.object(uuid).attr_list))
+ else
+ nil
+ end
+ rescue RestClient::ResourceNotFound
+ nil
+ end
+ end
+
+ def where(query_string)
+ self.set_warehouse_and_bucket if self.bucket.nil?
+ self.warehouse.query(@bucket_name, query_string)
+ end
+
+ def delete(uuid)
+ self.set_warehouse_and_bucket if self.bucket.nil?
+ begin
+ if self.bucket.include?(uuid)
+ self.bucket.object(uuid).delete!
+ else
+ false
+ end
+ rescue RestClient::ResourceNotFound
+ false
+ end
+ end
+
+ protected
+ # Copy over entirely too much code to load the config file
+ def load_config
+ # TODO - Is this always the case? We should probably have /etc/aeolus-cli or something too?
+ # Or allow Rails to override this
+ @config_location ||= "~/.aeolus-cli"
+ begin
+ file_str = read_file(@config_location)
+ if is_file?(@config_location) && !file_str.include?(":url")
+ lines = File.readlines(File.expand_path((a)config_location)).map do |line|
+ "#" + line
+ end
+ File.open(File.expand_path(@config_location), 'w') do |file|
+ file.puts lines
+ end
+ write_file
+ end
+ write_file unless is_file?(@config_location)
+ YAML::load(File.open(File.expand_path(@config_location)))
+ rescue Errno::ENOENT
+ #TODO: Create a custom exception to wrap CLI Exceptions
+ raise "Unable to locate or write configuration file: \"" + @config_location + "\""
+ end
+ end
+
+ def write_file
+ example = File.read(File.expand_path(File.dirname(__FILE__) + "/../../examples/aeolus-cli"))
+ File.open(File.expand_path(@config_location), 'a+') do |f|
+ f.write(example)
+ end
+ end
+
+ def read_file(path)
+ begin
+ full_path = File.expand_path(path)
+ if is_file?(path)
+ File.read(full_path)
+ else
+ return nil
+ end
+ rescue
+ nil
+ end
+ end
+
+ def is_file?(path)
+ full_path = File.expand_path(path)
+ if File.exist?(full_path) && !File.directory?(full_path)
+ return true
+ end
+ false
+ end
+
+ end
+
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/aeolus_image/model/warehouse_client.rb b/lib/aeolus_image/model/warehouse_client.rb
deleted file mode 100644
index f0da7ff..0000000
--- a/lib/aeolus_image/model/warehouse_client.rb
+++ /dev/null
@@ -1,180 +0,0 @@
-# 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 'rubygems'
-
-require 'rest-client'
-require 'nokogiri'
-
-#TODO: perform iwhd version-dependent URI mapping
-module Aeolus
- module Image
- module Warehouse
-
- class BucketObject
- attr_reader :key
-
- def initialize(connection, key, bucket)
- @connection = connection
- @key = key
- @bucket = bucket
- @path = "/#{@bucket.name}/#{(a)key}"
- end
-
- def self.create(connection, key, bucket, body, attrs = {})
- obj = new(connection, key, bucket)
- obj.set_body(body)
- obj.set_attrs(attrs)
- obj
- end
-
- def body
- @connection.do_request @path, :plain => true
- end
-
- def set_body(body)
- @connection.do_request @path, :content => body, :method => :put
- end
-
- def attr_list
- result = @connection.do_request @path, :content => 'op=parts', :method => :post
- return result.xpath('/object/object_attr/@name').to_a.map {|item| item.value}
- end
-
- def attrs(list)
- attrs = {}
- list.each do |att|
- next if att.match('-')
- attrs[att] = (@connection.do_request("#{@path}/#{att}", :plain => true) rescue nil)
- end
- attrs[:body] = body
- attrs
- end
-
- def attr(name)
- attrs([name])[name]
- end
-
- def set_attrs(hash)
- hash.each do |name, content|
- set_attr(name, content)
- end
- end
-
- def set_attr(name, content)
- path = "#{@path}/#{name}"
- @connection.do_request path, :content => content, :method => :put
- end
-
- def delete!
- @connection.do_request @path, :method => :delete
- true
- end
-
- end
-
- class Bucket
- attr_accessor :name
-
- def initialize(name, connection)
- @name = name
- @connection = connection
- end
-
- def to_s
- "Bucket: #{@name}"
- end
-
- def object_names
- result = @connection.do_request "/#{@name}"
- result.xpath('/objects/object').map do |obj|
- obj.at_xpath('./key/text()').to_s
- end
- end
-
- def objects
- object_names.map do |name|
- object(name)
- end
- end
-
- def object(key)
- BucketObject.new @connection, key, self
- end
-
- def create_object(key, body, attrs)
- BucketObject.create(@connection, key, self, body, attrs)
- end
-
- def include?(key)
- object_names.include?(key)
- end
- end
-
- class Connection
- attr_accessor :uri
-
- def initialize(uri)
- @uri = uri
- end
-
- def do_request(path = '', opts={})
- opts[:method] ||= :get
- opts[:content] ||= ''
- opts[:plain] ||= false
- opts[:headers] ||= {}
-
- result = RestClient::Request.execute :method => opts[:method], :url => @uri + path, :payload => opts[:content], :headers => opts[:headers]
-
- return Nokogiri::XML result unless opts[:plain]
- return result
- end
-
- end
-
- class Client
-
- def initialize(uri)
- @connection = Connection.new(uri)
- end
-
- def create_bucket(bucket)
- @connection.do_request "/#{bucket}", :method => :put rescue RestClient::InternalServerError
- Bucket.new(bucket, @connection)
- end
-
- def bucket(bucket)
- Bucket.new bucket, @connection
- end
-
- def buckets
- @connection.do_request.xpath('/api/link[@rel="bucket"]').map do |obj|
- obj.at_xpath('./@href').to_s.gsub(/.*\//, '')
- end
- end
-
- def get_iwhd_version
- result = @connection.do_request.at_xpath('/api[@service="image_warehouse"]/@version')
- raise "Response does not contain <api> tag or version information" if result == nil
- return result.value
- end
-
- def query(bucket_name, query_string)
- @connection.do_request "/#{bucket_name}/_query", {:method => :post, :content => query_string}
- end
- end
-
- end
- end
-end
diff --git a/lib/aeolus_image/model/warehouse_model.rb b/lib/aeolus_image/model/warehouse_model.rb
deleted file mode 100644
index 2586f6d..0000000
--- a/lib/aeolus_image/model/warehouse_model.rb
+++ /dev/null
@@ -1,162 +0,0 @@
-# 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.
-
-module Aeolus
- module Image
- # require 'warehouse_client'
- include Warehouse
- class BucketObjectNotFound < Exception;end
- class BucketNotFound < Exception;end
-
- class WarehouseModel
-
- def ==(other_obj)
- # If the objects have different instance variables defined, they're definitely not ==
- return false unless instance_variables.sort == other_obj.instance_variables.sort
- # Otherwise, ensure that they're all the same
- instance_variables.each do |iv|
- return false unless other_obj.instance_variable_get(iv) == instance_variable_get(iv)
- end
- # They have the same instance variables and values, so they're equal
- true
- end
-
- class << self
- attr_accessor :warehouse, :bucket, :bucket_name
-
- def set_warehouse_and_bucket
- begin
- @@config ||= load_config
- self.warehouse = Warehouse::Client.new(@@config[:iwhd][:url])
- self.bucket = self.warehouse.bucket(@bucket_name)
- rescue
- raise BucketNotFound
- end
- end
-
- def bucket_objects
- self.set_warehouse_and_bucket if self.bucket.nil?
-
- begin
- self.bucket.objects
- rescue RestClient::ResourceNotFound
- []
- end
- end
-
- def first
- obj = bucket_objects.first
- obj ? self.new(obj.attrs(obj.attr_list)) : nil
- end
-
- def last
- obj = bucket_objects.last
- obj ? self.new(obj.attrs(obj.attr_list)) : nil
- end
-
- def all
- bucket_objects.map do |wh_object|
- self.new(wh_object.attrs(wh_object.attr_list))
- end
- end
-
- def find(uuid)
- self.set_warehouse_and_bucket if self.bucket.nil?
- begin
- if self.bucket.include?(uuid)
- self.new(self.bucket.object(uuid).attrs(self.bucket.object(uuid).attr_list))
- else
- nil
- end
- rescue RestClient::ResourceNotFound
- nil
- end
- end
-
- def where(query_string)
- self.set_warehouse_and_bucket if self.bucket.nil?
- self.warehouse.query(@bucket_name, query_string)
- end
-
- def delete(uuid)
- self.set_warehouse_and_bucket if self.bucket.nil?
- begin
- if self.bucket.include?(uuid)
- self.bucket.object(uuid).delete!
- else
- false
- end
- rescue RestClient::ResourceNotFound
- false
- end
- end
-
- protected
- # Copy over entirely too much code to load the config file
- def load_config
- # TODO - Is this always the case? We should probably have /etc/aeolus-cli or something too?
- # Or allow Rails to override this
- @config_location ||= "~/.aeolus-cli"
- begin
- file_str = read_file(@config_location)
- if is_file?(@config_location) && !file_str.include?(":url")
- lines = File.readlines(File.expand_path((a)config_location)).map do |line|
- "#" + line
- end
- File.open(File.expand_path(@config_location), 'w') do |file|
- file.puts lines
- end
- write_file
- end
- write_file unless is_file?(@config_location)
- YAML::load(File.open(File.expand_path(@config_location)))
- rescue Errno::ENOENT
- #TODO: Create a custom exception to wrap CLI Exceptions
- raise "Unable to locate or write configuration file: \"" + @config_location + "\""
- end
- end
-
- def write_file
- example = File.read(File.expand_path(File.dirname(__FILE__) + "/../../examples/aeolus-cli"))
- File.open(File.expand_path(@config_location), 'a+') do |f|
- f.write(example)
- end
- end
-
- def read_file(path)
- begin
- full_path = File.expand_path(path)
- if is_file?(path)
- File.read(full_path)
- else
- return nil
- end
- rescue
- nil
- end
- end
-
- def is_file?(path)
- full_path = File.expand_path(path)
- if File.exist?(full_path) && !File.directory?(full_path)
- return true
- end
- false
- end
-
- end
-
- end
- end
-end
--
1.7.6.2
12 years, 6 months
[mspevack@fedoraproject.org: Re: Fedora Test AMI]
by Hugh O. Brock
Cloud-init is going into Fedora. I know it's only useful for EC2 at
the moment, but should we be looking at leveraging it?
--Hugh
--
== Hugh Brock, hbrock(a)redhat.com ==
== Engineering Manager, Cloud BU ==
== Aeolus Project: Manage virtual infrastructure across clouds. ==
== http://aeolusproject.org ==
"I know that you believe you understand what you think I said, but I’m
not sure you realize that what you heard is not what I meant."
--Robert McCloskey
12 years, 6 months
[PATCH conductor 0/1] BZ741711 - Fix HWP CPU bug
by Matt Wagner
Wes hit a bug with Hardware Profile matching. It turns out that HardwareProfile.generate_override_property_values was returning the front-end value for HWPs if the provider value was a range. This meant that if you designed a front-end profile with, say, nil CPUs (meaning "no prerefence"), and it matched onto a provider HWP with a range (1-4 for VMware), we'd end up passing the "nil CPUs" parameter to deltacloud when trying to start an instance.
This also adds a test case for this to try to keep us from having so many regressions here.
-- Matt
12 years, 6 months