class Cobbler::Base

Public Class Methods

new(defs = {},new_record = true) click to toggle source
# File lib/cobbler/base.rb, line 74
def initialize(defs = {},new_record = true)
    if new_record
        @user_definitions = defs
    else
        @definitions = defs
    end
end

Public Instance Methods

remove() click to toggle source

delete the item on the cobbler server

# File lib/cobbler/base.rb, line 121
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
save() click to toggle source

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.

# File lib/cobbler/base.rb, line 92
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