项目作者: mweisel

项目描述 :
A procedure for creating a Cisco Nexus 9000v Vagrant box for the libvirt provider.
高级语言: Shell
项目地址: git://github.com/mweisel/cisco-nxos9kv-vagrant-libvirt.git
创建时间: 2019-12-27T06:10:52Z
项目社区:https://github.com/mweisel/cisco-nxos9kv-vagrant-libvirt

开源协议:MIT License

下载


Vagrant

Cisco Nexus 9000v Vagrant box

A procedure for creating a Cisco Nexus 9000v Vagrant box for the libvirt provider.

Prerequisites

Steps

0. Verify the prerequisite tools are installed.

  1. $ which git python ansible libvirtd virsh qemu-system-x86_64 expect telnet vagrant
  2. $ vagrant plugin list
  3. vagrant-libvirt (0.9.0, global)

1. Install the ovmf package.

Ubuntu 18.04

  1. $ sudo apt install ovmf

Arch Linux

  1. $ sudo pacman -S edk2-ovmf

2. Log in and download the Cisco Nexus 9000/3000 Virtual Switch for KVM disk image file from your Cisco account. Save the file to your Downloads directory.

3. Copy (and rename) the disk image file to the /var/lib/libvirt/images directory. Use one of the following examples corresponding to the file version you downloaded:

7.0(3)I7(10)

  1. $ sudo cp $HOME/Downloads/nxosv-final.7.0.3.I7.10.qcow2 /var/lib/libvirt/images/cisco-nxosv.qcow2

9300v 9.3(7)

  1. $ sudo cp $HOME/Downloads/nexus9300v.9.3.7.qcow2 /var/lib/libvirt/images/cisco-nxosv.qcow2

9500v64 10.1(2)

  1. $ sudo cp $HOME/Downloads/nexus9500v64.10.1.2.qcow2 /var/lib/libvirt/images/cisco-nxosv.qcow2

9300v64 10.2(3)(F) lite

  1. $ sudo cp $HOME/Downloads/nexus9300v64-lite.10.2.3.F.qcow2 /var/lib/libvirt/images/cisco-nxosv.qcow2

4. Modify the file ownership and permissions. Note the owner may differ between Linux distributions.

Ubuntu 18.04

  1. $ sudo chown libvirt-qemu:kvm /var/lib/libvirt/images/cisco-nxosv.qcow2
  2. $ sudo chmod u+x /var/lib/libvirt/images/cisco-nxosv.qcow2

Arch Linux

  1. $ sudo chown libvirt-qemu:libvirt-qemu /var/lib/libvirt/images/cisco-nxosv.qcow2
  2. $ sudo chmod u+x /var/lib/libvirt/images/cisco-nxosv.qcow2

5. Create the boxes directory.

  1. $ mkdir -p $HOME/boxes

6. Start the vagrant-libvirt network (if not already started).

  1. $ virsh -c qemu:///system net-list
  2. $ virsh -c qemu:///system net-start vagrant-libvirt

7. Clone this GitHub repo and cd into the directory.

  1. $ git clone https://github.com/mweisel/cisco-nxos9kv-vagrant-libvirt
  2. $ cd cisco-nxos9kv-vagrant-libvirt

8. Get the path to your OVMF (x64) firmware image and runtime variables template.

Ubuntu 18.04

  1. $ dpkg -L ovmf | grep -E 'OVMF_(CODE|VARS)\.fd'

Arch Linux

  1. $ pacman -Ql edk2-ovmf | grep -E 'x64/OVMF_(CODE|VARS)\.fd'

9. Modify the OVMF paths.

Ubuntu 18.04

  1. $ vim files/cisco-nxosv.xml
  1. cisco-nxosv
  2. 10485760
  3. 2
  4. hvm
  5. /usr/share/OVMF/OVMF_CODE.fd
  6. ...
  1. $ vim files/create_box.sh
  1. ...
  2.  
  3. config.vm.provider :libvirt do |domain|
  4. domain.cpus = 2
  5. domain.features = ['acpi']
  6. domain.loader = '/usr/share/OVMF/OVMF_CODE.fd'
  7. domain.memory = 8192
  8. domain.disk_bus = 'sata'
  9. domain.disk_device = 'sda'
  10. domain.disk_driver :cache => 'none'
  11. domain.nic_model_type = 'e1000'
  12. domain.graphics_type = 'none'
  13. end
  14. ...


Arch Linux

  1. $ vim files/cisco-nxosv.xml
  1. cisco-nxosv
  2. 10485760
  3. 2
  4. hvm
  5. /usr/share/edk2-ovmf/x64/OVMF_CODE.fd
  6. ...
  1. $ vim files/create_box.sh
  1. ...
  2.  
  3. config.vm.provider :libvirt do |domain|
  4. domain.cpus = 2
  5. domain.features = ['acpi']
  6. domain.loader = '/usr/share/edk2-ovmf/x64/OVMF_CODE.fd'
  7. domain.memory = 8192
  8. domain.disk_bus = 'sata'
  9. domain.disk_device = 'sda'
  10. domain.disk_driver :cache => 'none'
  11. domain.nic_model_type = 'e1000'
  12. domain.graphics_type = 'none'
  13. end
  14. ...

10. Modify/Verify the variable values in the boot_image.exp script file. Use the following table and examples for guidance:

Disk image nxos is_64bit is_lite
nxosv-final.7.0.3.I7.10.qcow2 7.0.3.I7.10 0 0
nexus9300v.9.3.7.qcow2 9.3.7 0 0
nexus9500v64.10.1.2.qcow2 10.1.2 1 0
nexus9300v64-lite.10.2.3.F.qcow2 10.2.3.F 1 1


  1. $ vim files/boot_image.exp

7.0(3)I7(10)

  1. set timeout 360
  2. set prompt "(>|#) $"
  3. set nxos "7.0.3.I7.10"
  4. set is_64bit 0
  5. set is_lite 0
  6. log_file -noappend "~/nxosv-console.explog"
  7.  
  8. ...

9300v 9.3(7)

  1. set timeout 360
  2. set prompt "(>|#) $"
  3. set nxos "9.3.7"
  4. set is_64bit 0
  5. set is_lite 0
  6. log_file -noappend "~/nxosv-console.explog"
  7.  
  8. ...

9500v64 10.1(2)

  1. set timeout 360
  2. set prompt "(>|#) $"
  3. set nxos "10.1.2"
  4. set is_64bit 1
  5. set is_lite 0
  6. log_file -noappend "~/nxosv-console.explog"
  7.  
  8. ...

9300v64 10.2(3)(F) lite

  1. set timeout 360
  2. set prompt "(>|#) $"
  3. set nxos "10.2.3.F"
  4. set is_64bit 1
  5. set is_lite 1
  6. log_file -noappend "~/nxosv-console.explog"
  7.  
  8. ...

11. Run the Ansible playbook.

  1. $ ansible-playbook main.yml

12. Copy (and rename) the Vagrant box artifact to the boxes directory.

7.0(3)I7(10)

  1. $ cp cisco-nxosv.box $HOME/boxes/cisco-nexus9000v-7.0.3.I7.10.box

9300v 9.3(7)

  1. $ cp cisco-nxosv.box $HOME/boxes/cisco-nexus9300v-9.3.7.box

9500v64 10.1(2)

  1. $ cp cisco-nxosv.box $HOME/boxes/cisco-nexus9500v-10.1.2.box

9300v64 10.2(3)(F) lite

  1. $ cp cisco-nxosv.box $HOME/boxes/cisco-nexus9300v-10.2.3.F-lite.box

13. Copy the box metadata file to the boxes directory.

7.0(3)I7(10)

  1. $ cp ./files/cisco-nexus9000v.json $HOME/boxes/

9300v 9.3(7)

  1. $ cp ./files/cisco-nexus9300v.json $HOME/boxes/

9500v64 10.1(2)

  1. $ cp ./files/cisco-nexus9500v.json $HOME/boxes/

9300v64 10.2(3)(F) lite

  1. $ cp ./files/cisco-nexus9300v-lite.json $HOME/boxes/

14. Change the current working directory to boxes.

  1. $ cd $HOME/boxes

15. Substitute the HOME placeholder string in the box metadata file.

7.0(3)I7(10)

  1. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9000v.json
  2. "url": "file://HOME/boxes/cisco-nexus9000v-VER.box"
  3.  
  4. $ sed -i "s|HOME|${HOME}|" cisco-nexus9000v.json
  5.  
  6. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9000v.json
  7. "url": "file:///home/marc/boxes/cisco-nexus9000v-VER.box"

9300v 9.3(7)

  1. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9300v.json
  2. "url": "file://HOME/boxes/cisco-nexus9300v-VER.box"
  3.  
  4. $ sed -i "s|HOME|${HOME}|" cisco-nexus9300v.json
  5.  
  6. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9300v.json
  7. "url": "file:///home/marc/boxes/cisco-nexus9300v-VER.box"

9500v64 10.1(2)

  1. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9500v.json
  2. "url": "file://HOME/boxes/cisco-nexus9500v-VER.box"
  3.  
  4. $ sed -i "s|HOME|${HOME}|" cisco-nexus9500v.json
  5.  
  6. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9500v.json
  7. "url": "file:///home/marc/boxes/cisco-nexus9500v-VER.box"

9300v64 10.2(3)(F) lite

  1. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9300v-lite.json
  2. "url": "file://HOME/boxes/cisco-nexus9300v-VER-lite.box"
  3.  
  4. $ sed -i "s|HOME|${HOME}|" cisco-nexus9300v-lite.json
  5.  
  6. $ awk '/url/{gsub(/^ */,"");print}' cisco-nexus9300v-lite.json
  7. "url": "file:///home/marc/boxes/cisco-nexus9300v-VER-lite.box"

16. Also, substitute the VER placeholder string with the Cisco NX-OS version.

7.0(3)I7(10)

  1. $ awk '/VER/{gsub(/^ */,"");print}' cisco-nexus9000v.json
  2. "version": "VER",
  3. "url": "file:///home/marc/boxes/cisco-nexus9000v-VER.box"
  4.  
  5. $ sed -i 's/VER/7.0.3.I7.10/g' cisco-nexus9000v.json
  6.  
  7. $ awk '/\|url/{gsub(/^ */,"");print}' cisco-nexus9000v.json
  8. "version": "7.0.3.I7.10",
  9. "url": "file:///home/marc/boxes/cisco-nexus9000v-7.0.3.I7.10.box"

9300v 9.3(7)

  1. $ awk '/VER/{gsub(/^ */,"");print}' cisco-nexus9300v.json
  2. "version": "VER",
  3. "url": "file:///home/marc/boxes/cisco-nexus9300v-VER.box"
  4.  
  5. $ sed -i 's/VER/9.3.7/g' cisco-nexus9300v.json
  6.  
  7. $ awk '/\|url/{gsub(/^ */,"");print}' cisco-nexus9300v.json
  8. "version": "9.3.7",
  9. "url": "file:///home/marc/boxes/cisco-nexus9300v-9.3.7.box"

9500v64 10.1(2)

  1. $ awk '/VER/{gsub(/^ */,"");print}' cisco-nexus9500v.json
  2. "version": "VER",
  3. "url": "file:///home/marc/boxes/cisco-nexus9500v-VER.box"
  4.  
  5. $ sed -i 's/VER/10.1.2/g' cisco-nexus9500v.json
  6.  
  7. $ awk '/\|url/{gsub(/^ */,"");print}' cisco-nexus9500v.json
  8. "version": "10.1.2",
  9. "url": "file:///home/marc/boxes/cisco-nexus9500v-10.1.2.box"

9300v64 10.2(3)(F) lite

  1. $ awk '/VER/{gsub(/^ */,"");print}' cisco-nexus9300v-lite.json
  2. "version": "VER",
  3. "url": "file:///home/marc/boxes/cisco-nexus9300v-VER-lite.box"
  4.  
  5. $ sed -i 's/VER/10.2.3.F/g' cisco-nexus9300v-lite.json
  6.  
  7. $ awk '/\|url/{gsub(/^ */,"");print}' cisco-nexus9300v-lite.json
  8. "version": "10.2.3.F",
  9. "url": "file:///home/marc/boxes/cisco-nexus9300v-10.2.3.F-lite.box"

17. Add the Vagrant box to the local inventory.

7.0(3)I7(10)

  1. $ vagrant box add --box-version 7.0.3.I7.10 cisco-nexus9000v.json

9300v 9.3(7)

  1. $ vagrant box add --box-version 9.3.7 cisco-nexus9300v.json

9500v64 10.1(2)

  1. $ vagrant box add --box-version 10.1.2 cisco-nexus9500v.json

9300v64 10.2(3)(F) lite

  1. $ vagrant box add --box-version 10.2.3.F cisco-nexus9300v-lite.json

Debug

View the telnet session output for the expect task:

  1. $ tail -f ~/nxosv-console.explog

License

This project is licensed under the MIT License - see the LICENSE file for details