Skip to content

Commit

Permalink
Add support for Cisco C9800-CL platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
Subba Srinivas authored and glennmatthews committed Feb 18, 2019
1 parent 40bff30 commit 6bc95e6
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to `Semantic Versioning`_.
`Unreleased`_
-------------

**Added**

- COT now recognizes and validates the Cisco C9800-CL platform.

**Removed**

- Discontinued support for Python 3.3 as it has been retired since 2017.
Expand Down
3 changes: 2 additions & 1 deletion COPYRIGHT.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Common OVF Tool (COT)

Copyright (c) 2013-2018 by the following developers:
Copyright (c) 2013-2019 by the following developers:
Glenn F. Matthews
Kevin A. Keim
Quol Fontana
Jusheng Feng
Subba Srinivas
4 changes: 3 additions & 1 deletion COT/platforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# October 2013, Glenn F. Matthews
# Copyright (c) 2013-2017 the COT project developers.
# Copyright (c) 2013-2017, 2019 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.
#
Expand Down Expand Up @@ -41,6 +41,7 @@
COT.platforms.cisco_iosxrv_9000
COT.platforms.cisco_nexus_9000v
COT.platforms.cisco_nxosv
COT.platforms.cisco_c9800cl
"""

import logging
Expand All @@ -54,6 +55,7 @@
from .cisco_iosxrv_9000 import IOSXRv9000
from .cisco_nexus_9000v import Nexus9000v
from .cisco_nxosv import NXOSv
from .cisco_c9800cl import C9800CL

logger = logging.getLogger(__name__)

Expand Down
85 changes: 85 additions & 0 deletions COT/platforms/cisco_c9800cl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# February 2019, Subba Srinivas
# Copyright (c) 2019 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 C9800-CL Wireless Lan Controller."""

import logging

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

logger = logging.getLogger(__name__)


class C9800CL(Platform):
"""Platform-specific logic for Cisco C9800-CL platform."""

PLATFORM_NAME = "Cisco C9800-CL"

CONFIG_TEXT_FILE = 'iosxe_config.txt'
LITERAL_CLI_STRING = 'ios-config'
# C9800CL 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(4, 10),
Hardware.memory: ValidRange(8192, 32768),
Hardware.nic_count: ValidRange(1, 3),
Hardware.serial_count: ValidRange(0, 2),
})

def controller_type_for_device(self, device_type):
"""C9800CL 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(C9800CL, self).controller_type_for_device(
device_type)

def guess_nic_name(self, nic_number):
"""GigabitEthernet1, GigabitEthernet2, etc.
Args:
nic_number (int): Nth NIC to name.
Returns:
* "GigabitEthernet1"
* "GigabitEthernet2"
* etc.
"""
return "GigabitEthernet" + str(nic_number)

def validate_cpu_count(self, cpus):
"""C9800CL supports 4,6 or 10 CPUs.
Args:
cpus (int): Number of CPUs.
Raises:
ValueTooLowError: if ``cpus`` is less than 4
ValueTooHighError: if ``cpus`` is more than 10
ValueUnsupportedError: if ``cpus`` is a value other than 4, 6, 10
"""
super(C9800CL, self).validate_cpu_count(cpus)
if cpus not in [4, 6, 10]:
raise ValueUnsupportedError("CPUs", cpus, [4, 6, 10])


Platform.PRODUCT_PLATFORM_MAP['com.cisco.vwlc'] = C9800CL
93 changes: 93 additions & 0 deletions COT/platforms/tests/test_cisco_c9800cl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# test_cisco_c9800cl.py - Unit test cases for Cisco C9800-CL platform
#
# February 2019, Subba Srinivas
# Copyright (c) 2019 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 C9800-CL platform."""

from COT.platforms.cisco_c9800cl import C9800CL
from COT.data_validation import (
ValueUnsupportedError, ValueTooLowError, ValueTooHighError
)
from COT.platforms.tests import PlatformTests


class TestC9800CL(PlatformTests.PlatformTest):
"""Test cases for Cisco C9800CL platform handling."""

cls = C9800CL
product_string = "com.cisco.vwlc"

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")

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

def test_memory_amount(self):
"""Test RAM allocation limits."""
self.assertRaises(ValueTooLowError,
self.ins.validate_memory_amount, 8191)
self.ins.validate_memory_amount(8192)
self.ins.validate_memory_amount(32768)
self.assertRaises(ValueTooHighError,
self.ins.validate_memory_amount, 32769)

def test_nic_count(self):
"""Test NIC range limits."""
self.assertRaises(ValueTooLowError, self.ins.validate_nic_count, 0)
self.ins.validate_nic_count(1)
self.ins.validate_nic_count(2)
self.assertRaises(ValueTooHighError, self.ins.validate_nic_count, 4)

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)
4 changes: 4 additions & 0 deletions docs/COT.platforms.cisco_c9800cl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``COT.platforms.cisco_c9800cl`` module
======================================

.. automodule:: COT.platforms.cisco_c9800cl

0 comments on commit 6bc95e6

Please sign in to comment.