You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/12/19 14:30:22 UTC
Rev2 CIMI ResourceMetadata capabilities
Revision 2 of initial resourceMetadata implementation - gets rid of
edits/changes to volume_templates (no longer necessary here),
fixes typeURI and (possibly) fixes the way values for capability are
specified.
Patches tracked at http://tracker.deltacloud.org/set/213
(I self.nacked set 212 which was rev1)
curl -H "Accept: application/xml" http://localhost:3001/cimi/resource_metadata
XML looks like:
<Collection xmlns="http://schemas.dmtf.org/cimi/1" resourceURI="http://schemas.dmtf.org/cimi/1/ResourceMetadataCollection">
<id>http://localhost:3001/cimi/resource_metadata</id>
<count>1</count>
<ResourceMetadata>
<id>http://localhost:3001/cimi/resource_metadata/machine</id>
<name>Machine</name>
<typeUri>http://schemas.dmtf.org/cimi/1/Machine</typeUri>
<capability name="DefaultInitialState" uri="http://schemas.dmtf.org/cimi/1/capability/Machine/DefaultInitialState" description="Indicates what the default initial state of a new Machine ">STARTED</capability>
<capability name="InitialStates" uri="http://schemas.dmtf.org/cimi/1/capability/Machine/InitialStates" description="Indicates the list of allowable initial states">STARTED,STOPPED</capability>
</ResourceMetadata>
</Collection>
JSON looks like:
{
"id": "http://localhost:3001/cimi/resource_metadata",
"count": 1,
"resourceMetadata": [
{
"id": "http://localhost:3001/cimi/resource_metadata/machine",
"name": "Machine",
"typeUri": "http://schemas.dmtf.org/cimi/1/Machine",
"capabilities": [
{
"name": "DefaultInitialState",
"uri": "http://schemas.dmtf.org/cimi/1/capability/Machine/DefaultInitialState",
"description": "Indicates what the default initial state of a new Machine ",
"value": "STARTED"
},
{
"name": "InitialStates",
"uri": "http://schemas.dmtf.org/cimi/1/capability/Machine/InitialStates",
"description": "Indicates the list of allowable initial states",
"value": "STARTED,STOPPED"
}
]
}
],
"resourceURI": "http://schemas.dmtf.org/cimi/1/ResourceMetadataCollection"
}
marios
[PATCH 2/2] CIMI: Initial implementation of resource_metadata (capabilities) for Machine
Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/collections/resource_metadata.rb | 2 +-
server/lib/cimi/models/machine.rb | 9 ---
server/lib/cimi/models/resource_metadata.rb | 89 ++++++++++++++++-------
server/lib/deltacloud/drivers/mock/mock_driver.rb | 9 +++
4 files changed, 71 insertions(+), 38 deletions(-)
diff --git a/server/lib/cimi/collections/resource_metadata.rb b/server/lib/cimi/collections/resource_metadata.rb
index edd8d65..54de02a 100644
--- a/server/lib/cimi/collections/resource_metadata.rb
+++ b/server/lib/cimi/collections/resource_metadata.rb
@@ -32,7 +32,7 @@ module CIMI::Collections
operation :show do
description "Get the resource metadata for a specific collection"
control do
- resource_metadata = ResourceMetadata.find(params[:id], self)
+ resource_metadata = CIMI::Model::ResourceMetadata.find(params[:id], self)
respond_to do |format|
format.xml{resource_metadata.to_xml}
format.json{resource_metadata.to_json}
diff --git a/server/lib/cimi/models/machine.rb b/server/lib/cimi/models/machine.rb
index 53bdd37..e9d774b 100644
--- a/server/lib/cimi/models/machine.rb
+++ b/server/lib/cimi/models/machine.rb
@@ -116,15 +116,6 @@ class CIMI::Model::Machine < CIMI::Model::Base
context.driver.destroy_instance(context.credentials, id)
end
- def self.create_resource_metadata(context)
- cimi_resource = self.name.split("::").last
- metadata = CIMI::Model::ResourceMetadata.metadata_from_deltacloud_features(cimi_resource, :instances, context)
- unless metadata.includes_attribute?(:name)
- metadata.attributes << {:name=>"name", :required=>"false",
- :constraints=>"Determined by the cloud provider", :type=>"xs:string"}
- end
- metadata
- end
#returns the newly attach machine_volume
def self.attach_volume(volume, location, context)
context.driver.attach_storage_volume(context.credentials,
diff --git a/server/lib/cimi/models/resource_metadata.rb b/server/lib/cimi/models/resource_metadata.rb
index 5e62061..a87953b 100644
--- a/server/lib/cimi/models/resource_metadata.rb
+++ b/server/lib/cimi/models/resource_metadata.rb
@@ -16,8 +16,12 @@
class CIMI::Model::ResourceMetadata < CIMI::Model::Base
+ SCHEMA_CAPABILITY_BASE_URI = "http://schemas.dmtf.org/cimi/1/capability"
+
acts_as_root_entity
+ text :name
+
text :type_uri
array :attributes do
@@ -25,10 +29,20 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
scalar :namespace
scalar :type
scalar :required
- scalar :constraints
+ array :constraints do
+ text :value
+ end
end
- array :operations do
+ array :capabilities do
+ scalar :name
+ scalar :uri
+ scalar :description
+ scalar :value, :text => :direct
+ end
+
+
+ array :actions do
scalar :name
scalar :uri
scalar :description
@@ -37,49 +51,68 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
scalar :output_message
end
+ array :operations do
+ scalar :rel, :href
+ end
+
def self.find(id, context)
- resource_metadata = []
if id == :all
+ resource_metadata = []
CIMI::Model.root_entities.each do |resource_class|
- resource_metadata << resource_class.create_resource_metadata(context) if resource_class.respond_to?(:create_resource_metadata)
+ meta = resource_metadata_for(resource_class, context)
+ resource_metadata << meta unless none_defined(meta)
end
return resource_metadata
else
resource_class = CIMI::Model.const_get("#{id.camelize}")
- if resource_class.respond_to?(:create_resource_metadata)
- resource_class.create_resource_metadata(context)
- end
+ resource_metadata_for(resource_class, context)
end
end
- def self.metadata_from_deltacloud_features(cimi_resource, dcloud_resource, context)
- deltacloud_features = context.driver.class.features[dcloud_resource]
- metadata_attributes = deltacloud_features.map{|f| attributes_from_feature(f)}
- from_feature(cimi_resource, context, metadata_attributes.flatten!)
- end
-
- def includes_attribute?(attribute)
- self.attributes.any?{|attr| attr[:name] == attribute}
+ def self.resource_metadata_for(resource_class, context)
+ attributes = rm_attributes_for(resource_class, context)
+ capabilities = rm_capabilities_for(resource_class, context)
+ actions = rm_actions_for(resource_class, context)
+ cimi_resource = resource_class.name.split("::").last
+ self.new({ :id => context.resource_metadata_url(cimi_resource.underscore),
+ :name => cimi_resource,
+ :type_uri => resource_class.resource_uri,
+ :attributes => attributes,
+ :capabilities => capabilities,
+ :actions => actions
+ })
end
private
- def self.attributes_from_feature(feature)
- feature = CIMI::FakeCollection.feature(feature)
- feature.operations.first.params_array.map do |p|
- {
- :name=> p.name,
- :type=> "xs:string",
- :required=> p.required? ? "true" : "false",
- :constraints=> (feature.constraints.empty? ? (feature.description.nil? ? "" : feature.description): feature.constraints)
- }
+ def self.rm_attributes_for(resource_class, context)
+ []
+ end
+
+ def self.rm_capabilities_for(resource_class,context)
+ cimi_object = resource_class.name.split("::").last.underscore.pluralize.to_sym
+ capabilities = (context.driver.class.features[cimi_object] || []).inject([]) do |res, cur|
+ feat = CIMI::FakeCollection.feature(cur)
+ values = (context.driver.class.constraints[cimi_object][feat.name][:values] || []).inject([]) do |vals, val|
+ vals << val
+ vals
+ end
+ res << {:name => feat.name.to_s.camelize,
+ :uri => CMWG_NAMESPACE+"/capability/#{cimi_object.to_s.camelize.singularize}/#{feat.name.to_s.camelize}",
+ :description => feat.description,
+ :value => values.join(",") }
+ res
end
+#cimi_resource.underscore.pluralize.to_sym
+ end
+
+ def self.rm_actions_for(resource_class, context)
+ []
end
- def self.from_feature(cimi_resource, context, metadata_attributes)
- self.new(:name => cimi_resource, :uri=>"#{context.resource_metadata_url}/#{cimi_resource.underscore}",
- :type_uri=> context.send("#{cimi_resource.pluralize.underscore}_url"),
- :attributes => metadata_attributes)
+ def self.none_defined(metadata)
+ return true if metadata.capabilities.empty? && metadata.capabilities.empty? && metadata.attributes.empty?
+ return false
end
end
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 111196f..38cb042 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -84,6 +84,15 @@ module Deltacloud::Drivers::Mock
feature :images, :user_name
feature :images, :user_description
+ #cimi features
+ feature :machines, :default_initial_state do
+ { :values => ["STARTED"] }
+ end
+ feature :machines, :initial_states do
+ { :values => ["STARTED", "STOPPED"]}
+ end
+
+
def initialize
if ENV["DELTACLOUD_MOCK_STORAGE"]
storage_root = ENV["DELTACLOUD_MOCK_STORAGE"]
--
1.7.11.7
Re: Rev2 CIMI ResourceMetadata capabilities
Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2012-12-19 at 15:30 +0200, marios@redhat.com wrote:
> Revision 2 of initial resourceMetadata implementation - gets rid of
> edits/changes to volume_templates (no longer necessary here),
> fixes typeURI and (possibly) fixes the way values for capability are
> specified.
>
> Patches tracked at http://tracker.deltacloud.org/set/213
> (I self.nacked set 212 which was rev1)
>
> curl -H "Accept: application/xml" http://localhost:3001/cimi/resource_metadata
ACK
[PATCH 1/2] CIMI: Add CIMI Features (Sinatra rabbit features DSL)
Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/helpers.rb | 3 +-
server/lib/deltacloud/drivers/base_driver.rb | 2 +-
server/lib/deltacloud/drivers/cimi_features.rb | 42 ++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 2 deletions(-)
create mode 100644 server/lib/deltacloud/drivers/cimi_features.rb
diff --git a/server/lib/cimi/helpers.rb b/server/lib/cimi/helpers.rb
index ea71cbf..75f9770 100644
--- a/server/lib/cimi/helpers.rb
+++ b/server/lib/cimi/helpers.rb
@@ -14,12 +14,13 @@
# under the License.
require_relative '../deltacloud/drivers/features'
-
+require_relative '../deltacloud/drivers/cimi_features'
module CIMI
module Model; end
class FakeCollection
extend Sinatra::Rabbit::Features
include Deltacloud::Features
+ include CIMI::Features
end
end
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index c63f94f..f488f91 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -19,6 +19,7 @@ module Deltacloud
require_relative '../core_ext.rb'
require_relative './exceptions.rb'
require_relative './features.rb'
+ require_relative './cimi_features.rb'
require_relative '../models/state_machine.rb'
class BaseDriver
@@ -38,7 +39,6 @@ module Deltacloud
@features ||= {}
end
-
def self.feature(collection, feature_name)
return if has_feature?(collection, feature_name)
constraints[collection] ||= {}
diff --git a/server/lib/deltacloud/drivers/cimi_features.rb b/server/lib/deltacloud/drivers/cimi_features.rb
new file mode 100644
index 0000000..2cea9d7
--- /dev/null
+++ b/server/lib/deltacloud/drivers/cimi_features.rb
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+module CIMI
+ module Features
+
+ def self.included(k)
+ current_features = features
+ k.instance_eval do
+ features(¤t_features)
+ end
+ end
+
+ def self.features(&block)
+ block_given? ? @features = block : @features || Proc.new{}
+ end
+
+
+ features do
+ feature :default_initial_state, :for => :machines do
+ description "Indicates what the default initial state of a new Machine "
+ end
+
+ feature :initial_states, :for => :machines do
+ description "Indicates the list of allowable initial states"
+ end
+
+ end
+ end
+end
--
1.7.11.7