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 2013/01/07 14:51:20 UTC
[1/2] git commit: CIMI: Added 'constraints' to resourceMetadata
attributes for realms
CIMI: Added 'constraints' to resourceMetadata attributes for realms
Currently there is now way how to advertise available 'realms to
the client. This patch will make it possible through 'constraints'
defined for the 'realm' resourceMetadata atrribute defined for
the Machine resource.
This will allow to pass ':constraints' option to 'resource_attr' like:
resource_attr :realm, :required => false,
:constraints => lambda { |c| c.driver.realms(c.credentials).map { |r| r.id } }
The 'lamda' function must always return 'array' of possible values.
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/29a4ad3f
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/29a4ad3f
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/29a4ad3f
Branch: refs/heads/master
Commit: 29a4ad3f242e634545ae78cf60c7aaeab037860d
Parents: ca903d6
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon Jan 7 13:54:42 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Mon Jan 7 14:28:26 2013 +0100
----------------------------------------------------------------------
server/lib/cimi/models/machine.rb | 4 +++-
server/lib/cimi/models/resource_metadata.rb | 8 +++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/29a4ad3f/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 1b1c77e..7ac8f83 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -17,7 +17,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
acts_as_root_entity
- resource_attr :realm, :required => false
+ resource_attr :realm, :required => false,
+ :constraints => lambda { |c| c.driver.realms(c.credentials).map { |r| r.id } }
+
resource_attr :machine_image, :required => false, :type => :href
text :state
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/29a4ad3f/server/lib/cimi/models/resource_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/resource_metadata.rb b/server/lib/cimi/models/resource_metadata.rb
index 6976515..30e65d6 100644
--- a/server/lib/cimi/models/resource_metadata.rb
+++ b/server/lib/cimi/models/resource_metadata.rb
@@ -95,13 +95,19 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
def self.rm_attributes_for(resource_class, context)
return [] if resource_attributes[resource_class.name].nil?
resource_attributes[resource_class.name].map do |attr_name, attr_def|
+ if attr_def.has_key? :constraints
+ constraints = attr_def[:constraints].call(context)
+ else
+ constraints = []
+ end
{
:name => attr_name.to_s,
# TODO: We need to make this URI return description of this 'non-CIMI'
# attribute
:namespace => "http://deltacloud.org/cimi/#{resource_class.name.split('::').last}/#{attr_name}",
:type => translate_attr_type(attr_def[:type]),
- :required => attr_def[:required] ? 'true' : 'false'
+ :required => attr_def[:required] ? 'true' : 'false',
+ :constraints => constraints.map { |v| { :value => v }}
}
end
end