diff options
| author | Darryl L. Pierce <dpierce@redhat.com> | 2008-08-06 09:51:53 -0400 |
|---|---|---|
| committer | Darryl L. Pierce <dpierce@redhat.com> | 2008-08-13 11:42:19 -0400 |
| commit | 1cf6f177f25aeba510949f2d3ea1fad68697c4cf (patch) | |
| tree | 66145a7a077fb4baf90d9abc766d02801e8d7cce /contrib/ruby/lib | |
| parent | 31952586ba56d076a10c1d08d710d7d1f44580db (diff) | |
| download | cobbler-1cf6f177f25aeba510949f2d3ea1fad68697c4cf.tar.gz cobbler-1cf6f177f25aeba510949f2d3ea1fad68697c4cf.tar.xz cobbler-1cf6f177f25aeba510949f2d3ea1fad68697c4cf.zip | |
Added support for images to the Ruby bindings.
Also fixed some of the decoding for interfaces returned for systems. But I'm not happy with that binding still.
Diffstat (limited to 'contrib/ruby/lib')
| -rw-r--r-- | contrib/ruby/lib/cobbler.rb | 1 | ||||
| -rw-r--r-- | contrib/ruby/lib/cobbler/base.rb | 30 | ||||
| -rw-r--r-- | contrib/ruby/lib/cobbler/image.rb | 55 | ||||
| -rw-r--r-- | contrib/ruby/lib/cobbler/network_interface.rb | 4 | ||||
| -rw-r--r-- | contrib/ruby/lib/cobbler/system.rb | 43 |
5 files changed, 99 insertions, 34 deletions
diff --git a/contrib/ruby/lib/cobbler.rb b/contrib/ruby/lib/cobbler.rb index 379d746f..1247a631 100644 --- a/contrib/ruby/lib/cobbler.rb +++ b/contrib/ruby/lib/cobbler.rb @@ -20,6 +20,7 @@ require 'cobbler/base' require 'cobbler/distro' +require 'cobbler/image' require 'cobbler/network_interface' require 'cobbler/profile' require 'cobbler/system' diff --git a/contrib/ruby/lib/cobbler/base.rb b/contrib/ruby/lib/cobbler/base.rb index a2b3e838..ea75ef36 100644 --- a/contrib/ruby/lib/cobbler/base.rb +++ b/contrib/ruby/lib/cobbler/base.rb @@ -30,9 +30,10 @@ module Cobbler # Child classes can define fields that will be retrieved from Cobbler by # using the +cobbler_field+ method. For example: # - # class Farkle < Base - # cobbler_field :name, findable => 'get_farkle' - # cobbler_field :owner + # class System < Base + # cobbler_lifecycle :find_all => 'get_systems' + # cobbler_field :name + # cobbler_field :owner, :array => 'String' # end # # declares a class named Farkle that contains two fields. The first, "name", @@ -106,7 +107,7 @@ module Cobbler @@connection = nil end - def definition(key) + def definition(key) @definitions ? @definitions[key] : nil end @@ -203,8 +204,8 @@ module Cobbler when :findable then module_eval <<-"end;" - def self.find_by_#{field.to_s}(name,&block) - properties = make_call('#{arg[key]}',name) + def self.find_by_#{field.to_s}(value,&block) + properties = make_call('#{arg[key]}',value) return create(properties) if properties && !properties.empty? @@ -232,17 +233,26 @@ module Cobbler # other class must be provided. # def cobbler_collection(field, *args) # :nodoc: - classname = args[0][:type] + classname = 'String' + packing = :array + + # process collection definition + args.each do |arg| + classname = arg[:type] if arg[:type] + packing = arg[:packing] if arg[:packing] + end module_eval <<-"end;" def #{field.to_s}(&block) + unless @#{field.to_s} @#{field.to_s} = Array.new - definition('#{field.to_s}').values.each do |value| - @#{field.to_s} << #{classname}.new(value) + definition('#{field.to_s}').each do |value| + if value + @#{field.to_s} << #{classname}.new(value) + end end - end @#{field.to_s} diff --git a/contrib/ruby/lib/cobbler/image.rb b/contrib/ruby/lib/cobbler/image.rb new file mode 100644 index 00000000..ce12dacf --- /dev/null +++ b/contrib/ruby/lib/cobbler/image.rb @@ -0,0 +1,55 @@ +# image.rb +# +# Copyright (C) 2008 Red Hat, Inc. +# Written by Darryl L. Pierce <dpierce@redhat.com> +# +# 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. + +module Cobbler + + # +Image+ represents an image within Cobbler. + # + class Image < Base + + 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 + + def initialize(definitions) + super(definitions) + end + + private + + # Creates a new instance of +System+ from a result received from Cobbler. + # + def self.create(attrs) + Image.new(attrs) + end + end +end
\ No newline at end of file diff --git a/contrib/ruby/lib/cobbler/network_interface.rb b/contrib/ruby/lib/cobbler/network_interface.rb index 5ef4a3b0..3437714f 100644 --- a/contrib/ruby/lib/cobbler/network_interface.rb +++ b/contrib/ruby/lib/cobbler/network_interface.rb @@ -30,8 +30,8 @@ module Cobbler cobbler_field :virt_bridge cobbler_field :ip_address - def initialize(definitions) - @definitions = definitions + def initialize(args) + @definitions = args[1] end # A hack for getting the NIC's details over the wire. diff --git a/contrib/ruby/lib/cobbler/system.rb b/contrib/ruby/lib/cobbler/system.rb index acfa3f54..c15d2257 100644 --- a/contrib/ruby/lib/cobbler/system.rb +++ b/contrib/ruby/lib/cobbler/system.rb @@ -28,24 +28,23 @@ module Cobbler :find_one => 'get_system', :remove => 'remove_system' - cobbler_field :name - cobbler_field :parent - cobbler_field :profile - cobbler_field :depth - cobbler_field :kernel_options - cobbler_field :kickstart - cobbler_field :ks_meta - cobbler_field :netboot_enabled - cobbler_field :owners - cobbler_field :server - cobbler_field :virt_cpus - cobbler_field :virt_file_size - cobbler_field :virt_path - cobbler_field :virt_ram - cobbler_field :virt_type - cobbler_field :virt_bridge - - cobbler_collection :interfaces, :type => 'NetworkInterface' + cobbler_field :name + cobbler_field :parent + cobbler_field :profile + cobbler_field :depth + cobbler_field :kernel_options + cobbler_field :kickstart + cobbler_field :ks_meta + cobbler_field :netboot_enabled + cobbler_collection :owners + cobbler_field :server + cobbler_field :virt_cpus + cobbler_field :virt_file_size + cobbler_field :virt_path + cobbler_field :virt_ram + cobbler_field :virt_type + cobbler_field :virt_bridge + cobbler_collection :interfaces, :type => 'NetworkInterface', :packing => :hash def initialize(definitions) super(definitions) @@ -62,13 +61,13 @@ module Cobbler Base.make_call('modify_system',sysid,'name',self.name,token) Base.make_call('modify_system',sysid,'profile',profile,token) - unless interfaces.empty? + if @interfaces count = 0 - interfaces.each do |interface| + @interfaces.each do |interface| - values = interface.bundle_for_saving(count) + values = interface.bundle_for_saving(count) - unless values.empty? + unless values.empty? Base.make_call('modify_system',sysid,'modify-interface',values,token) count = count + 1 end |
