Support for relative path in Dynamips.

This commit is contained in:
Jeremy 2015-02-25 17:19:37 -07:00
parent de1be0961f
commit 473eb0280e

View File

@ -33,6 +33,8 @@ log = logging.getLogger(__name__)
from ...base_vm import BaseVM from ...base_vm import BaseVM
from ..dynamips_error import DynamipsError from ..dynamips_error import DynamipsError
from ..nios.nio_udp import NIOUDP from ..nios.nio_udp import NIOUDP
from gns3server.config import Config
from gns3server.utils.asyncio import wait_run_in_executor from gns3server.utils.asyncio import wait_run_in_executor
@ -413,6 +415,14 @@ class Router(BaseVM):
:param image: path to IOS image file :param image: path to IOS image file
""" """
if not os.path.dirname(image):
# this must be a relative path
server_config = Config.instance().get_section_config("Server")
image = os.path.join(os.path.expanduser(server_config.get("images_path", "~/GNS3/images")), image)
if not os.path.isfile(image):
raise DynamipsError("IOS image '{}' is not accessible".format(image))
yield from self._hypervisor.send('vm set_ios "{name}" "{image}"'.format(name=self._name, image=image)) yield from self._hypervisor.send('vm set_ios "{name}" "{image}"'.format(name=self._name, image=image))
log.info('Router "{name}" [{id}]: has a new IOS image set: "{image}"'.format(name=self._name, log.info('Router "{name}" [{id}]: has a new IOS image set: "{image}"'.format(name=self._name,