You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/30 13:01:22 UTC
[PATCH core 1/2] CIMI: Removed obsoleted helpers. Consolidated dependencies.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/dependencies.rb | 62 +++++++++++
server/lib/cimi/helpers/cmwgapp_helper.rb | 166 -----------------------------
server/lib/cimi/helpers/dmtfdep.rb | 64 -----------
server/lib/cimi/server.rb | 13 +--
4 files changed, 65 insertions(+), 240 deletions(-)
create mode 100644 server/lib/cimi/dependencies.rb
delete mode 100644 server/lib/cimi/helpers/cmwgapp_helper.rb
delete mode 100644 server/lib/cimi/helpers/dmtfdep.rb
diff --git a/server/lib/cimi/dependencies.rb b/server/lib/cimi/dependencies.rb
new file mode 100644
index 0000000..372f389
--- /dev/null
+++ b/server/lib/cimi/dependencies.rb
@@ -0,0 +1,62 @@
+#
+# 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.
+
+#this file defines all the required components for dmtf implementation.
+#if new dependencies are needed, please make changes to this file.
+
+require 'sinatra'
+require 'deltacloud/drivers'
+require 'deltacloud/core_ext'
+require 'deltacloud/base_driver'
+require 'deltacloud/hardware_profile'
+require 'deltacloud/state_machine'
+require 'deltacloud/helpers'
+require 'deltacloud/models/base_model'
+require 'deltacloud/models/realm'
+require 'deltacloud/models/image'
+require 'deltacloud/models/instance'
+require 'deltacloud/models/key'
+require 'deltacloud/models/address'
+require 'deltacloud/models/instance_profile'
+require 'deltacloud/models/storage_snapshot'
+require 'deltacloud/models/storage_volume'
+require 'deltacloud/models/bucket'
+require 'deltacloud/models/blob'
+require 'deltacloud/models/load_balancer'
+require 'deltacloud/models/firewall'
+require 'deltacloud/models/firewall_rule'
+
+require 'json'
+require 'sinatra/rack_accept'
+require 'sinatra/static_assets'
+require 'sinatra/rabbit'
+require 'sinatra/lazy_auth'
+require 'erb'
+require 'haml'
+require 'open3'
+require 'uuidtools'
+require 'xmlsimple'
+require 'benchmark'
+require 'deltacloud/helpers/blob_stream'
+require 'sinatra/rack_driver_select'
+require 'sinatra/rack_runtime'
+require 'sinatra/rack_etag'
+require 'sinatra/rack_date'
+require 'sinatra/rack_matrix_params'
+require 'sinatra/rack_syslog'
+require 'sinatra/sinatra_verbose'
+
+CMWG_NAMESPACE = "http://www.dmtf.org/cimi"
diff --git a/server/lib/cimi/helpers/cmwgapp_helper.rb b/server/lib/cimi/helpers/cmwgapp_helper.rb
deleted file mode 100644
index 3ab42ac..0000000
--- a/server/lib/cimi/helpers/cmwgapp_helper.rb
+++ /dev/null
@@ -1,166 +0,0 @@
-# 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.
-
-# Methods added to this helper will be available to all templates in the application.
-
-# this section defines constants used in the implementation.
-
-#this method is to fixup the hash object to make sure it can be serialized into json
-#as DMTF spec requires. as the spec keeps changing, this method may need to be revisited
-#and modified again.
-def fixup_content(hash_obj, key_name="content", attr_name="name")
- #this check is to make sure we are not handling nil values.
- if hash_obj
- hash_obj.each_pair do |key, value|
- if value.kind_of? Hash
- #We can only handle the element without any other attribute,
- #if the element also has other attribute, then we can not do fixups since it will lose information.
- if value[key_name] && value.size == 1
- hash_obj[key] = value[key_name]
- elsif value[key_name] && value[attr_name] && value.size == 2
- hash_obj[key] = { "#{value[attr_name]}" => value[key_name] }
- else
- fixup_content value, key_name, attr_name
- end
- end
- end
- end
-end
-
-module ApplicationHelper
-
- include Deltacloud
-
- def bread_crumb_ext
- s = "<ul class='breadcrumb'><li class='first'><a href='#{settings.root_url}'>δ home</a></li>"
- s+="<li class='docs'>#{link_to_documentation}</li>"
- s+="</ul>"
- end
-
- def respond_to_collection(collType)
- respond_to do |format|
- format.html do
- root_hash = XmlSimple.xml_in(File.join(STOREROOT, 'collections/' + collType),
- { 'ForceArray' => false, 'KeepRoot'=>true, 'KeyAttr' => ['name']})
-
- @xml_root_node = root_hash.first[0]
- @dmtfitem = root_hash.first[1]
- haml :"collection/index"
- end
- format.xml do
- root_hash = XmlSimple.xml_in(File.join(STOREROOT, 'collections/' + collType),
- { 'ForceArray' => true, 'KeepRoot'=>true, 'KeyAttr' => ['name']})
- col_item_name = root_hash.first[0]
- content_type get_response_content_type(col_item_name, 'xml'), :charset => 'utf-8'
- col_item_name = col_item_name.sub(/Collection/,'') #Remove the Collection at the end.
- col_item_name = col_item_name[0].downcase + col_item_name[1, col_item_name.length]
-
- urls = []
- @dmtf_col_items.map do |item|
- urls << {"href" => item["href"]}
- end
-
- root_hash.first[1][0]["#{col_item_name}"] = urls
-
- XmlSimple.xml_out(root_hash, { 'KeyAttr' => 'name', 'KeepRoot' => true, 'ContentKey' => 'content'})
- end
- format.json do
- root_hash = XmlSimple.xml_in(File.join(STOREROOT, 'collections/' + collType),
- { 'ForceArray' => false, 'KeepRoot'=>true, 'KeyAttr' => ['name']})
- col_item_name = root_hash.first[0]
- content_type get_response_content_type(col_item_name, 'json'), :charset => 'utf-8'
- #Remove the Collection at the end.
- col_item_name = col_item_name.sub(/Collection/,'')
- col_item_name = col_item_name[0].downcase + col_item_name[1, col_item_name.length]
-
- urls = []
- @dmtf_col_items.map do |item|
- urls << {"href" => item["href"]}
- end
-
- root_hash.first[1]["#{col_item_name}"] = urls
-
- json_hash = root_hash.first[1]
- if json_hash.has_key?("xmlns")
- json_hash.delete "xmlns"
- end
- fixup_content json_hash
- res = json_hash.to_json
- end
- end
- end
-
- def get_response_content_type(coll_type, format="html")
- case format
- when "text/html"
- ""
- when "xml"
- "application/CIMI-" + coll_type + "+xml"
- when "json"
- "application/CIMI-" + coll_type + "+json"
- end
- end
-
- def get_resource_default(coll_type)
- file_path = File.join STOREROOT, "default_res/" + coll_type + ".col.xml"
- if File.exist?(file_path)
- root_hash = XmlSimple.xml_in(file_path, {'ForceArray'=>false, 'KeepRoot'=>true, 'KeyAttr'=>['name']})
- { "xml_root_node" => root_hash.first[0], "dmtfitem" => root_hash.first[1]}
- end
- end
-
- def show_resource(resource_path, content_type, replace_keys = nil)
- respond_to do |format|
- format.xml do
- content_type "application/CIMI-#{content_type}+xml", :charset => 'utf-8'
- haml :"#{resource_path}", :layout => false
- end
- format.html do
- haml :"#{resource_path}"
- end
- format.json do
- content_type "application/CIMI-#{content_type}+json", :charset => 'utf-8'
- engine = Haml::Engine.new(File.read(settings.views + "/#{resource_path}.xml.haml"))
- responseXML = engine.render self
- hash_response = XmlSimple.xml_in responseXML, {'ForceArray' => false, 'KeepRoot'=>true, 'KeyAttr' => ['name']}
- hash_response = hash_response.first[1]
- if hash_response.has_key?("xmlns")
- hash_response.delete "xmlns"
- end
- if replace_keys
- replace_key!(hash_response, replace_keys)
- end
- hash_response.to_json
- end
- end
- end
-
- def replace_key!(an_object, key_maps = nil)
- if an_object.kind_of?(Hash)
- key_maps.each do |key, value|
- if an_object.key?(key)
- an_object[value] = an_object.delete(key)
- end
- end
- an_object.each do |key, value|
- replace_key!(value, key_maps)
- end
- elsif an_object.kind_of?(Array)
- an_object.each do |value|
- replace_key!(value, key_maps)
- end
- end
- end
-end
diff --git a/server/lib/cimi/helpers/dmtfdep.rb b/server/lib/cimi/helpers/dmtfdep.rb
deleted file mode 100644
index f501a1d..0000000
--- a/server/lib/cimi/helpers/dmtfdep.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# 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.
-
-#this file defines all the required components for dmtf implementation.
-#if new dependencies are needed, please make changes to this file.
-
-require 'sinatra'
-require 'deltacloud/drivers'
-require 'deltacloud/core_ext/integer'
-require 'deltacloud/core_ext/hash'
-require 'deltacloud/core_ext/string'
-require 'deltacloud/base_driver'
-require 'deltacloud/hardware_profile'
-require 'deltacloud/state_machine'
-require 'deltacloud/helpers'
-require 'deltacloud/models/base_model'
-require 'deltacloud/models/realm'
-require 'deltacloud/models/image'
-require 'deltacloud/models/instance'
-require 'deltacloud/models/key'
-require 'deltacloud/models/address'
-require 'deltacloud/models/instance_profile'
-require 'deltacloud/models/storage_snapshot'
-require 'deltacloud/models/storage_volume'
-require 'deltacloud/models/bucket'
-require 'deltacloud/models/blob'
-require 'deltacloud/models/load_balancer'
-require 'deltacloud/models/firewall'
-require 'deltacloud/models/firewall_rule'
-
-require 'json'
-require 'sinatra/rack_accept'
-require 'sinatra/static_assets'
-require 'sinatra/rabbit'
-require 'sinatra/lazy_auth'
-require 'erb'
-require 'haml'
-require 'open3'
-require 'uuidtools'
-require 'xmlsimple'
-require 'benchmark'
-require 'deltacloud/helpers/blob_stream'
-require 'sinatra/rack_driver_select'
-require 'sinatra/rack_runtime'
-require 'sinatra/rack_etag'
-require 'sinatra/rack_date'
-require 'sinatra/rack_matrix_params'
-require 'sinatra/rack_syslog'
-require 'sinatra/sinatra_verbose'
-
-CMWG_NAMESPACE = "http://www.dmtf.org/cimi"
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index afee932..fccff47 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -13,20 +13,17 @@
# License for the specific language governing permissions and limitations
# under the License.
-
-require 'cimi/helpers/dmtfdep'
-require 'cimi/helpers/cmwgapp_helper'
+require 'cimi/dependencies'
require 'cimi/helpers/cimi_helper'
-require 'deltacloud/core_ext'
require 'cimi/model'
set :version, '0.1.0'
include Deltacloud::Drivers
include CIMI::Model
+
set :drivers, Proc.new { driver_config }
-STOREROOT = File.join($top_srcdir, 'lib', 'cimi', 'data')
Sinatra::Application.register Rack::RespondTo
use Rack::ETag
@@ -39,12 +36,8 @@ use Rack::Date
configure do
set :root_url, "/cimi"
set :views, File::join($top_srcdir, 'views', 'cimi')
- # NOTE: Change :public to :public_folder once we update sinatra to 1.3
- # set :public_folder, File::join($top_srcdir, 'public')
set :public_folder, File::join($top_srcdir, 'public')
- # Try to load the driver on startup to fail early if there are issues
driver
- set :store, STOREROOT
end
configure :production do
@@ -77,7 +70,7 @@ end
get "#{settings.root_url}\/?" do
halt 401 if params[:force_auth] and not driver.valid_credentials?(credentials)
- redirect "#{settings.root_url}/cloudEntryPoint", 301
+ redirect cloudEntryPoint_url, 301
end
global_collection :cloudEntryPoint do
--
1.7.4.4
Re: [PATCH core 2/2] CIMI: Added cloudEntryPoint entity
Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK to both
On 30/11/11 14:01, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/lib/cimi/model.rb | 1 +
> server/lib/cimi/model/base.rb | 17 ++++++++++
> server/lib/cimi/model/cloud_entry_point.rb | 41 ++++++++++++++++++++++++
> server/lib/cimi/model/machine.rb | 2 +
> server/lib/cimi/model/machine_admin.rb | 2 +
> server/lib/cimi/model/machine_configuration.rb | 2 +
> server/lib/cimi/model/machine_image.rb | 2 +
> server/lib/cimi/model/machine_template.rb | 3 ++
> server/lib/cimi/model/schema.rb | 2 +-
> server/lib/cimi/model/volume.rb | 3 ++
> server/lib/cimi/model/volume_configuration.rb | 3 ++
> server/lib/cimi/model/volume_image.rb | 3 ++
> server/lib/cimi/model/volume_template.rb | 3 ++
> server/lib/cimi/server.rb | 7 +++-
> 14 files changed, 88 insertions(+), 3 deletions(-)
> create mode 100644 server/lib/cimi/model/cloud_entry_point.rb
>
> diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
> index acd72ce..243f693 100644
> --- a/server/lib/cimi/model.rb
> +++ b/server/lib/cimi/model.rb
> @@ -22,6 +22,7 @@ end
>
> require 'cimi/model/schema'
> require 'cimi/model/base'
> +require 'cimi/model/cloud_entry_point'
> require 'cimi/model/machine_template'
> require 'cimi/model/machine_image'
> require 'cimi/model/machine_configuration'
> diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
> index 0088b8b..ddc1b8a 100644
> --- a/server/lib/cimi/model/base.rb
> +++ b/server/lib/cimi/model/base.rb
> @@ -75,6 +75,19 @@ class CIMI::Model::NotFound < StandardError
> end
> end
>
> +module CIMI::Model
> +
> + def self.register_as_root_entity!(name)
> + @root_entities ||= []
> + @root_entities << name
> + end
> +
> + def self.root_entities
> + @root_entities || []
> + end
> +
> +end
> +
> class CIMI::Model::Base
>
> #
> @@ -191,5 +204,9 @@ class CIMI::Model::Base
> scalar :name
> end
>
> + def self.act_as_root_entity
> + CIMI::Model.register_as_root_entity! xml_tag_name.pluralize.uncapitalize
> + end
> +
> def self.all(_self); find(:all, _self); end
> end
> diff --git a/server/lib/cimi/model/cloud_entry_point.rb b/server/lib/cimi/model/cloud_entry_point.rb
> new file mode 100644
> index 0000000..edbcf0e
> --- /dev/null
> +++ b/server/lib/cimi/model/cloud_entry_point.rb
> @@ -0,0 +1,41 @@
> +# 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.
> +
> +class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
> +
> + def self.create(context)
> + root_entities = CIMI::Model.root_entities.inject({}) do |result, entity|
> + send(:href, entity.underscore) if not href_defined?(entity)
> + if context.respond_to? :"#{entity.underscore}_url"
> + result[entity.underscore] = { :href => context.send(:"#{entity.underscore}_url") }
> + end
> + result
> + end
> + root_entities.merge!({
> + :name => context.driver.name,
> + :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
> + :uri => context.cloudEntryPoint_url,
> + :created => Time.now
> + })
> + self.new(root_entities)
> + end
> +
> + private
> +
> + def self.href_defined?(entity)
> + true if schema.attribute_names.include? entity.underscore
> + end
> +
> +end
> diff --git a/server/lib/cimi/model/machine.rb b/server/lib/cimi/model/machine.rb
> index cff2dd5..e77e3b7 100644
> --- a/server/lib/cimi/model/machine.rb
> +++ b/server/lib/cimi/model/machine.rb
> @@ -17,6 +17,8 @@ require 'deltacloud/models/instance_address'
>
> class CIMI::Model::Machine < CIMI::Model::Base
>
> + act_as_root_entity
> +
> text :state
> text :cpu
>
> diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb
> index d3d3322..4f73223 100644
> --- a/server/lib/cimi/model/machine_admin.rb
> +++ b/server/lib/cimi/model/machine_admin.rb
> @@ -15,6 +15,8 @@
>
> class CIMI::Model::MachineAdmin < CIMI::Model::Base
>
> + act_as_root_entity
> +
> text :username
> text :password
> text :key
> diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
> index d36ebdf..6bf76b8 100644
> --- a/server/lib/cimi/model/machine_configuration.rb
> +++ b/server/lib/cimi/model/machine_configuration.rb
> @@ -15,6 +15,8 @@
>
> class CIMI::Model::MachineConfiguration < CIMI::Model::Base
>
> + act_as_root_entity
> +
> struct :memory do
> scalar :quantity
> scalar :units
> diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
> index e9aedf6..3d75d8f 100644
> --- a/server/lib/cimi/model/machine_image.rb
> +++ b/server/lib/cimi/model/machine_image.rb
> @@ -15,6 +15,8 @@
>
> class CIMI::Model::MachineImage < CIMI::Model::Base
>
> + act_as_root_entity
> +
> href :image_location
> text :image_data
>
> diff --git a/server/lib/cimi/model/machine_template.rb b/server/lib/cimi/model/machine_template.rb
> index 5f1ebfe..ac23933 100644
> --- a/server/lib/cimi/model/machine_template.rb
> +++ b/server/lib/cimi/model/machine_template.rb
> @@ -14,6 +14,9 @@
> # under the License.
>
> class CIMI::Model::MachineTemplate < CIMI::Model::Base
> +
> + act_as_root_entity
> +
> href :machine_config
> href :machine_image
> href :machine_admin
> diff --git a/server/lib/cimi/model/schema.rb b/server/lib/cimi/model/schema.rb
> index b6237e3..f301b69 100644
> --- a/server/lib/cimi/model/schema.rb
> +++ b/server/lib/cimi/model/schema.rb
> @@ -42,7 +42,7 @@ class CIMI::Model::Schema
> end
>
> def to_json(model, json)
> - json[@json_name] = model[@name] if model[@name]
> + json[@json_name] = model[@name] if model and model[@name]
> end
> end
>
> diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
> index 2246cad..b976027 100644
> --- a/server/lib/cimi/model/volume.rb
> +++ b/server/lib/cimi/model/volume.rb
> @@ -14,6 +14,9 @@
> # under the License.
>
> class CIMI::Model::Volume < CIMI::Model::Base
> +
> + act_as_root_entity
> +
> struct :capacity do
> scalar :quantity
> scalar :units
> diff --git a/server/lib/cimi/model/volume_configuration.rb b/server/lib/cimi/model/volume_configuration.rb
> index 2ac73d6..48fed59 100644
> --- a/server/lib/cimi/model/volume_configuration.rb
> +++ b/server/lib/cimi/model/volume_configuration.rb
> @@ -14,6 +14,9 @@
> # under the License.
>
> class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
> +
> + act_as_root_entity
> +
> text :format
> struct :capacity do
> scalar :quantity
> diff --git a/server/lib/cimi/model/volume_image.rb b/server/lib/cimi/model/volume_image.rb
> index 7745c6a..d7b3224 100644
> --- a/server/lib/cimi/model/volume_image.rb
> +++ b/server/lib/cimi/model/volume_image.rb
> @@ -14,6 +14,9 @@
> # under the License.
>
> class CIMI::Model::VolumeImage < CIMI::Model::Base
> +
> + act_as_root_entity
> +
> href :image_location
> text :image_data
> text :bootable
> diff --git a/server/lib/cimi/model/volume_template.rb b/server/lib/cimi/model/volume_template.rb
> index 1e0f5a7..aa12435 100644
> --- a/server/lib/cimi/model/volume_template.rb
> +++ b/server/lib/cimi/model/volume_template.rb
> @@ -14,6 +14,9 @@
> # under the License.
>
> class CIMI::Model::VolumeTemplate < CIMI::Model::Base
> +
> + act_as_root_entity
> +
> href :volume_config
> href :volume_image
> array :operations do
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index fccff47..1e85d0f 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -79,8 +79,11 @@ global_collection :cloudEntryPoint do
> operation :index do
> description "list all resources of the cloud"
> control do
> - @collections = entry_points.reject { |p| p[0] == :cloudEntryPoint }
> - show_resource "cloudEntryPoint/index", "CloudEntryPoint"
> + entry_point = CloudEntryPoint.create(self)
> + respond_to do |format|
> + format.xml { entry_point.to_xml }
> + format.json { entry_point.to_json }
> + end
> end
> end
> end
[PATCH core 2/2] CIMI: Added cloudEntryPoint entity
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model.rb | 1 +
server/lib/cimi/model/base.rb | 17 ++++++++++
server/lib/cimi/model/cloud_entry_point.rb | 41 ++++++++++++++++++++++++
server/lib/cimi/model/machine.rb | 2 +
server/lib/cimi/model/machine_admin.rb | 2 +
server/lib/cimi/model/machine_configuration.rb | 2 +
server/lib/cimi/model/machine_image.rb | 2 +
server/lib/cimi/model/machine_template.rb | 3 ++
server/lib/cimi/model/schema.rb | 2 +-
server/lib/cimi/model/volume.rb | 3 ++
server/lib/cimi/model/volume_configuration.rb | 3 ++
server/lib/cimi/model/volume_image.rb | 3 ++
server/lib/cimi/model/volume_template.rb | 3 ++
server/lib/cimi/server.rb | 7 +++-
14 files changed, 88 insertions(+), 3 deletions(-)
create mode 100644 server/lib/cimi/model/cloud_entry_point.rb
diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb
index acd72ce..243f693 100644
--- a/server/lib/cimi/model.rb
+++ b/server/lib/cimi/model.rb
@@ -22,6 +22,7 @@ end
require 'cimi/model/schema'
require 'cimi/model/base'
+require 'cimi/model/cloud_entry_point'
require 'cimi/model/machine_template'
require 'cimi/model/machine_image'
require 'cimi/model/machine_configuration'
diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
index 0088b8b..ddc1b8a 100644
--- a/server/lib/cimi/model/base.rb
+++ b/server/lib/cimi/model/base.rb
@@ -75,6 +75,19 @@ class CIMI::Model::NotFound < StandardError
end
end
+module CIMI::Model
+
+ def self.register_as_root_entity!(name)
+ @root_entities ||= []
+ @root_entities << name
+ end
+
+ def self.root_entities
+ @root_entities || []
+ end
+
+end
+
class CIMI::Model::Base
#
@@ -191,5 +204,9 @@ class CIMI::Model::Base
scalar :name
end
+ def self.act_as_root_entity
+ CIMI::Model.register_as_root_entity! xml_tag_name.pluralize.uncapitalize
+ end
+
def self.all(_self); find(:all, _self); end
end
diff --git a/server/lib/cimi/model/cloud_entry_point.rb b/server/lib/cimi/model/cloud_entry_point.rb
new file mode 100644
index 0000000..edbcf0e
--- /dev/null
+++ b/server/lib/cimi/model/cloud_entry_point.rb
@@ -0,0 +1,41 @@
+# 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.
+
+class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
+
+ def self.create(context)
+ root_entities = CIMI::Model.root_entities.inject({}) do |result, entity|
+ send(:href, entity.underscore) if not href_defined?(entity)
+ if context.respond_to? :"#{entity.underscore}_url"
+ result[entity.underscore] = { :href => context.send(:"#{entity.underscore}_url") }
+ end
+ result
+ end
+ root_entities.merge!({
+ :name => context.driver.name,
+ :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
+ :uri => context.cloudEntryPoint_url,
+ :created => Time.now
+ })
+ self.new(root_entities)
+ end
+
+ private
+
+ def self.href_defined?(entity)
+ true if schema.attribute_names.include? entity.underscore
+ end
+
+end
diff --git a/server/lib/cimi/model/machine.rb b/server/lib/cimi/model/machine.rb
index cff2dd5..e77e3b7 100644
--- a/server/lib/cimi/model/machine.rb
+++ b/server/lib/cimi/model/machine.rb
@@ -17,6 +17,8 @@ require 'deltacloud/models/instance_address'
class CIMI::Model::Machine < CIMI::Model::Base
+ act_as_root_entity
+
text :state
text :cpu
diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb
index d3d3322..4f73223 100644
--- a/server/lib/cimi/model/machine_admin.rb
+++ b/server/lib/cimi/model/machine_admin.rb
@@ -15,6 +15,8 @@
class CIMI::Model::MachineAdmin < CIMI::Model::Base
+ act_as_root_entity
+
text :username
text :password
text :key
diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
index d36ebdf..6bf76b8 100644
--- a/server/lib/cimi/model/machine_configuration.rb
+++ b/server/lib/cimi/model/machine_configuration.rb
@@ -15,6 +15,8 @@
class CIMI::Model::MachineConfiguration < CIMI::Model::Base
+ act_as_root_entity
+
struct :memory do
scalar :quantity
scalar :units
diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
index e9aedf6..3d75d8f 100644
--- a/server/lib/cimi/model/machine_image.rb
+++ b/server/lib/cimi/model/machine_image.rb
@@ -15,6 +15,8 @@
class CIMI::Model::MachineImage < CIMI::Model::Base
+ act_as_root_entity
+
href :image_location
text :image_data
diff --git a/server/lib/cimi/model/machine_template.rb b/server/lib/cimi/model/machine_template.rb
index 5f1ebfe..ac23933 100644
--- a/server/lib/cimi/model/machine_template.rb
+++ b/server/lib/cimi/model/machine_template.rb
@@ -14,6 +14,9 @@
# under the License.
class CIMI::Model::MachineTemplate < CIMI::Model::Base
+
+ act_as_root_entity
+
href :machine_config
href :machine_image
href :machine_admin
diff --git a/server/lib/cimi/model/schema.rb b/server/lib/cimi/model/schema.rb
index b6237e3..f301b69 100644
--- a/server/lib/cimi/model/schema.rb
+++ b/server/lib/cimi/model/schema.rb
@@ -42,7 +42,7 @@ class CIMI::Model::Schema
end
def to_json(model, json)
- json[@json_name] = model[@name] if model[@name]
+ json[@json_name] = model[@name] if model and model[@name]
end
end
diff --git a/server/lib/cimi/model/volume.rb b/server/lib/cimi/model/volume.rb
index 2246cad..b976027 100644
--- a/server/lib/cimi/model/volume.rb
+++ b/server/lib/cimi/model/volume.rb
@@ -14,6 +14,9 @@
# under the License.
class CIMI::Model::Volume < CIMI::Model::Base
+
+ act_as_root_entity
+
struct :capacity do
scalar :quantity
scalar :units
diff --git a/server/lib/cimi/model/volume_configuration.rb b/server/lib/cimi/model/volume_configuration.rb
index 2ac73d6..48fed59 100644
--- a/server/lib/cimi/model/volume_configuration.rb
+++ b/server/lib/cimi/model/volume_configuration.rb
@@ -14,6 +14,9 @@
# under the License.
class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
+
+ act_as_root_entity
+
text :format
struct :capacity do
scalar :quantity
diff --git a/server/lib/cimi/model/volume_image.rb b/server/lib/cimi/model/volume_image.rb
index 7745c6a..d7b3224 100644
--- a/server/lib/cimi/model/volume_image.rb
+++ b/server/lib/cimi/model/volume_image.rb
@@ -14,6 +14,9 @@
# under the License.
class CIMI::Model::VolumeImage < CIMI::Model::Base
+
+ act_as_root_entity
+
href :image_location
text :image_data
text :bootable
diff --git a/server/lib/cimi/model/volume_template.rb b/server/lib/cimi/model/volume_template.rb
index 1e0f5a7..aa12435 100644
--- a/server/lib/cimi/model/volume_template.rb
+++ b/server/lib/cimi/model/volume_template.rb
@@ -14,6 +14,9 @@
# under the License.
class CIMI::Model::VolumeTemplate < CIMI::Model::Base
+
+ act_as_root_entity
+
href :volume_config
href :volume_image
array :operations do
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index fccff47..1e85d0f 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -79,8 +79,11 @@ global_collection :cloudEntryPoint do
operation :index do
description "list all resources of the cloud"
control do
- @collections = entry_points.reject { |p| p[0] == :cloudEntryPoint }
- show_resource "cloudEntryPoint/index", "CloudEntryPoint"
+ entry_point = CloudEntryPoint.create(self)
+ respond_to do |format|
+ format.xml { entry_point.to_xml }
+ format.json { entry_point.to_json }
+ end
end
end
end
--
1.7.4.4