0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

model driven programmability advancement OSPF configuration using RESTCONF 2

Last updated at Posted at 2024-11-26

RESTCONFをCI/CD使ってOSPF設定を行う

image.png

ルーターのL3IPは事前に設定済み
R3とR4はすでに設定済みでOSPFが稼働済み
【変更】PythonプログラムをCI/CDでCSR1とCSR2を設定する
デバイス名.jsonファイルを使う
プログラム実行時にCSR1とCSR2はすべてのルーターとOSPFを形成

1の時とほとんど変わらないが定期的に実行するCI/CDを使って変更する。
この構成だと定期ジョブを利用する必要は無いが練習のため。

device-templates
++ios-xe1.json
++ios-xe2.json
restconf_deploy.py
gitlab-ci.yml

以下のファイルだけ追加になるが他は変わらない。

gitlab-ci.yml
stages:
 - deploy

deploy_ospf:
  stage: deploy
  script:
   - source .envrc
   - python restconf-deploy.py

方針

GITとGITLABをインストールしてGITをつかって実行ファイルをGITLABに登録。GIT-Runnerを動かして定期実行ジョブによって設定を実行する。

GITLABのインストール

GITLABはhttps://qiita.com/neetstar/items/55489ae35bc765890248
でインストールした。

GITでファイルをGITLABに登録する。

#####GITをインストール
$ sudo apt install git
#####GITを有功にするフォルダを開く
$ cd /devex/MDP_OSPF_RESTCONF
#####GITを開始する
~/devex/MDP_OSPF_RESTCONF$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>
Initialized empty Git repository in /home/aaa/devex/MDP_OSPF_RESTCONF/.git/
#####GITのユーザー名を指定
~/devex/MDP_OSPF_RESTCONF$ git config --global user.name "root"
#####GITのメールアドレス指定
~/devex/MDP_OSPF_RESTCONF$ git config --global user.email "root@localhost"
#####ファイルをステージングエリアに追加
~/devex/MDP_OSPF_RESTCONF$ git add .
#####ファイルをローカルリポジトリにコミット
~/devex/MDP_OSPF_RESTCONF$ git commit -m "Initial commit"
[master (root-commit) 25ee2f5] Initial commit
 5 files changed, 162 insertions(+)
 create mode 100644 .encrvc
 create mode 100644 .gitlab-ci.yml
 create mode 100644 device-templates/ios-xe1.json
 create mode 100644 device-templates/ios-xe2.json
 create mode 100644 restconf-deploy.py
#####ローカルリポジトリをリモートリポジトリに追加
~/devex/MDP_OSPF_RESTCONF$ git push --set-upstream http://127.0.0.1/root/MDP_OSPF_RESTCONF.git master
Username for 'http://127.0.0.1': root
Password for 'http://root@127.0.0.1': 
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 1.42 KiB | 242.00 KiB/s, done.
Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
remote: 
remote: 
remote: The private project root/MDP_OSPF_RESTCONF was successfully created.
remote: 
remote: To configure the remote, run:
remote:   git remote add origin http://127.0.0.1/root/MDP_OSPF_RESTCONF.git
remote: 
remote: To view the project, visit:
remote:   http://127.0.0.1/root/MDP_OSPF_RESTCONF
remote: 
remote: 
remote: 
To http://127.0.0.1/root/MDP_OSPF_RESTCONF.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'http://127.0.0.1/root/MDP_OSPF_RESTCONF.git'.

GIT RUNNERのインストール

#####結構重い500Mぐらいある
$curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
$sudo apt install gitlab-runner

GIT RUNNERの設定

GITLABに行き
Projects>MDP_OSPF_RESTCONFをクリックする。
Screenshot_2024-11-27_03-33-27.png

Settings>CI/CD>Variable>Add valiablesをクリックし.envrcの値を追加する
Screenshot_2024-11-27_04-05-59.png

Screenshot_2024-11-27_04-11-05.png
Screenshot_2024-11-27_04-11-36.png

Settings>CI/CD>Runners>New project runnerをクリックする。
Screenshot_2024-11-27_03-38-18.png

Run untagged jobs>Create runnerをクリックする。
Screenshot_2024-11-27_03-52-03.png

GIT RUNNERの起動

gitlab-runner registerとプロンプトから入力し以下の情報を元に対話形式で進める
Screenshot_2024-11-27_04-17-24.png

$ gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=138242 revision=374d34fd version=17.6.0
WARNING: Running in user-mode.                     
WARNING: The user-mode requires you to manually start builds processing: 
WARNING: $ gitlab-runner run                       
WARNING: Use sudo for system-mode:                 
WARNING: $ sudo gitlab-runner...                   
Enter the GitLab instance URL (for example, https://gitlab.com/):
########GITLABのアドレス
http://127.0.0.1
Enter the registration token:
########与えられたトークン
glrt-t3_RCj3BysBQtWnLWUCo35D
Verifying runner... is valid                        runner=t3_RCj3By
Enter a name for the runner. This is stored only in the local config.toml file:
########そのままENTER
[student-virtual-machine]: 
Enter an executor: shell, ssh, docker-windows, custom, virtualbox, docker, docker+machine, kubernetes, docker-autoscaler, instance, parallels:
########自分の場合はSHELL
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
 
Configuration (with the authentication token) was saved in "/home/student/.gitlab-runner/config.toml" 
########Gitlab runnerを起動する。
$ sudo gitlab-runner run

確認

IOS-XE1#sh ip ospf nei   

Neighbor ID     Pri   State           Dead Time   Address         Interface
4.4.4.4           0   FULL/  -        00:00:34    14.0.0.4        GigabitEthernet4
3.3.3.3           0   FULL/  -        00:00:38    13.0.0.3        GigabitEthernet3
2.2.2.2           0   FULL/  -        00:00:37    12.0.0.2        GigabitEthernet2
IOS-XE1#

IOS-XE2#sh ip ospf ne

Neighbor ID     Pri   State           Dead Time   Address         Interface
3.3.3.3           0   FULL/  -        00:00:34    23.0.0.3        GigabitEthernet4
4.4.4.4           0   FULL/  -        00:00:36    24.0.0.4        GigabitEthernet3
1.1.1.1           0   FULL/  -        00:00:35    12.0.0.1        GigabitEthernet2
IOS-XE2#

問題と対処。

なぜか分からないがGITLAB-RunnerがJOBをピックアップしないことがおおかったが、一般権限で実行してキャンセルしてSUDOで実行すると即時動いた。

$gitlab-runner run
$sudo gitlab-runner run
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?