summaryrefslogtreecommitdiffstats
path: root/contrib/ruby/examples
diff options
context:
space:
mode:
authorDarryl L. Pierce <dpierce@redhat.com>2009-03-03 10:39:43 -0500
committerDarryl L. Pierce <dpierce@redhat.com>2009-03-05 16:37:07 -0500
commit88eaff25762cb5b2b10352fa8c299104eda8f784 (patch)
treec42a1f78c78d0462af95c5028f81d977c1e1599f /contrib/ruby/examples
parentdbcfc5a2f0d191001cd8000a543e41eddefd20f7 (diff)
downloadcobbler-88eaff25762cb5b2b10352fa8c299104eda8f784.tar.gz
cobbler-88eaff25762cb5b2b10352fa8c299104eda8f784.tar.xz
cobbler-88eaff25762cb5b2b10352fa8c299104eda8f784.zip
Adds support for the XMLRPC changes for Cobbler 1.5.
Some additional features added as a result is the ability to debug a connection. If Base.debug is set to true then all communication between the client and server is sent to stdout. Also fixed the list_systems.rb example to show the image on which a system is based if it's not based on a profile. And some minor cleanup to those particular source modules.
Diffstat (limited to 'contrib/ruby/examples')
-rwxr-xr-xcontrib/ruby/examples/check_version.rb62
-rwxr-xr-xcontrib/ruby/examples/create_system.rb50
-rwxr-xr-xcontrib/ruby/examples/list_systems.rb36
3 files changed, 110 insertions, 38 deletions
diff --git a/contrib/ruby/examples/check_version.rb b/contrib/ruby/examples/check_version.rb
new file mode 100755
index 00000000..1d5653e5
--- /dev/null
+++ b/contrib/ruby/examples/check_version.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/ruby -w
+#
+# create_system.rb - example of using rubygem-cobbler to create a system.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce@redhat.com>
+#
+# This file is part of rubygem-cobbler.
+#
+# rubygem-cobbleris free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation, either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# rubygem-cobbler 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 rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
+#
+
+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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ['--hostname', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--help', '-h', GetoptLong::NO_ARGUMENT])
+
+hostname = nil
+
+def usage
+ puts "Usage: #{$0} --hostname hostname\n"
+ exit
+end
+
+opts.each do |opt, arg|
+ case opt
+ when '--hostname' then hostname = arg
+ when '--help' then usage
+ end
+end
+
+if hostname
+ Base.hostname = hostname
+ version = Base.remote_version
+ if version
+ puts "Remote version: #{version}"
+ else
+ puts "Unable to determine version."
+ end
+else
+ usage
+end
diff --git a/contrib/ruby/examples/create_system.rb b/contrib/ruby/examples/create_system.rb
index dd938fe1..b2d2138a 100755
--- a/contrib/ruby/examples/create_system.rb
+++ b/contrib/ruby/examples/create_system.rb
@@ -1,14 +1,14 @@
-#!/usr/bin/ruby -w
+#!/usr/bin/ruby -w
#
# create_system.rb - example of using rubygem-cobbler to create a system.
-#
+#
# Copyright (C) 2008 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com>
#
# This file is part of rubygem-cobbler.
#
# rubygem-cobbleris free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
+# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
@@ -20,7 +20,7 @@
# You should have received a copy of the GNU General Public License
# along with rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
#
-
+
base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH << File.join(base, "lib")
$LOAD_PATH << File.join(base, "examples")
@@ -31,41 +31,49 @@ require 'cobbler'
include Cobbler
-opts = GetoptLong.new(
- ['--hostname', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- ['--name', '-n', GetoptLong::REQUIRED_ARGUMENT ],
- ['--profile', '-f', GetoptLong::REQUIRED_ARGUMENT ],
- ['--username', '-u', GetoptLong::REQUIRED_ARGUMENT ],
- ['--password', '-p', GetoptLong::REQUIRED_ARGUMENT ],
- ['--help', '-h', GetoptLong::NO_ARGUMENT]
-)
+opts = GetoptLong.new(['--hostname', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--name', '-n', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--profile', '-f', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--image', '-i', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--username', '-u', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--password', '-p', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
+ ['--debug', '-d', GetoptLong::NO_ARGUMENT])
-name = profile = hostname = username = password = nil
+name = profile = image = hostname = username = password = debug = nil
def usage
- puts "Usage: #{$0} --name system-name --profile profile-name [--hostname hostname] [--username username] [--password password]\n"
+ puts "Usage: #{$0} --name system-name [--profile profile-name | --image image-name ] [--hostname hostname] [--username username] [--password password]\n"
exit
end
-
+
opts.each do |opt, arg|
case opt
when '--hostname' then hostname = arg
when '--name' then name = arg
when '--profile' then profile = arg
+ when '--image' then image = arg
when '--username' then username = arg
when '--password' then password = arg
when '--help' then usage
+ when '--debug' then debug = true
end
end
-if name && profile
-
+if (profile && image)
+ puts "\nYou must specify either a profile or an image, but not both.\n\n"
+ usage
+end
+
+if name && (profile || image)
System.hostname = hostname if hostname
System.username = username if username
System.password = password if password
-
- system = System.new('name' => name,'profile' => profile)
-
+ System.debug = true if debug
+
+ system = System.new('name' => name,'profile' => profile) if profile
+ system = System.new('name' => name,'image' => image) if image
+
system.interfaces=[NetworkInterface.new({'mac_address' => '00:11:22:33:44:55:66:77'})]
puts "Saving a new system with name #{system.name} based on the profile #{system.profile}."
@@ -78,4 +86,4 @@ if name && profile
end
else
usage
-end \ No newline at end of file
+end
diff --git a/contrib/ruby/examples/list_systems.rb b/contrib/ruby/examples/list_systems.rb
index 61afe800..4474905a 100755
--- a/contrib/ruby/examples/list_systems.rb
+++ b/contrib/ruby/examples/list_systems.rb
@@ -1,14 +1,14 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby
#
# list_systems.rb - example of using rubygem-cobbler to list system.
-#
-# Copyright (C) 2008 Red Hat, Inc.
+#
+# Copyright (C) 2008, 2009, Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com>
#
# This file is part of rubygem-cobbler.
#
# rubygem-cobbleris free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
+# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
@@ -20,7 +20,7 @@
# You should have received a copy of the GNU General Public License
# along with rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
#
-
+
base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$LOAD_PATH << File.join(base, "lib")
$LOAD_PATH << File.join(base, "examples")
@@ -31,14 +31,14 @@ require 'cobbler'
include Cobbler
-opts = GetoptLong.new(
- ['--hostname', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- ['--details', '-d', GetoptLong::NO_ARGUMENT ],
- ['--help', '-h', GetoptLong::NO_ARGUMENT ]
-)
+opts = GetoptLong.new(['--hostname', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ ['--details', '-v', GetoptLong::NO_ARGUMENT ],
+ ['--help', '-h', GetoptLong::NO_ARGUMENT ],
+ ['--debug', '-d', GetoptLong::NO_ARGUMENT ])
hostname = nil
details = false
+debug = false
def usage
puts "Usage: #{$0} [--hostname hostname] [--details]\n"
@@ -50,18 +50,20 @@ opts.each do |opt, arg|
when '--hostname' then hostname = arg
when '--details' then details = true
when '--help' then usage
+ when '--debug' then debug = true
end
end
Base.hostname = hostname if hostname
-
+Base.debug = debug if debug
+
puts "Results:"
-System.find do |system|
- puts "\"#{system.name}\" is based on \"#{system.profile}\"."
-
+System.find do |system|
+ puts "\"#{system.name}\" is based on the \"#{system.profile}\" profile." unless system.profile.empty?
+ puts "\"#{system.name}\" is based on the \"#{system.image}\" image." unless system.image.empty?
+
if details
puts "\tOwner: #{system.owners}"
- system.interfaces.each_pair { |id,nic| puts "\tNIC[#{id}]: #{nic.mac_address}"}
- end
+ system.interfaces.each_pair { |id,nic| puts "\tNIC[#{id}]: #{nic.mac_address}"}
+ end
end
-