Return-Path: X-Original-To: apmail-deltacloud-commits-archive@www.apache.org Delivered-To: apmail-deltacloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EEC409806 for ; Fri, 1 Mar 2013 09:38:06 +0000 (UTC) Received: (qmail 92912 invoked by uid 500); 1 Mar 2013 09:38:06 -0000 Delivered-To: apmail-deltacloud-commits-archive@deltacloud.apache.org Received: (qmail 92852 invoked by uid 500); 1 Mar 2013 09:38:06 -0000 Mailing-List: contact commits-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list commits@deltacloud.apache.org Received: (qmail 92813 invoked by uid 99); 1 Mar 2013 09:38:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 09:38:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 811631C70F; Fri, 1 Mar 2013 09:38:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mfojtik@apache.org To: commits@deltacloud.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/3] git commit: CIMI: Added VolumeImageCreate model Message-Id: <20130301093805.811631C70F@tyr.zones.apache.org> Date: Fri, 1 Mar 2013 09:38:05 +0000 (UTC) CIMI: Added VolumeImageCreate model Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/99a1198e Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/99a1198e Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/99a1198e Branch: refs/heads/master Commit: 99a1198e9ffb615d97117853129487f1aed20fce Parents: 246e621 Author: Michal Fojtik Authored: Wed Feb 27 15:25:34 2013 +0100 Committer: Michal fojtik Committed: Fri Mar 1 10:36:40 2013 +0100 ---------------------------------------------------------------------- server/lib/cimi/collections/volume_images.rb | 3 +- server/lib/cimi/models.rb | 1 + server/lib/cimi/models/volume_image.rb | 25 +++------- server/lib/cimi/models/volume_image_create.rb | 47 ++++++++++++++++++++ server/support/cimi/volume_image.xml | 7 +++ 5 files changed, 65 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99a1198e/server/lib/cimi/collections/volume_images.rb ---------------------------------------------------------------------- diff --git a/server/lib/cimi/collections/volume_images.rb b/server/lib/cimi/collections/volume_images.rb index 708f2f1..1596e2d 100644 --- a/server/lib/cimi/collections/volume_images.rb +++ b/server/lib/cimi/collections/volume_images.rb @@ -46,7 +46,8 @@ module CIMI::Collections operation :create, :with_capability => :create_storage_snapshot do description "Create a new volume image." control do - volume_image = CIMI::Model::VolumeImage.create(request.body, self) + img = CIMI::Model::VolumeImageCreate.parse(request.body, request.content_type) + volume_image = img.create(self) headers_for_create volume_image respond_to do |format| format.xml { volume_image.to_xml } http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99a1198e/server/lib/cimi/models.rb ---------------------------------------------------------------------- diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb index b41cb8f..2f7e158 100644 --- a/server/lib/cimi/models.rb +++ b/server/lib/cimi/models.rb @@ -68,6 +68,7 @@ require_relative './models/volume_configuration' require_relative './models/volume_image' require_relative './models/volume_template' require_relative './models/volume_create' +require_relative './models/volume_image_create' require_relative './models/machine' require_relative './models/machine_configuration' require_relative './models/machine_image' http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99a1198e/server/lib/cimi/models/volume_image.rb ---------------------------------------------------------------------- diff --git a/server/lib/cimi/models/volume_image.rb b/server/lib/cimi/models/volume_image.rb index 4858ad8..ef06552 100644 --- a/server/lib/cimi/models/volume_image.rb +++ b/server/lib/cimi/models/volume_image.rb @@ -20,6 +20,7 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base href :image_location text :image_data text :bootable + array :operations do scalar :rel, :href end @@ -38,29 +39,19 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base def self.all(context); find(:all, context); end - def self.create(request_body, context) - type = context.current_content_type - input = (type == :xml)? XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body.read) - params = {:volume_id => context.href_id(input["imageLocation"]["href"], :volumes), :name=>input["name"], :description=>input["description"]} - vol_image = context.driver.create_storage_snapshot(context.credentials, params) - from_storage_snapshot(vol_image, context) - end - def self.delete!(vol_image_id, context) context.driver.destroy_storage_snapshot(context.credentials, {:id=>vol_image_id}) end - private - def self.from_storage_snapshot(snapshot, context) self.new( { - :name => snapshot.name || snapshot.id, - :description => snapshot.description || snapshot.id, - :created => snapshot.created.nil? ? nil : Time.parse(snapshot.created).xmlschema, - :id => context.volume_image_url(snapshot.id), - :image_location => {:href=>context.volume_url(snapshot.storage_volume_id)}, - :bootable => "false" #FIXME - } ) + :name => snapshot.name, + :description => snapshot.description, + :created => snapshot.created.nil? ? nil : Time.parse(snapshot.created).xmlschema, + :id => context.volume_image_url(snapshot.id), + :image_location => {:href=>context.volume_url(snapshot.storage_volume_id)}, + :bootable => "false" #FIXME + } ) end end http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99a1198e/server/lib/cimi/models/volume_image_create.rb ---------------------------------------------------------------------- diff --git a/server/lib/cimi/models/volume_image_create.rb b/server/lib/cimi/models/volume_image_create.rb new file mode 100644 index 0000000..f953146 --- /dev/null +++ b/server/lib/cimi/models/volume_image_create.rb @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +class CIMI::Model::VolumeImageCreate < CIMI::Model::Base + + href :image_location + text :image_data + text :bootable, :required => true + + def create(context) + validate! + + params = { + :volume_id => context.href_id(image_location.href, :volumes), + :name => name, + :description => description + } + + unless context.driver.respond_to? :create_storage_snapshot + raise Deltacloud::Exceptions.exception_from_status( + 501, + 'Creating VolumeImage is not supported by the current driver' + ) + end + + new_snapshot = context.driver.create_storage_snapshot(context.credentials, params) + result = CIMI::Model::VolumeImage.from_storage_snapshot(new_snapshot, context) + result.name= name unless new_snapshot.name + result.description = description unless new_snapshot.description + result.property = property if property + result.save + result + end + +end http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99a1198e/server/support/cimi/volume_image.xml ---------------------------------------------------------------------- diff --git a/server/support/cimi/volume_image.xml b/server/support/cimi/volume_image.xml new file mode 100644 index 0000000..b89f1e5 --- /dev/null +++ b/server/support/cimi/volume_image.xml @@ -0,0 +1,7 @@ + + myVolumeImage + My very first VolumeImage + + false + bar +