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
[2/2] git commit: CIMI: Initial implementation of 'attributes' in
ResourceMetadata
Updated Branches:
refs/heads/master 4d4942a91 -> 29a4ad3f2
CIMI: Initial implementation of 'attributes' in ResourceMetadata
Provider can define an extra attributes for each resource. In case
of Deltacloud API we do need provide Consumer a way how to define
the 'realm_id' when creating Machine.
This patch will add 'realm' attribute that hold information about
the 'realm' (eg. where Machine is located).
This patch also add 'machineImage' attribute to Machine that point
client to MachineImage that was used for creating Machine
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/ca903d60
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/ca903d60
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/ca903d60
Branch: refs/heads/master
Commit: ca903d600de4d8ed3c376a8a9a2d10d02d5ed5b4
Parents: 4d4942a
Author: Michal Fojtik <mf...@redhat.com>
Authored: Fri Jan 4 14:00:52 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Mon Jan 7 14:28:26 2013 +0100
----------------------------------------------------------------------
server/lib/cimi/models/machine.rb | 5 +++
server/lib/cimi/models/resource_metadata.rb | 30 +++++++++++++++++++++-
server/lib/cimi/models/schema.rb | 10 +++++++
3 files changed, 44 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ca903d60/server/lib/cimi/models/machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index e9d774b..1b1c77e 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -17,6 +17,9 @@ class CIMI::Model::Machine < CIMI::Model::Base
acts_as_root_entity
+ resource_attr :realm, :required => false
+ resource_attr :machine_image, :required => false, :type => :href
+
text :state
text :cpu
@@ -159,6 +162,8 @@ class CIMI::Model::Machine < CIMI::Model::Base
if context.expand? :volumes
machine_spec[:volumes] = CIMI::Model::MachineVolume.find(instance.id, context, :all)
end
+ machine_spec[:realm] = instance.realm_id if instance.realm_id
+ machine_spec[:machine_image] = { :href => context.machine_image_url(instance.image_id) } if instance.image_id
machine = self.new(machine_spec)
machine
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ca903d60/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 858fcdc..6976515 100644
--- a/server/lib/cimi/models/resource_metadata.rb
+++ b/server/lib/cimi/models/resource_metadata.rb
@@ -81,10 +81,29 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
})
end
+ def self.resource_attributes
+ @resource_attributes ||= {}
+ end
+
+ def self.add_resource_attribute!(klass, name, opts={})
+ resource_attributes[klass.name] ||= {}
+ resource_attributes[klass.name][name] = opts
+ end
+
private
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|
+ {
+ :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'
+ }
+ end
end
def self.rm_capabilities_for(resource_class,context)
@@ -108,6 +127,15 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
[]
end
+ def self.translate_attr_type(type)
+ case type
+ when :href then 'URI'
+ when :text then 'string'
+ when :boolean then 'boolean'
+ else 'text'
+ end
+ end
+
def self.none_defined(metadata)
return true if metadata.capabilities.empty? && metadata.capabilities.empty? && metadata.attributes.empty?
return false
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ca903d60/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index b86fb08..4acd2dc 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -334,6 +334,16 @@ class CIMI::Model::Schema
# Requires that the class into which this is included has a
# +add_attributes!+ method
module DSL
+
+ def resource_attr(name, opts={})
+ CIMI::Model::ResourceMetadata.add_resource_attribute!(self, name, opts)
+ if opts[:type]
+ send(opts[:type], name)
+ else
+ text name
+ end
+ end
+
def href(*args)
opts = args.extract_opts!
args.each { |arg| struct(arg, opts) { scalar :href } }