Based on Bob's xml api examples and prior discussions with lutter and
Hugh on the portal AR model, I've come up with an initial model
specification. At this point I've only included those attributes that
Bob has already identified.
Once we've nailed down the attributes, associations and validation rules
for this stuff we can start integrating it into the controllers and UI bits.
Scott
>From 167ad82f42742a310be6c7787d21c0c711a37f65 Mon Sep 17 00:00:00 2001
From: Scott Seago <sseago(a)redhat.com>
Date: Wed, 5 Aug 2009 21:18:46 +0000
Subject: [PATCH server] first stab at dcloud portal model.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/cloud_account.rb | 16 ++++++++++++++++
src/app/models/flavor.rb | 16 ++++++++++++++++
src/app/models/image.rb | 13 +++++++++++++
src/app/models/instance.rb | 14 ++++++++++++++
src/app/models/portal_pool.rb | 11 +++++++++++
src/app/models/provider.rb | 11 +++++++++++
src/db/migrate/20090731200741_create_providers.rb | 15 +++++++++++++++
.../20090801045212_create_cloud_accounts.rb | 15 +++++++++++++++
.../migrate/20090803141507_create_portal_pools.rb | 14 ++++++++++++++
src/db/migrate/20090804135630_create_flavors.rb | 17 +++++++++++++++++
src/db/migrate/20090804140143_create_images.rb | 16 ++++++++++++++++
src/db/migrate/20090804142049_create_instances.rb | 18 ++++++++++++++++++
12 files changed, 176 insertions(+), 0 deletions(-)
create mode 100644 src/app/models/cloud_account.rb
create mode 100644 src/app/models/flavor.rb
create mode 100644 src/app/models/image.rb
create mode 100644 src/app/models/instance.rb
create mode 100644 src/app/models/portal_pool.rb
create mode 100644 src/app/models/provider.rb
create mode 100644 src/db/migrate/20090731200741_create_providers.rb
create mode 100644 src/db/migrate/20090801045212_create_cloud_accounts.rb
create mode 100644 src/db/migrate/20090803141507_create_portal_pools.rb
create mode 100644 src/db/migrate/20090804135630_create_flavors.rb
create mode 100644 src/db/migrate/20090804140143_create_images.rb
create mode 100644 src/db/migrate/20090804142049_create_instances.rb
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
new file mode 100644
index 0000000..29b9ccf
--- /dev/null
+++ b/src/app/models/cloud_account.rb
@@ -0,0 +1,16 @@
+class CloudAccount < ActiveRecord::Base
+ belongs_to :provider
+ has_many :portal_pools
+
+ # what form does the account quota take?
+
+ # we aren't yet defining the local user object
+ # has_many :portal_users
+
+
+ validates_presence of :provider_id
+
+ validates_presence_of :username
+ validates_uniqueness_of :username, :scope => provider_id
+ validates_presence_of :password
+end
diff --git a/src/app/models/flavor.rb b/src/app/models/flavor.rb
new file mode 100644
index 0000000..473546c
--- /dev/null
+++ b/src/app/models/flavor.rb
@@ -0,0 +1,16 @@
+class Flavor < ActiveRecord::Base
+ has_many :instances
+ belongs_to :provider
+
+ validates_presence_of :provider_id
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => :provider_id
+
+ validates_presence_of :storage
+ validates_numericality_of :storage
+ validates_presence_of :memory
+ validates_numericality_of :memory
+
+ validates_presence_of :architecture
+end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
new file mode 100644
index 0000000..15f4ccb
--- /dev/null
+++ b/src/app/models/image.rb
@@ -0,0 +1,13 @@
+class Image < ActiveRecord::Base
+ has_many :instances
+ belongs_to :provider
+
+ validates_presence_of :provider_id
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => :provider_id
+
+ validates_presence_of :description
+ validates_presence_of :architecture
+
+end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
new file mode 100644
index 0000000..a1e185c
--- /dev/null
+++ b/src/app/models/instance.rb
@@ -0,0 +1,14 @@
+class Instance < ActiveRecord::Base
+ belongs_to :portal_pool
+ belongs_to :flavor
+ belongs_to :image
+
+ validates_presence_of :portal_pool_id
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => :portal_pool_id
+
+ validates_presence_of :flavor_id
+ validates_presence_of :image_id
+
+end
diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb
new file mode 100644
index 0000000..b6af405
--- /dev/null
+++ b/src/app/models/portal_pool.rb
@@ -0,0 +1,11 @@
+class PortalPool < ActiveRecord::Base
+ belongs_to :cloud_account
+ has_many :instances
+
+ # what form does the pool quota take?
+
+ validates_presence_of :cloud_account_id
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => :cloud_account_id
+end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
new file mode 100644
index 0000000..866f741
--- /dev/null
+++ b/src/app/models/provider.rb
@@ -0,0 +1,11 @@
+class Provider < ActiveRecord::Base
+ has_many :cloud_accounts
+ has_many :flavors
+ has_many :images
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+
+ validates_presence_of :cloud_type
+
+end
diff --git a/src/db/migrate/20090731200741_create_providers.rb b/src/db/migrate/20090731200741_create_providers.rb
new file mode 100644
index 0000000..1a4e41e
--- /dev/null
+++ b/src/db/migrate/20090731200741_create_providers.rb
@@ -0,0 +1,15 @@
+class CreateProviders < ActiveRecord::Migration
+ def self.up
+ create_table :providers do |t|
+ t.string :name, :null => false
+ t.string :cloud_type, :null => false
+ t.string :url
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :providers
+ end
+end
diff --git a/src/db/migrate/20090801045212_create_cloud_accounts.rb b/src/db/migrate/20090801045212_create_cloud_accounts.rb
new file mode 100644
index 0000000..7d960e3
--- /dev/null
+++ b/src/db/migrate/20090801045212_create_cloud_accounts.rb
@@ -0,0 +1,15 @@
+class CreateCloudAccounts < ActiveRecord::Migration
+ def self.up
+ create_table :cloud_accounts do |t|
+ t.string :username, :null => false
+ t.string :password, :null => false
+ t.integer :provider_id, :null => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :cloud_accounts
+ end
+end
diff --git a/src/db/migrate/20090803141507_create_portal_pools.rb b/src/db/migrate/20090803141507_create_portal_pools.rb
new file mode 100644
index 0000000..0714d1c
--- /dev/null
+++ b/src/db/migrate/20090803141507_create_portal_pools.rb
@@ -0,0 +1,14 @@
+class CreatePortalPools < ActiveRecord::Migration
+ def self.up
+ create_table :portal_pools do |t|
+ t.string :name, :null => false
+ t.integer :cloud_account_id, :null => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :portal_pools
+ end
+end
diff --git a/src/db/migrate/20090804135630_create_flavors.rb b/src/db/migrate/20090804135630_create_flavors.rb
new file mode 100644
index 0000000..cdc34e3
--- /dev/null
+++ b/src/db/migrate/20090804135630_create_flavors.rb
@@ -0,0 +1,17 @@
+class CreateFlavors < ActiveRecord::Migration
+ def self.up
+ create_table :flavors do |t|
+ t.string :name, :null => false
+ t.integer :memory, :null => false
+ t.integer :storage, :null => false
+ t.string :architecture, :null => false
+ t.integer :provider_id, :null => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :flavors
+ end
+end
diff --git a/src/db/migrate/20090804140143_create_images.rb b/src/db/migrate/20090804140143_create_images.rb
new file mode 100644
index 0000000..0163ec7
--- /dev/null
+++ b/src/db/migrate/20090804140143_create_images.rb
@@ -0,0 +1,16 @@
+class CreateImages < ActiveRecord::Migration
+ def self.up
+ create_table :images do |t|
+ t.string :name, :null => false
+ t.string :description, :null => false
+ t.string :architecture, :null => false
+ t.integer :provider_id, :null => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :images
+ end
+end
diff --git a/src/db/migrate/20090804142049_create_instances.rb b/src/db/migrate/20090804142049_create_instances.rb
new file mode 100644
index 0000000..6c3bc5a
--- /dev/null
+++ b/src/db/migrate/20090804142049_create_instances.rb
@@ -0,0 +1,18 @@
+class CreateInstances < ActiveRecord::Migration
+ def self.up
+ create_table :instances do |t|
+ t.string :name, :null => false
+ t.integer :flavor_id, :null => false
+ t.integer :image_id, :null => false
+ t.integer :portal_pool_id, :null => false
+ t.string :public_address
+ t.string :private_address
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :instances
+ end
+end
--
1.6.0.6