cobbler 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/COPYING +510 -0
- data/ChangeLog +40 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +40 -0
- data/NEWS +5 -0
- data/README.rdoc +87 -0
- data/Rakefile +75 -0
- data/TODO +6 -0
- data/config/cobbler.yml +5 -0
- data/examples/example_distros.rb +119 -0
- data/examples/example_version.rb +31 -0
- data/examples/utils.rb +44 -0
- data/lib/cobbler/base.rb +128 -0
- data/lib/cobbler/common/debug.rb +59 -0
- data/lib/cobbler/common/finders.rb +55 -0
- data/lib/cobbler/common/lifecycle.rb +163 -0
- data/lib/cobbler/connection/common.rb +79 -0
- data/lib/cobbler/connection/handling.rb +108 -0
- data/lib/cobbler/distro.rb +32 -0
- data/lib/cobbler/image.rb +31 -0
- data/lib/cobbler/profile.rb +34 -0
- data/lib/cobbler/repo.rb +33 -0
- data/lib/cobbler/system.rb +45 -0
- data/lib/cobbler.rb +35 -0
- data/rubygem-cobbler.spec +100 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/unit/cobbler/base_spec.rb +194 -0
- data/spec/unit/cobbler/common/debug_spec.rb +44 -0
- data/spec/unit/cobbler/common/finders_spec.rb +101 -0
- data/spec/unit/cobbler/common/lifecycle_spec.rb +192 -0
- data/spec/unit/cobbler/connection/common_spec.rb +59 -0
- data/spec/unit/cobbler/connection/handling_spec.rb +119 -0
- data/spec/unit/cobbler/system_spec.rb +27 -0
- metadata +207 -0
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
data/config/cobbler.yml
ADDED
@@ -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
|
data/lib/cobbler/base.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#
|
2
|
+
# base.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/common/debug'
|
25
|
+
require 'cobbler/connection/handling'
|
26
|
+
require 'cobbler/connection/common'
|
27
|
+
require 'cobbler/common/lifecycle'
|
28
|
+
require 'cobbler/common/finders'
|
29
|
+
|
30
|
+
# +Base+ represents a type of item on the Cobbler server.
|
31
|
+
#
|
32
|
+
# Child classes can define fields that will be retrieved from Cobbler by
|
33
|
+
# using the +cobbler_field+ method. For example:
|
34
|
+
#
|
35
|
+
# class System < Base
|
36
|
+
# cobbler_lifecycle :find_all => 'get_systems'
|
37
|
+
# cobbler_field :name
|
38
|
+
# cobbler_collection :owners, :type => 'String', :packing => :hash
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# declares a class named System that contains two fields and a class-level
|
42
|
+
# method.
|
43
|
+
#
|
44
|
+
# The first field, "name", is a simple property. It will be retrieved from
|
45
|
+
# the value "name" in the remote definition for a system, identifyed by the
|
46
|
+
# +:owner+ argument.
|
47
|
+
#
|
48
|
+
# The second field, "owners", is similarly retrieved from a property also
|
49
|
+
# named "owners" in the remote definition. However, this property is a
|
50
|
+
# collection: in this case, it is an array of definitions itself. The
|
51
|
+
# +:type+ argument identifies what the +local+ class type is that will be
|
52
|
+
# used to represent each element in the collection.
|
53
|
+
#
|
54
|
+
# A +cobbler_collection+ is packed in one of two ways: either as an array
|
55
|
+
# of values or as a hash of keys and associated values. These are defined by
|
56
|
+
# the +:packing+ argument with the values +Array+ and +Hash+, respectively.
|
57
|
+
#
|
58
|
+
# The +cobbler_lifecycle+ method allows for declaring different methods for
|
59
|
+
# retrieving remote instances of the class. +cobbler_lifecycle+ also declares
|
60
|
+
# automatically the various API methods if they aren't overwritten.
|
61
|
+
# These methods are (defaults are shown for an item called Model):
|
62
|
+
#
|
63
|
+
# +find_one+ - to find a single instance (get_model)
|
64
|
+
# +find_all+ - to find all instances (get_models)
|
65
|
+
# +remove+ - to remove an instance (remove_model)
|
66
|
+
# +handle+ - to obtain the handle for this item (get_model_handle)
|
67
|
+
# +save+ - to store an item (save_model)
|
68
|
+
# +new+ - to create a new item (new_model)
|
69
|
+
# +modify+ - to modify an existing model (modfiy_model)
|
70
|
+
#
|
71
|
+
module Cobbler
|
72
|
+
class Base
|
73
|
+
|
74
|
+
def initialize(defs = {},new_record = true)
|
75
|
+
if new_record
|
76
|
+
@user_definitions = defs
|
77
|
+
else
|
78
|
+
@definitions = defs
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
include Cobbler::Common::Debug
|
83
|
+
include Cobbler::Connection::Handling
|
84
|
+
include Cobbler::Connection::Common
|
85
|
+
|
86
|
+
include Cobbler::Common::Lifecycle
|
87
|
+
include Cobbler::Common::Finders
|
88
|
+
|
89
|
+
# Save an item on the remote cobbler server
|
90
|
+
# This will first lookup if the item already exists on the remote server
|
91
|
+
# and use its handle store the attributes. Otherwise a new item is created.
|
92
|
+
def save
|
93
|
+
unless [ :handle, :new, :modify, :save ].all?{|method| api_methods[method] }
|
94
|
+
raise "Not all necessary api methods are defined to process this action!"
|
95
|
+
end
|
96
|
+
entry = self.class.find_one(name)
|
97
|
+
self.class.in_transaction(true) do |token|
|
98
|
+
if entry
|
99
|
+
entryid = self.class.make_call(api_methods[:handle],name,token)
|
100
|
+
else
|
101
|
+
entryid = self.class.make_call(api_methods[:new],token)
|
102
|
+
self.class.make_call(api_methods[:modify],entryid,'name', name, token)
|
103
|
+
end
|
104
|
+
|
105
|
+
cobbler_record_fields.each do |field|
|
106
|
+
field_s = field.to_s
|
107
|
+
if !locked_fields.include?(field) && user_definitions.has_key?(field_s)
|
108
|
+
self.class.make_call(api_methods[:modify],entryid,field_s, user_definitions[field_s], token)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
cobbler_collections_store_callbacks.each do |callback|
|
113
|
+
send(callback,entryid,token)
|
114
|
+
end
|
115
|
+
|
116
|
+
self.class.make_call(api_methods[:save],entryid,token)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# delete the item on the cobbler server
|
121
|
+
def remove
|
122
|
+
raise "Not all necessary api methods are defined to process this action!" unless api_methods[:remove]
|
123
|
+
self.class.in_transaction(true) do |token|
|
124
|
+
self.class.make_call(api_methods[:remove],name,token)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# debug.rb
|
3
|
+
#
|
4
|
+
# Copyright (C) 2008,2009 Red Hat, Inc.
|
5
|
+
# Written by Darryl L. Pierce <dpierce@redhat.com>
|
6
|
+
# 2.0 Work by Marcel Härry <haerry@puzzle.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
|
+
# +Debug+ provides a basic debugging infrastructure.
|
25
|
+
module Cobbler
|
26
|
+
module Common
|
27
|
+
module Debug
|
28
|
+
def self.included(base)
|
29
|
+
base.extend(ClassMethods)
|
30
|
+
end
|
31
|
+
|
32
|
+
def debug(msg)
|
33
|
+
self.class.debug(msg)
|
34
|
+
end
|
35
|
+
|
36
|
+
module ClassMethods
|
37
|
+
def debug_enabled
|
38
|
+
@debug_enabled ||= false
|
39
|
+
end
|
40
|
+
|
41
|
+
def debug_enabled=(enable)
|
42
|
+
@debug_enabled = enable
|
43
|
+
end
|
44
|
+
|
45
|
+
def output=(output)
|
46
|
+
@output = output
|
47
|
+
end
|
48
|
+
|
49
|
+
def output
|
50
|
+
@output ||= STDOUT
|
51
|
+
end
|
52
|
+
|
53
|
+
def debug(msg)
|
54
|
+
output.puts msg if @debug_enabled
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# finders.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
|
+
# +Finders+ provides the basic 2 finder methods to query a cobbler server
|
25
|
+
#
|
26
|
+
# +find_one+ to fetch exactly one item based on its name
|
27
|
+
# +find+ to find all items, takes a block to work with the fetched items
|
28
|
+
module Cobbler
|
29
|
+
module Common
|
30
|
+
module Finders
|
31
|
+
def self.included(base)
|
32
|
+
base.extend(ClassMethods)
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
def find(&block)
|
37
|
+
raise "No idea how to fetch a list of myself, as no find_all method is defined" unless api_methods[:find_all]
|
38
|
+
result = []
|
39
|
+
in_transaction { make_call(api_methods[:find_all]) }.to_a.each do |record|
|
40
|
+
c_record = new(record,false)
|
41
|
+
result << c_record
|
42
|
+
yield(c_record) if block_given?
|
43
|
+
end
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_one(name)
|
48
|
+
raise "No idea how to fetch myself, as no find_one method is defined" unless api_methods[:find_one]
|
49
|
+
properties = in_transaction { make_call(api_methods[:find_one],name) }
|
50
|
+
valid_properties?(properties) ? new(properties,false) : nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|