Java API Reference Guide for Cisco License Manager
Appendix A: Sample Client Program in Java

Table Of Contents

Sample Client Program in Java


Sample Client Program in Java


The following text is a client program in Java that completes the basic functions in Cisco License Manager. When you connect to Cisco License Manager, you must provide the following information:

IP address of Cisco License Manager host

Login name, password, port, and prompt


package com.cisco.nm.clm.sdk;


import com.cisco.nm.clm.common.*;
import com.cisco.nm.clm.sdk.LicenseManager;
import com.cisco.nm.clm.sdk.LicenseManagerTest.MyIDStatusListener;

import java.rmi.RemoteException;


public class CLMClientSample {

	// Listener for asynchronous calls to receiving IDStatus.
	public class MyIDStatusListener implements IDStatusListener {
		public void onStatus(String request_id, IDStatus status) {
			System.out.println("Received status for request " + request_id);
		}
	}

	public static void main(String[] args) {

		.
		.
		.

		// Create an instance of LicenseManager. 
		LicenseManager lm_instance = new LicenseManager();
		try {
			// login to the LM server located in the same host 
			// with no session timeout.
			EulaInfo eula= new EulaInfo();
			eula. I_have_read_and_I_accept_this_EULA=true;
			UserToken token = lm_instance.login("admin", "cisco", 
									"localhost", 1099, 0, eula);
			// Create a devices using IP address.
			String[] dev_ips = {"192.168.98.120"};
			DeviceStatus dev_status = 
				lm_instance.createDevicesByIPAddr(token, dev_ips);
			Device device = dev_status.getDeviceStatusItems()[0].getDevice();
			// Create a PAK object. 
			String[] pak_ids = {"1XSAU930025"};
			PAKStatus pak_status = lm_instance.createPAKs(token, pak_ids);
			// Download PAK information from Cisco.
			MyIDStatusListener my_listener = new MyIDStatusListener();
			String req_id = lm_instance.asyncDownloadPAKInfo(token, pak_ids,
					 my_listener);
			// Wait a while for PAK infor download to complete.....
			.
			.
			.
			// Read the PAK objects.
			pak_status = lm_instance.readPAKs(token, pak_ids);
			PAK pak = pak_status.getPAKStatusItems()[0].getPAK();

			// Prepare License request using the SKU list in the PAK object.
			LicenseRequest[] lic_req = new LicenseRequest[1];
			lic_req[0] = new LicenseRequest();
			lic_req[0].setSKUSelection(pak.getSkuList());
			lic_req[0].setDeviceID(device.getDeviceID());
			// Obtain license.
			req_id = lm_instance.asyncObtainLicense(token, lic_req, 													my_listener);
			// Assume we have 2 license obtained and stored in
			// the data storage, we can deploy them to the device.
			String[] lic_ids = {"lic00001", "lic0002"};
			req_id = lm_instance.asyncDeployLicenses(token, lic_ids, 													my_listener);	

		} catch(RemoteException ex){
			ex.printStackTrace();
		}
	}
}