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@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@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
On Wed, 2009-08-05 at 17:22 -0400, Scott Seago wrote:
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.
Looks good.
What is the Flavor object used for ? Do we need to keep track of capacity by architecture ? And if that's the case, shouldn't the Flavor belong to the CloudPool rather than the Provider ?
In terms of terminology, I would call CloudAccount just Account (or maybe Credentials ?) and PortalPool just Pool - if we need to handle cloud-side pools at some point, we can always call them something else like 'Partition' or some such.
Since I enjoy drawing UML diagrams lately, attached a diagram for what's in the Ruby code, both as a png and dia file.
There's of course no end to the attributes that could be added/changed, but I think this is a good start.
David
David Lutterkort wrote:
On Wed, 2009-08-05 at 17:22 -0400, Scott Seago wrote:
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.
Looks good.
What is the Flavor object used for ? Do we need to keep track of capacity by architecture ? And if that's the case, shouldn't the Flavor belong to the CloudPool rather than the Provider ?
Flavor is the the way of setting VM size. 'small' 'medium' 'large' etc. It's apparently what ec2 calls it, so the api that Bob is working on uses it as well. It doesn't belong to the CloudPool since that's purely a Proxy/Portal creation, and this belongs to the provider itself. i.e. on ec2, it's ec2 that defines what 'small' means, etc.
In terms of terminology, I would call CloudAccount just Account (or maybe Credentials ?) and PortalPool just Pool - if we need to handle cloud-side pools at some point, we can always call them something else like 'Partition' or some such.
I've got a more immediate reason to use PortalPool instead of Pool for the immediate term -- Pool exists in the oVirt model we're working out of, and I don't want to spend the time to rip it out right now. Lets stick with PortalPool now but we can discuss whether it should change later. The other reason I called it PortalPool was to make it clear that this isn't something that exists like this on the cloud side -- it only belongs to portal/proxy. Also, We have an Account object already -- that's the ldap construct in oVirt. In addition, CloudAccount makes it clear that these are external accounts that we're linking to internal (proxy/portal) Users. Should we call it ExternalAccount instead?
Since I enjoy drawing UML diagrams lately, attached a diagram for what's in the Ruby code, both as a png and dia file.
There's of course no end to the attributes that could be added/changed, but I think this is a good start.
Right. I'm sure we need more attributes -- the list below is based on Bob's API email from last Saturday.
Scott
David
deltacloud-devel@lists.fedorahosted.org