iiuc, you added a new realm resource_attr, and if the provider returns a realm_id then it will be reflected in the CIMI machine resource, under resource metadata. What I didn't understand is how do you pass this realm id when creating a new machine via CIMI? Also, how can I request for a list of realms? Will it be there when I request for list of realms using the CIMI API? (so that i would know what's the realm_id I wish to create the machine on?)
Thank you, Oved ----- Original Message ----- > From: [email protected] > To: [email protected] > Sent: Friday, January 4, 2013 3:05:16 PM > Subject: [PATCH core] CIMI: Initial implementation of 'attributes' in > ResourceMetadata > > From: Michal Fojtik <[email protected]> > > 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 > > Signed-off-by: Michal fojtik <[email protected]> > --- > 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 deletion(-) > > 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 > 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 > 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 } } > -- > 1.8.0.2 > >
