てくなべ (tekunabe)

ansible / network automation / 学習メモ

Cumulus Linux の仮想アプライアンス「Cumulus VX」を Vagrant で構築する

■ はじめに

つい最近、ホワイトボックススイッチ向けのネットワークOSであるCumulus Linux に、仮想アプライアンスCumulus VX」があることを知りました。

この記事では、Vagrant と Virtual Box を利用し、4 台の Cumulus VX を構築、接続、設定して、疎通確認するまでの手順をまとめます。


■ 想定構成

ネットワーク構成

以下のような 4 台(Cumulus VX 3.7.10)の構成を構築します。

f:id:akira6592:20191117192624p:plain
Cumulus VX 4台構成

なお、図には示していませんが、各スイッチは管理用ポートとして eth0 を持ち、eth0 からホストOSを経由してインターネット側にも抜けられます。

※もし最小構成(1台のみ、かつ管理ポートのみ)でよければ、今回紹介する手順よりも簡単な、以下の手順で構築できます。

# 最小構成の場合の手順
vagrant init CumulusCommunity/cumulus-vx   # Vagrantfile の作成
vagrant up    # 起動
vagrant ssh   # ログイン

ホストOS 環境


■ Vagrantfile の作成と起動

仮想マシンを定義する Vagrantfile を作成し、それを元にして起動します。

Vagrantfile の作成

まず、 Vagrantfile を作成します。

  • ポイント
    • 各スイッチのポート swp1swp2 を作成し、provision を利用して IP アドレスを設定するようにしています。
    • forwarded_port は、他の環境と重複しないようにします。
    • 最小メモリ要件は、こちらのページによると 512MB とのことなので、 512 MBにしています。
Vagrant.configure(2) do |config|

  config.vbguest.auto_update = false

  config.vm.provider "virtualbox" do |vb|
    vb.memory = 512
  end

  # spine1
  config.vm.define "spine1" do |device|
    device.vm.box = "CumulusCommunity/cumulus-vx"
    device.vm.hostname = "spine1" 
    device.vm.network "private_network", virtualbox__intnet: "nw101", auto_config: false
    device.vm.network "private_network", virtualbox__intnet: "nw102", auto_config: false

    device.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2211

    device.vm.provision :shell, inline: <<-SHELL
      sudo net add interface swp1 ip address 10.0.101.1/30
      sudo net add interface swp2 ip address 10.0.102.1/30
      sudo net commit
    SHELL
  end
  
  # spine2
  config.vm.define "spine2" do |device|
    device.vm.box = "CumulusCommunity/cumulus-vx"
    device.vm.hostname = "spine2" 
    device.vm.network "private_network", virtualbox__intnet: "nw201", auto_config: false
    device.vm.network "private_network", virtualbox__intnet: "nw202", auto_config: false
    
    device.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2212
    
    device.vm.provision :shell, inline: <<-SHELL
      sudo net add interface swp1 ip address 10.0.201.1/30
      sudo net add interface swp2 ip address 10.0.202.1/30
      sudo net commit
    SHELL
  end

  # leaf1
  config.vm.define "leaf1" do |device|
    device.vm.box = "CumulusCommunity/cumulus-vx"
    device.vm.hostname = "leaf1" 
    device.vm.network "private_network", virtualbox__intnet: "nw101", auto_config: false
    device.vm.network "private_network", virtualbox__intnet: "nw201", auto_config: false

    device.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2221

    device.vm.provision :shell, inline: <<-SHELL
      sudo net add interface swp1 ip address 10.0.101.2/30
      sudo net add interface swp2 ip address 10.0.201.2/30
      sudo net commit
    SHELL
  end

  # leaf2
  config.vm.define "leaf2" do |device|
    device.vm.box = "CumulusCommunity/cumulus-vx"
    device.vm.hostname = "leaf2" 
    device.vm.network "private_network", virtualbox__intnet: "nw102", auto_config: false
    device.vm.network "private_network", virtualbox__intnet: "nw202", auto_config: false
    device.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2222

    device.vm.provision :shell, inline: <<-SHELL
      sudo net add interface swp1 ip address 10.0.102.2/30
      sudo net add interface swp2 ip address 10.0.202.2/30
      sudo net commit
    SHELL
  end

end

vagrant up で起動

先ほど作成した Vagrantfile があるでディレクトリで vagrant up コマンドを実行し、仮想マシンを起動します。初回は、イメージのダウンロードから始まるため、相応の時間がかかります。

$ vagrant up
Bringing machine 'spine1' up with 'virtualbox' provider...
Bringing machine 'spine2' up with 'virtualbox' provider...
Bringing machine 'leaf1' up with 'virtualbox' provider...
Bringing machine 'leaf2' up with 'virtualbox' provider...
==> spine1: Box 'CumulusCommunity/cumulus-vx' could not be found. Attempting to find and install...
    spine1: Box Provider: virtualbox
    spine1: Box Version: >= 0
==> spine1: Loading metadata for box 'CumulusCommunity/cumulus-vx'
    spine1: URL: https://vagrantcloud.com/CumulusCommunity/cumulus-vx
==> spine1: Adding box 'CumulusCommunity/cumulus-vx' (v3.7.10) for provider: virtualbox
    spine1: Downloading: https://vagrantcloud.com/CumulusCommunity/boxes/cumulus-vx/versions/3.7.10/providers/virtualbox.box

...(略)...

    leaf2: User  Timestamp                   Command
    leaf2: ----  --------------------------  -----------------------------------------------
    leaf2: root  2019-11-17 09:21:38.336778  net add interface swp1 ip address 10.0.201.2/30
    leaf2: root  2019-11-17 09:21:38.372146  net add interface swp2 ip address 10.0.202.2/30
$

正常に起動ができたことを vagrant status コマンドで確認します。

$ vagrant status
Current machine states:

spine1                    running (virtualbox)
spine2                    running (virtualbox)
leaf1                     running (virtualbox)
leaf2                     running (virtualbox)

すべてが running であれば正常に起動していることを示しています。


■ ログインと状態・疎通確認

ログイン

ログインには大きく分けて 2の方法があります。

方法1: vagrant ssh コマンドによるログイン

1つ目は、 vagrant ssh 対象マシン名 コマンドによるログインです。vagrant で構築した環境ならではの方法です。ユーザーや下記の情報は .vagrant ディレクトリ配下の情報を自動で利用するため、特に指定は不要です。

例えば、leaf1 にログインする場合は、Vagrantfile があるでディレクトリで以下のコマンドを実行します。

$ vagrant ssh leaf1

Welcome to Cumulus VX (TM)

Cumulus VX (TM) is a community supported virtual appliance designed for
experiencing, testing and prototyping Cumulus Networks' latest technology.
For any questions or technical support, visit our community site at:
http://community.cumulusnetworks.com

The registered trademark Linux (R) is used pursuant to a sublicense from LMI,
the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide
basis.
vagrant@leaf1:~$ 

上記のような表示になれば、無事にログインできたことを示します。

方法2: ssh コマンドによるログイン

2つ目は、通常通り ssh コマンド(またはターミナルソフトなど)によるログインです。 ログインには以下の接続情報が必要です。(ユーザー1、2はどちらでもOK、お好みで)

接続情報
ホスト localhost
ポート (Vagrantfile で指定したポートフォワーディング用のポート)
ユーザー名1 cumulus
パスワード1 CumulusLinux! (デフォルト)
ユーザー名2 vagrant
パスワード2 vagrant (デフォルト)

ポートフォワーディング用のポート(Vagrantfile 内で指定)は以下のとおりです。

マシン名 ポート
spine1 2211
spine2 2212
leaf1 2221
leaf2 2222

例えば、leaf1 にログインする場合は、Vagrantfile があるでディレクトリで以下のコマンドを実行します。

$ ssh cumulus@localhost -p 2211
cumulus@localhost's password:   ( CumulusLinux! を入力)

Welcome to Cumulus VX (TM)

Cumulus VX (TM) is a community supported virtual appliance designed for
experiencing, testing and prototyping Cumulus Networks' latest technology.
For any questions or technical support, visit our community site at:
http://community.cumulusnetworks.com

The registered trademark Linux (R) is used pursuant to a sublicense from LMI,
the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide
basis.
cumulus@spine1:~$ 

上記のような表示になれば、無事にログインできたことを示します。

状態・疎通確認

ログインができたら、簡単な状態確認をしてみます。

まずは spine1 にて。

  • バージョンの確認
vagrant@spine1:~$ sudo net show version 
NCLU_VERSION=1.0-cl3u30
DISTRIB_ID="Cumulus Linux"
DISTRIB_RELEASE=3.7.10
DISTRIB_DESCRIPTION="Cumulus Linux 3.7.10"
  • インターフェースの確認
vagrant@spine1:~$ sudo net show interface 
State  Name  Spd  MTU    Mode          LLDP            Summary
-----  ----  ---  -----  ------------  --------------  ----------------------
UP     lo    N/A  65536  Loopback                      IP: 127.0.0.1/8
       lo                                              IP: ::1/128
UP     eth0  1G   1500   Mgmt                          IP: 10.0.2.15/24(DHCP)
UP     swp1  1G   1500   Interface/L3  cumulus (swp1)  IP: 10.0.101.1/30
UP     swp2  1G   1500   Interface/L3  cumulus (swp1)  IP: 10.0.102.1/30
vagrant@spine1:~$ ping 10.0.101.2 -c 2
PING 10.0.101.2 (10.0.101.2) 56(84) bytes of data.
64 bytes from 10.0.101.2: icmp_seq=1 ttl=64 time=0.517 ms
64 bytes from 10.0.101.2: icmp_seq=2 ttl=64 time=0.409 ms

--- 10.0.101.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.409/0.463/0.517/0.054 ms
vagrant@spine1:~$ ping 10.0.102.2 -c 2
PING 10.0.102.2 (10.0.102.2) 56(84) bytes of data.
64 bytes from 10.0.102.2: icmp_seq=1 ttl=64 time=0.588 ms
64 bytes from 10.0.102.2: icmp_seq=2 ttl=64 time=0.726 ms

--- 10.0.102.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.588/0.657/0.726/0.069 ms

spine2 とは直接接続していなく、ルートもないため未到達)

つづいて spine2 にて。

  • インターフェースの確認
vagrant@spine2:~$ sudo net show interface 
State  Name  Spd  MTU    Mode          LLDP            Summary
-----  ----  ---  -----  ------------  --------------  ----------------------
UP     lo    N/A  65536  Loopback                      IP: 127.0.0.1/8
       lo                                              IP: ::1/128
UP     eth0  1G   1500   Mgmt                          IP: 10.0.2.15/24(DHCP)
UP     swp1  1G   1500   Interface/L3  cumulus (swp2)  IP: 10.0.201.1/30
UP     swp2  1G   1500   Interface/L3  cumulus (swp2)  IP: 10.0.202.1/30
vagrant@spine2:~$ ping 10.0.201.2 -c 2
PING 10.0.201.2 (10.0.201.2) 56(84) bytes of data.
64 bytes from 10.0.201.2: icmp_seq=1 ttl=64 time=0.409 ms
64 bytes from 10.0.201.2: icmp_seq=2 ttl=64 time=0.344 ms

--- 10.0.201.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.344/0.376/0.409/0.037 ms
vagrant@spine2:~$ ping 10.0.202.2 -c 2
PING 10.0.202.2 (10.0.202.2) 56(84) bytes of data.
64 bytes from 10.0.202.2: icmp_seq=1 ttl=64 time=1.08 ms
64 bytes from 10.0.202.2: icmp_seq=2 ttl=64 time=0.615 ms

--- 10.0.202.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.615/0.850/1.086/0.237 ms

Cumulus に触るのは今回が初めてなので、あまり大した確認ができていませんが・・

leaf1leaf2 での確認は省略します。


■ まとめ

この記事では、Vagrant と Virtual Box を利用し、4 台の Cumulus VX を構築する手順をまとめました。

ホワイトボックススイッチは、なかなか遠い存在のように思いっていましたが、このように手軽に検証環境を準備できるのとはとてもありがたたいと思いました。

参考

cumulusnetworks.com

docs.cumulusnetworks.com

docs.cumulusnetworks.com

www.apresiatac.jp