summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorDarryl L. Pierce <dpierce@redhat.com>2008-11-04 10:51:09 -0500
committerDarryl L. Pierce <dpierce@redhat.com>2008-11-04 10:53:23 -0500
commite234b911e9b25d4690217f38ef3dd1b3424f88ac (patch)
tree9e740409c90bdde4bb03cbacb0a72a064a5da736 /contrib
parent00a2d0cb75fdb527f1db7ae8a74fc3a9399186ef (diff)
parent04b9e4d802ba7d8e886562999807c4741ec60afc (diff)
downloadcobbler-e234b911e9b25d4690217f38ef3dd1b3424f88ac.tar.gz
cobbler-e234b911e9b25d4690217f38ef3dd1b3424f88ac.tar.xz
cobbler-e234b911e9b25d4690217f38ef3dd1b3424f88ac.zip
Merge branch 'add-save-method-to-image' into devel
Diffstat (limited to 'contrib')
-rw-r--r--contrib/ruby/Rakefile2
-rw-r--r--contrib/ruby/lib/cobbler/image.rb63
2 files changed, 41 insertions, 24 deletions
diff --git a/contrib/ruby/Rakefile b/contrib/ruby/Rakefile
index c76c3988..7828c0ad 100644
--- a/contrib/ruby/Rakefile
+++ b/contrib/ruby/Rakefile
@@ -22,7 +22,7 @@ require 'rake/testtask'
require 'rake/gempackagetask'
PKG_NAME='rubygem-cobbler'
-PKG_VERSION='0.1.2'
+PKG_VERSION='0.1.3'
PKG_FILES=FileList[
'Rakefile', 'README', 'ChangeLog', 'COPYING', 'NEWS', 'TODO',
'lib/**/*.rb',
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)