----- Original Message ----- > From: "Michal Fojtik" <[email protected]> > To: "[email protected]" <[email protected]> > Cc: [email protected], "Oved Ourfalli" <[email protected]> > Sent: Monday, January 7, 2013 2:10:06 PM > Subject: Re: [PATCH core] CIMI: Initial implementation of 'attributes' in > ResourceMetadata > > On 01/07, [email protected] wrote: > > On 06/01/13 14:47, Oved Ourfalli wrote: > > > Thank you for the quick response! > > > Today some drivers support the "realms" function, so I guess it > > > should be somehow connected to the resource metadata. > > > (Don't know if that's what you meant by "attribute constraints") > > > > > > > Resource Metadata has 'capabilities', 'attributes' and 'actions'. > > In > > this case we are looking at 'attributes'. > > > > Each 'attribute' advertised via the ResourceMetadata has name, > > namespace, type and required attributes. This is what Michal's > > patch > > does for the Machine ResourceMetadata resource: > > > > e.g. GET /cimi/resource_metadata/machine : > > > > <ResourceMetadata xmlns="http://schemas.dmtf.org/cimi/1" > > resourceURI="http://schemas.dmtf.org/cimi/1/ResourceMetadata"> > > <id>http://localhost:3001/cimi/resource_metadata/machine</id> > > <name>Machine</name> > > <typeUri>http://schemas.dmtf.org/cimi/1/Machine</typeUri> > > <attribute name="realm" > > namespace="http://deltacloud.org/cimi/Machine/realm" type="text" > > required="false" /> > > > > ... > > > > > > The CIMI spec definition of ResourceMetadata also allows for > > 'constraints'. As Michal suggests this is how we should advertise > > the > > 'allowable values' for a given attribute, in this case realm: > > > > <attribute name="realm" > > namespace="http://deltacloud.org/cimi/Machine/realm" type="text" > > required="false"> > > <value>EU</value> > > <value>US</value> > > </attribute> > > Thanks for explaining this Marios. Actually I think advertising > 'realms' > and propably other attributes (API_PROVIDER, etc) here is good idea, > since > they are indeed 'constraints'. > Thank you both for the detailed explanation. The question is, can this list of possible values by dynamic? In oVirt, realms are the oVirt clusters, and they aren't predefined, so one can use whatever name he wants. That's why I think that the list of possible realms should come from the driver.
Will that be possible? > > > > > > marios > > > > > > > > > Oved > > > > > > > > > ----- Original Message ----- > > >> From: "Michal Fojtik" <[email protected]> > > >> To: [email protected] > > >> Sent: Sunday, January 6, 2013 2:38:48 PM > > >> Subject: Re: [PATCH core] CIMI: Initial implementation of > > >> 'attributes' in ResourceMetadata > > >> > > >> When creating a new Machine, you can pass 'realm' like this: > > >> > > >> <MachineCreate> > > >> .... > > >> <realm>us</realm> > > >> </MachineCreate> > > >> > > >> Currently I have no answer how to get list of possible realms. > > >> They > > >> could > > >> be probably advertised in resourceMetada as 'realm' attribute > > >> constrains. > > >> > > >> > > >> On Sun, Jan 6, 2013 at 1:35 PM, Oved Ourfalli <[email protected]> > > >> wrote: > > >> > > >>> 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 > > >>>> > > >>>> > > >>> > > >> > > >> > > >> > > >> -- > > >> ----------------------------------------------- > > >> Michal Fojtik <[email protected]> > > >> Enthusiastic Ruby programmer. > > >> > > > > -- > Michal Fojtik <[email protected]> > Deltacloud API, CloudForms >
