Remote Administration Daemon Developer Guide

Exit Print View

Updated: July 2014
 
 

Connecting to RAD

Communication with a RAD instance is provided through the RADConnection class. There are various mechanism to get different types of connections to RAD. Each mechanism returns a RADConnection instance which provides a standard interface to interact with RAD.

The preferred approach for managing a connection is to use the "with" keyword. The connection makes use of system resources and this style ensures that the resource is closed correctly when the object goes out of scope. If this style isn't used, then the system resources can be reclaimed explicitly with the close() method.


Note -  If you print the RadConnection object, it displays the state of the connection and will say closed if the connection is closed.

Connecting to a Local Instance

Implicit authentication is performed against your user id and most RAD tasks you request with this connection are performed with the privileges available to your user account.

Example 3-31   Creating a Local Connection
>>> import rad.connect as radcon

>>> with radcon.connect_unix() as rc:

Connecting to a Remote Instance and Authenticating

When connecting to a remote instance, there is no implicit authentication, so the connection is not useful until authentication is performed. The rad.auth module provides a utility class (RadAuth) which may be used to perform a PAM login. If you supply a username and password, authentication proceeds in a non-interactive fashion. If either is absent, you will receive a console prompt for the missing information.

Example 3-32   Remote Connection over TLS
>>> import rad.connect as radcon
>>> import rad.auth as rada

>>> rc=radcon.connect_tls("henry")
>>> # Illustrate examining RadConnection state.
>>> print rc
<open RadConnection >
>>> auth = rada.RadAuth(rc)
>>> auth.pam_login("garypen", "xxxpasswordxxx")
>>> <now authenticated and can use this connection>
>>> rc.close()
>>> print rc
<closed RadConnection >
>>>