summaryrefslogtreecommitdiffstats
path: root/contrib/ruby
diff options
context:
space:
mode:
authorDarryl L. Pierce <dpierce@redhat.com>2008-10-24 14:43:31 -0400
committerDarryl L. Pierce <dpierce@redhat.com>2008-10-24 14:43:31 -0400
commit04b9e4d802ba7d8e886562999807c4741ec60afc (patch)
tree5a4522d5abbbe3cc413a8acf2e15cf8b2d8ae26b /contrib/ruby
parent09c7b8668804b420550650cb677d68fdba719399 (diff)
downloadcobbler-04b9e4d802ba7d8e886562999807c4741ec60afc.tar.gz
cobbler-04b9e4d802ba7d8e886562999807c4741ec60afc.tar.xz
cobbler-04b9e4d802ba7d8e886562999807c4741ec60afc.zip
Submitted by Bryan Kearney (bkearney@redhat.com)
Adds a save method to Image.
Diffstat (limited to 'contrib/ruby')
-rw-r--r--contrib/ruby/lib/cobbler/image.rb63
1 files changed, 40 insertions, 23 deletions
diff --git a/contrib/ruby/lib/cobbler/image.rb b/contrib/ruby/lib/cobbler/image.rb
index 21b5c356..336713f2 100644
--- a/contrib/ruby/lib/cobbler/image.rb
+++ b/contrib/ruby/lib/cobbler/image.rb
@@ -1,13 +1,13 @@
#
-# image.rb
-#
+# image.rb
+#
# Copyright (C) 2008 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com>
#
# This file is part of rubygem-cobbler.
#
# rubygem-cobbleris free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
+# 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.
#
@@ -19,36 +19,53 @@
# You should have received a copy of the GNU General Public License
# along with rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
#
-
+
module Cobbler
-
+
# +Image+ represents an image within Cobbler.
#
class Image < Base
-
- cobbler_lifecycle :find_all => 'get_images',
- :find_one => 'get_image',
+
+ cobbler_lifecycle :find_all => 'get_images',
+ :find_one => 'get_image',
:remove => 'remove_image'
-
- cobbler_field :name
- cobbler_field :owners
- cobbler_field :depth
- cobbler_field :virt_file_size
- cobbler_field :virt_path
- cobbler_field :xml_file
- cobbler_field :virt_bridge
- cobbler_field :virt_ram
- cobbler_field :file
- cobbler_field :virt_cpus
- cobbler_field :parent
+
+ ATTRIBUTES = [:name, :owners, :depth, :virt_file_size,
+ :virt_path, :xml_file, :virt_bridge, :file, :parent]
+ # These attributes seem to not exist yet. :virt_ram, :virt_cpus,
+
+ ATTRIBUTES.each do |attr|
+ puts "Creating field with #{attr}"
+ cobbler_field attr
+ end
def initialize(definitions = nil)
super(definitions)
end
-
+
+ # Saves this instance.
+ #
+ def save
+ Base.begin_transaction(true)
+
+ token = Base.login
+
+ raise Exception.new('Update failed prior to saving') unless Base.make_call('update')
+
+ imgid = Base.make_call('new_image',token)
+
+ ATTRIBUTES.each do |attr|
+ Base.make_call('modify_image',imgid,attr.to_s, self.send(attr),token) if self.send(attr) != nil
+ end
+
+ Base.make_call('save_image',imgid,token)
+
+ Base.end_transaction
+ end
+
private
-
- # Creates a new instance of +System+ from a result received from Cobbler.
+
+ # Creates a new instance of +Image+ from a result received from Cobbler.
#
def self.create(attrs)
Image.new(attrs)