module Cobbler::Connection::Handling::ClassMethods

Attributes

hostname[RW]

Set hostname, username, password for the Cobbler server, overriding any settings from cobbler.yml.

password[RW]

Set hostname, username, password for the Cobbler server, overriding any settings from cobbler.yml.

username[RW]

Set hostname, username, password for the Cobbler server, overriding any settings from cobbler.yml.

Public Instance Methods

in_transaction(do_login=false) { |token| ... } click to toggle source
# File lib/cobbler/connection/handling.rb, line 68
def in_transaction(do_login=false,&blk)
    begin
        begin_transaction
        token = do_login ? login : nil 
        result = yield(token)
        logout if do_login
    ensure
        end_transaction
    end
    result
end
login() click to toggle source

Logs into the Cobbler server.

# File lib/cobbler/connection/handling.rb, line 48
def login
    @auth_token ||= make_call('login', username, password)
end
logout() click to toggle source
# File lib/cobbler/connection/handling.rb, line 52
def logout
    make_call('logout',@auth_token)
    @auth_token = nil
end
make_call(*args) click to toggle source

Makes a remote call.

# File lib/cobbler/connection/handling.rb, line 59
def make_call(*args)
    raise Exception.new("No connection established on #{self.name}.") unless connection
    
    debug("Remote call: #{args.first} (#{args[1..-1].inspect})")
    result = connection.call(*args)
    debug("Result: #{result}\n")
    result
end
remote_version() click to toggle source

Returns the version for the remote cobbler instance.

# File lib/cobbler/connection/handling.rb, line 42
def remote_version
    connect unless connection
    @version ||= make_call("version")
end

Protected Instance Methods

connect() click to toggle source

Returns a connection to the Cobbler server.

# File lib/cobbler/connection/handling.rb, line 82
def connect
    debug("Connecting to http://#{hostname}/cobbler_api")
    @connection = XMLRPC::Client.new2("http://#{hostname}/cobbler_api")
end

Private Instance Methods

begin_transaction() click to toggle source

Establishes a connection with the Cobbler system.

# File lib/cobbler/connection/handling.rb, line 89
def begin_transaction
    @connection = connect
end
connection() click to toggle source
# File lib/cobbler/connection/handling.rb, line 97
def connection
    @connection
end
end_transaction() click to toggle source

Ends a transaction and disconnects.

# File lib/cobbler/connection/handling.rb, line 93
def end_transaction
    @connection = @auth_token = @version = nil
end
valid_properties?(properties) click to toggle source
# File lib/cobbler/connection/handling.rb, line 101
def valid_properties?(properties)
    properties && !properties.empty? && properties != '~'
end