key indicators portlet
by Jan Provazník
key indicators portlet: displays summary about instances, accounts/pools/providers counts
13 years, 12 months
[PATCH aggregator] preliminary 'provider service quality' portlet
by Mo Morsi
most of the styling is done, all that remains is:
- including the actual graphs
- including the 'poor/good service' widget
- wiring up the arrow buttons to whatever their corresponding
actions are (clarification needed)
---
src/app/controllers/dashboard_controller.rb | 4 ++
src/app/views/dashboard/summary.haml | 20 ++++++++++++-
src/public/images/dashboard_summary_next.png | Bin 0 -> 412 bytes
src/public/images/dashboard_summary_prev.png | Bin 0 -> 375 bytes
src/public/stylesheets/components.css | 41 +++++++++++++++++++++++++-
5 files changed, 63 insertions(+), 2 deletions(-)
create mode 100644 src/public/images/dashboard_summary_next.png
create mode 100644 src/public/images/dashboard_summary_prev.png
diff --git a/src/app/controllers/dashboard_controller.rb b/src/app/controllers/dashboard_controller.rb
index ef89d95..3a9a6ed 100644
--- a/src/app/controllers/dashboard_controller.rb
+++ b/src/app/controllers/dashboard_controller.rb
@@ -32,6 +32,10 @@ class DashboardController < ApplicationController
end
def index
+ @providers = Provider.find(:all)
+
+ @is_admin = @current_user.permissions.collect { |p| p.role }.
+ find { |r| r.name == "Administrator" }
@hide_getting_started = cookies["#{(a)current_user.login}_hide_getting_started"]
@current_users_pool = Pool.find(:first, :conditions => ['name = ?', @current_user.login])
render :action => :summary
diff --git a/src/app/views/dashboard/summary.haml b/src/app/views/dashboard/summary.haml
index 4eeb58b..f3d6ab6 100644
--- a/src/app/views/dashboard/summary.haml
+++ b/src/app/views/dashboard/summary.haml
@@ -29,7 +29,7 @@
#actions_dashboard_section
%h2
Actions
- - if @current_user.permissions.collect { |p| p.role }.find { |r| r.name == "Administrator" }
+ - if @is_admin
%a{:href => url_for(:controller => "cloud_accounts", :action => "new")}
Add a Provider Account
%a{:href => url_for(:controller => "provider", :action => "new")}
@@ -44,6 +44,24 @@
%a{:href => url_for(:controller => "", :action => "")}
Enter a help ticket
+#service_quality_dashboard_section
+ - if @is_admin
+ %h2
+ Provider Service Quality
+ .dashboard_section_summary
+ Average time to submit tasks to provider, 24 hours
+ <img src="images/dashboard_summary_prev.png" /><img src="images/dashboard_summary_next.png" />
+ - @providers.each do |provider|
+ .provider_service_quality_graph
+ <!-- FIXME include graph -->
+ .provider_service_quality_graph_summary
+ = provider.name
+ <!-- FIXME 'good/poor/average service... -->
+ <div style="clear: both;" />
+ - else
+ %h2
+ Service Quality
+
:javascript
$("#hide_getting_started").click(function(){
$('#getting_started_dashboard_section').hide();
diff --git a/src/public/images/dashboard_summary_next.png b/src/public/images/dashboard_summary_next.png
new file mode 100644
index 0000000000000000000000000000000000000000..ae8b24a3fb0754caeabee6fc3ee2d0ee09d99570
GIT binary patch
literal 412
zcmV;N0b~A&P)<h;3K|Lk000e1NJLTq000;O000yS0ssI27}sjl00001b5ch_0Itp)
z=>Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RV1sM)0F!F(b!2kdOE=fc|R5;6}
zl)J5iFcgMOpx_}vB;*D}MacrtBf$V+0v13_kPS%B1i_voRZ2im(5H#Sqsjwui!`}W
zf)o68$2$7-`y9*6@puFj$g&I}WLcJ(rfIR|e!n+OGmfKS7%Q4M9LJfadA(k5w;Ms!
zbsf<q2m)DT+xFpb_$D1e)c1W51ZkSmiXLpY+bD|WugSgCo6Y8JA3~@oirsE!S=QTz
z*Y)eVKL2WxB=LR!`LM3*^?Lo=`un~Q!!XOTg)@4_aU9R{Xhm@xV~iC=ArBiN^jro(
zFf*NhOtWa3rfHh%x_O>|>Zz*gbUKl*=6N2*_|w+EO|;+dClZfDRNu&hvMg0qT~S(w
zVYpl_q9}61Ff6vTZF@eSA%p+`rYMTVB2g42N#c1P0PqJMO6kwB(fBq10000<MNUMn
GLSTZh>#cwQ
literal 0
HcmV?d00001
diff --git a/src/public/images/dashboard_summary_prev.png b/src/public/images/dashboard_summary_prev.png
new file mode 100644
index 0000000000000000000000000000000000000000..34ab07092795ddba41e3935920f7779f7dc50965
GIT binary patch
literal 375
zcmV--0f_#IP)<h;3K|Lk000e1NJLTq000*N000yS0ssI2>D)0{00001b5ch_0Itp)
z=>Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RV1sM)07{@dyI{*Ly2}wjjR5;6}
zl)(ywAP|P#iUh$!6ba#>lhFG=OcZp8Bs$b#CDO2BZxQX5;m&QG@gL`#!Iuz1Db=>^
zvMj*XJgqh7JV_Elh_#9{j$;r6|40A;oNe2D-@i{XHtQJg7eyhZG;q0zP197C<+`qB
zx>td|@9VmLI-{RmaL$Ke*iV|Kab0(J!!V4Z=uTyx=c=ksAWkmE`0g$9Jm-1-1jOBp
zAcS!o+w9B9Pm+W&cBEiQ7h{}d*^v&V6d|-Hd~fORNka%3WBa5KLf=Fm?XKr}X_`_>
zEjv0IAp~P=#N-+49En_Z1R)%T;h!%G0Pqq*bX}*EisSf6*-I4w!2A7{QfjU3R6at9
VdNubHEt&uT002ovPDHLkV1hsVmc0M~
literal 0
HcmV?d00001
diff --git a/src/public/stylesheets/components.css b/src/public/stylesheets/components.css
index 5b25cd4..b61fbc9 100644
--- a/src/public/stylesheets/components.css
+++ b/src/public/stylesheets/components.css
@@ -72,6 +72,22 @@ ul.nav li.selected {
}
/* dashboard style */
+.dashboard_section_summary {
+ background: #F2F2F2;
+ font-size: 0.8em;
+ font-weight: bolder;
+ margin: 0 15px 10px 0;
+ padding: 5px 0px 5px 5px;
+}
+
+.dashboard_section_summary img:first-child {
+ padding-left: 40px;
+}
+
+.dashboard_section_summary img {
+ vertical-align: middle;
+}
+
#getting_started_dashboard_section {
background: #F2F2F2;
width: 850px;
@@ -118,7 +134,6 @@ ul.nav li.selected {
width: 390px;
height: 100px;
border: 1px solid black;
- background: #F2F2F2;
padding: 5px 0 5px 15px;
margin: 10px 0px 10px 5px;
-moz-border-radius: 5px;
@@ -136,3 +151,27 @@ ul.nav li.selected {
color: blue;
text-decoration: underline;
}
+
+#service_quality_dashboard_section {
+ width: 390px;
+ border: 1px solid black;
+ padding: 5px 0 5px 15px;
+ margin: 10px 0px 10px 5px;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+}
+
+.provider_service_quality_graph {
+ width: 100px;
+ height: 50px;
+ border: 1px solid black;
+ float: left;
+ margin: 0px 5px 0px 5px;
+}
+
+.provider_service_quality_graph_summary {
+ float: left;
+ width: 60px;
+ height: 15px;
+ padding: 20px 0 24px 0;
+}
--
1.6.2.5
13 years, 12 months
[PATCH aggregator] JavaScript cleanup
by Tomas Sedovic
Howdy,
These two patches delete all the JavaScript code, libraries, layouts and views that are not used anymore.
Since the minified JS files have lines that are too long for poor git-send-email to handle, the patches are in this e-mail's attachment.
Thomas
13 years, 12 months
Quota CRUD + Audit + Enforcement
by Martyn Taylor
This Series of patches adds the ability to Create/Edit/Delete quota on Pools and Cloud Accounts. It Audits quota by storing totals on the quota model. Then enforces the Quota on Instance Create/Start in TaskOMatic
13 years, 12 months
[PATCH docs] Update documentation and add news to the site
by Tomas Sedovic
(another one of those patches that git refuses to send because of those not-entirely-text-not-really-binary-either files)
Two updates to our website: firstly, the API description now uses Hardware Profiles (yay!) and secondly, it shows some news.
14 years
Re: [deltacloud-devel] [PATCH aggregator] updated aggregator to use core hardware profiles; ; ; ; ; ; ; deltacloud-devel@lists.fedorahosted.org; "Scott Seago" <sseago@redhat.com>
by Tomas Sedovic
Hi Scott,
The patch works fine.
However, I noticed some code about enum entries that is commented out. Uncommenting it seems to break the tests but that is not obvious from the code.
Could you please either delete these parts or add an explanation to them about why they are commented out and what to do to make it work again?
Other than that, ACK.
Thomas
----- "Scott Seago" <sseago(a)redhat.com> wrote:
> Removes all references to core flavors and replaces them with hardware
> profiles.
> Updates aggregator model to include the range and enum properties for
> hardware profiles.
>
> To use this patch, you need to rebuild the aggregator database, and
> rebuild the
> client gem with this patch:
>
> [PATCH core] update to hardware profile client to include new property
> metadata.
>
> Signed-off-by: Scott Seago <sseago(a)redhat.com>
> ---
> src/app/models/hardware_profile.rb | 43 ++++++-
> src/app/models/hardware_profile_property.rb | 122
> ++++++++++++++++++++
> src/app/models/property_enum_entry.rb | 37 ++++++
> src/app/models/provider.rb | 21 ++--
> src/app/views/hardware_profiles/_list.html.erb | 8 +-
> .../20090804135630_create_hardware_profiles.rb | 25 ++++-
> src/spec/factories/hardware_profile.rb | 40 ++++---
> src/spec/factories/hardware_profile_property.rb | 122
> ++++++++++++++++++++
> src/spec/factories/pool.rb | 2 +-
> src/spec/factories/property_enum_entry.rb | 26 ++++
> src/spec/models/hardware_profile_spec.rb | 17 +---
> 11 files changed, 407 insertions(+), 56 deletions(-)
> create mode 100644 src/app/models/hardware_profile_property.rb
> create mode 100644 src/app/models/property_enum_entry.rb
> create mode 100644 src/spec/factories/hardware_profile_property.rb
> create mode 100644 src/spec/factories/property_enum_entry.rb
>
> diff --git a/src/app/models/hardware_profile.rb
> b/src/app/models/hardware_profile.rb
> index d98c2f9..a92b658 100644
> --- a/src/app/models/hardware_profile.rb
> +++ b/src/app/models/hardware_profile.rb
> @@ -25,6 +25,15 @@ class HardwareProfile < ActiveRecord::Base
> :foreign_key => "provider_hardware_profile_id"
> belongs_to :provider
>
> + belongs_to :memory, :class_name =>
> "HardwareProfileProperty",
> + :dependent => :destroy
> + belongs_to :storage, :class_name =>
> "HardwareProfileProperty",
> + :dependent => :destroy
> + belongs_to :cpu, :class_name =>
> "HardwareProfileProperty",
> + :dependent => :destroy
> + belongs_to :architecture, :class_name =>
> "HardwareProfileProperty",
> + :dependent => :destroy
> +
> has_and_belongs_to_many :aggregator_hardware_profiles,
> :class_name => "HardwareProfile",
> :join_table => "hardware_profile_map",
> @@ -43,12 +52,10 @@ class HardwareProfile < ActiveRecord::Base
> validates_presence_of :name
> validates_uniqueness_of :name, :scope => [:provider_id]
>
> - validates_presence_of :storage
> - validates_numericality_of :storage, :greater_than => 0
> - validates_presence_of :memory
> - validates_numericality_of :memory, :greater_than => 0
> -
> - validates_presence_of :architecture, :if => :provider
> + validates_associated :memory
> + validates_associated :storage
> + validates_associated :cpu
> + validates_associated :architecture
>
> def provider_hardware_profile?
> !provider.nil?
> @@ -68,4 +75,28 @@ class HardwareProfile < ActiveRecord::Base
> end
> end
> end
> +
> + def add_properties(api_profile)
> + self.memory = new_property(api_profile.memory)
> + self.storage = new_property(api_profile.storage)
> + self.cpu = new_property(api_profile.cpu)
> + self.architecture = new_property(api_profile.architecture)
> + end
> + def new_property(prop)
> + return nil unless prop.present?
> + the_property = HardwareProfileProperty.new(:name => prop.name,
> + :kind => prop.kind,
> + :unit => prop.unit,
> + :value => prop.value)
> + case prop.kind
> + when HardwareProfileProperty::RANGE
> + the_property.range_first = prop.range.first
> + the_property.range_last = prop.range.last
> + when HardwareProfileProperty::ENUM
> + the_property.property_enum_entries = prop.enum.entries.collect
> do |entry|
> + PropertyEnumEntry.new(:value => entry,
> :hardware_profile_property => the_property)
> + end
> + end
> + the_property
> + end
> end
> diff --git a/src/app/models/hardware_profile_property.rb
> b/src/app/models/hardware_profile_property.rb
> new file mode 100644
> index 0000000..1da5ba7
> --- /dev/null
> +++ b/src/app/models/hardware_profile_property.rb
> @@ -0,0 +1,122 @@
> +#
> +# Copyright (C) 2010 Red Hat, Inc.
> +#
> +# This program is free software; you can redistribute it and/or
> modify
> +# it under the terms of the GNU General Public License as published
> by
> +# the Free Software Foundation; version 2 of the License.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA 02110-1301, USA. A copy of the GNU General Public License is
> +# also available at http://www.gnu.org/copyleft/gpl.html.
> +
> +# Filters added to this controller apply to all controllers in the
> application.
> +# Likewise, all the methods added will be available for all
> controllers.
> +
> +class HardwareProfileProperty < ActiveRecord::Base
> +
> + MEMORY = "memory"
> + STORAGE = "storage"
> + CPU = "cpu"
> + ARCHITECTURE = "architecture"
> +
> + FIXED = "fixed"
> + RANGE = "range"
> + ENUM = "enum"
> +
> + UNIT_MB = "MB"
> + UNIT_GB = "GB"
> + UNIT_LABEL = "label"
> + UNIT_COUNT = "count"
> +
> + has_many :property_enum_entries
> +
> + validates_presence_of :name
> + validates_inclusion_of :name,
> + :in => [MEMORY, STORAGE, CPU, ARCHITECTURE]
> +
> + validates_presence_of :kind
> + validates_inclusion_of :kind,
> + :in => [FIXED, RANGE, ENUM]
> +
> + validates_presence_of :unit
> + validates_presence_of :value
> + validates_numericality_of :value, :greater_than => 0,
> + :if => Proc.new{|p| p.name == MEMORY or p.name ==
> STORAGE }
> + validates_numericality_of :value, :greater_than => 0,
> + :if => Proc.new{|p| p.name == CPU }, :only_integer =>
> true
> +
> + validates_numericality_of :range_first, :greater_than => 0,
> + :if => Proc.new{|p| (p.name == MEMORY or p.name ==
> STORAGE) and
> + p.kind == RANGE}
> + validates_numericality_of :range_last, :greater_than => 0,
> + :if => Proc.new{|p| (p.name == MEMORY or p.name ==
> STORAGE) and
> + p.kind == RANGE}
> + validates_numericality_of :range_first, :greater_than => 0,
> + :if => Proc.new{|p| (p.name == CPU) and
> + p.kind == RANGE}, :only_integer
> => true
> + validates_numericality_of :range_last, :greater_than => 0,
> + :if => Proc.new{|p| (p.name == CPU) and
> + p.kind == RANGE}, :only_integer
> => true
> + validates_associated :property_enum_entries
> + def validate
> + case name
> + when MEMORY
> + unless unit == UNIT_MB
> + errors.add(:unit, "Memory must be specified in MB")
> + end
> + when STORAGE
> + unless unit == UNIT_GB
> + errors.add(:unit, "Storage must be specified in GB")
> + end
> + when CPU
> + unless unit == UNIT_COUNT
> + errors.add(:unit, "CPUs must be specified as a count")
> + end
> + when ARCHITECTURE
> + unless unit == UNIT_LABEL
> + errors.add(:unit, "Architecture must be specified as a
> label")
> + end
> + end
> +
> + if kind==RANGE
> + if range_first.nil?
> + errors.add(:range_first,
> + "Range beginning must be specified for range
> properties")
> + end
> + if range_last.nil?
> + errors.add(:range_last,
> + "Range ending must be specified for range
> properties")
> + end
> + else
> + unless range_first.nil?
> + errors.add(:range_first,
> + "Range beginning must only be specified for range
> properties")
> + end
> + unless range_last.nil?
> + errors.add(:range_last,
> + "Range ending must only be specified for range
> properties")
> + end
> + end
> +
> +# if kind==ENUM
> +# if property_enum_entries.empty?
> +# errors.add(:property_enum_entries,
> +# "Enum values must be specified for enum
> properties")
> +# end
> +# else
> +# unless property_enum_entries.empty?
> +# errors.add(:property_enum_entries,
> +# "Enum values must only be specified for enum
> properties")
> +# end
> +# end
Commented out, breaks the tests otherwise.
> +
> + end
> +end
> +
> diff --git a/src/app/models/property_enum_entry.rb
> b/src/app/models/property_enum_entry.rb
> new file mode 100644
> index 0000000..eb246ff
> --- /dev/null
> +++ b/src/app/models/property_enum_entry.rb
> @@ -0,0 +1,37 @@
> +#
> +# Copyright (C) 2010 Red Hat, Inc.
> +#
> +# This program is free software; you can redistribute it and/or
> modify
> +# it under the terms of the GNU General Public License as published
> by
> +# the Free Software Foundation; version 2 of the License.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA 02110-1301, USA. A copy of the GNU General Public License is
> +# also available at http://www.gnu.org/copyleft/gpl.html.
> +
> +# Filters added to this controller apply to all controllers in the
> application.
> +# Likewise, all the methods added will be available for all
> controllers.
> +
> +class PropertyEnumEntry < ActiveRecord::Base
> +
> + belongs_to :hardware_profile_property
> +
> + validates_presence_of :value
> + validates_presence_of :hardware_profile_property
> + validates_numericality_of :value, :greater_than => 0,
> + :if => Proc.new{|p| p.hardware_profile_property.name
> ==
> + HardwareProfileProperty::MEMORY
> or
> + p.hardware_profile_property.name ==
> + HardwareProfileProperty::STORAGE
> }
> + validates_numericality_of :value, :greater_than => 0, :only_integer
> => true,
> + :if => Proc.new{|p| p.hardware_profile_property.name
> ==
> + HardwareProfileProperty::CPU }
> +
> +end
> diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
> index 20b9e1e..0a0120f 100644
> --- a/src/app/models/provider.rb
> +++ b/src/app/models/provider.rb
> @@ -50,16 +50,17 @@ class Provider < ActiveRecord::Base
>
> def populate_hardware_profiles
> # FIXME: once API has hw profiles, change the below
> - hardware_profiles = connect.flavors
> + hardware_profiles = connect.hardware_profiles
> # FIXME: this should probably be in the same transaction as
> provider.save
> self.transaction do
> hardware_profiles.each do |hardware_profile|
> - ar_hardware_profile = HardwareProfile.new(:external_key =>
> hardware_profile.id,
> - :name => hardware_profile.name ?
> hardware_profile.name : hardware_profile.id,
> - :memory => hardware_profile.memory,
> - :storage => hardware_profile.storage,
> - :architecture =>
> hardware_profile.architecture,
> - :provider_id => id)
> + ar_hardware_profile = HardwareProfile.new(:external_key =>
> +
> hardware_profile.id,
> + :name =>
> hardware_profile.name ?
> +
> hardware_profile.name :
> +
> hardware_profile.id,
> + :provider_id =>
> id)
> + ar_hardware_profile.add_properties(hardware_profile)
> ar_hardware_profile.save!
> front_hwp = HardwareProfile.new(:external_key =>
> name +
> @@ -67,10 +68,8 @@ class Provider < ActiveRecord::Base
>
> ar_hardware_profile.external_key,
> :name => name +
>
> Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER +
> - ar_hardware_profile.name,
> - :memory =>
> ar_hardware_profile.memory,
> - :storage =>
> ar_hardware_profile.storage,
> - :architecture =>
> ar_hardware_profile.architecture)
> + ar_hardware_profile.name)
> + front_hwp.add_properties(hardware_profile)
> front_hwp.provider_hardware_profiles << ar_hardware_profile
> front_hwp.save!
> end
> diff --git a/src/app/views/hardware_profiles/_list.html.erb
> b/src/app/views/hardware_profiles/_list.html.erb
> index 6b53194..1125c09 100644
> --- a/src/app/views/hardware_profiles/_list.html.erb
> +++ b/src/app/views/hardware_profiles/_list.html.erb
> @@ -7,6 +7,7 @@
> <th scope="col">Name</th>
> <th scope="col">Memory</th>
> <th scope="col">Storage</th>
> + <th scope="col">CPU</th>
> <th scope="col">Architecture</th>
> </tr>
> </thead>
> @@ -14,9 +15,10 @@
> <%(a)hardware_profiles.each {|hp| %>
> <tr>
> <td><%= hp.name %></td>
> - <td><%= hp.memory %></td>
> - <td><%= hp.storage %></td>
> - <td><%= hp.architecture %></td>
> + <td><%= hp.memory.value if hp.memory %></td>
> + <td><%= hp.storage.value if hp.storage %></td>
> + <td><%= hp.cpu.value if hp.cpu %></td>
> + <td><%= hp.architecture.value if hp.architecture %></td>
> </tr>
> <% } %>
> </tbody>
> diff --git a/src/db/migrate/20090804135630_create_hardware_profiles.rb
> b/src/db/migrate/20090804135630_create_hardware_profiles.rb
> index 95bc0ce..5ad0435 100644
> --- a/src/db/migrate/20090804135630_create_hardware_profiles.rb
> +++ b/src/db/migrate/20090804135630_create_hardware_profiles.rb
> @@ -21,12 +21,31 @@
>
> class CreateHardwareProfiles < ActiveRecord::Migration
> def self.up
> + create_table :hardware_profile_properties do |t|
> + t.string :name, :null => false
> + t.string :kind, :null => false
> + t.string :unit, :null => false
> + t.string :value, :null => false
> + t.string :range_first
> + t.string :range_last
> + t.integer :lock_version, :default => 0
> + t.timestamps
> + end
> +
> + create_table :property_enum_entries do |t|
> + t.integer :hardware_profile_property_id, :null => false
> + t.string :value, :null => false
> + t.integer :lock_version, :default => 0
> + t.timestamps
> + end
> +
> create_table :hardware_profiles do |t|
> t.string :external_key, :null => false
> t.string :name, :null => false, :limit => 1024
> - t.float :memory, :null => false
> - t.float :storage, :null => false
> - t.string :architecture, :null => false
> + t.integer :memory_id
> + t.integer :storage_id
> + t.integer :cpu_id
> + t.integer :architecture_id
> t.integer :provider_id
> t.integer :lock_version, :default => 0
> t.timestamps
> diff --git a/src/spec/factories/hardware_profile.rb
> b/src/spec/factories/hardware_profile.rb
> index 43f63f3..9b19f01 100644
> --- a/src/spec/factories/hardware_profile.rb
> +++ b/src/spec/factories/hardware_profile.rb
> @@ -3,29 +3,35 @@ Factory.define :hardware_profile do |p|
> end
>
> Factory.define :mock_hwp1, :parent => :hardware_profile do |p|
> - p.memory 1024
> - p.storage 100
> + p.memory { |p| p.association(:mock_hwp1_memory) }
> + p.storage { |p| p.association(:mock_hwp1_storage) }
> + p.cpu { |p| p.association(:mock_hwp1_cpu) }
> + p.architecture { |p| p.association(:mock_hwp1_arch) }
> p.external_key 'mock_hwp1_key'
> - p.architecture 'i686'
> end
>
> Factory.define :mock_hwp2, :parent => :hardware_profile do |p|
> - p.memory 2048
> - p.storage 400
> + p.memory { |p| p.association(:mock_hwp2_memory) }
> + p.storage { |p| p.association(:mock_hwp2_storage) }
> + p.cpu { |p| p.association(:mock_hwp2_cpu) }
> + p.architecture { |p| p.association(:mock_hwp2_arch) }
> p.external_key 'mock_hwp2_key'
> - p.architecture 'x86_64'
> end
>
> -Factory.define :pool_hwp1, :parent => :hardware_profile do |p|
> - p.memory 2048
> - p.storage 400
> - p.external_key 'pool_hwp1_key'
> - p.architecture 'x86_64'
> +Factory.define :agg_hwp1, :parent => :hardware_profile do |p|
> + p.memory { |p| p.association(:agg_hwp1_memory) }
> + p.storage { |p| p.association(:agg_hwp1_storage) }
> + p.cpu { |p| p.association(:agg_hwp1_cpu) }
> + p.architecture { |p| p.association(:agg_hwp1_arch) }
> + p.provider_hardware_profiles { |hp| [hp.association(:mock_hwp1)] }
> + p.external_key 'agg_hwp1_key'
> end
>
> -Factory.define :hardware_profile_auto, :parent => :hardware_profile
> do |p|
> - p.external_key { |hp| hp.name + "_key" }
> - p.storage 160
> - p.memory 1024
> - p.architecture "i386"
> -end
> \ No newline at end of file
> +Factory.define :agg_hwp2, :parent => :hardware_profile do |p|
> + p.memory { |p| p.association(:agg_hwp2_memory) }
> + p.storage { |p| p.association(:agg_hwp2_storage) }
> + p.cpu { |p| p.association(:agg_hwp2_cpu) }
> + p.architecture { |p| p.association(:agg_hwp2_arch) }
> + p.provider_hardware_profiles { |hp| [hp.association(:mock_hwp2)] }
> + p.external_key 'agg_hwp2_key'
> +end
> diff --git a/src/spec/factories/hardware_profile_property.rb
> b/src/spec/factories/hardware_profile_property.rb
> new file mode 100644
> index 0000000..7f470f6
> --- /dev/null
> +++ b/src/spec/factories/hardware_profile_property.rb
> @@ -0,0 +1,122 @@
> +Factory.define :hardware_profile_property do |p|
> +end
> +
> +Factory.define :mock_hwp1_memory, :parent =>
> :hardware_profile_property do |p|
> + p.name 'memory'
> + p.kind 'fixed'
> + p.unit 'MB'
> + p.value 1740.8
> +end
> +
> +Factory.define :mock_hwp1_storage, :parent =>
> :hardware_profile_property do |p|
> + p.name 'storage'
> + p.kind 'fixed'
> + p.unit 'GB'
> + p.value 160
> +end
> +
> +Factory.define :mock_hwp1_cpu, :parent => :hardware_profile_property
> do |p|
> + p.name 'cpu'
> + p.kind 'fixed'
> + p.unit 'count'
> + p.value 1
> +end
> +
> +Factory.define :mock_hwp1_arch, :parent => :hardware_profile_property
> do |p|
> + p.name 'architecture'
> + p.kind 'fixed'
> + p.unit 'label'
> + p.value 'i386'
> +end
> +
> +Factory.define :mock_hwp2_memory, :parent =>
> :hardware_profile_property do |p|
> + p.name 'memory'
> + p.kind 'range'
> + p.unit 'MB'
> + p.value 10240
> + p.range_first 7680
> + p.range_last 15360
> +end
> +
> +Factory.define :mock_hwp2_storage, :parent =>
> :hardware_profile_property do |p|
> + p.name 'storage'
> + p.kind 'enum'
> + p.unit 'GB'
> + p.value 850
> +# p.property_enum_entries { |p|
> [p.association(:mock_hwp2_storage_enum1),
> +#
> p.association(:mock_hwp2_storage_enum2)] }
> +end
Same here
> +
> +Factory.define :mock_hwp2_cpu, :parent => :hardware_profile_property
> do |p|
> + p.name 'cpu'
> + p.kind 'fixed'
> + p.unit 'count'
> + p.value 2
> +end
> +
> +Factory.define :mock_hwp2_arch, :parent => :hardware_profile_property
> do |p|
> + p.name 'architecture'
> + p.kind 'fixed'
> + p.unit 'label'
> + p.value 'x86_64'
> +end
> +
> +Factory.define :agg_hwp1_memory, :parent =>
> :hardware_profile_property do |p|
> + p.name 'memory'
> + p.kind 'fixed'
> + p.unit 'MB'
> + p.value 1740.8
> +end
> +
> +Factory.define :agg_hwp1_storage, :parent =>
> :hardware_profile_property do |p|
> + p.name 'storage'
> + p.kind 'fixed'
> + p.unit 'GB'
> + p.value 160
> +end
> +
> +Factory.define :agg_hwp1_cpu, :parent => :hardware_profile_property
> do |p|
> + p.name 'cpu'
> + p.kind 'fixed'
> + p.unit 'count'
> + p.value 1
> +end
> +
> +Factory.define :agg_hwp1_arch, :parent => :hardware_profile_property
> do |p|
> + p.name 'architecture'
> + p.kind 'fixed'
> + p.unit 'label'
> + p.value 'i386'
> +end
> +
> +Factory.define :agg_hwp2_memory, :parent =>
> :hardware_profile_property do |p|
> + p.name 'memory'
> + p.kind 'range'
> + p.unit 'MB'
> + p.value 10240
> + p.range_first 7680
> + p.range_last 15360
> +end
> +
> +Factory.define :agg_hwp2_storage, :parent =>
> :hardware_profile_property do |p|
> + p.name 'storage'
> + p.kind 'enum'
> + p.unit 'GB'
> + p.value 850
> +# p.property_enum_entries { |p|
> [p.association(:agg_hwp2_storage_enum1),
> +#
> p.association(:agg_hwp2_storage_enum2)] }
and here.
> +end
> +
> +Factory.define :agg_hwp2_cpu, :parent => :hardware_profile_property
> do |p|
> + p.name 'cpu'
> + p.kind 'fixed'
> + p.unit 'count'
> + p.value 2
> +end
> +
> +Factory.define :agg_hwp2_arch, :parent => :hardware_profile_property
> do |p|
> + p.name 'architecture'
> + p.kind 'fixed'
> + p.unit 'label'
> + p.value 'x86_64'
> +end
> diff --git a/src/spec/factories/pool.rb b/src/spec/factories/pool.rb
> index 2f9111e..d95fb13 100644
> --- a/src/spec/factories/pool.rb
> +++ b/src/spec/factories/pool.rb
> @@ -5,5 +5,5 @@ end
>
> Factory.define :tpool, :parent => :pool do |p|
> p.name 'tpool'
> - p.hardware_profiles { |hp| [hp.association(:pool_hwp1)] }
> +# p.hardware_profiles { |hp| [hp.association(:pool_hwp1)] }
And finally, here.
> end
> diff --git a/src/spec/factories/property_enum_entry.rb
> b/src/spec/factories/property_enum_entry.rb
> new file mode 100644
> index 0000000..78b99d5
> --- /dev/null
> +++ b/src/spec/factories/property_enum_entry.rb
> @@ -0,0 +1,26 @@
> +Factory.define :property_enum_entry do |e|
> +end
> +
> +Factory.define :mock_hwp2_storage_enum1, :parent =>
> :property_enum_entry do |e|
> + e.value 850
> + e.prop_name 'storage'
> + e.hardware_profile_property { |e| e.association(:mock_hwp2_storage)
> }
> +end
> +
> +Factory.define :mock_hwp2_storage_enum2, :parent =>
> :property_enum_entry do |e|
> + e.value 1024
> + e.prop_name 'storage'
> + e.hardware_profile_property { |e| e.association(:mock_hwp2_storage)
> }
> +end
> +
> +Factory.define :agg_hwp2_storage_enum1, :parent =>
> :property_enum_entry do |e|
> + e.value 850
> + e.prop_name 'storage'
> + e.hardware_profile_property { |e| e.association(:agg_hwp2_storage)
> }
> +end
> +
> +Factory.define :agg_hwp2_storage_enum2, :parent =>
> :property_enum_entry do |e|
> + e.value 1024
> + e.prop_name 'storage'
> + e.hardware_profile_property { |e| e.association(:agg_hwp2_storage)
> }
> +end
> diff --git a/src/spec/models/hardware_profile_spec.rb
> b/src/spec/models/hardware_profile_spec.rb
> index e2b09b4..ab04fe1 100644
> --- a/src/spec/models/hardware_profile_spec.rb
> +++ b/src/spec/models/hardware_profile_spec.rb
> @@ -30,31 +30,18 @@ describe HardwareProfile do
>
> it "should require valid amount of memory" do
> [nil, "hello", -1].each do |fail_value|
> - @hp.memory = fail_value
> + @hp.memory.value = fail_value
> @hp.should_not be_valid
> end
> end
>
> it "should require valid amount of storage" do
> [nil, "hello", -1].each do |fail_value|
> - @hp.storage = fail_value
> + @hp.storage.value = fail_value
> @hp.should_not be_valid
> end
> end
>
> - it "should not require architecture when there's no provider" do
> - @hp.architecture = nil
> - @hp.should be_valid
> - end
> -
> - it "should require architecture when it's with provider" do
> - @hp.provider = Provider.new
> -
> - @hp.should be_valid
> - @hp.architecture = nil
> - @hp.should_not be_valid
> - end
> -
> it "should allow Aggregator profiles only for provider profiles"
> do
> @hp.provider = nil
>
> --
> 1.6.2.5
>
> _______________________________________________
> deltacloud-devel mailing list
> deltacloud-devel(a)lists.fedorahosted.org
> https://fedorahosted.org/mailman/listinfo/deltacloud-devel
14 years
[PATCH aggregator] updated aggregator to use core hardware profiles
by Scott Seago
Removes all references to core flavors and replaces them with hardware profiles.
Updates aggregator model to include the range and enum properties for hardware profiles.
To use this patch, you need to rebuild the aggregator database, and rebuild the
client gem with this patch:
[PATCH core] update to hardware profile client to include new property metadata.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/models/hardware_profile.rb | 43 ++++++-
src/app/models/hardware_profile_property.rb | 122 ++++++++++++++++++++
src/app/models/property_enum_entry.rb | 37 ++++++
src/app/models/provider.rb | 21 ++--
src/app/views/hardware_profiles/_list.html.erb | 8 +-
.../20090804135630_create_hardware_profiles.rb | 25 ++++-
src/spec/factories/hardware_profile.rb | 40 ++++---
src/spec/factories/hardware_profile_property.rb | 122 ++++++++++++++++++++
src/spec/factories/pool.rb | 2 +-
src/spec/factories/property_enum_entry.rb | 26 ++++
src/spec/models/hardware_profile_spec.rb | 17 +---
11 files changed, 407 insertions(+), 56 deletions(-)
create mode 100644 src/app/models/hardware_profile_property.rb
create mode 100644 src/app/models/property_enum_entry.rb
create mode 100644 src/spec/factories/hardware_profile_property.rb
create mode 100644 src/spec/factories/property_enum_entry.rb
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index d98c2f9..a92b658 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -25,6 +25,15 @@ class HardwareProfile < ActiveRecord::Base
:foreign_key => "provider_hardware_profile_id"
belongs_to :provider
+ belongs_to :memory, :class_name => "HardwareProfileProperty",
+ :dependent => :destroy
+ belongs_to :storage, :class_name => "HardwareProfileProperty",
+ :dependent => :destroy
+ belongs_to :cpu, :class_name => "HardwareProfileProperty",
+ :dependent => :destroy
+ belongs_to :architecture, :class_name => "HardwareProfileProperty",
+ :dependent => :destroy
+
has_and_belongs_to_many :aggregator_hardware_profiles,
:class_name => "HardwareProfile",
:join_table => "hardware_profile_map",
@@ -43,12 +52,10 @@ class HardwareProfile < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:provider_id]
- validates_presence_of :storage
- validates_numericality_of :storage, :greater_than => 0
- validates_presence_of :memory
- validates_numericality_of :memory, :greater_than => 0
-
- validates_presence_of :architecture, :if => :provider
+ validates_associated :memory
+ validates_associated :storage
+ validates_associated :cpu
+ validates_associated :architecture
def provider_hardware_profile?
!provider.nil?
@@ -68,4 +75,28 @@ class HardwareProfile < ActiveRecord::Base
end
end
end
+
+ def add_properties(api_profile)
+ self.memory = new_property(api_profile.memory)
+ self.storage = new_property(api_profile.storage)
+ self.cpu = new_property(api_profile.cpu)
+ self.architecture = new_property(api_profile.architecture)
+ end
+ def new_property(prop)
+ return nil unless prop.present?
+ the_property = HardwareProfileProperty.new(:name => prop.name,
+ :kind => prop.kind,
+ :unit => prop.unit,
+ :value => prop.value)
+ case prop.kind
+ when HardwareProfileProperty::RANGE
+ the_property.range_first = prop.range.first
+ the_property.range_last = prop.range.last
+ when HardwareProfileProperty::ENUM
+ the_property.property_enum_entries = prop.enum.entries.collect do |entry|
+ PropertyEnumEntry.new(:value => entry, :hardware_profile_property => the_property)
+ end
+ end
+ the_property
+ end
end
diff --git a/src/app/models/hardware_profile_property.rb b/src/app/models/hardware_profile_property.rb
new file mode 100644
index 0000000..1da5ba7
--- /dev/null
+++ b/src/app/models/hardware_profile_property.rb
@@ -0,0 +1,122 @@
+#
+# Copyright (C) 2010 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class HardwareProfileProperty < ActiveRecord::Base
+
+ MEMORY = "memory"
+ STORAGE = "storage"
+ CPU = "cpu"
+ ARCHITECTURE = "architecture"
+
+ FIXED = "fixed"
+ RANGE = "range"
+ ENUM = "enum"
+
+ UNIT_MB = "MB"
+ UNIT_GB = "GB"
+ UNIT_LABEL = "label"
+ UNIT_COUNT = "count"
+
+ has_many :property_enum_entries
+
+ validates_presence_of :name
+ validates_inclusion_of :name,
+ :in => [MEMORY, STORAGE, CPU, ARCHITECTURE]
+
+ validates_presence_of :kind
+ validates_inclusion_of :kind,
+ :in => [FIXED, RANGE, ENUM]
+
+ validates_presence_of :unit
+ validates_presence_of :value
+ validates_numericality_of :value, :greater_than => 0,
+ :if => Proc.new{|p| p.name == MEMORY or p.name == STORAGE }
+ validates_numericality_of :value, :greater_than => 0,
+ :if => Proc.new{|p| p.name == CPU }, :only_integer => true
+
+ validates_numericality_of :range_first, :greater_than => 0,
+ :if => Proc.new{|p| (p.name == MEMORY or p.name == STORAGE) and
+ p.kind == RANGE}
+ validates_numericality_of :range_last, :greater_than => 0,
+ :if => Proc.new{|p| (p.name == MEMORY or p.name == STORAGE) and
+ p.kind == RANGE}
+ validates_numericality_of :range_first, :greater_than => 0,
+ :if => Proc.new{|p| (p.name == CPU) and
+ p.kind == RANGE}, :only_integer => true
+ validates_numericality_of :range_last, :greater_than => 0,
+ :if => Proc.new{|p| (p.name == CPU) and
+ p.kind == RANGE}, :only_integer => true
+ validates_associated :property_enum_entries
+ def validate
+ case name
+ when MEMORY
+ unless unit == UNIT_MB
+ errors.add(:unit, "Memory must be specified in MB")
+ end
+ when STORAGE
+ unless unit == UNIT_GB
+ errors.add(:unit, "Storage must be specified in GB")
+ end
+ when CPU
+ unless unit == UNIT_COUNT
+ errors.add(:unit, "CPUs must be specified as a count")
+ end
+ when ARCHITECTURE
+ unless unit == UNIT_LABEL
+ errors.add(:unit, "Architecture must be specified as a label")
+ end
+ end
+
+ if kind==RANGE
+ if range_first.nil?
+ errors.add(:range_first,
+ "Range beginning must be specified for range properties")
+ end
+ if range_last.nil?
+ errors.add(:range_last,
+ "Range ending must be specified for range properties")
+ end
+ else
+ unless range_first.nil?
+ errors.add(:range_first,
+ "Range beginning must only be specified for range properties")
+ end
+ unless range_last.nil?
+ errors.add(:range_last,
+ "Range ending must only be specified for range properties")
+ end
+ end
+
+# if kind==ENUM
+# if property_enum_entries.empty?
+# errors.add(:property_enum_entries,
+# "Enum values must be specified for enum properties")
+# end
+# else
+# unless property_enum_entries.empty?
+# errors.add(:property_enum_entries,
+# "Enum values must only be specified for enum properties")
+# end
+# end
+
+ end
+end
+
diff --git a/src/app/models/property_enum_entry.rb b/src/app/models/property_enum_entry.rb
new file mode 100644
index 0000000..eb246ff
--- /dev/null
+++ b/src/app/models/property_enum_entry.rb
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 2010 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class PropertyEnumEntry < ActiveRecord::Base
+
+ belongs_to :hardware_profile_property
+
+ validates_presence_of :value
+ validates_presence_of :hardware_profile_property
+ validates_numericality_of :value, :greater_than => 0,
+ :if => Proc.new{|p| p.hardware_profile_property.name ==
+ HardwareProfileProperty::MEMORY or
+ p.hardware_profile_property.name ==
+ HardwareProfileProperty::STORAGE }
+ validates_numericality_of :value, :greater_than => 0, :only_integer => true,
+ :if => Proc.new{|p| p.hardware_profile_property.name ==
+ HardwareProfileProperty::CPU }
+
+end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 20b9e1e..0a0120f 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -50,16 +50,17 @@ class Provider < ActiveRecord::Base
def populate_hardware_profiles
# FIXME: once API has hw profiles, change the below
- hardware_profiles = connect.flavors
+ hardware_profiles = connect.hardware_profiles
# FIXME: this should probably be in the same transaction as provider.save
self.transaction do
hardware_profiles.each do |hardware_profile|
- ar_hardware_profile = HardwareProfile.new(:external_key => hardware_profile.id,
- :name => hardware_profile.name ? hardware_profile.name : hardware_profile.id,
- :memory => hardware_profile.memory,
- :storage => hardware_profile.storage,
- :architecture => hardware_profile.architecture,
- :provider_id => id)
+ ar_hardware_profile = HardwareProfile.new(:external_key =>
+ hardware_profile.id,
+ :name => hardware_profile.name ?
+ hardware_profile.name :
+ hardware_profile.id,
+ :provider_id => id)
+ ar_hardware_profile.add_properties(hardware_profile)
ar_hardware_profile.save!
front_hwp = HardwareProfile.new(:external_key =>
name +
@@ -67,10 +68,8 @@ class Provider < ActiveRecord::Base
ar_hardware_profile.external_key,
:name => name +
Realm::AGGREGATOR_REALM_ACCOUNT_DELIMITER +
- ar_hardware_profile.name,
- :memory => ar_hardware_profile.memory,
- :storage => ar_hardware_profile.storage,
- :architecture => ar_hardware_profile.architecture)
+ ar_hardware_profile.name)
+ front_hwp.add_properties(hardware_profile)
front_hwp.provider_hardware_profiles << ar_hardware_profile
front_hwp.save!
end
diff --git a/src/app/views/hardware_profiles/_list.html.erb b/src/app/views/hardware_profiles/_list.html.erb
index 6b53194..1125c09 100644
--- a/src/app/views/hardware_profiles/_list.html.erb
+++ b/src/app/views/hardware_profiles/_list.html.erb
@@ -7,6 +7,7 @@
<th scope="col">Name</th>
<th scope="col">Memory</th>
<th scope="col">Storage</th>
+ <th scope="col">CPU</th>
<th scope="col">Architecture</th>
</tr>
</thead>
@@ -14,9 +15,10 @@
<%(a)hardware_profiles.each {|hp| %>
<tr>
<td><%= hp.name %></td>
- <td><%= hp.memory %></td>
- <td><%= hp.storage %></td>
- <td><%= hp.architecture %></td>
+ <td><%= hp.memory.value if hp.memory %></td>
+ <td><%= hp.storage.value if hp.storage %></td>
+ <td><%= hp.cpu.value if hp.cpu %></td>
+ <td><%= hp.architecture.value if hp.architecture %></td>
</tr>
<% } %>
</tbody>
diff --git a/src/db/migrate/20090804135630_create_hardware_profiles.rb b/src/db/migrate/20090804135630_create_hardware_profiles.rb
index 95bc0ce..5ad0435 100644
--- a/src/db/migrate/20090804135630_create_hardware_profiles.rb
+++ b/src/db/migrate/20090804135630_create_hardware_profiles.rb
@@ -21,12 +21,31 @@
class CreateHardwareProfiles < ActiveRecord::Migration
def self.up
+ create_table :hardware_profile_properties do |t|
+ t.string :name, :null => false
+ t.string :kind, :null => false
+ t.string :unit, :null => false
+ t.string :value, :null => false
+ t.string :range_first
+ t.string :range_last
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+
+ create_table :property_enum_entries do |t|
+ t.integer :hardware_profile_property_id, :null => false
+ t.string :value, :null => false
+ t.integer :lock_version, :default => 0
+ t.timestamps
+ end
+
create_table :hardware_profiles do |t|
t.string :external_key, :null => false
t.string :name, :null => false, :limit => 1024
- t.float :memory, :null => false
- t.float :storage, :null => false
- t.string :architecture, :null => false
+ t.integer :memory_id
+ t.integer :storage_id
+ t.integer :cpu_id
+ t.integer :architecture_id
t.integer :provider_id
t.integer :lock_version, :default => 0
t.timestamps
diff --git a/src/spec/factories/hardware_profile.rb b/src/spec/factories/hardware_profile.rb
index 43f63f3..9b19f01 100644
--- a/src/spec/factories/hardware_profile.rb
+++ b/src/spec/factories/hardware_profile.rb
@@ -3,29 +3,35 @@ Factory.define :hardware_profile do |p|
end
Factory.define :mock_hwp1, :parent => :hardware_profile do |p|
- p.memory 1024
- p.storage 100
+ p.memory { |p| p.association(:mock_hwp1_memory) }
+ p.storage { |p| p.association(:mock_hwp1_storage) }
+ p.cpu { |p| p.association(:mock_hwp1_cpu) }
+ p.architecture { |p| p.association(:mock_hwp1_arch) }
p.external_key 'mock_hwp1_key'
- p.architecture 'i686'
end
Factory.define :mock_hwp2, :parent => :hardware_profile do |p|
- p.memory 2048
- p.storage 400
+ p.memory { |p| p.association(:mock_hwp2_memory) }
+ p.storage { |p| p.association(:mock_hwp2_storage) }
+ p.cpu { |p| p.association(:mock_hwp2_cpu) }
+ p.architecture { |p| p.association(:mock_hwp2_arch) }
p.external_key 'mock_hwp2_key'
- p.architecture 'x86_64'
end
-Factory.define :pool_hwp1, :parent => :hardware_profile do |p|
- p.memory 2048
- p.storage 400
- p.external_key 'pool_hwp1_key'
- p.architecture 'x86_64'
+Factory.define :agg_hwp1, :parent => :hardware_profile do |p|
+ p.memory { |p| p.association(:agg_hwp1_memory) }
+ p.storage { |p| p.association(:agg_hwp1_storage) }
+ p.cpu { |p| p.association(:agg_hwp1_cpu) }
+ p.architecture { |p| p.association(:agg_hwp1_arch) }
+ p.provider_hardware_profiles { |hp| [hp.association(:mock_hwp1)] }
+ p.external_key 'agg_hwp1_key'
end
-Factory.define :hardware_profile_auto, :parent => :hardware_profile do |p|
- p.external_key { |hp| hp.name + "_key" }
- p.storage 160
- p.memory 1024
- p.architecture "i386"
-end
\ No newline at end of file
+Factory.define :agg_hwp2, :parent => :hardware_profile do |p|
+ p.memory { |p| p.association(:agg_hwp2_memory) }
+ p.storage { |p| p.association(:agg_hwp2_storage) }
+ p.cpu { |p| p.association(:agg_hwp2_cpu) }
+ p.architecture { |p| p.association(:agg_hwp2_arch) }
+ p.provider_hardware_profiles { |hp| [hp.association(:mock_hwp2)] }
+ p.external_key 'agg_hwp2_key'
+end
diff --git a/src/spec/factories/hardware_profile_property.rb b/src/spec/factories/hardware_profile_property.rb
new file mode 100644
index 0000000..7f470f6
--- /dev/null
+++ b/src/spec/factories/hardware_profile_property.rb
@@ -0,0 +1,122 @@
+Factory.define :hardware_profile_property do |p|
+end
+
+Factory.define :mock_hwp1_memory, :parent => :hardware_profile_property do |p|
+ p.name 'memory'
+ p.kind 'fixed'
+ p.unit 'MB'
+ p.value 1740.8
+end
+
+Factory.define :mock_hwp1_storage, :parent => :hardware_profile_property do |p|
+ p.name 'storage'
+ p.kind 'fixed'
+ p.unit 'GB'
+ p.value 160
+end
+
+Factory.define :mock_hwp1_cpu, :parent => :hardware_profile_property do |p|
+ p.name 'cpu'
+ p.kind 'fixed'
+ p.unit 'count'
+ p.value 1
+end
+
+Factory.define :mock_hwp1_arch, :parent => :hardware_profile_property do |p|
+ p.name 'architecture'
+ p.kind 'fixed'
+ p.unit 'label'
+ p.value 'i386'
+end
+
+Factory.define :mock_hwp2_memory, :parent => :hardware_profile_property do |p|
+ p.name 'memory'
+ p.kind 'range'
+ p.unit 'MB'
+ p.value 10240
+ p.range_first 7680
+ p.range_last 15360
+end
+
+Factory.define :mock_hwp2_storage, :parent => :hardware_profile_property do |p|
+ p.name 'storage'
+ p.kind 'enum'
+ p.unit 'GB'
+ p.value 850
+# p.property_enum_entries { |p| [p.association(:mock_hwp2_storage_enum1),
+# p.association(:mock_hwp2_storage_enum2)] }
+end
+
+Factory.define :mock_hwp2_cpu, :parent => :hardware_profile_property do |p|
+ p.name 'cpu'
+ p.kind 'fixed'
+ p.unit 'count'
+ p.value 2
+end
+
+Factory.define :mock_hwp2_arch, :parent => :hardware_profile_property do |p|
+ p.name 'architecture'
+ p.kind 'fixed'
+ p.unit 'label'
+ p.value 'x86_64'
+end
+
+Factory.define :agg_hwp1_memory, :parent => :hardware_profile_property do |p|
+ p.name 'memory'
+ p.kind 'fixed'
+ p.unit 'MB'
+ p.value 1740.8
+end
+
+Factory.define :agg_hwp1_storage, :parent => :hardware_profile_property do |p|
+ p.name 'storage'
+ p.kind 'fixed'
+ p.unit 'GB'
+ p.value 160
+end
+
+Factory.define :agg_hwp1_cpu, :parent => :hardware_profile_property do |p|
+ p.name 'cpu'
+ p.kind 'fixed'
+ p.unit 'count'
+ p.value 1
+end
+
+Factory.define :agg_hwp1_arch, :parent => :hardware_profile_property do |p|
+ p.name 'architecture'
+ p.kind 'fixed'
+ p.unit 'label'
+ p.value 'i386'
+end
+
+Factory.define :agg_hwp2_memory, :parent => :hardware_profile_property do |p|
+ p.name 'memory'
+ p.kind 'range'
+ p.unit 'MB'
+ p.value 10240
+ p.range_first 7680
+ p.range_last 15360
+end
+
+Factory.define :agg_hwp2_storage, :parent => :hardware_profile_property do |p|
+ p.name 'storage'
+ p.kind 'enum'
+ p.unit 'GB'
+ p.value 850
+# p.property_enum_entries { |p| [p.association(:agg_hwp2_storage_enum1),
+# p.association(:agg_hwp2_storage_enum2)] }
+end
+
+Factory.define :agg_hwp2_cpu, :parent => :hardware_profile_property do |p|
+ p.name 'cpu'
+ p.kind 'fixed'
+ p.unit 'count'
+ p.value 2
+end
+
+Factory.define :agg_hwp2_arch, :parent => :hardware_profile_property do |p|
+ p.name 'architecture'
+ p.kind 'fixed'
+ p.unit 'label'
+ p.value 'x86_64'
+end
diff --git a/src/spec/factories/pool.rb b/src/spec/factories/pool.rb
index 2f9111e..d95fb13 100644
--- a/src/spec/factories/pool.rb
+++ b/src/spec/factories/pool.rb
@@ -5,5 +5,5 @@ end
Factory.define :tpool, :parent => :pool do |p|
p.name 'tpool'
- p.hardware_profiles { |hp| [hp.association(:pool_hwp1)] }
+# p.hardware_profiles { |hp| [hp.association(:pool_hwp1)] }
end
diff --git a/src/spec/factories/property_enum_entry.rb b/src/spec/factories/property_enum_entry.rb
new file mode 100644
index 0000000..78b99d5
--- /dev/null
+++ b/src/spec/factories/property_enum_entry.rb
@@ -0,0 +1,26 @@
+Factory.define :property_enum_entry do |e|
+end
+
+Factory.define :mock_hwp2_storage_enum1, :parent => :property_enum_entry do |e|
+ e.value 850
+ e.prop_name 'storage'
+ e.hardware_profile_property { |e| e.association(:mock_hwp2_storage) }
+end
+
+Factory.define :mock_hwp2_storage_enum2, :parent => :property_enum_entry do |e|
+ e.value 1024
+ e.prop_name 'storage'
+ e.hardware_profile_property { |e| e.association(:mock_hwp2_storage) }
+end
+
+Factory.define :agg_hwp2_storage_enum1, :parent => :property_enum_entry do |e|
+ e.value 850
+ e.prop_name 'storage'
+ e.hardware_profile_property { |e| e.association(:agg_hwp2_storage) }
+end
+
+Factory.define :agg_hwp2_storage_enum2, :parent => :property_enum_entry do |e|
+ e.value 1024
+ e.prop_name 'storage'
+ e.hardware_profile_property { |e| e.association(:agg_hwp2_storage) }
+end
diff --git a/src/spec/models/hardware_profile_spec.rb b/src/spec/models/hardware_profile_spec.rb
index e2b09b4..ab04fe1 100644
--- a/src/spec/models/hardware_profile_spec.rb
+++ b/src/spec/models/hardware_profile_spec.rb
@@ -30,31 +30,18 @@ describe HardwareProfile do
it "should require valid amount of memory" do
[nil, "hello", -1].each do |fail_value|
- @hp.memory = fail_value
+ @hp.memory.value = fail_value
@hp.should_not be_valid
end
end
it "should require valid amount of storage" do
[nil, "hello", -1].each do |fail_value|
- @hp.storage = fail_value
+ @hp.storage.value = fail_value
@hp.should_not be_valid
end
end
- it "should not require architecture when there's no provider" do
- @hp.architecture = nil
- @hp.should be_valid
- end
-
- it "should require architecture when it's with provider" do
- @hp.provider = Provider.new
-
- @hp.should be_valid
- @hp.architecture = nil
- @hp.should_not be_valid
- end
-
it "should allow Aggregator profiles only for provider profiles" do
@hp.provider = nil
--
1.6.2.5
14 years
[PATCH core] update to hardware profile client to include new property metadata.
by Scott Seago
Hardware Profile client was missing the attributes to handle range and enum properties.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
client/lib/dcloud/hardware_profile.rb | 41 ++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/client/lib/dcloud/hardware_profile.rb b/client/lib/dcloud/hardware_profile.rb
index d6c4aa0..02ee303 100644
--- a/client/lib/dcloud/hardware_profile.rb
+++ b/client/lib/dcloud/hardware_profile.rb
@@ -22,7 +22,33 @@ module DCloud
class HardwareProfile < BaseModel
class Property
- attr_reader :name, :unit, :value
+ class Range
+ attr_reader :first, :last
+ def initialize(element)
+ if element
+ @first = element.attributes['first']
+ @last = element.attributes['last']
+ end
+ end
+ def present?
+ ! @first.nil?
+ end
+ end
+ class Enum
+ attr_reader :entries
+ def initialize(element)
+ @entries = []
+ if element
+ element.get_elements( 'entry' ).each do |entry|
+ @entries << entry.attributes['value']
+ end
+ end
+ end
+ def present?
+ ! @entries.empty?
+ end
+ end
+ attr_reader :name, :kind, :unit, :value, :range, :enum
def initialize(xml, name)
@name = name
@@ -30,6 +56,9 @@ module DCloud
if p
@value = p.attributes['value']
@unit = p.attributes['unit']
+ @kind = p.attributes['kind']
+ @range = Range.new(p.get_elements('range')[0]) if @kind=='range'
+ @enum = Enum.new(p.get_elements('enum')[0]) if @kind=='enum'
end
end
@@ -37,6 +66,7 @@ module DCloud
! @value.nil?
end
+ # FIXME: how to range/enum/kind bits fit into this?
def to_s
v = @value || "---"
u = @unit || ""
@@ -52,10 +82,18 @@ module DCloud
end
end
+ class IntegerProperty < Property
+ def initialize(xml, name)
+ super(xml, name)
+ @value = @value.to_i if @value
+ end
+ end
+
xml_tag_name :hardware_profile
attribute :memory
attribute :storage
+ attribute :cpu
attribute :architecture
def initialize(client, uri, xml=nil)
@@ -67,6 +105,7 @@ module DCloud
unless xml.nil?
@memory = FloatProperty.new(xml, 'memory')
@storage = FloatProperty.new(xml, 'storage')
+ @cpu = IntegerProperty.new(xml, 'cpu')
@architecture = Property.new(xml, 'architecture')
end
end
--
1.6.2.5
14 years