The interface is stored in a module named Cobbler.
Examples for using the interface are stored in ./examples.

Signed-off-by: Darryl L. Pierce <[EMAIL PROTECTED]>
---
 ruby/rubygem-cobbler/Rakefile                      |   30 ++++++
 ruby/rubygem-cobbler/cobbler.gemspec               |   37 +++++++
 ruby/rubygem-cobbler/examples/create_system.rb     |   52 +++++++++
 ruby/rubygem-cobbler/examples/has_profile.rb       |   73 +++++++++++++
 ruby/rubygem-cobbler/examples/has_system.rb        |   39 +++++++
 ruby/rubygem-cobbler/examples/list_distros.rb      |   48 +++++++++
 ruby/rubygem-cobbler/examples/list_profiles.rb     |   63 +++++++++++
 ruby/rubygem-cobbler/examples/list_systems.rb      |   49 +++++++++
 ruby/rubygem-cobbler/examples/remove_system.rb     |   43 ++++++++
 ruby/rubygem-cobbler/lib/cobbler.rb                |   25 +++++
 ruby/rubygem-cobbler/lib/cobbler/base.rb           |  110 ++++++++++++++++++++
 ruby/rubygem-cobbler/lib/cobbler/profile.rb        |   78 ++++++++++++++
 .../nbproject/private/private.properties           |    4 +
 ruby/rubygem-cobbler/nbproject/project.properties  |   12 ++
 ruby/rubygem-cobbler/nbproject/project.xml         |   17 +++
 ruby/rubygem-cobbler/test/test_base.rb             |   51 +++++++++
 ruby/rubygem-cobbler/test/test_profile.rb          |   94 +++++++++++++++++
 17 files changed, 825 insertions(+), 0 deletions(-)
 create mode 100644 ruby/rubygem-cobbler/README
 create mode 100644 ruby/rubygem-cobbler/Rakefile
 create mode 100644 ruby/rubygem-cobbler/cobbler.gemspec
 create mode 100755 ruby/rubygem-cobbler/examples/create_system.rb
 create mode 100755 ruby/rubygem-cobbler/examples/has_profile.rb
 create mode 100755 ruby/rubygem-cobbler/examples/has_system.rb
 create mode 100755 ruby/rubygem-cobbler/examples/list_distros.rb
 create mode 100755 ruby/rubygem-cobbler/examples/list_profiles.rb
 create mode 100755 ruby/rubygem-cobbler/examples/list_systems.rb
 create mode 100755 ruby/rubygem-cobbler/examples/remove_system.rb
 create mode 100644 ruby/rubygem-cobbler/lib/cobbler.rb
 create mode 100644 ruby/rubygem-cobbler/lib/cobbler/base.rb
 create mode 100644 ruby/rubygem-cobbler/lib/cobbler/profile.rb
 create mode 100644 ruby/rubygem-cobbler/nbproject/private/private.properties
 create mode 100644 ruby/rubygem-cobbler/nbproject/project.properties
 create mode 100644 ruby/rubygem-cobbler/nbproject/project.xml
 create mode 100755 ruby/rubygem-cobbler/test/test_base.rb
 create mode 100644 ruby/rubygem-cobbler/test/test_profile.rb

diff --git a/ruby/rubygem-cobbler/README b/ruby/rubygem-cobbler/README
new file mode 100644
index 0000000..e69de29
diff --git a/ruby/rubygem-cobbler/Rakefile b/ruby/rubygem-cobbler/Rakefile
new file mode 100644
index 0000000..448a67e
--- /dev/null
+++ b/ruby/rubygem-cobbler/Rakefile
@@ -0,0 +1,30 @@
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+
+require 'rake'
+require 'rake/clean'
+require 'rake/testtask'
+require 'rake/gempackagetask'
+
+GEM_VERSION="1.0"
+
+Rake::TestTask.new do |task|
+  task.libs << 'test'
+  task.test_files = Dir.glob( 'test/test*.rb' )
+  task.verbose = true
+end
diff --git a/ruby/rubygem-cobbler/cobbler.gemspec 
b/ruby/rubygem-cobbler/cobbler.gemspec
new file mode 100644
index 0000000..5057300
--- /dev/null
+++ b/ruby/rubygem-cobbler/cobbler.gemspec
@@ -0,0 +1,37 @@
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+require 'rubygems'
+
+spec = Gem::Specification.new do |s|
+  s.name = 'Cobbler'
+  s.version = '0.0.1'
+  s.author = 'Darryl L. Pierce'
+  s.email = '[EMAIL PROTECTED]'
+  s.homepage = 'http://cobbler.et.redhat.com/'
+  s.platform = Gem::Platform::RUBY
+  s.summary = 'An interface for interacting with a Cobbler server.'
+  s.files = ["lib/cobbler.rb", "lib/cobbler/system.rb"]
+  s.require_path =  "."
+  s.autorequire = "cobbler"
+end
+
+if $0 == __FILE__
+  Gem::manage_gems
+  Gem::Builder.new(spec).build
+end
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/examples/create_system.rb 
b/ruby/rubygem-cobbler/examples/create_system.rb
new file mode 100755
index 0000000..ead6609
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/create_system.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/ruby -W0
+#
+# create_system.rb - example of using rubygem-cobbler to create a system.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'cobbler'
+
+if ARGV.empty? || ARGV.size < 6
+  puts "Usage: #{$0} hostname system-name profile-name mac-address username 
password"
+  exit 1
+end
+
+hostname     = ARGV[0]
+system_name  = ARGV[1]
+profile_name = ARGV[2]
+mac_address  = ARGV[3]
+username     = ARGV[4]
+password     = ARGV[5]
+
+puts "Attempting to create a new system named #{system_name} based on profile 
#{profile_name}"
+
+system = Cobbler::System.new(hostname)
+system.username = username
+system.password = password
+
+unless system.has_profile?(profile_name)
+  puts "No such profile: #{profile_name}"
+  exit 1
+end
+
+system.create_system(system_name,profile_name,mac_address)
diff --git a/ruby/rubygem-cobbler/examples/has_profile.rb 
b/ruby/rubygem-cobbler/examples/has_profile.rb
new file mode 100755
index 0000000..e778ab9
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/has_profile.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/ruby -W0
+#
+# has_profile.rb - example of using rubygem-cobbler to chekc if a profile 
exists.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'getoptlong'
+
+require 'cobbler/base'
+require 'cobbler/profile'
+
+include Cobbler
+
+opts = GetoptLong.new(
+  ["--server",  "-s", GetoptLong::REQUIRED_ARGUMENT ],
+  ["--profile", "-p", GetoptLong::REQUIRED_ARGUMENT ],
+  ["--first",   "-1", GetoptLong::NO_ARGUMENT],
+  ["--help",    "-h", GetoptLong::NO_ARGUMENT]
+)
+
[EMAIL PROTECTED] = nil
[EMAIL PROTECTED]  = nil
[EMAIL PROTECTED] = true
+
+opts.each do |opt, arg|
+  case opt
+  when '--server'  then @hostname = arg
+  when '--profile' then @profile  = arg
+  when '--first'   then @find_all = false
+  when '--help'    then 
+    puts "Usage: #{$0} --server hostname --profile profile-name\n"
+  end
+end
+
+SystemExit.new('No hostname specified.') unless @hostname
+
+if @hostname
+  Base.hostname = @hostname
+  
+  puts "Finding [EMAIL PROTECTED] ? 'all profiles' : 'first profile'} that 
match \"[EMAIL PROTECTED]""
+    
+  result = Profile.find_by_name((@find_all ? :all : :first),@profile)
+  
+  if result
+    if @find_all
+      result.each { |profile| puts "Found #{profile.name}."}
+    else
+      puts "#{result.name} exists."
+    end
+  else
+    puts "No such profile: [EMAIL PROTECTED]"
+  end
+end
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/examples/has_system.rb 
b/ruby/rubygem-cobbler/examples/has_system.rb
new file mode 100755
index 0000000..ae62255
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/has_system.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/ruby -W0
+#
+# has_system.rb - example of using rubygem-cobbler to check if a system exists.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'cobbler'
+
+if ARGV.empty? || ARGV.size < 2
+  puts "Usage: #{$0} hostname system-name"
+  exit 1
+end
+
+hostname     = ARGV[0]
+system_name = ARGV[1]
+
+system = Cobbler::System.new(hostname)
+
+puts "Does #{system_name} exist? #{system.has_system?(system_name)}"
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/examples/list_distros.rb 
b/ruby/rubygem-cobbler/examples/list_distros.rb
new file mode 100755
index 0000000..be99ef8
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/list_distros.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/ruby -W0
+# list_distros.rb - example of using rubygem-cobbler to list distros.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'cobbler'
+
+if ARGV.empty?
+  puts "Usage: #{$0} hostname"
+  exit 1
+end
+
+hostname = ARGV[0]
+
+puts "Connecting to #{hostname}"
+
+system = Cobbler::System.new(hostname)
+
+system.distros.each do |distro|
+  puts "[Distro: #{distro['name']}]"
+  
+  distro.keys.each do |key|
+    puts "#{key}: #{distro[key]}" unless key == 'name'
+  end
+  
+  puts "\n"
+end
+
diff --git a/ruby/rubygem-cobbler/examples/list_profiles.rb 
b/ruby/rubygem-cobbler/examples/list_profiles.rb
new file mode 100755
index 0000000..6e5cc72
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/list_profiles.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/ruby -W0
+#
+# list_profiles.rb - example of using rubygem-cobbler to list profiles.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'getoptlong'
+
+require 'cobbler/base'
+require 'cobbler/profile'
+
+include Cobbler
+
+opts = GetoptLong.new(
+  ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+  ["--help",   "-h", GetoptLong::NO_ARGUMENT]
+)
+
[EMAIL PROTECTED]
+
+opts.each do |opt, arg|
+  case opt
+  when '--server' then @hostname = arg
+  when '--help'   then 
+    puts "Usage: #{$0} --server hostname\n"
+  end
+end
+
+if @hostname
+  Base.hostname = @hostname
+  
+  profiles = Profile.find(:all)
+  
+  if profiles.empty?
+    puts "No profiles found." 
+  else
+    puts "Found #{profiles.size} profiles."
+    
+    profiles.each do |profile|
+      puts "#{profile.name} is based on #{profile.distro}."
+    end  
+  end
+end
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/examples/list_systems.rb 
b/ruby/rubygem-cobbler/examples/list_systems.rb
new file mode 100755
index 0000000..f82913e
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/list_systems.rb
@@ -0,0 +1,49 @@
+#!/usr/bin/ruby -W0
+#
+# list_systems.rb - example of using rubygem-cobbler to list systems.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'cobbler'
+
+if ARGV.empty?
+  puts "Usage: #{$0} hostname"
+  exit 1
+end
+
+hostname = ARGV[0]
+
+puts "Connecting to #{hostname}"
+
+system = Cobbler::System.new(hostname)
+
+system.systems.each do |system|
+  puts "[System: #{system['name']}]"
+  
+  system.keys.each do |key|
+    puts "#{key}: #{system[key]}" unless key == 'name'
+  end
+  
+  puts "\n"
+end
+
diff --git a/ruby/rubygem-cobbler/examples/remove_system.rb 
b/ruby/rubygem-cobbler/examples/remove_system.rb
new file mode 100755
index 0000000..21e77bf
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/remove_system.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby -W0
+#
+# remove_system.rb - example of using rubygem-cobbler to remove a system.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+$LOAD_PATH << File.join(base, "lib")
+$LOAD_PATH << File.join(base, "examples")
+
+require 'cobbler'
+
+if ARGV.empty? || ARGV.size < 4
+  puts "Usage: #{$0} hostname system-name username password"
+  exit 1
+end
+
+hostname     = ARGV[0]
+system_name  = ARGV[1]
+username     = ARGV[2]
+password     = ARGV[3]
+
+system = Cobbler::System.new(hostname)
+system.username = username
+system.password = password
+
+system.remove_system(system_name)
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/lib/cobbler.rb 
b/ruby/rubygem-cobbler/lib/cobbler.rb
new file mode 100644
index 0000000..df78813
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler.rb
@@ -0,0 +1,25 @@
+# cobbler.rb - Cobbler module declaration.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+
+require 'cobbler/system'
+ 
+module Cobbler
+    
+end
diff --git a/ruby/rubygem-cobbler/lib/cobbler/base.rb 
b/ruby/rubygem-cobbler/lib/cobbler/base.rb
new file mode 100644
index 0000000..fa3a450
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler/base.rb
@@ -0,0 +1,110 @@
+# base.rb
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+require 'xmlrpc/client'
+require 'pp'
+
+module Cobbler
+  include XMLRPC
+  
+  # +Base+ represents a remote Cobbler server.
+  #
+  class Base
+    
+    @@connection = nil
+    @@hostname   = nil
+    
+    @attrs 
+
+    def attributes(name)
+      return @attrs ? @attrs[name] : nil
+    end
+    
+    # Makes a remote call to the Cobbler server.
+    #
+    def self.make_call(*args)
+      conn = connection(false)
+      
+      conn.call(*args)
+    end
+    
+    def self.connection=(connection)
+      @@connection = connection
+    end
+    
+    def self.connection(writable)
+      result = @@connection
+      
+      unless result
+        result = 
XMLRPC::Client.new2("http://#{@@hostname}/cobbler_api#{writable ? '_rw' : ''}")
+      end
+      
+      return result
+    end
+    
+    def self.hostname=(hostname)
+      @@hostname = hostname
+    end
+ 
+    class << self
+      # Allows for dynamically declaring fields that will come from
+      # Cobbler.
+      #
+      def cobbler_field(field,*args) # :nodoc:
+        findable = false
+        
+        if args
+          for arg in args
+            case arg
+            when :findable then findable = true
+            end        
+          end    
+        end        
+
+        module_eval <<-"end;"
+            def #{field.to_s}(&block)
+              return attributes('#{field.to_s}') 
+            end
+        end;
+        
+        if findable
+          module_eval <<-"end;"
+              def self.find_by_#{field.to_s}(how_many,filter, &block)
+                all = find(:all)
+
+                if all
+                  candidates = Array.new
+
+                  all.each { |candidate| candidates << candidate if 
candidate.#{field.to_s}.index(filter) }
+
+                  case how_many
+                  when :all then return candidates unless candidates.empty?
+                  when :first then return candidates[0] unless 
candidates.empty?
+                  end
+                end
+
+                return nil
+              end
+          end;
+        end
+      end
+    end
+  end   
+end
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/lib/cobbler/profile.rb 
b/ruby/rubygem-cobbler/lib/cobbler/profile.rb
new file mode 100644
index 0000000..a8afc5a
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler/profile.rb
@@ -0,0 +1,78 @@
+# base.rb 
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+
+# +Profile+ represents a single profile.
+#
+module Cobbler
+  
+  # +Profile+ represents a single profile within Cobbler.
+  #
+  class Profile < Base
+    cobbler_field :name, :findable
+    cobbler_field :owners, :findable
+    cobbler_field :dhcp_tag
+    cobbler_field :depth
+    cobbler_field :virt_file_size
+    cobbler_field :virt_path
+    cobbler_field :virt_type
+    cobbler_field :repos
+    cobbler_field :distro
+    cobbler_field :server
+    cobbler_field :virt_bridge
+    cobbler_field :virt_ram
+    cobbler_field :kernel_options
+    cobbler_field :virt_cpus
+    cobbler_field :parent
+    cobbler_field :ks_meta
+    cobbler_field :kickstart
+
+    def initialize(attrs)
+      @attrs = attrs
+    end
+    
+    # Finds all profiles on the specified cobbler server.
+    #
+    def self.find(which = :all)
+      profiles = Array.new
+      result   = nil
+      
+      make_call("get_profiles").each do |profile|
+        profiles << Profile.create(profile)
+      end
+      
+      unless profiles == nil
+        case which
+        when :all then result = profiles
+        when :first then result = profiles[0]
+        end
+      end
+        
+      return result
+    end
+    
+    private
+    
+    # Creates a new instance of +Profile+ from a result received from Cobbler.
+    #
+    def self.create(attrs)
+      Profile.new(attrs)
+    end
+  end
+end
diff --git a/ruby/rubygem-cobbler/nbproject/private/private.properties 
b/ruby/rubygem-cobbler/nbproject/private/private.properties
new file mode 100644
index 0000000..45c547d
--- /dev/null
+++ b/ruby/rubygem-cobbler/nbproject/private/private.properties
@@ -0,0 +1,4 @@
+file.reference.ruby-rubygem-cobbler=/home/mcpierce/Programming/cobbler/ruby/rubygem-cobbler
+file.reference.rubygem-cobbler-lib=/home/mcpierce/Programming/cobbler/ruby/rubygem-cobbler/lib
+file.reference.rubygem-cobbler-test=/home/mcpierce/Programming/cobbler/ruby/rubygem-cobbler/test
+platform.active=Ruby
diff --git a/ruby/rubygem-cobbler/nbproject/project.properties 
b/ruby/rubygem-cobbler/nbproject/project.properties
new file mode 100644
index 0000000..f5ba218
--- /dev/null
+++ b/ruby/rubygem-cobbler/nbproject/project.properties
@@ -0,0 +1,12 @@
+file.reference.ruby-rubygem-cobbler=.
+file.reference.rubygem-cobbler-lib=lib
+file.reference.rubygem-cobbler-test=test
+javac.classpath=
+main.file=
+platform.active=Ruby
+ruby.includejava=false
+source.encoding=UTF-8
+src.dir=${file.reference.rubygem-cobbler-lib}
+src.docs.dir=docs
+src.examples.dir=examples
+test.src.dir=${file.reference.rubygem-cobbler-test}
diff --git a/ruby/rubygem-cobbler/nbproject/project.xml 
b/ruby/rubygem-cobbler/nbproject/project.xml
new file mode 100644
index 0000000..532bfe6
--- /dev/null
+++ b/ruby/rubygem-cobbler/nbproject/project.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1";>
+    <type>org.netbeans.modules.ruby.rubyproject</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/ruby-project/1";>
+            <name>rubygem-cobbler</name>
+            <source-roots>
+                <root id="src.examples.dir"/>
+                <root id="src.docs.dir"/>
+                <root id="src.dir"/>
+            </source-roots>
+            <test-roots>
+                <root id="test.src.dir"/>
+            </test-roots>
+        </data>
+    </configuration>
+</project>
diff --git a/ruby/rubygem-cobbler/test/test_base.rb 
b/ruby/rubygem-cobbler/test/test_base.rb
new file mode 100755
index 0000000..4370af3
--- /dev/null
+++ b/ruby/rubygem-cobbler/test/test_base.rb
@@ -0,0 +1,51 @@
+# test_system.rb - Unit tests.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+
+require 'test/unit'
+require 'flexmock/test_unit'
+require 'cobbler/base'
+
+module Cobbler
+  class TestBase < Test::Unit::TestCase
+    def setup
+      @connection = flexmock('connection')
+      Base.connection = @connection
+      Base.hostname   = "localhost"
+    end
+    
+    # Ensures that the default behavior for the base is to create a connection
+    # if one wasn't set.
+    #
+    def test_connection_without_mock
+      Base.connection = nil
+      
+      assert Base.connection, 'Should have created a new connection.'
+    end
+
+    # Ensures that setting a mock connection works (for unit tests).
+    #
+    def test_connection
+      assert_same @connection, Base.connection
+    end
+  end
+end
diff --git a/ruby/rubygem-cobbler/test/test_profile.rb 
b/ruby/rubygem-cobbler/test/test_profile.rb
new file mode 100644
index 0000000..1e265d9
--- /dev/null
+++ b/ruby/rubygem-cobbler/test/test_profile.rb
@@ -0,0 +1,94 @@
+# test_profile.rb - Tests the Profile class.
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <[EMAIL PROTECTED]>
+#
+# 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.
+ 
+
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+
+require 'test/unit'
+require 'flexmock/test_unit'
+require 'cobbler/base'
+require 'cobbler/profile'
+
+module Cobbler
+  class TestBase < Test::Unit::TestCase
+    def setup
+      @connection = flexmock('connection')
+      Base.connection = @connection
+      Base.hostname   = "localhost"
+      
+      @profiles = Array.new
+      @profiles[0] = Hash.new
+      @profiles[0]['profile']         = 'Fedora-9-i386'
+      @profiles[0]['distro']          = 'Fedora-9-i386'
+      @profiles[0]['dhcp tag']        = 'default'
+      @profiles[0]['kernel options']  = {}
+      @profiles[0]['kickstart']       = '/etc/cobbler/sample_end.ks'
+      @profiles[0]['ks metadata']     = {}
+      @profiles[0]['owners']          = ['admin']
+      @profiles[0]['repos']           = []
+      @profiles[0]['server']          = '<<inherit>>'
+      @profiles[0]['virt bridge']     = 'xenbr0'
+      @profiles[0]['virt cpus']       = '1'
+      @profiles[0]['virt file size']  = '5'
+      @profiles[0]['virt path']       = ''
+      @profiles[0]['virt ram']        = '512'
+      @profiles[0]['virt type']       = 'xenpv'
+      
+      @profiles[1] = Hash.new
+      @profiles[1]['profile']         = 'Fedora-9-x86_64'
+      @profiles[1]['distro']          = 'Fedora-9-x86_64'
+      @profiles[1]['dhcp tag']        = 'default'
+      @profiles[1]['kernel options']  = {}
+      @profiles[1]['kickstart']       = '/etc/cobbler/sample_end.ks'
+      @profiles[1]['ks metadata']     = {}
+      @profiles[1]['owners']          = ['admin']
+      @profiles[1]['repos']           = []
+      @profiles[1]['server']          = '<<inherit>>'
+      @profiles[1]['virt bridge']     = 'xenbr0'
+      @profiles[1]['virt cpus']       = '1'
+      @profiles[1]['virt file size']  = '5'
+      @profiles[1]['virt path']       = ''
+      @profiles[1]['virt ram']        = '512'
+      @profiles[1]['virt type']       = 'xenpv'
+    end
+
+    # Ensures that an attempt to find all of a profile works as expected.
+    #
+    def test_find_with_all
+      
@connection.should_receive(:call).with('get_profiles').once.returns(@profiles)
+
+      result = Profile.find(:all)
+
+      assert result, 'Expected a result set.'
+      assert_equal 2, result.size, 'Did not receive the right number of 
results'
+    end
+    
+    # Ensures that an attempt to get the first profile works as expected.
+    #
+    def test_find_first
+      
@connection.should_receive(:call).with('get_profiles').once.returns(@profiles)
+
+      result = Profile.find(:first)      
+      
+      assert result, 'Expected a result.'
+      assert_equal result.profile, @profiles[0]['profile'], 'Did not get the 
right profile back.'
+    end
+  end
+end
-- 
1.5.5.1

_______________________________________________
cobbler mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/cobbler

Reply via email to