この付録では、プラグインのコード例を示します。この例は、Sun N1 Service Provisioning System 5.2 ソフトウェアに付属する Solaris プラグインに基づいています。
この例では、Solaris プラグインの version 1.1 を参照しています。Sun N1 Service Provisioning System 5.2 ソフトウェアに付属する Solaris プラグインの機能は反映していません。
このプラグイン例は、com.sun.solaris_1.1.jar ファイルに次のファイルとディレクトリが含まれます。
META-INF/ META-INF/MANIFEST.MF 1.1/ 1.1/components/ 1.1/components/com/ 1.1/components/com/sun/ 1.1/components/com/sun/solaris/ 1.1/components/com/sun/solaris/Container.xml 1.1/components/com/sun/solaris/container_util.xml 1.1/components/com/sun/solaris/Patch.xml 1.1/plans/com/ 1.1/plans/com/sun/ 1.1/plans/com/sun/solaris/ 1.1/plans/com/sun/solaris/Container-create 1.1/resources/ 1.1/resources/com/ 1.1/resources/com/sun/ 1.1/resources/com/sun/solaris/ 1.1/resources/com/sun/solaris/container_util/ 1.1/resources/com/sun/solaris/container_util/sps_svcwait.sh 1.1/resources/com/sun/solaris/container_util/sps_sysidwait_zhalt.sh 1.1/resources/com/sun/solaris/container_util/sps_zattach.sh 1.1/resources/com/sun/solaris/container_util/sps_zboot.sh 1.1/resources/com/sun/solaris/container_util/sps_zcreate.sh 1.1/resources/com/sun/solaris/container_util/sps_zdelete.sh 1.1/resources/com/sun/solaris/container_util/sps_zdetach.sh 1.1/resources/com/sun/solaris/container_util/sps_zhalt.sh 1.1/resources/com/sun/solaris/container_util/sps_zinstall.sh 1.1/resources/com/sun/solaris/container_util/sps_zmatch.sh 1.1/resources/com/sun/solaris/container_util/sps_zra.sh 1.1/resources/com/sun/solaris/plugin-com.sun.solaris.jar gui/ gui/pluginUI.xml gui/solaris.gif plugin-descriptor.xml readme.txt
plugin-descriptor.xml でプラグイン例を定義します。このあとに示す例の各項目について説明します。
<plugin> 要素のほとんどの属性には標準の値を使用しています。3 つの例外は、name、version、description の各属性です。
<dependencyList> 要素では、このプラグイン例が正常に機能するために system プラグインの version 1.0 が必要であることを示しています。system プラグインは Sun N1 Service Provisioning System ソフトウェアのコアの部分であり、常に存在する必要があります。
<folder> 要素では、Solaris のオブジェクトを保存するフォルダを作成しています。
<hostType> 要素では、プラグインで global_zone ホストタイプを参照することを宣言しています。varlist 属性で、このホストタイプに一連の変数を関連付けています。
<hostSearch> 要素では、このプラグインがプロビジョニングできるターゲットホストを特定する一連の条件を定義しています。
<hostSet> 要素では、このプラグインがプロビジョニングできるターゲットホストのサブセットを定義しています。
最初の <component> 要素では、リソースが solaris/container_util.xml のコンポーネントを定義しています。
2 番目の <component> 要素では、プラグインに Container コンポーネントを含めています。
3 番目の <component> 要素では、Patch という新しいコンポーネントタイプを作成しています。このコンポーネントタイプには次のような特徴があります。
Patch コンポーネントタイプは solaris グループに表示されます。
「Component Create」ページでコンポーネントタイプのドロップダウンメニューにコンポーネントタイプが表示されないようにするには、グループの値を hidden に変更します。
Patch コンポーネントタイプのバッキングコンポーネントは 1.1/components/com/sun/solaris/Patch.xml です。
<plan> 要素では、Container-create.xml プランをプラグインの一部として指定しています。
<?xml version="1.0" encoding="UTF-8"?>
<plugin name="com.sun.solaris"
description="Solaris plugin @buildtag@"
version="1.1"
vendor="Sun Microsystems Inc"
xmlns="http://www.sun.com/schema/SPS"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sun.com/schema/SPS plugin.xsd"
schemaVersion="5.2">
<readme jarPath="readme.txt"/>
<serverPluginJAR jarPath="1.1/resources/com/sun/solaris/plugin-com.sun.solaris.jar"/>
<gui jarPath="gui/pluginUI.xml"/>
<dependencyList>
<pluginRef name="system" version="1.0"/>
</dependencyList>
<memberList>
<folder name="/com/sun/solaris" description="Solaris plugin folder"/>
<hostType name="global_zone"
description="a physical host from which partitioned
local zones can be created">
<varList>
<var name="local_zone_base_path" default="/export/zones"/>
<var name="local_zone_default_name" default=""/>
<var name="local_zone_default_filesystem" default="SPARSE"/>
<var name="local_zone_connection_type" default="RAW"/>
<var name="local_zone_port" default="1131"/>
<var name="local_zone_advanced_params" default=""/>
<var name="n1sps_cli_host" default="masterserver"/>
<var name="n1sps_cli_path"
default="/opt/SUNWn1sps/N1_Service_Provisioning_System_*/cli/bin/cr_cli"/>
</varList>
</hostType>
<hostSearch name="global_zones"
description="matches Solaris global zone hosts">
<criteriaList>
<criteria name="sys.OS" pattern="SunOS"/>
<criteria name="sys.OSVersion" pattern="5.10"/>
<criteria name="sys.hostType"
pattern="com.sun.solaris#global_zone"/>
</criteriaList>
<appTypeCriteria ra="true"/>
<physicalCriteria physical="true"/>
</hostSearch>
<hostSet name="global_zones" description="Solaris global zones">
<hostSearchRef name="global_zones"/>
</hostSet>
...
<component jarPath="1.1/components/com/sun/solaris/container_util.xml"
majorVersion="true">
<resource jarPath="1.1/resources/com/sun/solaris/container_util/"
name="/com/sun/solaris/container_util" type="DIRECTORY"
majorVersion="true"/>
</component>
<component jarPath="1.1/components/com/sun/solaris/Container.xml"
majorVersion="true"/>
<component jarPath="1.1/components/com/sun/solaris/Patch.xml"
majorVersion="true">
<componentType name="Patch" group="solaris" order="000000-000000-000001"
indentLevel="1" />
</component>
...
<plan jarPath="1.1/plans/com/sun/solaris/Container-create.xml"
majorVersion="true"/>
...
</memberList>
</plugin>
このプラグイン例では、components ディレクトリに Container.xml ファイルがあります。このコンポーネントは型付けされておらず、Solaris 10 OS が稼働しているシステムを別々のゾーンに区分化するように設計されています。このあとに示す例では、次の要素を指定してコンポーネントを作成しています。
<component> 要素の path、name、 description、platform の各要素では、コンポーネントタイプに固有の情報を指定しています。
<varlist> 要素では、ユーザーがこのコンポーネントタイプに基づくコンポーネントをカスタマイズできるようにする複数の変数を定義しています。
<componentReflList> 要素では、container_util コンポーネントを呼び出して、コンポーネントに対する複数の処理を行っています。
<installList> 要素では、<execNative> ステップを呼び出して、Solaris のコマンドを実行してゾーンを作成しています。
<uninstallList> 要素では、<execNative> ステップを呼び出して、Solaris のコマンドを実行してゾーンを削除しています。
<controllList> 要素では、<execNative> ステップを呼び出して、さまざまなシステムチェックを行うシェルスクリプトを実行しています。
<?xml version="1.0" encoding="UTF-8"?>
<component platform='system#Solaris 10'
installPath=':[installPath]'
xmlns='http://www.sun.com/schema/SPS'
name='Container' version='5.2'
description='Solaris Container'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
limitToHostSet='com.sun.solaris#global_zones'
softwareVendor='Sun Microsystems'
path='/com/sun/solaris'
xsi:schemaLocation='http://www.sun.com/schema/SPS component.xsd'>
<varList>
<var name='installPath' default=':[target:local_zone_default_name]'
prompt='Zone Name'></var>
<var name='local_zone_filesystem' default=':[target:local_zone_default_filesystem]'
prompt='SPARSE,FULL'></var>
<var name='local_zone_connection_type' default=':[target:local_zone_connection_type]'
access='PRIVATE'></var>
<var name='local_zone_port' default=':[target:local_zone_port]'
access='PRIVATE'></var>
<var name='local_zone_advanced_params' default=':[target:local_zone_advanced_params]'
access='PRIVATE'></var>
<var name='n1sps_cli_host' default=':[target:n1sps_cli_host]'
access='PRIVATE'></var>
<var name='n1sps_cli_path' default=':[target:n1sps_cli_path]' access='PRIVATE'></var>
<var name='zoneIfaceDetails' default=''
prompt='Semicolon separted network_interface,IPAddress/netmask pairs.
Example: hme0,123.123.123.123/24;eri0,124.124.124.124/8.'></var>
<var name='zoneFsLayout' default=''
prompt="Semicolon separted filesystem infos.
Example: dir=/usr/local special=/opt/local raw=/dev/rdsk/c0t0d0s7
type=lofs [ro,nodevices];dir=/opt/mystuff special=/empty type=lofs ro.
(see 'man zonecfg')"></var>
</varList>
<targetRef hostName=':[installPath]' typeName='com.sun.solaris#local_zone'>
<agent params=':[local_zone_advanced_params]' ipAddr=':[installPath]'
port=':[local_zone_port]' connection=':[local_zone_connection_type]'></agent>
</targetRef>
<componentRefList>
<componentRef name='container_util' installMode='TOPLEVEL'>
<component name='container_util' path='/com/sun/solaris'
version='1.1'></component>
</componentRef>
</componentRefList>
<installList>
<installSteps returns='false' name='create'>
<varList>
<var name='raHomeDir' default=':[target:sys.raHomeDir]'></var>
<var name='raDataDir' default=':[target:sys.raDataDir]'></var>
<var name='raTmpDir' default=':[target:sys.raTmpDir]'></var>
<var name='binPath'
default=':[target:sys.raDataDir]:[/]systemcomps:[/]com.sun.solaris:
[/]container_util'></var>
<var name='local_zone_base_path'
default=':[target:local_zone_base_path]'></var>
</varList>
<try>
<block>
<checkDependency>
<toplevelRef name='container_util'></toplevelRef>
</checkDependency>
</block>
<catch>
<install blockName='default'>
<toplevelRef name='container_util'></toplevelRef>
</install>
</catch>
</try>
<createDependency name='local_zone'>
<toplevelRef name='container_util'></toplevelRef>
</createDependency>
<execNative userToRunAs='root' timeout='10800'>
<exec cmd=':[binPath]/sps_zcreate.sh'>
<arg value=':[installPath]'></arg>
<arg value=':[local_zone_base_path]'></arg>
<arg value=':[local_zone_filesystem]'></arg>
<arg value=':[zoneIfaceDetails]'></arg>
<arg value=':[zoneFsLayout]'></arg>
</exec>
</execNative>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_zinstall.sh'>
<arg value=':[installPath]'></arg>
<arg value=':[raHomeDir]'></arg>
<arg value=':[raDataDir]'></arg>
<arg value=':[raTmpDir]'></arg>
<arg value=':[local_zone_connection_type]'></arg>
<arg value=':[local_zone_port]'></arg>
<arg value=':[local_zone_advanced_params]'></arg>
</exec>
</execNative>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_zboot.sh'>
<arg value=':[installPath]'></arg>
</exec>
</execNative>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_sysidwait_zhalt.sh'>
<arg value=':[installPath]'></arg>
</exec>
</execNative>
</installSteps>
<installSteps returns='false' name='markOnly'></installSteps>
</installList>
<uninstallList>
<uninstallSteps returns='false' name='delete'>
<varList>
<var name='binPath'
default=':[target:sys.raDataDir]:[/]systemcomps:[/]com.sun.solaris:
[/]container_util'></var>
</varList>
<dependantCleanup>
<uninstall blockName='unprep'>
<thisComponent></thisComponent>
</uninstall>
</dependantCleanup>
<checkDependency>
<toplevelRef name='container_util'></toplevelRef>
</checkDependency>
<call blockName='deactivate'>
<thisComponent></thisComponent>
</call>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_zdelete.sh'>
<arg value=':[installPath]'></arg>
</exec>
</execNative>
</uninstallSteps>
<uninstallSteps returns='false' name='markOnly'>
<dependantCleanup>
<uninstall blockName='unprep'>
<thisComponent></thisComponent>
</uninstall>
</dependantCleanup>
</uninstallSteps>
</uninstallList>
<controlList>
<control returns='false' name='activate'>
<varList>
<var name='raHomeDir'
default=':[target:sys.raHomeDir]'></var>
<var name='binPath'
default=':[target:sys.raDataDir]:[/]systemcomps:[/]com.sun.solaris:
[/]container_util'></var>
</varList>
<checkDependency>
<toplevelRef name='container_util'></toplevelRef>
</checkDependency>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_zboot.sh'>
<arg value=':[installPath]'></arg>
</exec>
</execNative>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_svcwait.sh'>
<arg value=':[installPath]'></arg>
<arg value='/milestone/multi-user'></arg>
</exec>
<successCriteria></successCriteria>
</execNative>
<if>
<condition>
<equals value2='SSH' value1=':[local_zone_connection_type]'></equals>
</condition>
<then></then>
<else>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_zra.sh'>
<arg value=':[installPath]'></arg>
<arg value=':[raHomeDir]'></arg>
<arg value='start noprompt'></arg>
</exec>
</execNative>
</else>
</if>
<try>
<block>
<retarget host=':[n1sps_cli_host]'>
<varList>
<var name='sessionID'
default=':[session:sys:sessionID]'></var>
</varList>
<execNative timeout='60'>
<inputText><![CDATA[
/bin/pkginfo -q SUNWspscl
if [ $? -eq 0 ]; then
N1SPS_CLI=`/bin/pkginfo -r SUNWspscl`/cli/bin/cr_cli
else
N1SPS_CLI=`/bin/ls :[n1sps_cli_path] | /bin/tail -1`
if [ -z "$N1SPS_CLI" ]; then
echo "N1 SPS cli not found"
exit 1
fi
fi
echo "Testing connection to RA on local zone ':[installPath]'"
index=1
while [ $index -le 3 ];do
output=`$N1SPS_CLI -cmd net.ping -d :[installPath]::[local_zone_port] -s :[sessionID]`
echo $output | grep "Succeeded"
if [ $? -eq 0 ]; then
exit 0
fi
index=`expr $index + 1`
done
exit 1
]]></inputText>
<exec cmd='/bin/sh'></exec>
</execNative>
<execNative>
<inputText><![CDATA[
/bin/pkginfo -q SUNWspscl
if [ $? -eq 0 ]; then
N1SPS_CLI=`/bin/pkginfo -r SUNWspscl`/cli/bin/cr_cli
else
N1SPS_CLI=`/bin/ls :[n1sps_cli_path] | /bin/tail -1`
if [ -z "$N1SPS_CLI" ]; then
echo "N1 SPS cli not found"
exit 1
fi
fi
echo "prep local zone ':[installPath]'"
$N1SPS_CLI -cmd pe.h.prep -tar NM::[installPath] -s :[sessionID]
]]></inputText>
<exec cmd='/bin/sh'></exec>
</execNative>
</retarget>
</block>
<catch></catch>
</try>
</control>
<control returns='false' name='deactivate'>
<varList>
<var name='raHomeDir' default=':[target:sys.raHomeDir]'></var>
<var name='binPath' default=':[target:sys.raDataDir]:
[/]systemcomps:[/]com.sun.solaris:[/]container_util'></var>
</varList>
<checkDependency>
<toplevelRef name='container_util'></toplevelRef>
</checkDependency>
<execNative userToRunAs='root'>
<exec cmd=':[binPath]/sps_zhalt.sh'>
<arg value=':[installPath]'></arg>
<arg value=':[raHomeDir]'></arg>
</exec>
<successCriteria></successCriteria>
</execNative>
</control>
</controlList>
</component>
このプラグイン例では、components ディレクトリに container_util.xml ファイルがあります。このファイルでは、container_util コンポーネントを定義しています。このコンポーネントでは、Solaris のコンテナをインストール、起動、および管理する複数のユーティリティーを定義しています。このあとに示す例では、次の要素を指定して単純コンポーネントを作成しています。
<component> 要素の path、name、 description、platform の各要素では、コンポーネントタイプに固有の情報を指定しています。
<extends> 要素では、container_util コンポーネントが system#directory コンポーネントタイプの機能を拡張することを指定しています。
<varlist> 要素では、ユーザーがこのコンポーネントタイプに基づくコンポーネントをカスタマイズできるようにする複数の変数を定義しています。
<resourceReflList> 要素では、container_util のリソースを参照しています。
<installList> 要素では、container_util のリソースを配備し、リソースの配備後にターゲットホストのスナップショットを作成しています。
<?xml version="1.0" encoding="UTF-8"?> <component platform='system#Solaris 10' xmlns='http://www.sun.com/schema/SPS' name='container_util' version='5.2' description='Solaris Container Utilities' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' softwareVendor='Sun Microsystems' path='/com/sun/solaris' xsi:schemaLocation='http://www.sun.com/schema/SPS component.xsd'> <extends> <type name='system#directory'></type> </extends> <varList> <var name='installPath' default=':[target:sys.raDataDir]:[/]systemcomps:[/]com.sun.solaris'></var> <var name='installPermissions' default='555'></var> <var name='installDiffDeploy' default='FALSE'></var> </varList> <resourceRef> <resource name='/com/sun/solaris/container_util' version='2.0'></resource> </resourceRef> <installList> <installSteps returns='false' name='default'> <deployResource></deployResource> <createSnapshot blockName='default'></createSnapshot> </installSteps> </installList> </component>
このプラグイン例では、plans ディレクトリに Container-create.xml ファイルがあります。このファイルでは、プラグインで実行するステップ、およびこれらのステップで使用するコンポーネントを定義しています。
このプラン例には、次の要素が含まれます。
simpleSteps 要素では、インストールブロックの create を呼び出しています。
component 要素では、Container コンポーネントで指定されている create インストールステップをプランで使用するように指定しています。
<?xml version="1.0" encoding="UTF-8"?> <executionPlan xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' name='Container-create' version='5.2' xsi:schemaLocation='http://www.sun.com/schema/SPS plan.xsd' xmlns='http://www.sun.com/schema/SPS' path='/com/sun/solaris'> <simpleSteps> <install blockName='create'> <component name='Container' path='/com/sun/solaris'></component> </install> </simpleSteps> </executionPlan>