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
@@ -0,0 +1,163 @@
|
|
1
|
+
#
|
2
|
+
# lifecycle.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
|
+
# +Lifecycle+ implements a default set of functionality that a cobbler item
|
24
|
+
# can have.
|
25
|
+
# Usually the +Lifecycle+ methods are used to define query functions and define
|
26
|
+
# which fields of a cobbler item is exposed through the api.
|
27
|
+
module Cobbler
|
28
|
+
module Common
|
29
|
+
module Lifecycle
|
30
|
+
def self.included(base)
|
31
|
+
base.extend ClassMethods
|
32
|
+
end
|
33
|
+
|
34
|
+
def definitions
|
35
|
+
@definitions ||= {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_definitions
|
39
|
+
@user_definitions ||= {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def locked_fields
|
43
|
+
self.class.locked_fields
|
44
|
+
end
|
45
|
+
|
46
|
+
def cobbler_record_fields
|
47
|
+
self.class.cobbler_record_fields
|
48
|
+
end
|
49
|
+
def cobbler_collections_store_callbacks
|
50
|
+
self.class.cobbler_collections_store_callbacks
|
51
|
+
end
|
52
|
+
|
53
|
+
def api_methods
|
54
|
+
self.class.api_methods
|
55
|
+
end
|
56
|
+
|
57
|
+
module ClassMethods
|
58
|
+
def api_methods
|
59
|
+
return @api_methods if @api_methods
|
60
|
+
model_name = self.name.gsub(/.*::/,'').underscore
|
61
|
+
@api_methods = {
|
62
|
+
:find_all => "get_#{model_name.pluralize}",
|
63
|
+
:find_one => "get_#{model_name}",
|
64
|
+
:handle => "get_#{model_name}_handle",
|
65
|
+
:remove => "remove_#{model_name}",
|
66
|
+
:save => "save_#{model_name}",
|
67
|
+
:new => "new_#{model_name}",
|
68
|
+
:modify => "modify_#{model_name}"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def cobbler_record_fields
|
73
|
+
@cobbler_record_fields ||= []
|
74
|
+
end
|
75
|
+
|
76
|
+
def locked_fields
|
77
|
+
@locked_fields ||= []
|
78
|
+
end
|
79
|
+
|
80
|
+
def cobbler_collections_store_callbacks
|
81
|
+
@cobbler_collections_store_callbacks ||= []
|
82
|
+
end
|
83
|
+
|
84
|
+
# Define/adjust all necessary lookup methods for a usual
|
85
|
+
# cobbler item.
|
86
|
+
#
|
87
|
+
def cobbler_lifecycle(lookup_methods={})
|
88
|
+
api_methods.merge!(lookup_methods)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Allows for dynamically declaring fields that will come from
|
92
|
+
# Cobbler.
|
93
|
+
#
|
94
|
+
def cobbler_field(field,options={})
|
95
|
+
# name is always locked and findable as this is a special field
|
96
|
+
if field == :name
|
97
|
+
options[:locked] = true if options[:locked] || options[:locked].nil?
|
98
|
+
options[:findable] = api_methods[:find_one] if options[:findable] || options[:findable].nil?
|
99
|
+
end
|
100
|
+
options.each do |key,value|
|
101
|
+
case key
|
102
|
+
when :findable then
|
103
|
+
if value
|
104
|
+
module_eval <<-"MEND"
|
105
|
+
def self.find_by_#{field}(value)
|
106
|
+
properties = in_transaction{ make_call('#{value}',value) }
|
107
|
+
valid_properties?(properties) ? new(properties,false) : nil
|
108
|
+
end
|
109
|
+
MEND
|
110
|
+
end
|
111
|
+
when :locked then
|
112
|
+
locked_fields << field if value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
module_eval("def #{field}() user_definitions['#{field}'] || definitions['#{field}']; end")
|
117
|
+
module_eval("def #{field}=(val) user_definitions['#{field}'] = val; end")
|
118
|
+
|
119
|
+
cobbler_record_fields << field
|
120
|
+
end
|
121
|
+
|
122
|
+
# Declare many fields at once.
|
123
|
+
def cobbler_fields(*fields)
|
124
|
+
fields.to_a.each {|field| cobbler_field field }
|
125
|
+
end
|
126
|
+
|
127
|
+
# Allows a field to be defined as a collection of objects. The type for that
|
128
|
+
# other class must be provided.
|
129
|
+
#
|
130
|
+
def cobbler_collection(field, options={})
|
131
|
+
classname = options[:type] || 'String'
|
132
|
+
packing = options[:packing] ? options[:packing].to_s.classify : 'Array'
|
133
|
+
|
134
|
+
packing_code = {
|
135
|
+
'Array' => "(definitions['#{field}']||[]).each{|value| new_value << #{classname}.new(value) }",
|
136
|
+
'Hash' => "(definitions['#{field}']||{}).each{|key,value| new_value[key] = #{classname}.new(value) }"
|
137
|
+
}
|
138
|
+
|
139
|
+
cobbler_collections_store_callbacks << options[:store] if options[:store]
|
140
|
+
# unless we have a seperate store callback we store collections normally
|
141
|
+
cobbler_record_fields << field unless options[:store]
|
142
|
+
|
143
|
+
module_eval <<-"MEND"
|
144
|
+
def #{field}
|
145
|
+
if !user_definitions['#{field}'] && !definitions['#{field}'].is_a?(#{packing})
|
146
|
+
new_value = #{packing}.new
|
147
|
+
#{packing_code[packing]}
|
148
|
+
definitions['#{field}'] = new_value
|
149
|
+
end
|
150
|
+
user_definitions['#{field}'] ||= definitions['#{field}']
|
151
|
+
# return always the user_definitions as we might do operations on these objects, e.g. <<
|
152
|
+
user_definitions['#{field}']
|
153
|
+
end
|
154
|
+
|
155
|
+
def #{field}=(value)
|
156
|
+
user_definitions['#{field}'] = value
|
157
|
+
end
|
158
|
+
MEND
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# common.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
|
+
# +Common+ provides common methods of the cobbler server exposed through the
|
24
|
+
# api.
|
25
|
+
module Cobbler
|
26
|
+
module Connection
|
27
|
+
module Common
|
28
|
+
def self.included(base)
|
29
|
+
base.extend(ClassMethods)
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
# tests a connections
|
34
|
+
def test_connection
|
35
|
+
!in_transaction do
|
36
|
+
result = login
|
37
|
+
logout if result
|
38
|
+
result
|
39
|
+
end.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
# start a sync on the cobbler server
|
43
|
+
def sync
|
44
|
+
in_transaction(true) do |token|
|
45
|
+
make_call('sync',token)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# get all events (for a certain user)
|
50
|
+
def events(for_user='')
|
51
|
+
in_transaction do
|
52
|
+
make_call('get_events',for_user)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# get the log for a certain event
|
57
|
+
def event_log(event_id)
|
58
|
+
in_transaction do
|
59
|
+
make_call('get_event_log',event_id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# import a tree into cobbler
|
64
|
+
def import(path,name,arch,additional_options={})
|
65
|
+
in_transaction(true) do |token|
|
66
|
+
make_call('background_import',{'path' => path ,'name' => name , 'arch' => arch}.merge(additional_options),token)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# start syncing the following repositories.
|
71
|
+
def reposync(repos=[],tries=3)
|
72
|
+
in_transaction(true) do |token|
|
73
|
+
make_call('background_reposync',{'repos' => repos, 'tries' => tries},token)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#
|
2
|
+
# handling.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
|
+
require 'xmlrpc/client'
|
24
|
+
|
25
|
+
# +Handling+ provides common methods to handle the xmlrpc connection to the
|
26
|
+
# cobbler server
|
27
|
+
module Cobbler
|
28
|
+
module Connection
|
29
|
+
module Handling
|
30
|
+
include Cobbler::Common::Debug
|
31
|
+
def self.included(base)
|
32
|
+
base.extend ClassMethods
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
|
37
|
+
# Set hostname, username, password for the Cobbler server, overriding any settings
|
38
|
+
# from cobbler.yml.
|
39
|
+
attr_accessor :hostname, :username, :password
|
40
|
+
|
41
|
+
# Returns the version for the remote cobbler instance.
|
42
|
+
def remote_version
|
43
|
+
connect unless connection
|
44
|
+
@version ||= make_call("version")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Logs into the Cobbler server.
|
48
|
+
def login
|
49
|
+
@auth_token ||= make_call('login', username, password)
|
50
|
+
end
|
51
|
+
|
52
|
+
def logout
|
53
|
+
make_call('logout',@auth_token)
|
54
|
+
@auth_token = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# Makes a remote call.
|
59
|
+
def make_call(*args)
|
60
|
+
raise Exception.new("No connection established on #{self.name}.") unless connection
|
61
|
+
|
62
|
+
debug("Remote call: #{args.first} (#{args[1..-1].inspect})")
|
63
|
+
result = connection.call(*args)
|
64
|
+
debug("Result: #{result}\n")
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def in_transaction(do_login=false,&blk)
|
69
|
+
begin
|
70
|
+
begin_transaction
|
71
|
+
token = do_login ? login : nil
|
72
|
+
result = yield(token)
|
73
|
+
logout if do_login
|
74
|
+
ensure
|
75
|
+
end_transaction
|
76
|
+
end
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
# Returns a connection to the Cobbler server.
|
82
|
+
def connect
|
83
|
+
debug("Connecting to http://#{hostname}/cobbler_api")
|
84
|
+
@connection = XMLRPC::Client.new2("http://#{hostname}/cobbler_api")
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
# Establishes a connection with the Cobbler system.
|
89
|
+
def begin_transaction
|
90
|
+
@connection = connect
|
91
|
+
end
|
92
|
+
# Ends a transaction and disconnects.
|
93
|
+
def end_transaction
|
94
|
+
@connection = @auth_token = @version = nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def connection
|
98
|
+
@connection
|
99
|
+
end
|
100
|
+
|
101
|
+
def valid_properties?(properties)
|
102
|
+
properties && !properties.empty? && properties != '~'
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# distro.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
|
+
# +Distro+ represents a single distrobution within Cobbler.
|
24
|
+
#
|
25
|
+
module Cobbler
|
26
|
+
class Distro < Base
|
27
|
+
cobbler_fields :name, :kernel, :breed, :depth, :arch, :initrd,
|
28
|
+
:source_repos, :kernel_options, :parent, :ks_meta
|
29
|
+
|
30
|
+
cobbler_collection :owners
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# image.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
|
+
# +Image+ represents an image within Cobbler.
|
24
|
+
#
|
25
|
+
module Cobbler
|
26
|
+
class Image < Base
|
27
|
+
cobbler_fields :name, :owners, :depth, :virt_file_size,
|
28
|
+
:virt_path, :xml_file, :virt_bridge, :file, :parent,
|
29
|
+
:image_type, :virt_ram, :virt_auto_boot, :virt_cpus, :virt_type, :network_count
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# profile.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
|
+
# +Profile+ represents a single profile within Cobbler.
|
24
|
+
#
|
25
|
+
module Cobbler
|
26
|
+
class Profile < Base
|
27
|
+
cobbler_fields :name, :parent, :dhcp_tag, :depth, :virt_file_size,
|
28
|
+
:virt_path, :virt_type, :repos, :distro, :server, :virt_bridge,
|
29
|
+
:virt_ram, :virt_auto_boot, :kernel_options, :virt_cpus, :ks_meta,
|
30
|
+
:kickstart
|
31
|
+
|
32
|
+
cobbler_collection :owners
|
33
|
+
end
|
34
|
+
end
|
data/lib/cobbler/repo.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# repo.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
|
+
# +Repo+ represents a single repository within Cobbler.
|
24
|
+
#
|
25
|
+
module Cobbler
|
26
|
+
class Repo < Base
|
27
|
+
cobbler_fields :name, :arch, :breed, :comment, :keep_updated, :mirror,
|
28
|
+
:parent, :rpm_list, :createrepo_flags, :environment, :mirror_locally, :priority,
|
29
|
+
:yumopts
|
30
|
+
|
31
|
+
cobbler_collection :owners
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
# system.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
|
+
# +System+ represents a system within Cobbler.
|
24
|
+
#
|
25
|
+
module Cobbler
|
26
|
+
class System < Base
|
27
|
+
cobbler_fields :name, :profile, :image, :kickstart, :netboot_enabled, :server, :virt_cpus,
|
28
|
+
:virt_file_size, :virt_path, :virt_ram, :virt_auto_boot, :virt_type, :gateway, :hostname
|
29
|
+
|
30
|
+
cobbler_collection :kernel_options, :packing => :hash
|
31
|
+
cobbler_collection :ks_meta, :packing => :hash
|
32
|
+
cobbler_collection :owners
|
33
|
+
cobbler_collection :interfaces, :packing => :hash, :store => :store_interfaces
|
34
|
+
|
35
|
+
def store_interfaces(sysid,token)
|
36
|
+
interfaces.each do |interface,values|
|
37
|
+
values2store = values.keys.inject({}) do |result,member|
|
38
|
+
result["#{member.to_s.gsub(/_/,'')}-#{interface}"] = values[member] if values[member]
|
39
|
+
result
|
40
|
+
end
|
41
|
+
self.class.make_call('modify_system',sysid,'modify_interface',values2store,token) unless values2store.empty?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/cobbler.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# cobbler.rb - Cobbler module declaration.
|
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
|
+
require 'active_support/inflector'
|
24
|
+
require 'cobbler/base'
|
25
|
+
require 'cobbler/distro'
|
26
|
+
require 'cobbler/image'
|
27
|
+
require 'cobbler/profile'
|
28
|
+
require 'cobbler/repo'
|
29
|
+
require 'cobbler/system'
|
30
|
+
|
31
|
+
module Cobbler
|
32
|
+
|
33
|
+
VERSION = '2.0.0'
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Generated from cobbler-0.0.1.gem by gem2rpm -*- rpm-spec -*-
|
2
|
+
%define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
|
3
|
+
%define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
|
4
|
+
%define gemname cobbler
|
5
|
+
%define geminstdir %{gemdir}/gems/%{gemname}-%{version}
|
6
|
+
%define installroot %{buildroot}%{geminstdir}
|
7
|
+
|
8
|
+
Summary: An interface for interacting with a Cobbler server
|
9
|
+
Name: rubygem-%{gemname}
|
10
|
+
Version: 2.0.0
|
11
|
+
Release: 1%{?dist}
|
12
|
+
Group: Development/Languages
|
13
|
+
License: LGPLv2+
|
14
|
+
URL: https://github.com/duritong/ruby-cobbler
|
15
|
+
Source0: https://rubygems.org/downloads/%{gemname}-%{version}.gem
|
16
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
17
|
+
Requires: rubygems
|
18
|
+
BuildRequires: ruby-flexmock
|
19
|
+
BuildRequires: rubygems
|
20
|
+
BuildRequires: rubygem-rake
|
21
|
+
BuildArch: noarch
|
22
|
+
Provides: rubygem(%{gemname}) = %{version}
|
23
|
+
|
24
|
+
%description
|
25
|
+
Provides Ruby bindings to interact with a Cobbler server.
|
26
|
+
|
27
|
+
%prep
|
28
|
+
|
29
|
+
%build
|
30
|
+
|
31
|
+
%check
|
32
|
+
|
33
|
+
cd %{installroot}
|
34
|
+
|
35
|
+
rake test
|
36
|
+
|
37
|
+
%install
|
38
|
+
rm -rf %{buildroot}
|
39
|
+
mkdir -p %{buildroot}%{gemdir}
|
40
|
+
gem install --local --install-dir %{buildroot}%{gemdir} --force %{SOURCE0}
|
41
|
+
|
42
|
+
chmod +x %{installroot}/examples/*.rb
|
43
|
+
|
44
|
+
%clean
|
45
|
+
rm -rf %{buildroot}
|
46
|
+
|
47
|
+
%files
|
48
|
+
%defattr(-, root, root, -)
|
49
|
+
%{gemdir}/gems/%{gemname}-%{version}/
|
50
|
+
%{gemdir}/cache/%{gemname}-%{version}.gem
|
51
|
+
%{gemdir}/specifications/%{gemname}-%{version}.gemspec
|
52
|
+
|
53
|
+
%doc %{geminstdir}/COPYING
|
54
|
+
%doc %{geminstdir}/NEWS
|
55
|
+
%doc %{geminstdir}/README
|
56
|
+
|
57
|
+
%{geminstdir}/config/cobbler.yml
|
58
|
+
|
59
|
+
|
60
|
+
%changelog
|
61
|
+
* Thu Jan 05 2012 duritong <peter.meier@immerda.ch> - 2.0.0-1
|
62
|
+
- Fix all issues when API returns ~ on a nonexisting system
|
63
|
+
- Add some missing fields to the System model
|
64
|
+
- Remove unnecessary object abstraction for interfaces
|
65
|
+
- Fix storing of interfaces
|
66
|
+
- Rework connection handling
|
67
|
+
- Rewrite to enable capabilities for all items and to work against 2.0
|
68
|
+
|
69
|
+
* Mon Sep 08 2008 Darryl Pierce <dpierce@redhat.com> - 0.1.0-1
|
70
|
+
- First official build for Fedora.
|
71
|
+
|
72
|
+
* Fri Sep 05 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-4
|
73
|
+
- Bad BuildRequires slipped into the last version.
|
74
|
+
|
75
|
+
* Wed Sep 03 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-3
|
76
|
+
- Added a build requirement for rubygem-rake.
|
77
|
+
|
78
|
+
* Tue Aug 26 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-2
|
79
|
+
- Fixed the licensing in each source module to show the code is released under
|
80
|
+
LGPLv2.1.
|
81
|
+
- Added %check to the spec file to run tests prior to creating the RPM.
|
82
|
+
|
83
|
+
* Thu Aug 21 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.2-1
|
84
|
+
- Added a call to update prior to saving or updating a system. If the update
|
85
|
+
fails, then an Exception is raised.
|
86
|
+
|
87
|
+
* Wed Aug 13 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.1-3
|
88
|
+
- Added caching for the auth_token to prevent extraneous calls to login.
|
89
|
+
- Reworked and refined how cobbler_collection fields are processed, adding
|
90
|
+
support for both array and has properties.
|
91
|
+
- Rewrote the documentation for Cobbler::Base to make it easier to understand
|
92
|
+
how to extend it to support other Cobbler types.
|
93
|
+
- Refactored the examples to clean up the code.
|
94
|
+
|
95
|
+
* Wed Aug 13 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.1-2
|
96
|
+
- Removed markup of cobbler.yml and a config file. Fixed a few small bugs
|
97
|
+
in the code for using it as a gem.
|
98
|
+
|
99
|
+
* Mon Aug 04 2008 Darryl Pierce <dpierce@redhat.com> - 0.0.1-1
|
100
|
+
- Initial package
|