From: David Lutterkort lutter@redhat.com
--- server/deltacloud.rb | 1 + server/lib/deltacloud/models/instance.rb | 1 + server/lib/deltacloud/models/instance_profile.rb | 47 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 0 deletions(-) create mode 100644 server/lib/deltacloud/models/instance_profile.rb
diff --git a/server/deltacloud.rb b/server/deltacloud.rb index c879316..2a60679 100644 --- a/server/deltacloud.rb +++ b/server/deltacloud.rb @@ -10,5 +10,6 @@ require 'deltacloud/models/flavor' require 'deltacloud/models/realm' require 'deltacloud/models/image' require 'deltacloud/models/instance' +require 'deltacloud/models/instance_profile' require 'deltacloud/models/storage_snapshot' require 'deltacloud/models/storage_volume' diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb index 485ffb2..e5c1f9c 100644 --- a/server/lib/deltacloud/models/instance.rb +++ b/server/lib/deltacloud/models/instance.rb @@ -27,6 +27,7 @@ class Instance < BaseModel attr_accessor :actions attr_accessor :public_addresses attr_accessor :private_addresses + attr_accessor :instance_profile
def initialize(init=nil) super(init) diff --git a/server/lib/deltacloud/models/instance_profile.rb b/server/lib/deltacloud/models/instance_profile.rb new file mode 100644 index 0000000..a9e3854 --- /dev/null +++ b/server/lib/deltacloud/models/instance_profile.rb @@ -0,0 +1,47 @@ +# +# Copyright (C) 2009 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +# Model to store the hardware profile applied to an instance together with +# any instance-specific overrides +class InstanceProfile < BaseModel + attr_accessor :memory + attr_accessor :storage + attr_accessor :architecture + attr_accessor :cpu + + def initialize(hwp_name, args = {}) + opts = args.inject({ :id => hwp_name.to_s }) do |m, e| + k, v = e + m[$1] = v if k.to_s =~ /^hwp_(.*)$/ + m + end + super(opts) + end + + def name + id + end + + def overrides + [:memory, :storage, :architecture, :cpu].inject({}) do |h, p| + if v = instance_variable_get("@#{p}") + h[p] = v + end + h + end + end +end