Manage Remote Linux Servers from iManager

0 Likes
This article discusses a way to manage a Linux server in the eDirectory tree from iManager. In NetWare, management and configuration of remote servers was done using NJCL. With the ceased support of NJCL in Linux, iManager plugins can now utilize owcimom to access remote files or manage services in a Linux server.

The article is divided into the following sections:




Introduction


In NetWare, most iManager plugin developers use NJCL to configure and manage remote servers. NJCL provides file and directory access APIs in Java. When accessing iManager the eDirectory admin (or any user with sufficient rights) logs into the tree and hence has access to all volumes and files on all the servers that are in the tree. Hence writing information (configuration information that needs to be written) to a remote server using NJCL was a good solution. However NJCL is not being supported in Linux any more. Thus we need an alternative way to satisfy the same requirement in Linux servers. Three alternative approaches can be thought of to solve the problem of remote configuration and management in Linux servers:




  • xplat libraries: These are C libraries which can be used for remote file system access. However, to use xplat libraries from java-based iManager successfully we need to write JNI wrappers.

  • cifs: CIFS can be used as the alternative way. However, for that jcifs needs to be configured in each server for accessing a remote service in the server. This seems to be a cumbersome procedure

  • CIMOM: All OES 2.0 servers run CIMOM by default. We can make use of CIM libraries to access the files or manage the server. This seems to be the most feasible way.



In the following sections iManager developers will get introduced to the convenient way of using CIM based services for remote management of Linux servers. It is assumed that the reader is familiar with iManager plugin development and the basics of writing a CIM provider. The reader is advised to go through the Supplementary section for better familiarity with CIM technologies.



Use of WBEM in iManager


We consider a case when the developer wants to read and write to a configuration file in a remote server from iManager. The steps to do this are:

Implementing the MOF and the CIM provider:


This section assumes that the reader is conversant with the basics of CIM and WBEM development.


  1. The MOF file: Figure 1 shows the description of the mof. We define a class, which will do the basic operations of read, write to a file. An instance of the file is identified by an id and a filename. The id is the key of the file access operation.

    [Description ("This class represents a session with a file.")]
    class MyFileSession {
    [Description ("The ID of the current session"), Key ]
    uint32 ID;

    [Description ("The name of the file to access") ]
    String filename;

    [Description ("Write to the file. Returns 0 on success ") ]
    uint32 write ([in (true), out (false)] string to Write);

    [Description ("Read from the file."
    "Returns OK on success, EOF if end of file is reached "
    "while reading, and ERROR if an error occurred while reading. "
    "Length is the desired length requested by the client. ") ,
    ValueMap {“0", "1", "2”},
    Values {“OK", "EOF", "ERROR”}]
    uint32 read ([out (true), in (false)] string buf,
    [in (true), out (false)] uint32 length);
    };



    Figure 1: The MOF for file access provider.



  • The CIM provider: We need to write a CIM provider for OpenWbem.The invokeMethod () of this provider will implement read and write functionalities for a file in the server. The method definitions of read () and write () are as per the MOF specified in Figure 1. I am not writing the code here as I assume that the links in the Supplemented section and some experience in CIM programming is enough to make it work. Also, OWCIMOM being an Open Source project, an existing provider often already exists to suffice your requirement.


Implementing the CIM Client


Remote read and write of any file can be done by directly calling the invokeMethod() of the provider from a CIM client interface defined in iManager. Given below are the steps to define the CIM client in iManager. The details regarding string manipulations and exception handling have been deliberately removed to stress on the basic functionality.



Authenticating to CIMOM: In Linux LUM is required for authentication. The authenticator calls into PAM. Authentication to CIMOM occurs when a user logs into an eDirectory tree and tries to access CIM for the first time. This will set up the Session. Given below are the steps of authenticating an iManager CIM client.




  1. Get the user credentials from the AuthenticationBroker object from iManager.

           String [] auth = broker.getIdentity();


  • Get the NDS Namespace from iManager.

           ObjectEntry rootOE = (ObjectEntry)broker.

           getAPIObject ("NDSNamespace");

           NDSNamespace ns = (NDSNamespace) rootOE.getNamespace();


  • Get the treeName

           String tree = rootOE.getName();


  • Get the user object and password credentials

           ObjectEntry userOE = ns.getObjectEntry(rootOE, auth[0]);

           String user = userOE.getName();

           UserPrincipal principal = new UserPrincipal(user);

           PasswordCredential cred = new PasswordCredential(auth[1]);


  • Finally, instantiate the cimom client.
           MyCIMClient client = new MyCIMClient(ipAddress, principal, cred);



From here onwards iManager can call on the MyCIMClient’s read() or write() methods. These methods call invokemethods() on the CIM provider which we have defined in the earlier section. An implementation of the CIM client is given in the next section.



Defining a CIM client from iManager: Figure 2 is the skeleton program of a CIM client class in iManager.



public class MyCIMClient 
{
private CIMObjectPath cop = null;
private CIMClient client;
private CIMObjectPath myCop;
private CIMClass myClass;
private String MY_CIM_CLASS = "MyFileSession";

public MyCIMClient (
String uriHostOrIP, //Host or IPAddres of the server to contact
UserPrincipal principal,
PasswordCredential credential){

CIMNameSpace cns = new CIMNameSpace (“https://” uriHostOrIP “: 5989”);
try{
client = new CIMClient(cns, principal, credential);
myCop = new CIMObjectPath (MY_CIM_CLASS);
myClass = client.getClass (myCop);
} catch (CIMException e){/*Ignoring Exception handling*/}

}

private CIMObjectPath getMyPath(long sessionID){

CIMValue sessionIDValue = new CIMValue (new UnsignedInt32 (sessionID),
new CIMDataType(CIMDataType.UINT32));

CIMObjectPath myPath = new CIMObjectPath (MY_CIM_CLASS);
myPath.addKey ("ID", sessionIDValue);
return myPath;
}

private CIMObjectPath createMyInstance (String filename){

long sessionID = 0;
CIMInstance myInstance = myClass.newInstance ();
CIMValue filenameValue = new CIMValue (filename, new CIMDataType (CIMDataType.STRING));

try {
myInstance.setProperty ("filename", filenameValue);
} catch (CIMException e){/*Ignoring Exception Handling*/}

CIMValue sessionIDValue = new CIMValue (new UnsignedInt32 (sessionID), new CIMDataType (CIMDataType.UINT32));

try {
myInstance.setProperty ("ID", sessionIDValue);
} catch (CIMException e){/*Ignoring Exception Handling*/}
CIMObjectPath cop = new CIMObjectPath ();
cop = client.createInstance (myCop, myInstance);
}


public void open(String filename){ //filename for the file with path to open

CIMObjectPath newCop = null;
try{
newCop = createMyInstance (filename);
} catch (CIMException e){/*Ignoring Exception Handling*/}

CIMProperty key = newCop.getKey("ID");
CIMValue sessionIDValue = key.getValue();
long sessionID = ((UnsignedInt32)sessionIDValue.getValue()).longValue();
cop = getMyPath(sessionID);
}

public void close(){

try{
client.deleteInstance(cop);
} catch (CIMException e){}
}

public String read(long length){

CIMArgument[] inArgs = new CIMArgument[1];
CIMValue lengthValue = new CIMValue(new UnsignedInt32(length), new
CIMDataType(CIMDataType.UINT32));
inArgs[0] = new CIMArgument("length", lengthValue);
CIMArgument[] outArgs = new CIMArgument[1];

String buf = null;
CIMValue bufValue = new CIMValue(buf, new
CIMDataType(CIMDataType.STRING));
outArgs[0] = new CIMArgument("buf", bufValue);
CIMValue returnVal = new CIMValue(new UnsignedInt32(1), new
CIMDataType(CIMDataType.UINT32));

try{
returnVal = client.invokeMethod( cop, //object path to instance
"read", // method to invoke
inArgs, //input array
outArgs); //output parameters
}catch (CIMException e){/*Ignoring Exception Handling*/}
String str= returnVal.toString();
return str;
}

public void write(String toWrite){ /* Ignoring the details of this method*/}



Figure 2: The CIM client code



Supplementary Section


1. Developer_Primer_to_WBEM_and_CIM

2. An introduction to WBEM and OpenWBEM in SUSE Linux

Labels:

How To-Best Practice
Comment List
Related
Recommended