Skip to content
This repository was archived by the owner on Mar 14, 2019. It is now read-only.
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
7 changes: 7 additions & 0 deletions gns3converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, topology, debug=False):
self.port_id = 1
self.links = []
self.configs = []
self.datas = []
self.images = []

logging.getLogger(__name__)
Expand Down Expand Up @@ -230,6 +231,12 @@ def generate_nodes(self, topology):
and tmp_node.device_info['chassis'] == '3660':
tmp_node.node['properties']['slot0'] = 'Leopard-2FE'

for name in ['rom', 'nvram', 'bootflash', 'disk0', 'disk1', 'slot0', 'slot1']:
self.datas.append({
'old': os.path.join('working', tmp_node.device_info['model'] + '_' + device + '_' + name),
'new': tmp_node.device_info['model'] + '_i' + str(tmp_node.node['router_id']) + '_' + name
})

# Calculate the router links
tmp_node.calc_device_links()

Expand Down
27 changes: 27 additions & 0 deletions gns3converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def save(output_dir, converter, json_topology, snapshot, quiet):
config_err = copy_configs(converter.configs, old_topology_dir,
topology_files_dir)

copy_datas(converter.datas, old_topology_dir,
topology_files_dir)

# Copy any VPCS configurations to the the new topology
copy_vpcs_configs(old_topology_dir, topology_files_dir)

Expand Down Expand Up @@ -292,6 +295,30 @@ def save(output_dir, converter, json_topology, snapshot, quiet):
logging.error(error)


def copy_datas(datas, source, target):
"""
Copy dynamips data to converted topology

:param datas: Configs to copy
:param str source: Source topology directory
:param str target: Target topology files directory
:return: True when a data cannot be found, otherwise false
:rtype: bool
"""
data_err = False
if len(datas) > 0:
data_dir = os.path.join(target, 'dynamips')
os.makedirs(data_dir, exist_ok=True)
for data in datas:
old_data_file = os.path.join(source, data['old'])
new_data_file = os.path.join(data_dir, data['new'])
if os.path.isfile(old_data_file):
# Copy and rename the data
shutil.copy(old_data_file, new_data_file)
return data_err



def copy_configs(configs, source, target):
"""
Copy dynamips configs to converted topology
Expand Down
42 changes: 42 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,47 @@ def test_generate_notes(self):
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'}
])

if __name__ == '__main__':
unittest.main()