Class: Cobbler::Base

Inherits:
Object
  • Object
show all
Includes:
Common::Debug, Common::Finders, Common::Lifecycle, Connection::Common, Connection::Handling
Defined in:
lib/cobbler/base.rb

Direct Known Subclasses

Distro, Image, Profile, Repo, System

Instance Method Summary collapse

Methods included from Common::Finders

included

Methods included from Common::Lifecycle

#api_methods, #cobbler_collections_store_callbacks, #cobbler_record_fields, #definitions, included, #locked_fields, #user_definitions

Methods included from Connection::Common

included

Methods included from Connection::Handling

included

Methods included from Common::Debug

#debug, included

Constructor Details

#initialize(defs = {}, new_record = true) ⇒ Base

Returns a new instance of Base.



75
76
77
78
79
80
81
# File 'lib/cobbler/base.rb', line 75

def initialize(defs = {},new_record = true)
    if new_record
        @user_definitions = defs
    else
        @definitions = defs
    end
end

Instance Method Details

#copy(newname) ⇒ Object

copy the item on the cobbler server



130
131
132
133
134
135
136
137
138
139
# File 'lib/cobbler/base.rb', line 130

def copy(newname)
    raise "Not all necessary api methods are defined to process this action!" unless api_methods[:copy]
    entry = self.class.find_one(name)
    if entry
        self.class.in_transaction(true) do |token|
            entryid = self.class.make_call(api_methods[:handle],name,token)
            self.class.make_call(api_methods[:copy],entryid,newname,token)
        end
    end
end

#removeObject

delete the item on the cobbler server



122
123
124
125
126
127
# File 'lib/cobbler/base.rb', line 122

def remove
    raise "Not all necessary api methods are defined to process this action!" unless api_methods[:remove]
    self.class.in_transaction(true) do |token|
        self.class.make_call(api_methods[:remove],name,token)
    end
end

#saveObject

Save an item on the remote cobbler server This will first lookup if the item already exists on the remote server and use its handle store the attributes. Otherwise a new item is created.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/cobbler/base.rb', line 93

def save
    unless [ :handle, :new, :modify, :save ].all?{|method| api_methods[method] }
        raise "Not all necessary api methods are defined to process this action!"            
    end
    entry = self.class.find_one(name)
    self.class.in_transaction(true) do |token|
        if entry
            entryid = self.class.make_call(api_methods[:handle],name,token) 
        else
            entryid = self.class.make_call(api_methods[:new],token)
            self.class.make_call(api_methods[:modify],entryid,'name', name, token)
        end
        
        cobbler_record_fields.each do |field|
            field_s = field.to_s
            if !locked_fields.include?(field) && user_definitions.has_key?(field_s)
                self.class.make_call(api_methods[:modify],entryid,field_s, user_definitions[field_s], token)
            end
        end
        
        cobbler_collections_store_callbacks.each do |callback|
            send(callback,entryid,token)
        end
        
        self.class.make_call(api_methods[:save],entryid,token)
    end
end