Support uploading iourc

This commit is contained in:
Julien Duponchelle committed 2015-03-17 16:31:45 +01:00
1 parent 964ea0f577
commit 66cdf39ea2
7 files changed
+98 -3

No files matched your search

+11
View File
@@ -20,6 +20,7 @@ import logging
import aiohttp
import shutil
import asyncio
import tempfile
from ..utils.asyncio import wait_run_in_executor
@@ -45,6 +46,7 @@ class BaseVM:
self._project = project
self._manager = manager
self._console = console
self._temporary_directory = None
if self._console is not None:
self._console = self._manager.port_manager.reserve_tcp_port(self._console)
@@ -61,6 +63,9 @@ class BaseVM:
def __del__(self):
self.close()
if self._temporary_directory is not None:
if os.path.exists(self._temporary_directory):
shutil.rmtree(self._temporary_directory)
@property
def project(self):
@@ -124,6 +129,12 @@ class BaseVM:
return self._project.vm_working_directory(self)
@property
def temporary_directory(self):
if self._temporary_directory is None:
self._temporary_directory = tempfile.mkdtemp()
return self._temporary_directory
def create(self):
"""
Creates the VM.
+21 -2
View File
@@ -67,6 +67,7 @@ class IOUVM(BaseVM):
:params nvram: Nvram KB
:params l1_keepalives: Always up ethernet interface:
:params initial_config: Content of the initial configuration file
:params iourc_content: Content of the iourc file if no licence is installed on server
"""
def __init__(self, name, vm_id, project, manager,
@@ -76,7 +77,8 @@ class IOUVM(BaseVM):
ethernet_adapters=None,
serial_adapters=None,
l1_keepalives=None,
initial_config=None):
initial_config=None,
iourc_content=None):
super().__init__(name, vm_id, project, manager, console=console)
@@ -99,6 +101,7 @@ class IOUVM(BaseVM):
self._ram = 256 if ram is None else ram # Megabytes
self._l1_keepalives = False if l1_keepalives is None else l1_keepalives # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
self.iourc_content = iourc_content
if initial_config is not None:
self.initial_config = initial_config
@@ -209,7 +212,8 @@ class IOUVM(BaseVM):
"nvram": self._nvram,
"l1_keepalives": self._l1_keepalives,
"initial_config": self.relative_initial_config_file,
"use_default_iou_values": self._use_default_iou_values}
"use_default_iou_values": self._use_default_iou_values,
"iourc_path": self.iourc_path}
# return the relative path if the IOU image is in the images_path directory
server_config = self.manager.config.get_section_config("Server")
@@ -250,6 +254,10 @@ class IOUVM(BaseVM):
path = os.path.join(self.working_dir, "iourc")
if os.path.exists(path):
return path
# look for the iourc file in the temporary dir.
path = os.path.join(self.temporary_directory, "iourc")
if os.path.exists(path):
return path
return iourc_path
@property
@@ -322,6 +330,17 @@ class IOUVM(BaseVM):
def application_id(self):
return self._manager.get_application_id(self.id)
@property
def iourc_content(self):
with open(os.path.join(self.temporary_directory, "iourc")) as f:
return f.read()
@iourc_content.setter
def iourc_content(self, value):
if value is not None:
with open(os.path.join(self.temporary_directory, "iourc"), "w+") as f:
f.write(value)
@asyncio.coroutine
def _library_check(self):
"""