Esempio 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'])
Esempio 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'])
Esempio n. 3
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)
Esempio 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)
Esempio n. 5
0
 def setUp(self):
     self.app = JSONTopology()
Esempio n. 6
0
class TestJSONTopology(unittest.TestCase):
    def setUp(self):
        self.app = JSONTopology()

    def test_nodes(self):
        self.assertListEqual(self.app.nodes, [])
        self.app.nodes = [{'node_id': 1}]
        self.assertListEqual(self.app.nodes, [{'node_id': 1}])

    def test_links(self):
        self.assertListEqual(self.app.links, [])
        self.app.links = [{'id': 1}]
        self.assertListEqual(self.app.links, [{'id': 1}])

    def test_notes(self):
        self.assertListEqual(self.app.notes, [])
        self.app.notes = [{'id': 1}]
        self.assertListEqual(self.app.notes, [{'id': 1}])

    def test_shapes(self):
        self.assertDictEqual(self.app.shapes,
                             {'ellipse': None, 'rectangle': None})
        self.app.shapes = {'ellipse': {'id': 1},
                           'rectangle': {'id': 2}}
        self.assertDictEqual(self.app.shapes, {'ellipse': {'id': 1},
                                               'rectangle': {'id': 2}})

    def test_images(self):
        self.assertListEqual(self.app.images, [])
        self.app.images = [{'id': 1}]
        self.assertListEqual(self.app.images, [{'id': 1}])

    def test_servers(self):
        exp_res = [{'host': '127.0.0.1', 'id': 1, 'local': True, 'port': 8000}]
        self.assertListEqual(self.app.servers, exp_res)
        self.app.servers = [{'host': '127.0.0.1', 'id': 2, 'local': True,
                            'port': 8001}]
        exp_res = [{'host': '127.0.0.1', 'id': 2, 'local': True,
                    'port': 8001}]
        self.assertListEqual(self.app.servers, exp_res)

    def test_name(self):
        self.assertIsNone(self.app.name)
        self.app.name = 'Super Topology'
        self.assertEqual(self.app.name, 'Super Topology')

    def test_get_topology(self):
        exp_res = {'name': None,
                   'resources_type': 'local',
                   'topology': {'servers': [{'host': '127.0.0.1', 'id': 1,
                                             'local': True, 'port': 8000}]},
                   'type': 'topology',
                   'version': '1.0'}

        result = self.app.get_topology()
        self.assertDictEqual(result, exp_res)

    def test_get_vboxes(self):
        # TODO
        pass

    def test_get_qemus(self):
        # TODO
        pass
Esempio n. 7
0
 def setUp(self):
     self.app = JSONTopology()
Esempio n. 8
0
class TestJSONTopology(unittest.TestCase):
    def setUp(self):
        self.app = JSONTopology()

    def test_nodes(self):
        self.assertListEqual(self.app.nodes, [])
        self.app.nodes = [{'node_id': 1}]
        self.assertListEqual(self.app.nodes, [{'node_id': 1}])

    def test_links(self):
        self.assertListEqual(self.app.links, [])
        self.app.links = [{'id': 1}]
        self.assertListEqual(self.app.links, [{'id': 1}])

    def test_notes(self):
        self.assertListEqual(self.app.notes, [])
        self.app.notes = [{'id': 1}]
        self.assertListEqual(self.app.notes, [{'id': 1}])

    def test_shapes(self):
        self.assertDictEqual(self.app.shapes, {
            'ellipse': None,
            'rectangle': None
        })
        self.app.shapes = {'ellipse': {'id': 1}, 'rectangle': {'id': 2}}
        self.assertDictEqual(self.app.shapes, {
            'ellipse': {
                'id': 1
            },
            'rectangle': {
                'id': 2
            }
        })

    def test_images(self):
        self.assertListEqual(self.app.images, [])
        self.app.images = [{'id': 1}]
        self.assertListEqual(self.app.images, [{'id': 1}])

    def test_servers(self):
        exp_res = [{'host': '127.0.0.1', 'id': 1, 'local': True, 'port': 8000}]
        self.assertListEqual(self.app.servers, exp_res)
        self.app.servers = [{
            'host': '127.0.0.1',
            'id': 2,
            'local': True,
            'port': 8001
        }]
        exp_res = [{'host': '127.0.0.1', 'id': 2, 'local': True, 'port': 8001}]
        self.assertListEqual(self.app.servers, exp_res)

    def test_name(self):
        self.assertIsNone(self.app.name)
        self.app.name = 'Super Topology'
        self.assertEqual(self.app.name, 'Super Topology')

    def test_get_topology(self):
        exp_res = {
            'name': None,
            'resources_type': 'local',
            'topology': {
                'servers': [{
                    'host': '127.0.0.1',
                    'id': 1,
                    'local': True,
                    'port': 8000
                }]
            },
            'type': 'topology',
            'version': '1.0'
        }

        result = self.app.get_topology()
        self.assertDictEqual(result, exp_res)

    def test_get_vboxes(self):
        # TODO
        pass

    def test_get_qemus(self):
        # TODO
        pass