Skip to content

Add support for Cisco Catalyst 8000v #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Kevin A. Keim
Quol Fontana
Jusheng Feng
Subba Srinivas
Will Lester
2 changes: 2 additions & 0 deletions COT/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

COT.platforms.platform
COT.platforms.cisco_csr1000v
COT.platforms.cisco_c8000v
COT.platforms.cisco_iosv
COT.platforms.cisco_iosxrv
COT.platforms.cisco_iosxrv_9000
Expand All @@ -50,6 +51,7 @@

from .platform import Platform
from .cisco_csr1000v import CSR1000V
from .cisco_c8000v import C8000V
from .cisco_iosv import IOSv
from .cisco_iosxrv import IOSXRv, IOSXRvRP, IOSXRvLC
from .cisco_iosxrv_9000 import IOSXRv9000
Expand Down
93 changes: 93 additions & 0 deletions COT/platforms/cisco_c8000v.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# September 2016, Glenn F. Matthews
# Copyright (c) 2013-2017 the COT project developers.
# See the COPYRIGHT.txt file at the top-level directory of this distribution
# and at https://github.com/glennmatthews/cot/blob/master/COPYRIGHT.txt.
#
# This file is part of the Common OVF Tool (COT) project.
# It is subject to the license terms in the LICENSE.txt file found in the
# top-level directory of this distribution and at
# https://github.com/glennmatthews/cot/blob/master/LICENSE.txt. No part
# of COT, including this file, may be copied, modified, propagated, or
# distributed except according to the terms contained in the LICENSE.txt file.

"""Platform logic for the Cisco C8000V virtual router."""

import logging

from COT.platforms.platform import Platform, Hardware
from COT.data_validation import ValueUnsupportedError, ValidRange

logger = logging.getLogger(__name__)


class C8000V(Platform):
"""Platform-specific logic for Cisco C8000V platform."""

PLATFORM_NAME = "Cisco C8000V"

CONFIG_TEXT_FILE = 'iosxe_config.txt'
LITERAL_CLI_STRING = 'ios-config'
# CSR1000v doesn't 'officially' support E1000, but it mostly works
SUPPORTED_NIC_TYPES = ["E1000", "virtio", "VMXNET3"]

HARDWARE_LIMITS = Platform.HARDWARE_LIMITS.copy()
HARDWARE_LIMITS.update({
Hardware.cpus: ValidRange(1, 8), # but see below
Hardware.memory: ValidRange(4096, 8192),
Hardware.nic_count: ValidRange(3, 8),
Hardware.serial_count: ValidRange(0, 2),
})

def controller_type_for_device(self, device_type):
"""C8000V uses SCSI for hard disks and IDE for CD-ROMs.

Args:
device_type (str): 'harddisk' or 'cdrom'
Returns:
str: 'ide' for CD-ROM, 'scsi' for hard disk
"""
if device_type == 'harddisk':
return 'scsi'
elif device_type == 'cdrom':
return 'ide'
else:
return super(C8000V, self).controller_type_for_device(
device_type)

def guess_nic_name(self, nic_number):
"""GigabitEthernet1, GigabitEthernet2, etc.

.. warning::
In all current CSR releases, NIC names start at "GigabitEthernet1".
Some early versions started at "GigabitEthernet0" but we don't
support that.

Args:
nic_number (int): Nth NIC to name.
Returns:
str: such as

* "GigabitEthernet1"
* "GigabitEthernet2"
* etc.
"""
return "GigabitEthernet" + str(nic_number)

def validate_cpu_count(self, cpus):
"""C8000V supports 1, 2, 4, or 8 CPUs.

Args:
cpus (int): Number of CPUs.

Raises:
ValueTooLowError: if ``cpus`` is less than 1
ValueTooHighError: if ``cpus`` is more than 8
ValueUnsupportedError: if ``cpus`` is an unsupported value
between 1 and 8
"""
super(C8000V, self).validate_cpu_count(cpus)
if cpus not in [1, 2, 4, 8]:
raise ValueUnsupportedError("CPUs", cpus, [1, 2, 4, 8])


Platform.PRODUCT_PLATFORM_MAP['com.cisco.c8000v'] = C8000V
99 changes: 99 additions & 0 deletions COT/platforms/tests/test_cisco_c8000v.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# test_cisco_c8000v.py - Unit test cases for Cisco C8000V platform
#
# October 2016, Glenn F. Matthews
# Copyright (c) 2014-2017 the COT project developers.
# See the COPYRIGHT.txt file at the top-level directory of this distribution
# and at https://github.com/glennmatthews/cot/blob/master/COPYRIGHT.txt.
#
# This file is part of the Common OVF Tool (COT) project.
# It is subject to the license terms in the LICENSE.txt file found in the
# top-level directory of this distribution and at
# https://github.com/glennmatthews/cot/blob/master/LICENSE.txt. No part
# of COT, including this file, may be copied, modified, propagated, or
# distributed except according to the terms contained in the LICENSE.txt file.

"""Unit test cases for C8000V platform."""

from COT.platforms.cisco_c8000v import C8000V
from COT.data_validation import (
ValueUnsupportedError, ValueTooLowError, ValueTooHighError
)
from COT.platforms.tests import PlatformTests


class TestC8000V(PlatformTests.PlatformTest):
"""Test cases for Cisco C8000V platform handling."""

cls = C8000V
product_string = "com.cisco.c8000v"

def test_controller_type_for_device(self):
"""Test platform-specific logic for device controllers."""
self.assertEqual(self.ins.controller_type_for_device('harddisk'),
'scsi')
self.assertEqual(self.ins.controller_type_for_device('cdrom'),
'ide')
# fallthrough to parent class
self.assertEqual(self.ins.controller_type_for_device('dvd'),
'ide')

def test_nic_name(self):
"""Test NIC name construction."""
self.assertEqual(self.ins.guess_nic_name(1),
"GigabitEthernet1")
self.assertEqual(self.ins.guess_nic_name(2),
"GigabitEthernet2")
self.assertEqual(self.ins.guess_nic_name(3),
"GigabitEthernet3")
self.assertEqual(self.ins.guess_nic_name(4),
"GigabitEthernet4")

def test_cpu_count(self):
"""Test CPU count limits."""
self.assertRaises(ValueTooLowError, self.ins.validate_cpu_count, 0)
self.ins.validate_cpu_count(1)
self.ins.validate_cpu_count(2)
self.assertRaises(ValueUnsupportedError,
self.ins.validate_cpu_count, 3)
self.ins.validate_cpu_count(4)
self.assertRaises(ValueUnsupportedError,
self.ins.validate_cpu_count, 5)
self.assertRaises(ValueUnsupportedError,
self.ins.validate_cpu_count, 6)
self.assertRaises(ValueUnsupportedError,
self.ins.validate_cpu_count, 7)
self.ins.validate_cpu_count(8)
self.assertRaises(ValueTooHighError, self.ins.validate_cpu_count, 9)

def test_memory_amount(self):
"""Test RAM allocation limits."""
self.assertRaises(ValueTooLowError,
self.ins.validate_memory_amount, 2559)
self.ins.validate_memory_amount(2560)
self.ins.validate_memory_amount(8192)
self.assertRaises(ValueTooHighError,
self.ins.validate_memory_amount, 8193)

def test_nic_count(self):
"""Test NIC range limits."""
self.assertRaises(ValueTooLowError, self.ins.validate_nic_count, 2)
self.ins.validate_nic_count(3)
self.ins.validate_nic_count(26)
self.assertRaises(ValueTooHighError, self.ins.validate_nic_count, 27)

def test_nic_type(self):
"""Test NIC valid and invalid types."""
self.assertRaises(ValueUnsupportedError,
self.ins.validate_nic_type, "E1000e")
self.ins.validate_nic_type("E1000")
self.assertRaises(ValueUnsupportedError,
self.ins.validate_nic_type, "PCNet32")
self.ins.validate_nic_type("virtio")
self.ins.validate_nic_type("VMXNET3")

def test_serial_count(self):
"""Test serial port range limits."""
self.assertRaises(ValueTooLowError, self.ins.validate_serial_count, -1)
self.ins.validate_serial_count(0)
self.ins.validate_serial_count(2)
self.assertRaises(ValueTooHighError, self.ins.validate_serial_count, 3)
Loading