davidban77 / gns3fy

Python library wrapper around GNS3 Server REST API
https://davidban77.github.io/gns3fy/
56 stars 28 forks source link

provide delete_link function #79

Open ghost opened 3 years ago

ghost commented 3 years ago

It would be nice to have a delete_link function (analog to the create_link funcrton) which takes the same parameters (node_a, port_a, node_b, port_b).

Internaly it would need to find the link ID used for that connection and then call the delete() method of the link object.

This would be usefull in updating existing topologies (e.g. when using the ansible modules) in order to not only add missing links, but also remove not needed links from topolgies without the need to remove/delete the complete topology.

We might have a go on that soon, for now this shall serve as a feature request :)

davidban77 commented 3 years ago

Don't have enough cycles to give this a spin for the time being, it is a good idea to have that method implemented.

Feel free to give it a shot? I can later help on moving this functionality to the ansible modules

Krlosromero commented 3 years ago

Hello all,

I had created the project function to delete the links as required, running on my local lab for now

n [7]: print(tabulate(links_summary, headers=["Node A", "Port A", "Node B", "Port B"]))                                                                                                                                        
Node A            Port A       Node B            Port B
----------------  -----------  ----------------  -----------
PC-1              Ethernet0    Ethernetswitch-1  Ethernet0
Ethernetswitch-1  Ethernet1    PC-2              Ethernet0
Ethernetswitch-1  Ethernet5    vEOS-4.21.5F-2    Management
IOU1              Ethernet0/0  Ethernetswitch-1  Ethernet2
inet0-VMNET1      eth0         Ethernetswitch-1  Ethernet3
switch2           Ethernet1    IOU2              Ethernet0/0
switch2           Ethernet0    Ethernetswitch-1  Ethernet4

In [8]: first_lab.delete_link('switch2','Ethernet0','Ethernetswitch-1','Ethernet4')                                                                                                                                             
Deleted Link-ID: 45d4d13d-d333-4e9b-a193-d50898847c4b from node switch2, port: Ethernet0 <--> node Ethernetswitch-1, port: Ethernet4 

In [9]: first_lab.get()                                                                                                                                                                                                         

In [10]: links_summary = first_lab.links_summary(is_print=False)                                                                                                                                                                

In [11]: print(tabulate(links_summary, headers=["Node A", "Port A", "Node B", "Port B"]))                                                                                                                                       
Node A            Port A       Node B            Port B
----------------  -----------  ----------------  -----------
PC-1              Ethernet0    Ethernetswitch-1  Ethernet0
Ethernetswitch-1  Ethernet1    PC-2              Ethernet0
Ethernetswitch-1  Ethernet5    vEOS-4.21.5F-2    Management
IOU1              Ethernet0/0  Ethernetswitch-1  Ethernet2
inet0-VMNET1      eth0         Ethernetswitch-1  Ethernet3
switch2           Ethernet1    IOU2              Ethernet0/0