diff options
| author | Darryl L. Pierce <dpierce@redhat.com> | 2008-08-06 09:51:53 -0400 |
|---|---|---|
| committer | Darryl L. Pierce <dpierce@redhat.com> | 2008-08-13 11:42:19 -0400 |
| commit | 1cf6f177f25aeba510949f2d3ea1fad68697c4cf (patch) | |
| tree | 66145a7a077fb4baf90d9abc766d02801e8d7cce /contrib/ruby/examples | |
| parent | 31952586ba56d076a10c1d08d710d7d1f44580db (diff) | |
| download | cobbler-1cf6f177f25aeba510949f2d3ea1fad68697c4cf.tar.gz cobbler-1cf6f177f25aeba510949f2d3ea1fad68697c4cf.tar.xz cobbler-1cf6f177f25aeba510949f2d3ea1fad68697c4cf.zip | |
Added support for images to the Ruby bindings.
Also fixed some of the decoding for interfaces returned for systems. But I'm not happy with that binding still.
Diffstat (limited to 'contrib/ruby/examples')
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/create_system.rb | 6 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/has_distro.rb | 0 | ||||
| -rwxr-xr-x | contrib/ruby/examples/has_image.rb | 65 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/has_profile.rb | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/has_system.rb | 18 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/list_distros.rb | 0 | ||||
| -rwxr-xr-x | contrib/ruby/examples/list_images.rb | 52 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/list_profiles.rb | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/list_systems.rb | 19 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/remove_distro.rb | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | contrib/ruby/examples/remove_system.rb | 0 |
11 files changed, 145 insertions, 15 deletions
diff --git a/contrib/ruby/examples/create_system.rb b/contrib/ruby/examples/create_system.rb index 0196573c..43a8fc41 100644..100755 --- a/contrib/ruby/examples/create_system.rb +++ b/contrib/ruby/examples/create_system.rb @@ -60,9 +60,13 @@ end if name && profile + System.hostname = hostname if hostname + System.username = username if username + System.password = password if password + system = System.new('name' => name,'profile' => profile) - system.interfaces=[ NetworkInterface.new('mac_address' => '00:11:22:33:44:55:66:77') ] + system.interfaces=[NetworkInterface.new(["intf",{'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}." diff --git a/contrib/ruby/examples/has_distro.rb b/contrib/ruby/examples/has_distro.rb index 22093d72..22093d72 100644..100755 --- a/contrib/ruby/examples/has_distro.rb +++ b/contrib/ruby/examples/has_distro.rb 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 diff --git a/contrib/ruby/examples/has_profile.rb b/contrib/ruby/examples/has_profile.rb index 401a6c1c..401a6c1c 100644..100755 --- a/contrib/ruby/examples/has_profile.rb +++ b/contrib/ruby/examples/has_profile.rb diff --git a/contrib/ruby/examples/has_system.rb b/contrib/ruby/examples/has_system.rb index 9088666d..69c52a9d 100644..100755 --- a/contrib/ruby/examples/has_system.rb +++ b/contrib/ruby/examples/has_system.rb @@ -50,16 +50,14 @@ end SystemExit.new('No hostname specified.') unless hostname -if hostname - Base.hostname = hostname +Base.hostname = hostname if hostname - puts "Finding any system that matches \"#{system}\"" +puts "Finding any system that matches \"#{system}\"" - result = System.find_one(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 +if result + puts "#{result.name} exists, and is owned by #{result.owners}." +else + puts "No such system: #{system}" +end diff --git a/contrib/ruby/examples/list_distros.rb b/contrib/ruby/examples/list_distros.rb index 27dcd0a9..27dcd0a9 100644..100755 --- a/contrib/ruby/examples/list_distros.rb +++ b/contrib/ruby/examples/list_distros.rb diff --git a/contrib/ruby/examples/list_images.rb b/contrib/ruby/examples/list_images.rb new file mode 100755 index 00000000..0df5611e --- /dev/null +++ b/contrib/ruby/examples/list_images.rb @@ -0,0 +1,52 @@ +#!/usr/bin/ruby +# +# list_images.rb - example of using rubygem-cobbler to list images. +# +# 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:" +Image.find { |image| puts "\"#{image.name}\" uses \"#{image.file}\"."} diff --git a/contrib/ruby/examples/list_profiles.rb b/contrib/ruby/examples/list_profiles.rb index 578922b0..578922b0 100644..100755 --- a/contrib/ruby/examples/list_profiles.rb +++ b/contrib/ruby/examples/list_profiles.rb diff --git a/contrib/ruby/examples/list_systems.rb b/contrib/ruby/examples/list_systems.rb index d614460f..fbee42c9 100644..100755 --- a/contrib/ruby/examples/list_systems.rb +++ b/contrib/ruby/examples/list_systems.rb @@ -31,15 +31,18 @@ require 'cobbler' include Cobbler opts = GetoptLong.new( - ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - ["--help", "-h", GetoptLong::NO_ARGUMENT] + ["--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], + ["--details", "-d", GetoptLong::NO_ARGUMENT ], + ["--help", "-h", GetoptLong::NO_ARGUMENT ] ) hostname = nil +details = false opts.each do |opt, arg| case opt - when '--server' then hostname = arg + when '--server' then hostname = arg + when '--details' then details = true when '--help' then puts "Usage: #{$0} --server hostname\n" end @@ -49,4 +52,12 @@ end Base.hostname = hostname if hostname puts "Results:" -System.find { |system| puts "\"#{system.name}\" is based on \"#{system.profile}\"."} +System.find do |system| + puts "\"#{system.name}\" is based on \"#{system.profile}\"." + + if details + puts "\tOwner: #{system.owners}" + system.interfaces.each { |nic| puts "\tNIC: #{nic.mac_address}"} + end + +end
\ No newline at end of file diff --git a/contrib/ruby/examples/remove_distro.rb b/contrib/ruby/examples/remove_distro.rb index d4e34adc..d4e34adc 100644..100755 --- a/contrib/ruby/examples/remove_distro.rb +++ b/contrib/ruby/examples/remove_distro.rb diff --git a/contrib/ruby/examples/remove_system.rb b/contrib/ruby/examples/remove_system.rb index d592165a..d592165a 100644..100755 --- a/contrib/ruby/examples/remove_system.rb +++ b/contrib/ruby/examples/remove_system.rb |
