mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Support conversion to dynamips new directory layout on remote
Ref https://github.com/GNS3/gns3-gui/issues/1761
This commit is contained in:
parent
a2fdc92fcb
commit
6150929a5b
@ -69,6 +69,11 @@ class Router(BaseNode):
|
||||
|
||||
super().__init__(name, node_id, project, manager, console=console, aux=aux, allocate_aux=aux)
|
||||
|
||||
self._working_directory = os.path.join(self.project.module_working_directory(self.manager.module_name.lower()), self.id)
|
||||
os.makedirs(os.path.join(self._working_directory, "configs"), exist_ok=True)
|
||||
if dynamips_id:
|
||||
self._convert_before_2_0_0_b3(dynamips_id)
|
||||
|
||||
self._hypervisor = hypervisor
|
||||
self._dynamips_id = dynamips_id
|
||||
self._platform = platform
|
||||
@ -115,8 +120,27 @@ class Router(BaseNode):
|
||||
self._dynamips_id = 0
|
||||
self._name = "Ghost"
|
||||
|
||||
self._working_directory = os.path.join(self.project.module_working_directory(self.manager.module_name.lower()), self.id)
|
||||
os.makedirs(os.path.join(self._working_directory, "configs"), exist_ok=True)
|
||||
def _convert_before_2_0_0_b3(self, dynamips_id):
|
||||
"""
|
||||
Before 2.0.0 beta3 the node didn't have a folder by node
|
||||
when we start we move the file, we can't do it in the topology
|
||||
conversion due to case of remote servers
|
||||
"""
|
||||
dynamips_dir = self.project.module_working_directory(self.manager.module_name.lower())
|
||||
for path in glob.glob(os.path.join(glob.escape(dynamips_dir), "configs", "i{}_*".format(dynamips_id))):
|
||||
dst = os.path.join(self._working_directory, "configs", os.path.basename(path))
|
||||
if not os.path.exists(dst):
|
||||
try:
|
||||
shutil.move(path, dst)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Can't move {}: {}".format(path, str(e)))
|
||||
for path in glob.glob(os.path.join(glob.escape(dynamips_dir), "*_i{}_*".format(dynamips_id))):
|
||||
dst = os.path.join(self._working_directory, os.path.basename(path))
|
||||
if not os.path.exists(dst):
|
||||
try:
|
||||
shutil.move(path, dst)
|
||||
except OSError as e:
|
||||
raise DynamipsError("Can't move {}: {}".format(path, str(e)))
|
||||
|
||||
def __json__(self):
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import asyncio
|
||||
import configparser
|
||||
@ -44,6 +45,21 @@ def test_router(project, manager):
|
||||
assert router.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
def test_convert_project_before_2_0_0_b3(project, manager):
|
||||
wdir = project.module_working_directory(manager.module_name.lower())
|
||||
os.makedirs(os.path.join(wdir, "00010203-0405-0607-0809-0a0b0c0d0e0f"))
|
||||
os.makedirs(os.path.join(wdir, "configs"))
|
||||
open(os.path.join(wdir, "configs", "i1_startup-config.cfg"), "w+").close()
|
||||
open(os.path.join(wdir, "configs", "i2_startup-config.cfg"), "w+").close()
|
||||
open(os.path.join(wdir, "c7200_i1_nvram"), "w+").close()
|
||||
open(os.path.join(wdir, "c7200_i2_nvram"), "w+").close()
|
||||
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, dynamips_id=1)
|
||||
assert os.path.exists(os.path.join(wdir, "00010203-0405-0607-0809-0a0b0c0d0e0f", "configs", "i1_startup-config.cfg"))
|
||||
assert not os.path.exists(os.path.join(wdir, "00010203-0405-0607-0809-0a0b0c0d0e0f", "configs", "i2_startup-config.cfg"))
|
||||
assert os.path.exists(os.path.join(wdir, "00010203-0405-0607-0809-0a0b0c0d0e0f", "c7200_i1_nvram"))
|
||||
assert not os.path.exists(os.path.join(wdir, "00010203-0405-0607-0809-0a0b0c0d0e0f", "c7200_i2_nvram"))
|
||||
|
||||
|
||||
def test_router_invalid_dynamips_path(project, manager, loop):
|
||||
|
||||
config = Config.instance()
|
||||
|
Loading…
Reference in New Issue
Block a user