More details on system imaging -- livecd based proposal
by Michael DeHaan
I've been talking with Andrew Brown from NCSU, and we have some ideas on
how to implement a cobbler imaging solution utilizing livecd's and
partimage. He's going to be taking a crack at implementing this for a
future cobbler release. I've included basic details here so others
could see what we are thinking and weigh in. The use case is for the
Virtual Compute Lab (http://vcl.ncsu.edu/) though this should be
extensible to any other place that needs to clone images and might have
mixed Linux/other deployments. Naturally, if you can do kickstart (or
preseed, or autoyast, or ...), it's always preferable to do kickstart
(or equivalents) -- maintaining security updates on images and so forth
and dealing with hardware differences is an additional layer of complexity.
This is somewhat based around some capabilities of IBM's xcat, though
we're going to rework it to make it work idiomatically in cobbler where
there is much less setup involved.
The following instructions assume pxe_just_once is turned on in
/etc/cobbler/settings and the systems PXE first in BIOS order. That
makes some things simpler as the live images can simply reboot when done.
The idea/syntax is as follows:
# from a base of the imported RHEL5 distro, use livecd-tools to create a
livecd and convert it to a PXE-able image.
# this livecd image will contain a post script that uses partimage to
export partitions to a configured NFS share (in cobbler)
# and/or load the image based on kernel arguments configured via flags
below.
cobbler distro make-cloner --name=RHEL5-cloner --distro=RHEL5
# here we make a profile for what is being cloned. For example,
"RHEL5-image-myclassproject37", this name will be used
# by the NFS share, and because it is parented by a cloner image, it
will have special symantics in terms of what kernel
# arguments get fed to it, such that our special live image (or modified
initrd, TBD) knows what to do.
cobbler profile add --name=RHEL5-image-projectX --distro=RHEL5-cloner
# now we assign a system via PXE boot to be cloned. Note that we are
assigning it to a live image not to be installed, but to
# be netbooted and then cloned.
cobbler system edit --name=foo --profile=RHEL5-image-projectX
--save-clone [--netboot-enabled=1]
# to clone the image, we assign another system to the cloner profile,
like so, and reboot it once finished
cobbler system edit --name=bar --profile=RHEL5-image-projectX
--load-clone [--netboot-enabled=1]
This should cover all partition types supported by partimage but not the
"weird stuff".
This also seems to imply that we would have a settting in
/etc/cobbler/settings to configure the address info of the NFS
server to save things to.
Comments? Questions?
--Michael
15 years, 7 months
[SURVEY] How are you using Cobbler?
by Michael DeHaan
If you don't mind sharing, I'm curious about a few things.
(A)
How many cobbler objects do you have of each type?
cobbler distro list | wc -l
cobbler profile list | wc -l
cobbler system list | wc -l
cobbler repo list | wc -l
(B) About how many systems (machines and virtual machines) do you have
at your organization that are being managed by Cobbler? Ballpark is
ok, if you can't say "a lot" is fine too :)
(C) How many cobbler servers do you have?
(D) Generally, what does your organization do? You can omit this if
you want. Short answers like "school", "university", "hosting",
"government", "research", "finance", etc are fine.
(E) What do you use for config management if any (puppet, cfengine,
bcfg2, home grown, proprietary apps)
(F) What do you use for package management if any (yum directly,
Satellite, etc)
(G) What do you use for monitoring if any (nagios, proprietary apps, etc)
(H) Are you using virtualization? If so, which (VMware, Xen, KVM,
other)? Are you using Cobbler for virtualization deployment?
(I) Feel free to share whatever else you want :)
Basically I'm just curious as to whether system records are in wide use,
how many people are using cobbler for repo management, and how many
multi-cobbler server setups there are. I'm also a bit curious as to
what other apps are in use at the same time, for potential
integration/awareness reasons. This can help me better understand
where to go in the future, and which corners of things are less relevant
to the userbase.
Please reply to me off-list. I'll try to report back some
non-identifying aggregrate findings.
Thanks!
--Michael
15 years, 8 months
Problem installing updatet packages / Reposync
by Tim.Einmahl@kba.de
Hi,
I have created a repo for RHEL5 on my cobbler server
with "repo add --name=rhel-i386-server-5
--mirror=rhn://rhel-i386-server-5"
When running "cobbler reposync", everything got downloaded.
Then I ran cobbler profile edit --name=RHEL5-xen-i386
--repos="rhel-i386-server-5"
But when I install via koan, only the old packages are getting installed
from the install tree.
I thought that setting up repo and running "cobbler profile edit" with
--repos would mean, that
installing would be done with the updated packages ??
I only want to use updatet packages in install phase, not afterwards.
Am I wrong or did I overlook something ?
Regards
Tim
cobbler profile report:
profile : RHEL5-xen-i386
distro : RHEL5-xen-i386
dhcp tag : default
kernel options : {}
kickstart : /root/ks-RHEL5-xen-i386.cfg
ks metadata : {}
owners : ['admin']
repos : ['rhel-i386-server-5']
server : <<inherit>>
virt bridge : xenbr0
virt cpus : 1
virt file size : 5
virt path :
virt ram : 1024
virt type : auto
cobbler repo report:
repo : rhel-i386-server-5
arch : i386 -l
createrepo_flags : -c cache
keep updated : True
mirror : rhn://rhel-i386-server-5
mirror locally : 1
owners : ['admin']
priority : 99
rpm list :
yum options : {}
cobbler distro report:
distro : RHEL5-xen-i386
breed : redhat
architecture : i386
initrd :
/var/www/cobbler/ks_mirror/RHEL5-i386/images/xen/initrd.img
kernel :
/var/www/cobbler/ks_mirror/RHEL5-i386/images/xen/vmlinuz
kernel options : {}
ks metadata : {'tree':
'http://@@http_server@@/cblr/links/RHEL5-xen-i386'}
owners : ['admin']
cobbler list
distro RHEL5-xen-i386
profile RHEL5-xen-i386
repo rhel-i386-server-5
15 years, 8 months
Improving the YAML serializer (warning: technical developer-ery content)
by Michael DeHaan
One thing I've been thinking about is finally improving the YAML serializer.
It's fine for a reasonable number of systems, but it's not easy to
hand-edit (if needed) a system if you have 500 of them in the systems
file. There's also the problem if you are hand editing and mess up
your file. Backups are great, but wouldn't it be better to break just
that one object, rather than all objects of the same type? Probably true.
A solution to this is probably a directory layout like:
/var/lib/cobbler/config/systems.d/
/var/lib/cobbler/config/repos.d/
And so on...
The idea is we can tweak the YAML serializer to load the original file
if it exists, and on those loads, write the new files out. This should
allow for seamless upgrades to the new version without anyone needing to
change modules.conf.
I'm only going to do this if performance does not suffer on each invocation.
However as we can lazy-load the objects as needed (unless making a
"find" call), I'm not sure that will be a problem.
As a design point, we will not be requiring a database, and I think
things have been working pretty good so far, so, by default, no database :)
--Michael
15 years, 8 months
[PATCH] Ruby interface for Cobbler XML-RPC APIs.
by Darryl L. Pierce
The interface is stored in a module named Cobbler.
Examples for using the interface are stored in ./examples.
Still looking for some feedback from anybody with some experience with Ruby.
I'm now working on the save functionality. I'm playing with having each child
class declare a saving script and passing it to the cobbler_save_method code
generator. I'd like some input from anybody on that path.
Looking forward to some input. :)
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
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 | 66 +++++++++
ruby/rubygem-cobbler/examples/has_system.rb | 67 +++++++++
ruby/rubygem-cobbler/examples/list_distros.rb | 48 ++++++
ruby/rubygem-cobbler/examples/list_profiles.rb | 63 ++++++++
ruby/rubygem-cobbler/examples/list_systems.rb | 63 ++++++++
ruby/rubygem-cobbler/examples/remove_system.rb | 43 ++++++
ruby/rubygem-cobbler/lib/cobbler.rb | 25 ++++
ruby/rubygem-cobbler/lib/cobbler/base.rb | 150 ++++++++++++++++++++
ruby/rubygem-cobbler/lib/cobbler/distro.rb | 52 +++++++
ruby/rubygem-cobbler/lib/cobbler/profile.rb | 60 ++++++++
ruby/rubygem-cobbler/lib/cobbler/system.rb | 62 ++++++++
.../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 | 83 +++++++++++
19 files changed, 985 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/distro.rb
create mode 100644 ruby/rubygem-cobbler/lib/cobbler/profile.rb
create mode 100644 ruby/rubygem-cobbler/lib/cobbler/system.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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+require 'rubygems'
+
+spec = Gem::Specification.new do |s|
+ s.name = 'Cobbler'
+ s.version = '0.0.1'
+ s.author = 'Darryl L. Pierce'
+ s.email = 'dpierce(a)redhat.com'
+ 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 <dpierce(a)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.
+
+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..1c5c920
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/has_profile.rb
@@ -0,0 +1,66 @@
+#!/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 <dpierce(a)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.
+
+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 ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+@hostname = nil
+@profile = nil
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then @hostname = arg
+ when '--profile' then @profile = arg
+ 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 any profile that matches \"#{@profile}\""
+
+ result = Profile.find_by_name(@profile)
+
+ if result
+ puts "#{result.name} exists, and is owned by #{result.owners}."
+ else
+ puts "No such profile: #{@profile}"
+ 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..529e94b
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/has_system.rb
@@ -0,0 +1,67 @@
+#!/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 <dpierce(a)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.
+
+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/system'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--system", "-t", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+@hostname = nil
+@system = nil
+@find_all = true
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then @hostname = arg
+ when '--system' then @system = arg
+ when '--help' then
+ puts "Usage: #{$0} --server hostname --system system-name\n"
+ end
+end
+
+SystemExit.new('No hostname specified.') unless @hostname
+
+if @hostname
+ Base.hostname = @hostname
+
+ puts "Finding any system that matches \"#{@system}\""
+
+ result = System.find_by_name(@system)
+
+ if result
+ puts "#{result.name} exists, and is owned by #{result.owners}."
+ else
+ puts "No such system: #{@system}"
+ end
+end
\ 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 <dpierce(a)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.
+
+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..620a2c6
--- /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 <dpierce(a)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.
+
+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]
+)
+
+@hostname
+
+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
+
+ 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..3304378
--- /dev/null
+++ b/ruby/rubygem-cobbler/examples/list_systems.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/ruby -W0
+#
+# list_systems.rb - example of using rubygem-cobbler to list system.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)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.
+
+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/system'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+@hostname
+
+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
+
+ systems = System.find
+
+ if systems.empty?
+ puts "No systems found."
+ else
+ puts "Found #{systems.size} profiles."
+
+ systems.each do |system|
+ puts "#{system.name} is based on #{system.profile}."
+ end
+ end
+end
\ No newline at end of file
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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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..fdd696d
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler/base.rb
@@ -0,0 +1,150 @@
+# base.rb
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)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.
+
+require 'xmlrpc/client'
+require 'pp'
+
+module Cobbler
+ include XMLRPC
+
+ # +Base+ represents a remote Cobbler server.
+ #
+ # 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
+ # end
+ #
+ # declares a class named Farkle that contains two fields. The first, "name",
+ # will be one that is searchable on Cobbler; i.e., a method named "find_by_name"
+ # will be generated and will use the "get_farkle" remote method to retrieve
+ # that instance from Cobbler.
+ #
+ # The second field, "owner", will simply be a field named Farkle.owner that
+ # returns a character string.
+ #
+ # +Base+ provides some common functionality for all child classes:
+ #
+ #
+ 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 = false)
+ 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 the class to define the means by which it is saved.
+ #
+ def cobbler_save_method(script)
+ module_eval <<-"end;"
+ def save
+ begin_transaction(true)
+ #{script}
+ end_transaction
+ end
+ end;
+ end
+
+ # Creates a complete finder method
+ #
+ def cobbler_find_all(method_name)
+ module_eval <<-"end;"
+ def self.find
+ records = make_call('#{method_name}')
+
+ result = Array.new
+
+ if records
+ records.each { |record| result << create(record) }
+ end
+
+ return result
+ end
+ end;
+ end
+
+ # Allows for dynamically declaring fields that will come from
+ # Cobbler.
+ #
+ def cobbler_field(field,*args) # :nodoc:
+
+ if args
+ for arg in args
+ for key in arg.keys
+ case key
+ when :findable then
+
+ module_eval <<-"end;"
+ def self.find_by_#{field.to_s}(name,&block)
+ properties = make_call('#{arg[key]}',name)
+
+ return create(properties) if properties && !properties.empty?
+
+ return nil
+ end
+ end;
+
+ end
+ end
+ end
+
+ module_eval <<-"end;"
+ def #{field.to_s}(&block)
+ return attributes('#{field.to_s}')
+ end
+ end;
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/ruby/rubygem-cobbler/lib/cobbler/distro.rb b/ruby/rubygem-cobbler/lib/cobbler/distro.rb
new file mode 100644
index 0000000..6294ce1
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler/distro.rb
@@ -0,0 +1,52 @@
+# distro.rb
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)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.
+
+# +Distro+ represents a single distrobution.
+#
+module Cobbler
+
+ # +Distro+ represents a single distrobution within Cobbler.
+ #
+ class Distro < Base
+ cobbler_field :name, :findable => 'get_distro'
+ cobbler_field :owners
+ cobbler_field :kernel
+ cobbler_field :breed
+ cobbler_field :depth
+ cobbler_field :arch
+ cobbler_field :initrd
+ cobbler_field :source_repos
+ cobbler_field :kernel_options
+ cobbler_field :parent
+ cobbler_field :ks_meta
+
+ def initialize(attrs)
+ @attrs = attrs
+ 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/lib/cobbler/profile.rb b/ruby/rubygem-cobbler/lib/cobbler/profile.rb
new file mode 100644
index 0000000..66a304c
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler/profile.rb
@@ -0,0 +1,60 @@
+# profile.rb
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)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.
+
+# +Profile+ represents a single profile.
+#
+module Cobbler
+
+ # +Profile+ represents a single profile within Cobbler.
+ #
+ class Profile < Base
+ cobbler_find_all 'get_profiles'
+
+ cobbler_field :name, :findable => 'get_profile'
+ cobbler_field :parent
+ cobbler_field :owners
+ 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 :ks_meta
+ cobbler_field :kickstart
+
+ def initialize(attrs)
+ @attrs = attrs
+ 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/lib/cobbler/system.rb b/ruby/rubygem-cobbler/lib/cobbler/system.rb
new file mode 100644
index 0000000..a02a6f3
--- /dev/null
+++ b/ruby/rubygem-cobbler/lib/cobbler/system.rb
@@ -0,0 +1,62 @@
+# system.rb
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)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
+
+ # +System+ represents a system within Cobbler.
+ #
+ class System < Base
+
+ cobbler_save_method <<-"SCRIPT"
+ puts "WOO!"
+ SCRIPT
+
+ cobbler_find_all 'get_systems'
+ cobbler_field :name, :findable => 'get_system'
+ 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_field :interfaces
+
+ def initialize(attrs)
+ @attrs = attrs
+ end
+
+ private
+
+ # Creates a new instance of +System+ from a result received from Cobbler.
+ #
+ def self.create(attrs)
+ System.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 <dpierce(a)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.
+
+
+$:.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..01a8184
--- /dev/null
+++ b/ruby/rubygem-cobbler/test/test_profile.rb
@@ -0,0 +1,83 @@
+# test_profile.rb - Tests the Profile class.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce(a)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.
+
+
+$:.unshift File.join(File.dirname(__FILE__),'..','lib')
+
+require 'test/unit'
+require 'flexmock/test_unit'
+require 'cobbler/base'
+require 'cobbler/profile'
+
+module Cobbler
+ class TestProfile < 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
+ @connection.should_receive(:call).with('get_profiles').once.returns(@profiles)
+
+ result = Profile.find
+
+ assert result, 'Expected a result set.'
+ assert_equal 2, result.size, 'Did not receive the right number of results'
+ end
+ end
+end
--
1.5.5.1
15 years, 9 months
Cobbler live CD still going to be supported, updates coming
by Michael DeHaan
So, we talked about replacing the Cobbler Live CD (really not limited to
just CD's) with Cobbler Build ISO. It turns out, it's right to keep
both, as some people /are/ using the live image to simulate PXE in
environments that don't have PXE.
If you are new to this, you can read about it here:
https://fedorahosted.org/cobbler/wiki/CobblerLiveCd
And here's BuildIso:
https://fedorahosted.org/cobbler/wiki/BuildIso
I am updating the livecd-builder scripts in question so they will work
with F9 instead of F8 so it should have better hardware support. The
changes are minor, namely a new URL for packages to base the live image
off of, and livecd-tools is now the package name, not livecd-creator.
You may ask why we don't host a live CD that people can just download,
the answer is because we need to burn the address of the cobbler server
into the image. It will still be possible to do that for one that
points at any machine it can find named "cobbler", so I am going to look
into it with fedora infrastructure what it will take to offer that via a
torrent.
Then you can just set up a cobbler CNAME and be good to go, without
having to build the ISO.
--Michael
15 years, 9 months
LiveCD -- not going away after all!
by Michael DeHaan
So, we talked about replacing the Cobbler Live CD (really not limited to
just CD's) with Cobbler Build ISO. It turns out, it's right to keep
both, as some people /are/ using the live image to simulate PXE in
environments that don't have PXE.
If you are new to this, you can read about it here:
https://fedorahosted.org/cobbler/wiki/CobblerLiveCd
And here's BuildIso:
https://fedorahosted.org/cobbler/wiki/BuildIso
I am updating the livecd-builder scripts in question so they will work
with F9 instead of F8 so it should have better hardware support. The
changes are minor, namely a new URL for packages to base the live image
off of, and livecd-tools is now the package name, not livecd-creator.
You may ask why we don't host a live CD that people can just download,
the answer is because we need to burn the address of the cobbler server
into the image. It will still be possible to do that for one that
points at any machine it can find named "cobbler", so I am going to look
into it with fedora infrastructure what it will take to offer that via a
torrent.
Then you can just set up a cobbler CNAME and be good to go, without
having to build the ISO.
--Michael
15 years, 9 months
python error on starting cobbler
by Tom Brown
Hi
# rpm -qa | grep cobbler
cobbler-1.0.3-1
I was adding some boxes to cobbler with a script but had to kill it half
way through due to a box being added by mistake. I killed it but now
when i run a cobbler sync or try to restart cobbler i get this
Starting cobbler daemon: Traceback (most recent call last):
File "/usr/bin/cobblerd", line 32, in ?
api = bootapi.BootAPI()
File "/usr/lib/python2.3/site-packages/cobbler/api.py", line 73, in
__init__
self.deserialize()
File "/usr/lib/python2.3/site-packages/cobbler/api.py", line 381, in
deserialize
return self._config.deserialize()
File "/usr/lib/python2.3/site-packages/cobbler/config.py", line 169,
in deserialize
if not serializer.deserialize(x,topological=True):
File "/usr/lib/python2.3/site-packages/cobbler/serializer.py", line
88, in deserialize
rc = storage_module.deserialize(obj,topological)
File
"/usr/lib/python2.3/site-packages/cobbler/modules/serializer_yaml.py",
line 103, in deserialize
datastruct = yaml.load(data).next() # first record
File "/usr/lib/python2.3/site-packages/cobbler/yaml/load.py", line 89,
in next
self.nestedDocs.nestToNextLine()
File "/usr/lib/python2.3/site-packages/cobbler/yaml/stream.py", line
137, in nestToNextLine
indentation = indentLevel(line)
File "/usr/lib/python2.3/site-packages/cobbler/yaml/stream.py", line
12, in indentLevel
while n < len(line) and line[n] == ' ':
TypeError: len() of unsized object
[FAILED]
Anyone got any ideas how to clean this back up again?
thanks
15 years, 9 months
[PATCH] Ruby interface for Cobbler XML-RPC APIs.
by Darryl L. Pierce
The interface is stored in a module named Cobbler.
Examples for using the interface are stored in ./examples.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+require 'rubygems'
+
+spec = Gem::Specification.new do |s|
+ s.name = 'Cobbler'
+ s.version = '0.0.1'
+ s.author = 'Darryl L. Pierce'
+ s.email = 'dpierce(a)redhat.com'
+ 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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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]
+)
+
+@hostname = nil
+@profile = nil
+@find_all = 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 #{@find_all ? 'all profiles' : 'first profile'} that match \"#{@profile}\""
+
+ 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: #{@profile}"
+ 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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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]
+)
+
+@hostname
+
+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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+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 <dpierce(a)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.
+
+# +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 <dpierce(a)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.
+
+
+$:.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 <dpierce(a)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.
+
+
+$:.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
15 years, 9 months
RE: Snippet with generalized functions
by Dan G
OK, hotmail sucks! Please see below. hopefully this time with proper line breaks.
________________________________
> From: danpg102(a)hotmail.com
> To: cobbler(a)lists.fedorahosted.org
> Subject: Snippet with generalized functions
> Date: Mon, 28 Jul 2008 18:26:37 -0500
>
> Attached is a snippet that makes use of cheetah methods. These are similar to some of the functionality that the Solaris SST offers. They basically encapsulate many (usually obscure) sed commands into handy functions.
$set_config_value('/etc/login.defs', 'LOGIN_RETRIES', 3)
is more readable than:
perl -npe 's/^([ \t]*$LOGIN_RETRIES[ \t]+)[\x21-\x7E]*([ \t]*(#.*)?)$/\${1}3\${2}/' -i '/etc/login.defs'
and the perl (sed) command doesn't take into account the possibility that LOGIN_RETRIES may not already be present in the file. The use of a function makes kickstart templates more readable and helps avoid errors.
Because of the utility of these functions, I would suggest they be distributed with cobbler, possibly as 'built-in' methods.
Development note: although I have tested that these functions do not cause any Cheetah errors, I have not tested the resulting kickstarts in an actual provision. They may still cause errors on the client side :( .
~
Dan
> ________________________________
> With Windows Live for mobile, your contacts travel with you. Connect on the go.
_________________________________________________________________
With Windows Live for mobile, your contacts travel with you.
http://www.windowslive.com/mobile/overview.html?ocid=TXT_TAGLM_WL_mobile_...
15 years, 9 months