Ejemplo n.º 1
0
def do_conversion(topology_def, args):
    """
    Convert the topology

    :param dict topology_def: Dict containing topology file and snapshot bool
    """
    # Create a new instance of the the Converter
    gns3_conv = Converter(topology_def['file'], args.debug)
    # Read the old topology
    old_top = gns3_conv.read_topology()
    new_top = JSONTopology()

    # Process the sections
    (topology) = gns3_conv.process_topology(old_top)

    # Generate the nodes
    new_top.nodes = gns3_conv.generate_nodes(topology)
    # Generate the links
    new_top.links = gns3_conv.generate_links(new_top.nodes)

    new_top.notes = gns3_conv.generate_notes(topology['artwork']['NOTE'])
    new_top.shapes = gns3_conv.generate_shapes(topology['artwork']['SHAPE'])
    new_top.images = gns3_conv.generate_images(topology['artwork']['PIXMAP'])

    # Enter topology name
    new_top.name = name(args)

    # Save the new topology
    save(args, gns3_conv, new_top, topology_def['snapshot'])
Ejemplo n.º 2
0
def do_conversion(topology_def, args):
    """
    Convert the topology

    :param dict topology_def: Dict containing topology file and snapshot bool
    """
    # Create a new instance of the the Converter
    gns3_conv = Converter(topology_def['file'], args.debug)
    # Read the old topology
    old_top = gns3_conv.read_topology()
    new_top = JSONTopology()

    # Process the sections
    (topology) = gns3_conv.process_topology(old_top)

    # Generate the nodes
    new_top.nodes = gns3_conv.generate_nodes(topology)
    # Generate the links
    new_top.links = gns3_conv.generate_links(new_top.nodes)

    new_top.notes = gns3_conv.generate_notes(topology['artwork']['NOTE'])
    new_top.shapes = gns3_conv.generate_shapes(topology['artwork']['SHAPE'])
    new_top.images = gns3_conv.generate_images(topology['artwork']['PIXMAP'])

    # Enter topology name
    new_top.name = name(args)

    # Save the new topology
    save(args, gns3_conv, new_top, topology_def['snapshot'])
Ejemplo n.º 3
0
class TestConverter(unittest.TestCase):
    def setUp(self):
        if os.path.isfile(os.path.abspath('./tests/topology.net')):
            self._topology = os.path.abspath('./tests/topology.net')
        else:
            self._topology = os.path.abspath('./topology.net')
        self.app = Converter(self._topology)

    def test_get_topology(self):
        topo_file = self.app.topology
        exp_res = (os.path.abspath('./tests/topology.net'),
                   os.path.abspath('./topology.net'))

        self.assertIn(topo_file, exp_res)

    def test_read_topology(self):
        self.maxDiff = None
        topology = self.app.read_topology()
        self.assertIsInstance(topology, ConfigObj)
        self.assertDictEqual(tests.data.old_top, topology)

    def test_get_sections(self):
        topology = self.app.read_topology()
        sections = self.app.get_sections(topology)
        self.assertEqual(['127.0.0.1:7200', 'GNS3-DATA'], sections)

    def test_process_topology(self):
        topology = self.app.read_topology()
        (processed) = self.app.process_topology(topology)
        self.assertDictEqual(tests.data.devices, processed['devices'])
        self.assertListEqual(tests.data.conf, processed['conf'])
        self.assertDictEqual(tests.data.artwork, processed['artwork'])

    def test_generate_shapes(self):
        shapes = {'1': {'type': 'ellipse', 'x': 20, 'y': 25, 'width': 500,
                        'height': 250, 'border_style': 2},
                  '2': {'type': 'rectangle', 'x': 40, 'y': 250, 'width': 250,
                        'height': 275, 'border_style': 2}}
        exp_res = {'ellipse': [{'x': 20, 'y': 25, 'width': 500,
                                'height': 250, 'border_style': 2}],
                   'rectangle': [{'x': 40, 'y': 250, 'width': 250,
                                  'height': 275, 'border_style': 2}]}
        res = self.app.generate_shapes(shapes)
        self.assertDictEqual(res, exp_res)

    def test_generate_notes(self):
        notes = {'1': {'text': 'SomeText', 'x': 20, 'y': 25,
                       'color': '#1a1a1a'}}
        exp_res = [{'text': 'SomeText', 'x': 20, 'y': 25, 'color': '#1a1a1a'}]

        res = self.app.generate_notes(notes)
        self.assertListEqual(res, exp_res)
Ejemplo n.º 4
0
def do_conversion(topology_def,
                  topology_name,
                  output_dir=None,
                  debug=False,
                  quiet=False):
    """
    Convert the topology

    :param dict topology_def: Dict containing topology file and snapshot bool.
                              For example:
                              ``{'file': filename, 'snapshot': False}``
    :param str topology_name: The name of the topology
    :param str output_dir: The directory in which to output the topology.
                           (Default: None)
    :param bool debug: Enable debugging (Default: False)
    """
    # Create a new instance of the the Converter
    gns3_conv = Converter(topology_def['file'], debug)
    # Read the old topology
    old_top = gns3_conv.read_topology()
    new_top = JSONTopology()

    # Process the sections
    (topology) = gns3_conv.process_topology(old_top)

    # Generate the nodes
    new_top.nodes = gns3_conv.generate_nodes(topology)
    # Generate the links
    new_top.links = gns3_conv.generate_links(new_top.nodes)

    new_top.notes = gns3_conv.generate_notes(topology['artwork']['NOTE'])
    new_top.shapes = gns3_conv.generate_shapes(topology['artwork']['SHAPE'])
    new_top.images = gns3_conv.generate_images(topology['artwork']['PIXMAP'])

    # Enter topology name
    new_top.name = topology_name

    # Save the new topology
    save(output_dir, gns3_conv, new_top, topology_def['snapshot'], quiet)
Ejemplo n.º 5
0
def do_conversion(topology_def, topology_name, output_dir=None, debug=False,
                  quiet=False):
    """
    Convert the topology

    :param dict topology_def: Dict containing topology file and snapshot bool.
                              For example:
                              ``{'file': filename, 'snapshot': False}``
    :param str topology_name: The name of the topology
    :param str output_dir: The directory in which to output the topology.
                           (Default: None)
    :param bool debug: Enable debugging (Default: False)
    """
    # Create a new instance of the the Converter
    gns3_conv = Converter(topology_def['file'], debug)
    # Read the old topology
    old_top = gns3_conv.read_topology()
    new_top = JSONTopology()

    # Process the sections
    (topology) = gns3_conv.process_topology(old_top)

    # Generate the nodes
    new_top.nodes = gns3_conv.generate_nodes(topology)
    # Generate the links
    new_top.links = gns3_conv.generate_links(new_top.nodes)

    new_top.notes = gns3_conv.generate_notes(topology['artwork']['NOTE'])
    new_top.shapes = gns3_conv.generate_shapes(topology['artwork']['SHAPE'])
    new_top.images = gns3_conv.generate_images(topology['artwork']['PIXMAP'])

    # Enter topology name
    new_top.name = topology_name

    # Save the new topology
    save(output_dir, gns3_conv, new_top, topology_def['snapshot'], quiet)
Ejemplo n.º 6
0
 def setUp(self):
     if os.path.isfile(os.path.abspath('./tests/topology.net')):
         self._topology = os.path.abspath('./tests/topology.net')
     else:
         self._topology = os.path.abspath('./topology.net')
     self.app = Converter(self._topology)
Ejemplo n.º 7
0
class TestConverter(unittest.TestCase):
    def setUp(self):
        if os.path.isfile(os.path.abspath('./tests/topology.net')):
            self._topology = os.path.abspath('./tests/topology.net')
        else:
            self._topology = os.path.abspath('./topology.net')
        self.app = Converter(self._topology)

    def test_read_topology(self):
        self.maxDiff = None
        topology = self.app.read_topology()
        self.assertIsInstance(topology, ConfigObj)
        self.assertDictEqual(tests.data.old_top, topology)

    def test_get_sections(self):
        topology = self.app.read_topology()
        sections = self.app.get_sections(topology)
        self.assertEqual(['127.0.0.1:7200', 'GNS3-DATA'], sections)

    def test_process_topology(self):
        topology = self.app.read_topology()
        (processed) = self.app.process_topology(topology)
        self.assertDictEqual(tests.data.devices, processed['devices'])
        self.assertListEqual(tests.data.conf, processed['conf'])
        self.assertDictEqual(tests.data.artwork, processed['artwork'])

    def test_generate_shapes(self):
        shapes = {
            '1': {
                'type': 'ellipse',
                'x': 20,
                'y': 25,
                'width': 500,
                'height': 250,
                'border_style': 2
            },
            '2': {
                'type': 'rectangle',
                'x': 40,
                'y': 250,
                'width': 250,
                'height': 275,
                'border_style': 2
            }
        }
        exp_res = {
            'ellipse': [{
                'x': 20,
                'y': 25,
                'width': 500,
                'height': 250,
                'border_style': 2
            }],
            'rectangle': [{
                'x': 40,
                'y': 250,
                'width': 250,
                'height': 275,
                'border_style': 2
            }]
        }
        res = self.app.generate_shapes(shapes)
        self.assertDictEqual(res, exp_res)

    def test_generate_notes(self):
        notes = {
            '1': {
                'text': 'SomeText',
                'x': 20,
                'y': 25,
                'color': '#1a1a1a'
            }
        }
        exp_res = [{'text': 'SomeText', 'x': 20, 'y': 25, 'color': '#1a1a1a'}]

        res = self.app.generate_notes(notes)
        self.assertListEqual(res, exp_res)
Ejemplo n.º 8
0
class TestConverter(unittest.TestCase):
    def setUp(self):
        if os.path.isfile(os.path.abspath('./tests/topology.net')):
            self._topology = os.path.abspath('./tests/topology.net')
        else:
            self._topology = os.path.abspath('./topology.net')
        self.app = Converter(self._topology)

    def test_get_topology(self):
        topo_file = self.app.topology
        exp_res = (os.path.abspath('./tests/topology.net'),
                   os.path.abspath('./topology.net'))

        self.assertIn(topo_file, exp_res)

    def test_read_topology(self):
        self.maxDiff = None
        topology = self.app.read_topology()
        self.assertIsInstance(topology, ConfigObj)
        self.assertDictEqual(tests.data.old_top, topology)

    def test_get_sections(self):
        topology = self.app.read_topology()
        sections = self.app.get_sections(topology)
        self.assertEqual(['127.0.0.1:7200', 'GNS3-DATA'], sections)

    def test_process_topology(self):
        topology = self.app.read_topology()
        (processed) = self.app.process_topology(topology)
        self.assertDictEqual(tests.data.devices, processed['devices'])
        self.assertListEqual(tests.data.conf, processed['conf'])
        self.assertDictEqual(tests.data.artwork, processed['artwork'])

    def test_generate_shapes(self):
        shapes = {
            '1': {
                'type': 'ellipse',
                'x': 20,
                'y': 25,
                'width': 500,
                'height': 250,
                'border_style': 2
            },
            '2': {
                'type': 'rectangle',
                'x': 40,
                'y': 250,
                'width': 250,
                'height': 275,
                'border_style': 2
            }
        }
        exp_res = {
            'ellipse': [{
                'x': 20,
                'y': 25,
                'width': 500,
                'height': 250,
                'border_style': 2
            }],
            'rectangle': [{
                'x': 40,
                'y': 250,
                'width': 250,
                'height': 275,
                'border_style': 2
            }]
        }
        res = self.app.generate_shapes(shapes)
        self.assertDictEqual(res, exp_res)

    def test_generate_notes(self):
        notes = {
            '1': {
                'text': 'SomeText',
                'x': 20,
                'y': 25,
                'color': '#1a1a1a'
            }
        }
        exp_res = [{'text': 'SomeText', 'x': 20, 'y': 25, 'color': '#1a1a1a'}]

        res = self.app.generate_notes(notes)
        self.assertListEqual(res, exp_res)

    def test_generate_nodes(self):
        topology = {}
        topology['conf'] = [{
            'sparsemem': True,
            'ghostios': True,
            'idlepc': '0x60bec828',
            'ram': 128,
            'model': 'c3725',
            'image': 'c3725-adventerprisek9-mz.124-15.T5.image'
        }]
        topology['devices'] = {
            'GooglISP': {
                'model': 'c7200',
                'aux': 2512,
                'hx': 19.5,
                'z': 1.0,
                'type': 'Router',
                'node_id': 11,
                'p1/0': 'VerISPon p1/0',
                'hv_id': 3,
                'x': -261.643648086,
                'cnfg': 'configs\\GooglISP.cfg',
                'f0/0': 'SW1 f0/0',
                'y': -419.773080371,
                'console': 2012,
                'from': 'ROUTER',
                'hy': -25.0,
                'slot0': 'C7200-IO-FE',
                'desc': 'Router',
                'slot1': 'PA-POS-OC3'
            }
        }

        config = self.app.generate_nodes(topology)
        self.assertEqual(self.app.datas,
                         [{
                             'new': 'c7200_i11_rom',
                             'old': 'working/c7200_GooglISP_rom'
                         }, {
                             'new': 'c7200_i11_nvram',
                             'old': 'working/c7200_GooglISP_nvram'
                         }, {
                             'new': 'c7200_i11_bootflash',
                             'old': 'working/c7200_GooglISP_bootflash'
                         }, {
                             'new': 'c7200_i11_disk0',
                             'old': 'working/c7200_GooglISP_disk0'
                         }])
Ejemplo n.º 9
0
 def setUp(self):
     if os.path.isfile(os.path.abspath('./tests/topology.net')):
         self._topology = os.path.abspath('./tests/topology.net')
     else:
         self._topology = os.path.abspath('./topology.net')
     self.app = Converter(self._topology)