deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core 2/2] CIMI: Added cloudEntryPoint entity
Date Wed, 30 Nov 2011 13:04:44 GMT
ACK to both

On 30/11/11 14:01, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mfojtik@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


Mime
View raw message