Remote Administration Daemon Developer Guide

Exit Print View

Updated: July 2014
 
 

Rad Namespace

All RAD objects, which are represented in the ADR IDL as <interfaces>, are found by searching the RAD namespace. The key point to note is that to access a RAD object, you need a proxy, which is used to search the RAD namespace. This capability is provided by an interface proxy class, which is defined in each interface's binding module.

The proxy provides the base name (and version details) for interface instances and is structured as follows:

<domain name>:type=<interface name>[,optional additional key value pairs]

The <domain name> and the <interface name> are automatically derived from the ADR IDL definition and are stored in the module binding.

Searching for Objects

The RADConnection class provides mechanisms for listing objects by name and for obtaining a remote object reference.

Obtaining a Reference to a Singleton

If a module developer creates a "singleton" to represent an interface, then this can be accessed very simply. For instance, the zonemgr module defines a singleton interface: ZoneInfo. It contains information about the zone which contains the RAD instance with which we are communicating.

Example 3-33   Obtaining a Reference to a Singleton
>>> import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
>>> import rad.connect as radcon
>>> with radcon.connect_unix() as rc:
...     zi = rc.get_object(zonemgr.ZoneInfo())
...     print zi.name
...
global
>>>

We have imported our binding and the rad.connect module, connected to the local RAD instance and obtained a remote object reference directly using a proxy instance. Once we have the remote reference we can access properties and method directly as we would with any Python object.

Listing Instances of an Interface

Most interfaces contain more than one instance of the interface. For instance, the zonemgr module defines a Zone interface and there is an instance for each zone on the system. The RADConnection class provides the list_objects() method to list interface instances. For instance:

Example 3-34   Listing Interface Instances
>>> import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
>>> import rad.connect as radcon
>>> with radcon.connect_unix() as rc:
... zonelist = rc.list_objects(zonemgr.Zone())
... print zonelist
... 
[Name: com.oracle.solaris.rad.zonemgr:type=Zone,name=test-0,id=-1 Version: (1.0), Name: 
com.oracle.solaris.rad.zonemgr:type=Zone,name=test-1,id=-1 Version: (1.0), Name: 
com.oracle.solaris.rad.zonemgr:type=Zone,name=NOT-TEST,id=-1 Version: (1.0)]
>>> 

Obtaining a Remote Object Reference from a Name

Names (ADRName is the class name) are returned by the RADConnection list_objects method. Once we have a "name" we can obtain a remote object reference easily:

Example 3-35   Obtaining a remote object reference
>>> import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
>>> import rad.connect as radcon
>>> with radcon.connect_unix() as rc:
... zonelist = rc.list_objects(zonemgr.Zone())
... zone = rc.get_object(zonelist[0])
... print zone.name
... 
test-0
>>>

Sophisticated Searching

Clearly, the last example is not a very realistic use case. Rarely are we going to want to just pick a (semi-random) zone from a list and interact with it. More often than not we'll be looking for a zone which has a particular name or id or maybe a set of zones where the names all match some kind of pattern. The key idea to bear in mind is that you can extend the basic definition of a name provided by a Proxy. For instance, if zones are uniquely identified by a key: "name", then we can find a zone with name "test-0" as follows:

Example 3-36   Using Glob Patterns
>>> import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
>>> import rad.client as radc
>>> import rad.connect as radcon
>>> with radcon.connect_unix() as rc:
... zonelist = rc.list_objects(zonemgr.Zone(), radc.ADRGlobPattern({"name" : "test-0"}))
... print zonelist
... 
[Name: com.oracle.solaris.rad.zonemgr:type=Zone,name=test-0,id=-1 Version: (1.0)]
>>> 

The ADRGlobPattern class (imported from the rad.client module) to refine our search. We are using the same RADConnection list_objects() method, but we are refining the search by extending the name definition. ADRGlobPattern takes a key:value dictionary and extends the name used for the search.

Glob Pattern Searching

We have already seen how we can use glob pattern searching to find a zone with a specific name. We can also use a glob pattern to find zones with wildcard pattern matching. Keys or Values in the pattern may contain "*" which is interpreted as expected. For instance if we wanted to find all zones with a name which begins with "test":

Example 3-37   Using Glob Patterns with Wildcards
>>> import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
>>> import rad.client as radc
>>> import rad.connect as radcon
>>> with radcon.connect_unix() as rc:
... zonelist = rc.list_objects(zonemgr.Zone(), radc.ADRGlobPattern({"name" : "test*"})) 
...  print zonelist
... 
[Name: com.oracle.solaris.rad.zonemgr:type=Zone,name=test-0,id=-1 Version: (1.0), Name:
com.oracle.solaris.rad.zonemgr:type=Zone,name=test-1,id=-1 Version: (1.0)]
>>> 
Regex Pattern Searching

We can also take advantage of RAD's ERE (Extended Regular Expression) search capabilities. If we wanted to find only zones with name "test-0" or "test-1", then:

Example 3-38   Using Regex Patterns
>>> import rad.bindings.com.oracle.solaris.rad.zonemgr as zonemgr
>>> import rad.client as radc
>>> import rad.connect as radcon
>>> with radcon.connect_unix() as rc:
... zonelist = rc.list_objects(zonemgr.Zone(), radc.ADRRegexPattern({"name" : "test-0|test-1"}))
...  print zonelist... 
[Name: com.oracle.solaris.rad.zonemgr:type=Zone,name=test-0,id=-1 Version: (1.0), Name:
com.oracle.solaris.rad.zonemgr:type=Zone,name=test-1,id=-1 Version: (1.0)]
>>> 

The key and the value must be valid Extended Regular Expressions as determined by the instance of RAD to which you are connected. (i.e.: the expression is compiled and executed in the server.)