6.3.2 テンプレートの作成
- 〈この項の構成〉
 
(1) テンプレートの作成および終了
テンプレートを作成する場合は,グローバルコンフィグレーションモードでtemplateコマンドを使用します。templateコマンドを実行するとテンプレートを編集するモード(templateモードと呼びます)に移行して,テンプレートにコンフィグレーションコマンドを登録できるようになります。このとき,プロンプトにはtemplateモードを示す「-TPL」が付きます。テンプレートの作成例を次の図に示します。
(config)# template EtherDEF $PORT (config-TPL)# show template EtherDEF $PORT end-template ! (config-TPL)#  | 
               
テンプレートの編集を終了する場合は,次の表に示すコマンドのどれかを使用します。
| 
                         コマンド名  | 
                     
                         説明  | 
                  
|---|---|
| 
                         end  | 
                     
                         templateモードを終了して,装置管理者モードに移行します。  | 
                  
| 
                         end-template  | 
                     
                         templateモードを終了して,グローバルコンフィグレーションモードに移行します。  | 
                  
| 
                         quit (exit)  | 
                     
                         config-TPLモードの場合,templateモードを終了してグローバルコンフィグレーションモードに移行します。config-TPLモード以外の場合,一つ上の階層に移行します。  | 
                  
| 
                         top  | 
                     
                         templateモードを終了して,グローバルコンフィグレーションモードに移行します。  | 
                  
テンプレートにはend-templateコマンドが自動で登録されるため,end-templateコマンド以外のコマンドでtemplateモードを終了した場合でも,テンプレートにはend-templateコマンドが登録されます。テンプレートの編集終了例を次の図に示します。
(config-TPL)# end-template (config)#  | 
               
(2) テンプレートへの登録方法
テンプレートには,コンフィグレーションを設定するコンフィグレーションコマンドとコンフィグレーションを削除するコンフィグレーションコマンドを登録できます。テンプレートへの登録例を次の図に示します。
(config)# template EtherDEF $PORT
(config-TPL)# interface gigabitethernet $PORT          <-1
(config-if-TPL)# shutdown                              <-1
(config-if-TPL)# speed 1000                            <-1
(config-if-TPL)# no shutdown                           <-2
(config-if-TPL)# exit
(config-TPL)# show 
template EtherDEF $PORT
  interface gigabitethernet $PORT
    shutdown
    speed 1000
    no shutdown
  end-template
!
(config-TPL)# | 
               
- 
                  
コンフィグレーションを設定するコンフィグレーションコマンドをテンプレートに登録します。
 - 
                  
コンフィグレーションを削除するコンフィグレーションコマンドをテンプレートに登録します。
 
テンプレートには通常のコンフィグレーション編集時と同様のモードがあり,同様にモード遷移します。このとき,すべてのモードでプロンプトにtemplateモードを示す「-TPL」が付きます。テンプレートのモード遷移例を次の図に示します。
(config)# interface gigabitethernet 1/1 <-1 (config-if)# <-1 (config-if)# exit (config)# template EtherDEF $PORT (config-TPL)# interface gigabitethernet $PORT <-2 (config-if-TPL)# <-2  | 
               
- 
                  
通常のコンフィグレーション編集時のモード遷移です。
 - 
                  
テンプレート編集時のモード遷移です。通常のコンフィグレーション編集時と同様にモード遷移します。プロンプトにはtemplateモードを示す「-TPL」が付きます。
 
templateモードでは,コンフィグレーションコマンドは入力した順にテンプレートに登録されます。コマンドの入力順がテンプレートの登録順となる例を次の図に示します。
(config)# template EtherDEF $PORT
(config-TPL)# interface gigabitethernet $PORT          <-1
(config-if-TPL)# shutdown                              <-1
(config-if-TPL)# speed 1000                            <-1
(config-if-TPL)# no shutdown                           <-1
(config-if-TPL)# exit
(config-TPL)# show                                     <-2
template EtherDEF $PORT
  interface gigabitethernet $PORT                      <-3
    shutdown                                           <-3
    speed 1000                                         <-3
    no shutdown                                        <-3
  end-template
!
(config-TPL)# | 
               
- 
                  
テンプレートにコンフィグレーションコマンドを登録します。
 - 
                  
showコマンドでテンプレートの登録内容を確認します。
 - 
                  
入力した順にコンフィグレーションコマンドが登録されています。