deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 2/8] CIMI: Migrated database models to use Sequel
Date Wed, 16 Jan 2013 11:58:27 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/db/address_template.rb     | 10 ---------
 server/lib/db/entity.rb               | 25 +++++----------------
 server/lib/db/machine_template.rb     |  5 -----
 server/lib/db/provider.rb             | 41 +++++------------------------------
 server/lib/db/volume_configuration.rb |  4 ----
 server/lib/db/volume_template.rb      |  4 ----
 6 files changed, 11 insertions(+), 78 deletions(-)

diff --git a/server/lib/db/address_template.rb b/server/lib/db/address_template.rb
index 5a08346..8586255 100644
--- a/server/lib/db/address_template.rb
+++ b/server/lib/db/address_template.rb
@@ -2,16 +2,6 @@ module Deltacloud
   module Database
 
     class AddressTemplate < Entity
-      belongs_to :provider
-
-      property :ip, String
-      property :hostname, String
-      property :allocation, String, :default => 'dynamic'
-      property :default_gateway, String, :default => 'unknown'
-      property :dns, String, :default => 'unknown'
-      property :protocol, String, :default => 'ipv4'
-      property :mask, String, :default => 'unknown'
-      property :network, String
     end
 
   end
diff --git a/server/lib/db/entity.rb b/server/lib/db/entity.rb
index f9b34ff..963a26b 100644
--- a/server/lib/db/entity.rb
+++ b/server/lib/db/entity.rb
@@ -1,33 +1,18 @@
 module Deltacloud
   module Database
 
-    class BaseEntity
-      include DataMapper::Resource
+    class Entity < Sequel::Model
 
-      belongs_to :provider
+      many_to_one :provider
 
-      property :id, Serial
-      property :type, Discriminator
-
-      property :be_kind, String, :required => true # => Machine, MachineImage, ...
-      property :be_id, String # => Original Machine 'id'
-
-      timestamps :created_at, :updated_on
-    end
-
-    class Entity < BaseEntity
-
-      belongs_to :provider
-
-      property :name, String
-      property :description, String
-      property :ent_properties, Json
+      plugin :single_table_inheritance, :model
+      plugin :timestamps, :create => :created_at
 
       def to_hash
         retval = {}
         retval.merge!(:name => self.name) if !self.name.nil?
         retval.merge!(:description => self.description) if !self.description.nil?
-        retval.merge!(:property => self.ent_properties) if !self.ent_properties.nil?
+        retval.merge!(:property => JSON::parse(self.ent_properties)) if !self.ent_properties.nil?
         retval
       end
 
diff --git a/server/lib/db/machine_template.rb b/server/lib/db/machine_template.rb
index 134eb23..1b34161 100644
--- a/server/lib/db/machine_template.rb
+++ b/server/lib/db/machine_template.rb
@@ -2,11 +2,6 @@ module Deltacloud
   module Database
 
     class MachineTemplate < Entity
-      belongs_to :provider
-
-      property :machine_config, String, :length => 255
-      property :machine_image, String, :length => 255
-
     end
 
   end
diff --git a/server/lib/db/provider.rb b/server/lib/db/provider.rb
index e8ca4f5..c0b8485 100644
--- a/server/lib/db/provider.rb
+++ b/server/lib/db/provider.rb
@@ -1,41 +1,12 @@
 module Deltacloud
   module Database
 
-    class Provider
-      include DataMapper::Resource
-
-      property :id, Serial
-      property :driver, String, :required => true
-      property :url, Text
-
-      has n, :entities
-      has n, :machine_templates
-      has n, :address_templates
-      has n, :volume_configurations
-      has n, :volume_templates
-
-      # This is a workaround for strange bug in Fedora MRI:
-      #
-      def machine_templates
-        MachineTemplate.all(:provider_id => self.id)
-      end
-
-      def address_templates
-        AddressTemplate.all(:provider_id => self.id)
-      end
-
-      def volume_configurations
-        VolumeConfiguration.all(:provider_id => self.id)
-      end
-
-      def volume_templates
-        VolumeTemplate.all(:provider_id => self.id)
-      end
-
-      def entities
-        Entity.all(:provider_id => self.id)
-      end
-
+    class Provider < Sequel::Model
+      one_to_many :entities
+      one_to_many :machine_templates
+      one_to_many :address_templates
+      one_to_many :volume_templates
+      one_to_many :volume_configurations
     end
 
   end
diff --git a/server/lib/db/volume_configuration.rb b/server/lib/db/volume_configuration.rb
index 58aa624..aa956ce 100644
--- a/server/lib/db/volume_configuration.rb
+++ b/server/lib/db/volume_configuration.rb
@@ -2,10 +2,6 @@ module Deltacloud
   module Database
 
     class VolumeConfiguration < Entity
-      belongs_to :provider
-
-      property :format, String
-      property :capacity, String
     end
 
   end
diff --git a/server/lib/db/volume_template.rb b/server/lib/db/volume_template.rb
index 8658b8b..0d876bf 100644
--- a/server/lib/db/volume_template.rb
+++ b/server/lib/db/volume_template.rb
@@ -2,10 +2,6 @@ module Deltacloud
   module Database
 
     class VolumeTemplate < Entity
-      belongs_to :provider
-
-      property :volume_config, String
-      property :volume_image, String
     end
 
   end
-- 
1.8.0.2


Mime
View raw message