[PATCH aeolus-image-rubygem 4/4] Create an Aeolus::Image.import method
Tomas Sedovic
tsedovic at redhat.com
Fri Dec 16 13:35:04 UTC 2011
On 12/15/2011 07:58 PM, Matt Wagner wrote:
> It belongs to neither Warehouse or Factory, but references both,
> so using the top-level makes the most sense here.
> ---
> lib/aeolus_image.rb | 2 ++
> lib/aeolus_image/import.rb | 35 +++++++++++++++++++++++++++++++++++
> 2 files changed, 37 insertions(+), 0 deletions(-)
> create mode 100644 lib/aeolus_image/import.rb
>
> diff --git a/lib/aeolus_image.rb b/lib/aeolus_image.rb
> index 6f9b0a0..6d428f8 100644
> --- a/lib/aeolus_image.rb
> +++ b/lib/aeolus_image.rb
> @@ -31,3 +31,5 @@ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'provide
> require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'target_image')
> require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'builder')
> require File.join(File.dirname(__FILE__), 'aeolus_image', 'active_resource_oauth_client')
> +
> +require File.join(File.dirname(__FILE__), 'aeolus_image', 'import')
> diff --git a/lib/aeolus_image/import.rb b/lib/aeolus_image/import.rb
> new file mode 100644
> index 0000000..fe0ce22
> --- /dev/null
> +++ b/lib/aeolus_image/import.rb
> @@ -0,0 +1,35 @@
> +# 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
> + def self.import(provider_name, deltacloud_driver, image_id, account_id, xml=nil)
> + xml ||= "<image><name>#{image_id}</name></image>"
> + image = Factory::Image.new(
> + :target_name => deltacloud_driver,
> + :provider_name => provider_name,
> + :target_identifier => image_id,
> + :image_descriptor => xml
> + )
> + image.save!
> + # Set the provider_account_id on the image
> + iwhd_image = Warehouse::Image.find(image.id)
> + # Set the account on the provider image
> + # This assumes (as is currently correct) that there will only be one provider image for imported images
> + pimg = iwhd_image.provider_images.first
> + pimg.set_attr('provider_account_identifier', account_id)
> + image
> + end
> + end
> +end
ACK to the series.
Thomas
--
No trees were killed to send this message, but a large number of
electrons were terribly inconvenienced.
More information about the aeolus-devel
mailing list