summaryrefslogtreecommitdiffstats
path: root/contrib/ruby/examples/has_image.rb
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ruby/examples/has_image.rb')
-rwxr-xr-xcontrib/ruby/examples/has_image.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/contrib/ruby/examples/has_image.rb b/contrib/ruby/examples/has_image.rb
new file mode 100755
index 00000000..8442f6e6
--- /dev/null
+++ b/contrib/ruby/examples/has_image.rb
@@ -0,0 +1,65 @@
+#!/usr/bin/ruby
+#
+# has_image.rb - example of using rubygem-cobbler to check if an image 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 ],
+ ["--image", "-i", GetoptLong::REQUIRED_ARGUMENT ],
+ ["--help", "-h", GetoptLong::NO_ARGUMENT]
+)
+
+hostname = nil
+image = nil
+
+opts.each do |opt, arg|
+ case opt
+ when '--server' then hostname = arg
+ when '--image' then image = arg
+ when '--help' then
+ puts "Usage: #{$0} --server hostname --image image-name\n"
+ end
+end
+
+SystemExit.new('No hostname specified.') unless hostname
+
+if hostname
+ Base.hostname = hostname
+
+ puts "Finding any system that matches \"#{image}\""
+
+ result = Image.find_one(image)
+
+ if result
+ puts "#{result.name} exists, and uses #{result.file}."
+ else
+ puts "No such system: #{image}"
+ end
+end \ No newline at end of file