You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/10/23 13:25:34 UTC
git commit: CIMI: Fixed bug when instance does not have storage
defined (DTACLOUD-350)
Updated Branches:
refs/heads/master 8116e6a35 -> e830868d4
CIMI: Fixed bug when instance does not have storage defined (DTACLOUD-350)
* This patch will fix the bug above and also make sure that the 'disks' are
reported correctly for instances:
1. Check if instance hardware profiles contains :storage override
2. If no, then use the hardware_profile storage default value
3. If hardware_profile don't have any storage defined, display empty
collection.
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/e830868d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/e830868d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/e830868d
Branch: refs/heads/master
Commit: e830868d40e111277c38ed8db0be5133355ea1a6
Parents: 8116e6a
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon Oct 22 16:10:51 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue Oct 23 13:25:15 2012 +0200
----------------------------------------------------------------------
server/lib/cimi/collections/machines.rb | 2 +-
server/lib/cimi/models.rb | 2 +-
server/lib/cimi/models/disk.rb | 49 +++++++++++++----
server/lib/deltacloud/models/instance_profile.rb | 4 ++
4 files changed, 45 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e830868d/server/lib/cimi/collections/machines.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb
index a1d060a..5390140 100644
--- a/server/lib/cimi/collections/machines.rb
+++ b/server/lib/cimi/collections/machines.rb
@@ -123,7 +123,7 @@ module CIMI::Collections
description "Retrieve the Machine's DiskCollection"
param :id, :string, :required
control do
- disks = DiskCollection.default(params[:id], self)
+ disks = CIMI::Model::Disk.collection_for_instance(params[:id], self)
respond_to do |format|
format.json {disks.to_json}
format.xml {disks.to_xml}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e830868d/server/lib/cimi/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index 1eae2c9..3f5dace 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -24,8 +24,8 @@ require_relative './models/base'
require_relative './models/collection'
require_relative './models/errors'
require_relative './models/action'
-require_relative './models/disk'
require_relative './models/machine_volume'
+require_relative './models/disk'
# Toplevel entities; order matters as it determines the order
# in which the entities appear in the CEP
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e830868d/server/lib/cimi/models/disk.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/disk.rb b/server/lib/cimi/models/disk.rb
index d74ec54..b069207 100644
--- a/server/lib/cimi/models/disk.rb
+++ b/server/lib/cimi/models/disk.rb
@@ -24,17 +24,46 @@ class CIMI::Model::Disk < CIMI::Model::Base
def self.find(instance, machine_config, context, id=:all)
if id == :all
- storage_override = instance.instance_profile.overrides.find { |p, v| p == :storage }
- capacity = storage_override.nil? ? machine_config.disks[0][:capacity] : context.to_kibibyte(storage_override[1].to_i, "MB")
- name = instance.id+"_disk_#{capacity}" #assuming one disk for now...
- [ self.new(
- :id => context.machine_url(instance.id)+"/disks/#{name}",
- :name => name,
- :description => "DiskCollection for Machine #{instance.id}",
- :created => instance.launch_time,
- :capacity => capacity
- ) ]
+ return machine_config.disks if machine_config
+
+ capacity = false
+
+ if instance
+ if instance.instance_profile.override? :storage
+ capacity = context.to_kibibyte(instance.instance_profile.storage, 'MB')
+ else
+ hw_profile = context.driver.hardware_profile(context.credentials, :id => instance.instance_profile.name)
+ if hw_profile.storage
+ capacity = context.to_kibibyte(hw_profile.storage.value, 'MB')
+ end
+ end
+
+ return [] unless capacity
+
+ name = instance.id+"_disk_#{capacity}" #assuming one disk for now...
+
+ [self.new(
+ :id => context.machine_url(instance.id)+"/disks/#{name}",
+ :name => name,
+ :description => "Disk for Machine #{instance.id}",
+ :created => instance.launch_time,
+ :capacity => capacity
+ )]
+ end
else
end
end
+
+ def self.collection_for_instance(instance_id, context)
+ instance = context.driver.instance(context.credentials, :id => instance_id)
+ disks = find(instance, nil, context)
+ CIMI::Model::DiskCollection.new(
+ :id => context.url("/machines/#{instance_id}/disks"),
+ :name => 'default',
+ :count => disks.size,
+ :description => "Disk collection for Machine #{instance_id}",
+ :entries => disks
+ )
+ end
+
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e830868d/server/lib/deltacloud/models/instance_profile.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/instance_profile.rb b/server/lib/deltacloud/models/instance_profile.rb
index ccd1d67..3ecaf5d 100644
--- a/server/lib/deltacloud/models/instance_profile.rb
+++ b/server/lib/deltacloud/models/instance_profile.rb
@@ -40,6 +40,10 @@ class InstanceProfile < BaseModel
name
end
+ def override?(property)
+ overrides.find { |p, v| p == property }
+ end
+
def overrides
[:memory, :storage, :architecture, :cpu].inject({}) do |h, p|
if v = instance_variable_get("@#{p}")