gapinc-cobbler 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,40 @@
1
+ * Thu Jan 05 2012 duritong <peter.meier@immerda.ch> - 2.0.0-1
2
+ - Fix all issues when API returns ~ on a nonexisting system
3
+ - Add some missing fields to the System model
4
+ - Remove unnecessary object abstraction for interfaces
5
+ - Fix storing of interfaces
6
+ - Rework connection handling
7
+ - Rewrite to enable capabilities for all items and to work against 2.0
8
+
9
+ * Fri Oct 10 2008 Darryl Pierce <dpierce@redhat.com> - 0.1.1-1
10
+ - Added support for image-based systems.
11
+
12
+ * Mon Sep 08 2008 Darryl Pierce <dpierce@redhat.com> - 0.1.0-1
13
+ - First official build for Fedora.
14
+
15
+ * Wed Sep 03 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-3
16
+ - Added a build requirement for rubygem-rake.
17
+
18
+ * Tue Aug 26 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-2
19
+ - Fixed the licensing in each source module to show the code is released under
20
+ LGPLv2.1.
21
+ - Added %check to the spec file to run tests prior to creating the RPM.
22
+
23
+ * Thu Aug 21 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-1
24
+ - Added a call to update prior to saving or updating a system. If the update
25
+ fails, then an Exception is raised.
26
+
27
+ * Wed Aug 13 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.1-3
28
+ - Added caching for the auth_token to prevent extraneous calls to login.
29
+ - Reworked and refined how cobbler_collection fields are processed, adding
30
+ support for both array and has properties.
31
+ - Rewrote the documentation for Cobbler::Base to make it easier to understand
32
+ how to extend it to support other Cobbler types.
33
+ - Refactored the examples to clean up the code.
34
+
35
+ * Wed Aug 13 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.1-2
36
+ - Removed markup of cobbler.yml and a config file. Fixed a few small bugs
37
+ in the code for using it as a gem.
38
+
39
+ * Mon Aug 04 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.1-1
40
+ - Initial package
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'activesupport'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.5.0"
12
+ gem "rdoc", "~> 3.8"
13
+ gem "jeweler", "~> 1.6.4"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.0)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ diff-lcs (1.1.3)
11
+ git (1.2.6)
12
+ i18n (0.6.9)
13
+ jeweler (1.6.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ json (1.8.1)
18
+ minitest (5.3.2)
19
+ rake (10.2.2)
20
+ rdoc (3.12.2)
21
+ json (~> 1.4)
22
+ rspec (2.5.0)
23
+ rspec-core (~> 2.5.0)
24
+ rspec-expectations (~> 2.5.0)
25
+ rspec-mocks (~> 2.5.0)
26
+ rspec-core (2.5.2)
27
+ rspec-expectations (2.5.0)
28
+ diff-lcs (~> 1.1.2)
29
+ rspec-mocks (2.5.0)
30
+ thread_safe (0.3.3)
31
+ tzinfo (1.1.0)
32
+ thread_safe (~> 0.1)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ activesupport
39
+ jeweler (~> 1.6.4)
40
+ rdoc (~> 3.8)
41
+ rspec (~> 2.5.0)
data/NEWS ADDED
@@ -0,0 +1,5 @@
1
+ 2012-01-05 2.0
2
+ * Rewrite to be compatible with 2.0
3
+
4
+ 2008-08-01 0.0.1
5
+ * Initial release.
data/README.rdoc ADDED
@@ -0,0 +1,87 @@
1
+ = ruby-cobbler
2
+
3
+ Ruby bindings for interacting with Cobbler.
4
+
5
+ These bindings were once part of the official cobbler repository. They were
6
+ written by Darryl L. Pierce <dpierce@redhat.com>. However, they got stalled to
7
+ work for cobbler 1.x and no further development was done. Also
8
+ this version was missing a lot of features, like creating various objects etc.
9
+
10
+ So I took over the development and while the work was done to get it working
11
+ with a more recent cobbler version, but also to add the various missing
12
+ features, the development of cobbler by RedHat stopped and the people continuing
13
+ the work on cobbler decided to drop the ruby gem.
14
+ So I decided to publish that gem on its own, but still keep it under the same
15
+ License as Darryl L. Pierce <dpierce@redhat.com> published it originally.
16
+
17
+ It is used to talk to a cobbler installation that ships with the latest RedHat
18
+ Satellite and have tested with that.
19
+ It is still a work in progress, but it is used, to create systems, delete systems,
20
+ create and/or import repositories, sync repositories, work with the task engine,
21
+ and so on.
22
+
23
+ WARNING: It is possible that it does not work with a current cobbler version as
24
+ the author does currently not have access to such an installation nor is any
25
+ work planned to do so.
26
+ Just give it a shot with a newer cobbler and if things don't work: pull requests
27
+ are welcomed! See below.
28
+
29
+ == USAGE
30
+
31
+ To use the code, you must install the ruby gem named "cobbler" and then
32
+ require 'cobbler' in your application.
33
+
34
+ Minimally you need to provide a server name for your Cobbler machine using:
35
+
36
+ Cobbler::Base.hostname = my.cobbler.server
37
+
38
+ If you intend to modify data on the Cobbler server, you'll need to also provide
39
+ a username and password that has authorization:
40
+
41
+ Cobbler::Base.username = username
42
+ Cobbler::Base.password = password
43
+
44
+ == Examples
45
+
46
+ You'll find a few working examples in `examples/`
47
+
48
+ An example on how to import a distribution is:
49
+
50
+ Cobbler::Base.hostname = localhost
51
+ Cobbler::Base.username = cobbler
52
+ Cobbler::Base.password = cobbler
53
+ log_id = Cobbler::Base.import("/mnt/centos6.iso",'centos6','x86_64', 'breed' => 'redhat')
54
+ while (event = Cobbler::Base.events[log_id])[2] == 'running' do
55
+ puts "Current state is: #{event[2]} - #{event.inspect}"
56
+ sleep 60
57
+ end
58
+ puts "Import event: #{event.inspect}"
59
+ puts "All distros:"
60
+ Cobbler::Distro.find { |distro| puts "\"#{distro.name}\" is a breed of \"#{distro.breed}\"."}
61
+
62
+
63
+ == CONFIGURATION
64
+
65
+ By default, Cobbler::Base will load the file $SEARCHPATH/config/cobbler.yml,
66
+ if it exists, and use that information for talking to Cobbler. To override
67
+ where this file lives, set the COBBLER_ENV environment variable *before*
68
+ requiring the 'cobbler' file.
69
+
70
+ However, these values can be overridden afterward by changing the fields in
71
+ Cobbler::Base directly.
72
+
73
+ == Contributing to cobbler
74
+
75
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
76
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
77
+ * Fork the project
78
+ * Start a feature/bugfix branch
79
+ * Commit and push until you are happy with your contribution
80
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
81
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
82
+
83
+ == Copyright
84
+
85
+ Copyright (c) 2012 duritong. See COPYING for
86
+ further details.
87
+
data/Rakefile ADDED
@@ -0,0 +1,75 @@
1
+ # Copyright (C) 2008 Red Hat, Inc.
2
+ # Written by Darryl L. Pierce <dpierce@redhat.com>
3
+ # Extended 2012 by duritong <peter.meier@immerda.ch>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; version 2 of the License.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
+ # MA 02110-1301, USA. A copy of the GNU General Public License is
18
+ # also available at http://www.gnu.org/copyleft/gpl.html.
19
+
20
+ # encoding: utf-8
21
+
22
+ require 'rubygems'
23
+ require 'bundler'
24
+ begin
25
+ Bundler.setup(:default, :development)
26
+ rescue Bundler::BundlerError => e
27
+ $stderr.puts e.message
28
+ $stderr.puts "Run `bundle install` to install missing gems"
29
+ exit e.status_code
30
+ end
31
+ require 'rake'
32
+
33
+
34
+ require 'jeweler'
35
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
36
+ require 'cobbler'
37
+ Jeweler::Tasks.new do |gem|
38
+ # gem is a Gem::Specification... see http://docgem.rubygems.org/read/chapter/20 for more options
39
+ gem.name = 'cobbler'
40
+ gem.version = "2.0.0"
41
+ gem.author = 'duritong'
42
+ gem.email = 'peter.meier@immerda.ch'
43
+ gem.homepage = 'http://github.com/duritong/ruby-cobbler/'
44
+ gem.platform = Gem::Platform::RUBY
45
+ gem.summary = 'An interface for interacting with a Cobbler server.'
46
+ gem.license = 'GPLv2'
47
+ gem.description = <<EOF
48
+ Provides Ruby bindings to interact with a Cobbler server.
49
+ EOF
50
+ end
51
+ Jeweler::RubygemsDotOrgTasks.new
52
+
53
+ require 'rspec/core'
54
+ require 'rspec/core/rake_task'
55
+ RSpec::Core::RakeTask.new(:spec) do |spec|
56
+ spec.pattern = FileList['spec/**/*_spec.rb']
57
+ end
58
+
59
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
60
+ spec.pattern = 'spec/**/*_spec.rb'
61
+ spec.rcov = true
62
+ end
63
+
64
+ task :default => :spec
65
+
66
+ gem 'rdoc'
67
+ require 'rdoc/task'
68
+ RDoc::Task.new do |rdoc|
69
+ version = '2.0.0'
70
+ rdoc.rdoc_dir = 'rdoc'
71
+ rdoc.title = "iuid #{version}"
72
+ rdoc.rdoc_files.include('README*')
73
+ rdoc.rdoc_files.include('lib/**/*.rb')
74
+ end
75
+
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ This is a list of features to be developed in future.
2
+
3
+ * Rewrite examples to fit the new style
4
+
5
+ * Add hierarchical relationships, so that a Profile will load it's
6
+ Distro, a System will load it's Profile, etc.
@@ -0,0 +1,5 @@
1
+ # Cobbler connection details
2
+
3
+ hostname: localhost
4
+ username: cobbler
5
+ password: cobbler
@@ -0,0 +1,119 @@
1
+ #
2
+ # example_version.rb
3
+ #
4
+ # Copyright (C) 2008,2009 Red Hat, Inc.
5
+ # Written by Darryl L. Pierce <dpierce@redhat.com>
6
+ # Extended 2012 by duritong <peter.meier@immerda.ch>
7
+ #
8
+ # This file is part of rubygem-cobbler.
9
+ #
10
+ # rubygem-cobbler is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU Lesser General Public License as published
12
+ # by the Free Software Foundation, either version 2.1 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # rubygem-cobbler is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
25
+ $LOAD_PATH << File.join(base, "lib")
26
+ $LOAD_PATH << File.join(base, "examples")
27
+
28
+ require 'utils'
29
+ Cobbler::Examples::Utils.enhance(Cobbler::Distro)
30
+
31
+ require 'getoptlong'
32
+
33
+ opts = GetoptLong.new(
34
+ ['--show', '-s', GetoptLong::REQUIRED_ARGUMENT ],
35
+ ['--list', '-l', GetoptLong::NO_ARGUMENT],
36
+ ['--create', '-c', GetoptLong::REQUIRED_ARGUMENT ],
37
+ ['--remove', '-r', GetoptLong::REQUIRED_ARGUMENT ],
38
+ ['--testrun', '-t', GetoptLong::REQUIRED_ARGUMENT ]
39
+ )
40
+
41
+ def list
42
+ puts "All distros:"
43
+ Cobbler::Distro.find { |distro| puts "\"#{distro.name}\" is a breed of \"#{distro.breed}\"."}
44
+ end
45
+
46
+ def show(name)
47
+ puts "Finding the distro named \"#{name}\""
48
+
49
+ if (distro = Cobbler::Distro.find_one(name))
50
+ puts "#{distro.name} exists, and is a breed of #{distro.breed}."
51
+ puts "Kernel: #{distro.kernel} - Initrd: #{distro.initrd}"
52
+ else
53
+ puts "No such distro"
54
+ end
55
+ end
56
+
57
+ def create(name)
58
+ existing_distro = Cobbler::Distro.find.first
59
+ unless existing_distro
60
+ puts "No existing distro found to copy data from... -> abort!"
61
+ exit 1
62
+ end
63
+ distro = Cobbler::Distro.new
64
+ distro.name = name
65
+ distro.breed = existing_distro.breed
66
+ distro.kernel = existing_distro.kernel
67
+ distro.initrd = existing_distro.initrd
68
+ distro.arch = existing_distro.arch
69
+ distro.save
70
+
71
+ puts "Distro #{name} saved!"
72
+ end
73
+
74
+ def remove(name)
75
+ if (distro=Cobbler::Distro.find_one(name))
76
+ distro.remove
77
+ puts "Distro #{name} successfully removed!"
78
+ else
79
+ puts "No such distro named #{name} found! -> abort!"
80
+ exit 1
81
+ end
82
+ end
83
+
84
+ def testrun(name)
85
+ puts "Distros at the beginning"
86
+ puts "------------------------"
87
+ list
88
+ puts
89
+ puts "Create distro #{name}"
90
+ puts "---------------------"
91
+ create(name)
92
+ puts
93
+ puts "All distros after creating #{name}"
94
+ puts "----------------------------------"
95
+ list
96
+ puts
97
+ puts "Display distro #{name}"
98
+ puts "----------------------"
99
+ show(name)
100
+ puts
101
+ puts "Remove distro #{name}"
102
+ puts "---------------------"
103
+ remove(name)
104
+ puts
105
+ puts "Distros at the end"
106
+ puts "------------------"
107
+ list
108
+ end
109
+
110
+ opts.each do |opt, arg|
111
+ case opt
112
+ when '--show' then show(arg)
113
+ when '--list' then list
114
+ when '--create' then create(arg)
115
+ when '--remove' then remove(arg)
116
+ when '--testrun' then testrun(arg)
117
+ end
118
+ exit 0
119
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # example_distros.rb
3
+ #
4
+ # Copyright (C) 2008,2009 Red Hat, Inc.
5
+ # Written by Darryl L. Pierce <dpierce@redhat.com>
6
+ # Extended 2012 by duritong <peter.meier@immerda.ch>
7
+ #
8
+ # This file is part of rubygem-cobbler.
9
+ #
10
+ # rubygem-cobbler is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU Lesser General Public License as published
12
+ # by the Free Software Foundation, either version 2.1 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # rubygem-cobbler is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
25
+ $LOAD_PATH << File.join(base, "lib")
26
+ $LOAD_PATH << File.join(base, "examples")
27
+
28
+ require 'utils'
29
+ Cobbler::Examples::Utils.enhance
30
+
31
+ puts "Cobbler version: #{Cobbler::Base.remote_version}"
data/examples/utils.rb ADDED
@@ -0,0 +1,44 @@
1
+ #
2
+ # cli.rb
3
+ #
4
+ # Copyright (C) 2008,2009 Red Hat, Inc.
5
+ # Written by Darryl L. Pierce <dpierce@redhat.com>
6
+ # Extended 2012 by duritong <peter.meier@immerda.ch>
7
+ #
8
+ # This file is part of rubygem-cobbler.
9
+ #
10
+ # rubygem-cobbler is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU Lesser General Public License as published
12
+ # by the Free Software Foundation, either version 2.1 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # rubygem-cobbler is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with rubygem-cobbler. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+
24
+ require 'cobbler'
25
+ require 'yaml'
26
+
27
+ module Cobbler
28
+ module Examples
29
+ module Utils
30
+ def self.enhance(clazz=Cobbler::Base)
31
+ config = (ENV['COBBLER_YML'] || File.expand_path(File.join(File.dirname(__FILE__),'..','config','cobbler.yml')))
32
+ if File.exist?(config) && (yml = YAML::load(File.open(config))) && (yml['hostname'] && yml['username'] && yml['password'])
33
+ clazz.hostname = yml['hostname']
34
+ clazz.username = yml['username']
35
+ clazz.password = yml['password']
36
+ clazz.debug_enabled = yml['debug']||false
37
+ else
38
+ puts "Can't load configuration file (#{config}) with all necessary parameters. Either fix the yaml file or point COBBLER_YML to an appropriate file."
39
+ exit 1
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end