キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 
cancel
773
閲覧回数
0
いいね!
0
コメント
Takayuki Noro
Cisco Employee
Cisco Employee

 

1. はじめに

パッケージの開発の際などに Python のバージョンを変更したいようなケースがあると思いますが、設定ファイル ( デフォルトは ncs-start-python-vm が読み込まれている ) を変更することで、柔軟に Python のバージョンを変更することができます。 

Manual では Development の The NSO Python VM の項目に当たる内容となりますが、現在の Manual に記載されている推奨の方法では不足している箇所がございますので、本ドキュメントでは、その不足点を補完し改めて Python のバージョン変更の方法をまとめます。

本記事でのログの出力結果は NSO 4.7.2.1 を System Install した環境で採取したものです。 

2. 設定手順

既存の python VM の設定ファイル ( ncs-start-python-vm ) をコピーして、自分用の設定ファイルを作成します。 

admin@system:/opt/ncs/current/bin$ pwd
/opt/ncs/current/bin
admin@system:/opt/ncs/current/bin$cp ncs-start-python-vm my-start-python-vm

作成した自分用の設定ファイルの最終行を使用したい Python に変更します。 

admin@system:/opt/ncs/current/bin$ cat my-start-python-vm
#!/bin/sh

pypath="${NCS_DIR}/src/ncs/pyapi"

# Make sure everyone finds the NCS Python libraries at startup
if [ "x$PYTHONPATH" != "x" ]; then
    PYTHONPATH=${pypath}:$PYTHONPATH
    echo "test $*"
else
    PYTHONPATH=${pypath}
fi
export PYTHONPATH

main="${pypath}/ncs_pyvm/startup.py"

echo "Starting ${main} $*"
exec /usr/bin/python3 -u ${main} $*

現在のところ ( NSO 4.7.2.1 ) 、Manual には記載がございませんが、 System Install の場合は ncs.conf の変更が必要となります。 デフォルトでは以下のようになっています。

 <python-vm>
    <start-command>DEFAULT</start-command>
    <run-in-terminal>
      <terminal-command>DEFAULT</terminal-command>
    </run-in-terminal>
    <logging>
      <log-file-prefix>${NCS_LOG_DIR}/ncs-python-vm</log-file-prefix>
    </logging>
  </python-vm>

 start-command を作成した my-start-python-vm のファイルが置かれているディレクトリのパスに書き換えます。

  <python-vm>
    <start-command> /opt/ncs/current/bin/my-start-python-vm </start-command>
    <run-in-terminal>
      <terminal-command>DEFAULT</terminal-command>
    </run-in-terminal>
    <logging>
      <log-file-prefix>${NCS_LOG_DIR}/ncs-python-vm</log-file-prefix>
    </logging>
  </python-vm>

最後に Python VM を起動します。

admin@ncs# config
Entering configuration mode terminal
admin@ncs(config)# python-vm start-command /opt/ncs/current/bin/my-start-python-vm
admin@ncs(config)# commit
Commit complete.

 

Getting Started

検索バーにキーワード、フレーズ、または質問を入力し、お探しのものを見つけましょう

シスコ コミュニティをいち早く使いこなしていただけるよう役立つリンクをまとめました。みなさんのジャーニーがより良いものとなるようお手伝いします