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 2012/11/29 14:05:42 UTC

[PATCH core 4/6] CIMI: Added MachineTemplate database model

From: Michal Fojtik <mf...@redhat.com>

* Added BaseEntity as a parent model for Entity

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/db.rb                  |  1 +
 server/lib/db/entity.rb           | 11 +++++++++--
 server/lib/db/machine_template.rb | 13 +++++++++++++
 server/lib/db/provider.rb         |  1 +
 4 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 server/lib/db/machine_template.rb

diff --git a/server/lib/db.rb b/server/lib/db.rb
index e0f28d4..db98709 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -4,6 +4,7 @@ module Deltacloud
 
   require_relative './db/provider'
   require_relative './db/entity'
+  require_relative './db/machine_template'
 
   DATABASE_LOCATION = ENV['DATABASE_LOCATION'] || "/var/tmp/deltacloud-mock-#{ENV['USER']}/db.sqlite"
 
diff --git a/server/lib/db/entity.rb b/server/lib/db/entity.rb
index b220f9e..c9845a4 100644
--- a/server/lib/db/entity.rb
+++ b/server/lib/db/entity.rb
@@ -1,19 +1,26 @@
 module Deltacloud
   module Database
 
-    class Entity
+    class BaseEntity
       include DataMapper::Resource
 
       belongs_to :provider
 
       property :id, Serial
+      property :type, Discriminator
+
       property :be_kind, String, :required => true # => Machine, MachineImage, ...
       property :be_id, String, :required => true # => Original Machine 'id'
 
-      property :ent_properties, Json
+    end
+
+    class Entity < BaseEntity
+
+      belongs_to :provider
 
       property :name, String
       property :description, String
+      property :ent_properties, Json
 
       def to_hash
         retval = {}
diff --git a/server/lib/db/machine_template.rb b/server/lib/db/machine_template.rb
new file mode 100644
index 0000000..813588d
--- /dev/null
+++ b/server/lib/db/machine_template.rb
@@ -0,0 +1,13 @@
+module Deltacloud
+  module Database
+
+    class MachineTemplateEntity < Entity
+      belongs_to :provider
+
+      property :machine_config, String
+      property :machine_image, String
+
+    end
+
+  end
+end
diff --git a/server/lib/db/provider.rb b/server/lib/db/provider.rb
index 6a761e5..e227a73 100644
--- a/server/lib/db/provider.rb
+++ b/server/lib/db/provider.rb
@@ -9,6 +9,7 @@ module Deltacloud
       property :url, Text
 
       has n, :entities
+      has n, :machine_template_entities
     end
 
   end
-- 
1.8.0


Re: [PATCH core 4/6] CIMI: Added MachineTemplate database model

Posted by Michal Fojtik <mf...@redhat.com>.
On 11/29, David Lutterkort wrote:
> On Thu, 2012-11-29 at 14:05 +0100, mfojtik@redhat.com wrote:
> > From: Michal Fojtik <mf...@redhat.com>
> > 
> > * Added BaseEntity as a parent model for Entity
> > 
> > Signed-off-by: Michal fojtik <mf...@redhat.com>
> 
> ACK. Nice. Though do we need to call it MachineTemplateEntity ? Isn't
> Deltacloud::Database::MachineTemplate enough ? If we do need the extra
> distinction, I suggest we use 'Record' instead of 'Entity', since the
> latter is so overloaded, i.e. call this MachineTemplateRecord

Sure, I renamed it to just MachineTemplate, hope the ruby namespacing works
well :-)

I was a bit afraid about confusion caused by having two classes with the
same name, but not a big deal :-)

  -- Michal


-- 
Michal Fojtik <mf...@redhat.com>
Deltacloud API, CloudForms

Re: [PATCH core 4/6] CIMI: Added MachineTemplate database model

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-11-29 at 14:05 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> * Added BaseEntity as a parent model for Entity
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>

ACK. Nice. Though do we need to call it MachineTemplateEntity ? Isn't
Deltacloud::Database::MachineTemplate enough ? If we do need the extra
distinction, I suggest we use 'Record' instead of 'Entity', since the
latter is so overloaded, i.e. call this MachineTemplateRecord

David