<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://help.openclovis.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://help.openclovis.com/index.php?action=history&amp;feed=atom&amp;title=Doc%3ASdk_4.1%2Fawdguide%2Fapiexamples</id>
		<title>Doc:Sdk 4.1/awdguide/apiexamples - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://help.openclovis.com/index.php?action=history&amp;feed=atom&amp;title=Doc%3ASdk_4.1%2Fawdguide%2Fapiexamples"/>
		<link rel="alternate" type="text/html" href="https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;action=history"/>
		<updated>2026-05-09T03:12:39Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.2</generator>

	<entry>
		<id>https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=484&amp;oldid=prev</id>
		<title>Bot: 3 revisions</title>
		<link rel="alternate" type="text/html" href="https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=484&amp;oldid=prev"/>
				<updated>2011-10-24T18:43:09Z</updated>
		
		<summary type="html">&lt;p&gt;3 revisions&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:43, 24 October 2011&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Bot</name></author>	</entry>

	<entry>
		<id>https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=483&amp;oldid=prev</id>
		<title>Karthick: /* API Examples */</title>
		<link rel="alternate" type="text/html" href="https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=483&amp;oldid=prev"/>
				<updated>2009-07-29T00:40:58Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;API Examples&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 00:40, 29 July 2009&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==API Examples==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==API Examples==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;API documentation is included in this documentation package.&amp;#160; Additionally, there are several examples located in the &amp;quot;bin&amp;quot; directory of the distribution.&amp;#160; These examples provide a basic overview of the APIs and how to use them and also show some simple client/server implementations.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;API documentation is included in this documentation package.&amp;#160; Additionally, there are several examples located in the &amp;quot;bin&amp;quot; directory of the distribution.&amp;#160; These examples provide a basic overview of the APIs and how to use them and also show some simple client/server implementations.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Karthick</name></author>	</entry>

	<entry>
		<id>https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=482&amp;oldid=prev</id>
		<title>Karthick: /* API Examples */</title>
		<link rel="alternate" type="text/html" href="https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=482&amp;oldid=prev"/>
				<updated>2009-07-29T00:40:26Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;API Examples&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 00:40, 29 July 2009&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==API Examples==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==API Examples==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;API documentation is included in this documentation package.&amp;#160; Additionally, there are several examples located in the &amp;quot;bin&amp;quot; directory of the distribution.&amp;#160; These examples provide a basic overview of the APIs and how to use them and also show some simple client/server implementations.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;API documentation is included in this documentation package.&amp;#160; Additionally, there are several examples located in the &amp;quot;bin&amp;quot; directory of the distribution.&amp;#160; These examples provide a basic overview of the APIs and how to use them and also show some simple client/server implementations.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Karthick</name></author>	</entry>

	<entry>
		<id>https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=481&amp;oldid=prev</id>
		<title>Suraj at 17:26, 27 July 2009</title>
		<link rel="alternate" type="text/html" href="https://help.openclovis.com/index.php?title=Doc:Sdk_4.1/awdguide/apiexamples&amp;diff=481&amp;oldid=prev"/>
				<updated>2009-07-27T17:26:57Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==API Examples==&lt;br /&gt;
API documentation is included in this documentation package.  Additionally, there are several examples located in the &amp;quot;bin&amp;quot; directory of the distribution.  These examples provide a basic overview of the APIs and how to use them and also show some simple client/server implementations.&lt;br /&gt;
&lt;br /&gt;
===Basic API Use Example: apiexample.py===&lt;br /&gt;
&lt;br /&gt;
This is intended to be an interactive example (i.e. cut-and-paste the lines into a Python shell running under SAFplus Platform).  It presents an overview of the highest layer of APIs and shows how cluster information can be retrieved, software can be installed, and an upgrade started.&lt;br /&gt;
&lt;br /&gt;
It can be run in any SAFplus-connected python shell.  To get to an SAFplus-connected Python shell, either use the shell embedded in the SAFplus Platform web server (browse to /shell), or run one from the command line.  To run from the command line (recommended because you get a full-featured standard python shell) do the following:&lt;br /&gt;
&lt;br /&gt;
Set up paths to get ARD libraries:&lt;br /&gt;
 $ export PYTHONPATH={ardDir}/lib:{ardDir}/bin&lt;br /&gt;
 $ export PATH={ardDir}/bin:$PATH&lt;br /&gt;
&lt;br /&gt;
Run Python. Make SURE to specify ARD's embedded Python, and not your distribution's installed version!&lt;br /&gt;
 $ {ASP_Dir}/bin/asp_run {ardDir}/bin/python2.5&lt;br /&gt;
&lt;br /&gt;
Now at the Python prompt, run this line FIRST to hook into the SAFplus Platform AMF:&lt;br /&gt;
 &amp;gt;&amp;gt; import amfpy; amfpy.initializeAmf()&lt;br /&gt;
&lt;br /&gt;
At this point you can use all ARD Python services, as shown in the following script:&lt;br /&gt;
&lt;br /&gt;
====apiexample.py====&lt;br /&gt;
&lt;br /&gt;
 # Standard Python modules&lt;br /&gt;
 import os&lt;br /&gt;
 import time&lt;br /&gt;
&lt;br /&gt;
 # ARD Python API example code, including deployment and upgrade:&lt;br /&gt;
 import upgrade; import clusterinfo; import aspApp; import aspAmf; import appdeploy&lt;br /&gt;
&lt;br /&gt;
 # Hook into the various services&lt;br /&gt;
 ci = clusterinfo.ci     # The clusterinfo.ci objects reflect the entire state of the cluster&lt;br /&gt;
 amf = aspAmf.Session()  # The aspAmf.Session class lets you modify the cluster state&lt;br /&gt;
&lt;br /&gt;
 # Example of getting the node names&lt;br /&gt;
 print [x.name for x in ci.nodeList]&lt;br /&gt;
&lt;br /&gt;
 # Get the name of the node in slot 1&lt;br /&gt;
 print ci.nodes[1].name&lt;br /&gt;
&lt;br /&gt;
 # Example of getting the sg started/stopped status&lt;br /&gt;
 print &amp;quot;Running Service Groups:&amp;quot;&lt;br /&gt;
 for x in clusterinfo.ci.sgList:&lt;br /&gt;
   if x.isRunning():&lt;br /&gt;
     print x.name&lt;br /&gt;
&lt;br /&gt;
 # Example of getting SU status and of traversing the entity hierarchy&lt;br /&gt;
 print &amp;quot;Active Service Units:&amp;quot;&lt;br /&gt;
 for x in clusterinfo.ci.suList:&lt;br /&gt;
   if x.isActive():&lt;br /&gt;
     print &amp;quot;%s is active for service group %s and is running on node %s (slot: %d)&amp;quot; % (x.name,x.sg.name,x.node.name,x.node.slot)&lt;br /&gt;
&lt;br /&gt;
 # Example of stopping and restarting an entity&lt;br /&gt;
 su = ci.suList[0]&lt;br /&gt;
 print &amp;quot;Stopping %s&amp;quot; % su.name&lt;br /&gt;
 amf.Shutdown(su)&lt;br /&gt;
 # Now we must reload the clusterinfo to reflect changes.&lt;br /&gt;
 ci.load()&lt;br /&gt;
 su = ci.entities[su.name]  # and reload our temporary.  Its best to access your entities by name in case the list order changes&lt;br /&gt;
 if su.isRunning():&lt;br /&gt;
   print &amp;quot;SU %s is still running&amp;quot; % su.name&lt;br /&gt;
 else:&lt;br /&gt;
   print &amp;quot;SU %s is stopped&amp;quot; % su.name&lt;br /&gt;
 amf.Startup(su)&lt;br /&gt;
 ci.load()&lt;br /&gt;
 su = ci.entities[su.name]  # its best to access your entities by name in case the list order changes&lt;br /&gt;
 if su.isRunning():&lt;br /&gt;
   print &amp;quot;SU %s is running&amp;quot; % su.name&lt;br /&gt;
 else:&lt;br /&gt;
   print &amp;quot;SU %s is still stopped&amp;quot; % su.name&lt;br /&gt;
&lt;br /&gt;
 # Initialize the Application bundle DB &amp;amp; pass the bundle repository directory.  Note that you should only create 1 of these per bundle repository directory  or you will have 2 entities managing the same data.&lt;br /&gt;
 appDb = aspApp.AppDb(os.getenv(&amp;quot;ASP_DIR&amp;quot;,&amp;quot;/tmp&amp;quot;) + &amp;quot;/apps&amp;quot;)&lt;br /&gt;
 ci.setAppDb(appDb)  # Hook them up (so clusterinfo knows about application versions)&lt;br /&gt;
 myNode = &amp;quot;ctrlI0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # Set additional data that SAFplus Platform may not know into the node&lt;br /&gt;
 # This info is necessary to deploy software&lt;br /&gt;
 # (it also can be entered via the GUI, or via etc/clustercfg.xml file)&lt;br /&gt;
 # You need to change these values to correctly reflect your setup&lt;br /&gt;
 if ci.entities[myNode].localUser == 'unknown':&lt;br /&gt;
   ci.entities[myNode].setIntraclusterAccess(&amp;quot;192.168.66.130&amp;quot;,&amp;quot;root&amp;quot;,&amp;quot;clovis&amp;quot;,&amp;quot;/root/ocmsdemo7&amp;quot;)&lt;br /&gt;
 # The above example sets 1 node.  For the application deployment example&lt;br /&gt;
 # below to work, you must set all of the nodes to the correct values.&lt;br /&gt;
&lt;br /&gt;
 # Add 2 bundle files into the system.  Of course you must modify the path to&lt;br /&gt;
 # point to valid bundle files.&lt;br /&gt;
 appDb.NewAppFile(&amp;quot;/code/vipapp1.4.0.0.tgz&amp;quot;)&lt;br /&gt;
 appDb.NewAppFile(&amp;quot;/code/vipapp1.4.0.1.tgz&amp;quot;)&lt;br /&gt;
 # Note that if you want AppDb to automatically find them again, &lt;br /&gt;
 # you must copy them into the repository (the directory you specified&lt;br /&gt;
 # when creating &amp;quot;appDb&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
 # Show all bundles and versions&lt;br /&gt;
 print [(x.name,x.version) for x in appDb.AppList()]&lt;br /&gt;
&lt;br /&gt;
 # Find all &amp;quot;live&amp;quot; nodes&lt;br /&gt;
 # Of course, you can't deploy to nodes that aren't powered up!&lt;br /&gt;
 liveNodes = filter(lambda x: x.isRunning(),ci.nodeList)&lt;br /&gt;
 print [x.name for x in liveNodes]&lt;br /&gt;
&lt;br /&gt;
 # Get an application&lt;br /&gt;
 appFile = appDb.apps['virtualIp'].version['1.4.0.0']&lt;br /&gt;
 print &amp;quot;Name: &amp;quot;, appFile.name, &amp;quot;Located At: &amp;quot;, appFile.dir, &amp;quot;Version: &amp;quot;, appFile.version  &lt;br /&gt;
&lt;br /&gt;
Deploy the application:&lt;br /&gt;
&lt;br /&gt;
 # Tweak the configuration for just this deployment&lt;br /&gt;
 # If I didn't copy the configuration, I would be modifying it in RAM&lt;br /&gt;
 # which would affect other deployments I do within this Python session.&lt;br /&gt;
 import copy&lt;br /&gt;
 newCfg = copy.deepcopy(appFile.cfg)&lt;br /&gt;
 # For example, set failback parameter to True:&lt;br /&gt;
 newCfg.virtualIp.modifiers.failBack = True&lt;br /&gt;
&lt;br /&gt;
 # Really Deploy&lt;br /&gt;
 import appdeploy&lt;br /&gt;
 (sgList,(errors,notes)) = appdeploy.deploy(appFile.dir,newCfg,liveNodes,abortIfCantAccess=True,copy=True,deploy=True)&lt;br /&gt;
 # Did you get a pexpect exception?  You probably forgot to specify the node &lt;br /&gt;
 # intracluster access data as shown above.  Or you may have specified&lt;br /&gt;
 # incorrect information.&lt;br /&gt;
 myNewSg  = sgList[0]&lt;br /&gt;
 mySgName = myNewSg.name &lt;br /&gt;
 print &amp;quot;Deployed application and created SG %s&amp;quot; % mySgName&lt;br /&gt;
 # Reload the AMF information model&lt;br /&gt;
 ci.load()&lt;br /&gt;
&lt;br /&gt;
 # Reaccess via ci global to get refreshed data.&lt;br /&gt;
 mySg = ci.entities[mySgName]&lt;br /&gt;
 # Let's start it up&lt;br /&gt;
 amf.Startup(mySg)&lt;br /&gt;
 # Give it time to come up&lt;br /&gt;
 # I reaccess through ci each time to get refreshed data.&lt;br /&gt;
 while not ci.entities[mySgName].isRunning():&lt;br /&gt;
   time.sleep(5)&lt;br /&gt;
   ci.refresh()&lt;br /&gt;
 print &amp;quot;It is running&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Let's do an upgrade!&lt;br /&gt;
&lt;br /&gt;
 # Start the upgrade manager...&lt;br /&gt;
 umgr = upgrade.UpgradeMgr()&lt;br /&gt;
 umgr.add(mySg)  # Add my Service Group to it.&lt;br /&gt;
 upSg = umgr.entities[mySgName]  # Get my sg's upgrade entity &lt;br /&gt;
 upSg.upMethod = upgrade.RollingUpgrade&lt;br /&gt;
 print mySg.appVer.version&lt;br /&gt;
&lt;br /&gt;
 # Start the upgrade...&lt;br /&gt;
 upSg.Upgrade(appDb.apps['virtualIp'].version['1.4.0.1'])&lt;br /&gt;
 ci.load() # Reload the database.&lt;br /&gt;
 mySg = ci.entities[mySg.name]  # Get the new SG object&lt;br /&gt;
 print mySg.appVer.version&lt;br /&gt;
&lt;br /&gt;
===XML client/server example===&lt;br /&gt;
&lt;br /&gt;
This example is located in the &amp;quot;bin&amp;quot; directory and consists of 2 files &amp;quot;xmlclientexample.py&amp;quot; and &amp;quot;xmlserverexample.py&amp;quot;.  It implements a simple XML-RPC client server application that demonstrates how the ARD can interface with 3rd party off-box element management systems.  Please look at these files to see how it works.&lt;br /&gt;
&lt;br /&gt;
===HTTP client/server example===&lt;br /&gt;
&lt;br /&gt;
This example is located in the &amp;quot;bin&amp;quot; directory and consists of 2 files &amp;quot;httpclientexample.py&amp;quot; and &amp;quot;httpserverexample.py&amp;quot;.  It implements a simple http server application that demonstrates how the ARD can interface with 3rd party off-box element management systems.  The intention behind this example is to show a client-server application communicating via http not a human browseable web site (the main ARD GUI application demonstrates how a web-based EMS can be constructed).&lt;/div&gt;</summary>
		<author><name>Suraj</name></author>	</entry>

	</feed>