summaryrefslogtreecommitdiffstats
path: root/contrib/ruby/examples
diff options
context:
space:
mode:
authorDarryl L. Pierce <dpierce@redhat.com>2008-08-04 16:20:22 -0400
committerDarryl L. Pierce <dpierce@redhat.com>2008-08-04 16:20:42 -0400
commit18d59cd57a1b32216b32e6295fd04878c83d1e3f (patch)
treee2b48a14b897ce831ffa729e13c62db86fc6f11f /contrib/ruby/examples
parente32078747922d51ed74452a039c0ff676c78ac58 (diff)
downloadcobbler-18d59cd57a1b32216b32e6295fd04878c83d1e3f.tar.gz
cobbler-18d59cd57a1b32216b32e6295fd04878c83d1e3f.tar.xz
cobbler-18d59cd57a1b32216b32e6295fd04878c83d1e3f.zip
Ruby bindings for the Cobbler XMLRCP interface.
This first pass is very simple, only wrapping the Distro, Profile and System objects and the NetworkInterface type. All classes extended a class named Base, and all are in the Cobbler module. Configuration is held within the config/cobbler.yml file, but can be overridden at runtime. Unit tests, examples, etc. are also provided.
Diffstat (limited to 'contrib/ruby/examples')
-rw-r--r--contrib/ruby/examples/create_system.rb77
-rw-r--r--contrib/ruby/examples/has_distro.rb66
-rw-r--r--contrib/ruby/examples/has_profile.rb65
-rw-r--r--contrib/ruby/examples/has_system.rb65
-rw-r--r--contrib/ruby/examples/list_distros.rb52
-rw-r--r--contrib/ruby/examples/list_profiles.rb53
-rw-r--r--contrib/ruby/examples/list_systems.rb52
-rw-r--r--contrib/ruby/examples/remove_distro.rb71
-rw-r--r--contrib/ruby/examples/remove_system.rb71
9 files changed, 572 insertions, 0 deletions
diff --git a/contrib/ruby/examples/create_system.rb b/contrib/ruby/examples/create_system.rb
new file mode 100644
index 00000000..0196573c
--- /dev/null
+++ b/contrib/ruby/examples/create_system.rb
@@ -0,0 +1,77 @@
+#!/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 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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--name", "-n", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--profile", "-f", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--system", "-y", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = name = profile = system = username = password = nil
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then hostname = arg
+ when '--name' then name = arg
+ when '--system' then system = arg
+ when '--profile' then profile = arg
+ when '--username' then username = arg
+ when '--password' then password = arg
+ when '--help' then usage
+ end
+end
+
+def usage
+ puts "Usage: #{$0} [--server hostname] --name system-name --system system-name [--username username] [--password password]\n"
+end
+
+if name && profile
+
+ system = System.new('name' => name,'profile' => profile)
+
+ 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}."
+
+ begin
+ system.save
+ puts "Successfully saved the new system."
+ rescue Exception => error
+ puts "Unable to create system: #{error.message}"
+ end
+else
+ usage
+end \ No newline at end of file
diff --git a/contrib/ruby/examples/has_distro.rb b/contrib/ruby/examples/has_distro.rb
new file mode 100644
index 00000000..22093d72
--- /dev/null
+++ b/contrib/ruby/examples/has_distro.rb
@@ -0,0 +1,66 @@
+#!/usr/bin/ruby
+#
+# has_distro.rb - example of using rubygem-cobbler to check if a distro exists.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierceredhat.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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--distro", "-t", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+distro = nil
+find_all = true
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then hostname = arg
+ when '--distro' then distro = arg
+ when '--help' then
+ puts "Usage: #{$0} --server hostname --distro distro-name\n"
+ end
+end
+
+SystemExit.new('No hostname specified.') unless hostname
+
+if hostname && distro
+ Distro.hostname = hostname
+
+ puts "Finding any distro that matches \"#{distro}\""
+
+ result = Distro.find_one(distro)
+
+ if result
+ puts "#{result.name} exists, and is a breed of #{result.breed}."
+ else
+ puts "No such system: #{distro}"
+ end
+end \ No newline at end of file
diff --git a/contrib/ruby/examples/has_profile.rb b/contrib/ruby/examples/has_profile.rb
new file mode 100644
index 00000000..401a6c1c
--- /dev/null
+++ b/contrib/ruby/examples/has_profile.rb
@@ -0,0 +1,65 @@
+#!/usr/bin/ruby
+#
+# 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@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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--profile", "-t", 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 --system system-name\n"
+ end
+end
+
+SystemExit.new('No hostname specified.') unless hostname
+
+if hostname
+ Profile.hostname = hostname
+
+ puts "Finding any system that matches \"#{profile}\""
+
+ result = Profile.find_one(profile)
+
+ if result
+ puts "#{result.name} exists, and is owned by #{result.owners}."
+ else
+ puts "No such system: #{profile}"
+ end
+end \ No newline at end of file
diff --git a/contrib/ruby/examples/has_system.rb b/contrib/ruby/examples/has_system.rb
new file mode 100644
index 00000000..9088666d
--- /dev/null
+++ b/contrib/ruby/examples/has_system.rb
@@ -0,0 +1,65 @@
+#!/usr/bin/ruby
+#
+# 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 <dpierceredhat.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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--system", "-t", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+system = nil
+
+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_one(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/contrib/ruby/examples/list_distros.rb b/contrib/ruby/examples/list_distros.rb
new file mode 100644
index 00000000..27dcd0a9
--- /dev/null
+++ b/contrib/ruby/examples/list_distros.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/ruby
+# list_distros.rb - example of using rubygem-cobbler to list distros.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+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(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+
+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
+ Distro.hostname = hostname
+
+ puts "Results:"
+ Distro.find { |distro| puts "\"#{distro.name}\" is a breed of \"#{distro.breed}\"."}
+end \ No newline at end of file
diff --git a/contrib/ruby/examples/list_profiles.rb b/contrib/ruby/examples/list_profiles.rb
new file mode 100644
index 00000000..3ca97c50
--- /dev/null
+++ b/contrib/ruby/examples/list_profiles.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/ruby
+#
+# list_profiles.rb - example of using rubygem-cobbler to list profiles.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+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(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+
+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
+ Profile.hostname = hostname
+
+ puts "Results:"
+ Profile.find { |profile| puts "\"#{profile.name}\" is based on \"#{profile.distro}\"."}
+end \ No newline at end of file
diff --git a/contrib/ruby/examples/list_systems.rb b/contrib/ruby/examples/list_systems.rb
new file mode 100644
index 00000000..d614460f
--- /dev/null
+++ b/contrib/ruby/examples/list_systems.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/ruby
+#
+# list_systems.rb - example of using rubygem-cobbler to list system.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+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(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then hostname = arg
+ when '--help' then
+ puts "Usage: #{$0} --server hostname\n"
+ end
+end
+
+
+Base.hostname = hostname if hostname
+
+puts "Results:"
+System.find { |system| puts "\"#{system.name}\" is based on \"#{system.profile}\"."}
diff --git a/contrib/ruby/examples/remove_distro.rb b/contrib/ruby/examples/remove_distro.rb
new file mode 100644
index 00000000..d4e34adc
--- /dev/null
+++ b/contrib/ruby/examples/remove_distro.rb
@@ -0,0 +1,71 @@
+#!/usr/bin/ruby
+#
+# remove_system.rb - example of using rubygem-cobbler to remove a system.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierceredhat.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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--distro", "-d", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+distro = nil
+username = nil
+password = nil
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then hostname = arg
+ when '--distro' then distro = arg
+ when '--username' then username = arg
+ when '--password' then password = arg
+ when '--help' then
+ puts "Usage: #{$0} --server hostname --distro distro-name --username username --password password\n"
+ end
+end
+
+SystemExit.new('No hostname specified.') unless hostname
+
+if hostname && distro && username && password
+ System.hostname = hostname
+ System.username = username
+ System.password = password
+
+ puts "Removing \"#{distro}\"..."
+
+ begin
+ puts "Deleted \"#{distro}" if System.remove(distro)
+ rescue Exception => e
+ puts "Error: #{e.message}"
+ end
+end \ No newline at end of file
diff --git a/contrib/ruby/examples/remove_system.rb b/contrib/ruby/examples/remove_system.rb
new file mode 100644
index 00000000..d592165a
--- /dev/null
+++ b/contrib/ruby/examples/remove_system.rb
@@ -0,0 +1,71 @@
+#!/usr/bin/ruby
+#
+# remove_system.rb - example of using rubygem-cobbler to remove a system.
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierceredhat.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'
+
+include Cobbler
+
+opts = GetoptLong.new(
+ ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--system", "-t", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--username", "-u", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+system = nil
+username = nil
+password = nil
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then hostname = arg
+ when '--system' then system = arg
+ when '--username' then username = arg
+ when '--password' then password = arg
+ when '--help' then
+ puts "Usage: #{$0} --server hostname --system system-name\n"
+ end
+end
+
+SystemExit.new('No hostname specified.') unless hostname
+
+if hostname && system && username && password
+ System.hostname = hostname
+ System.username = username
+ System.password = password
+
+ puts "Removing \"#{system}\"..."
+
+ begin
+ puts "Deleted \"#{system}" if System.remove(system)
+ rescue Exception => e
+ puts "Error: #{e.message}"
+ end
+end \ No newline at end of file