1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Merge pull request #48 from planctechnologies/pr3

Add support for Qemu devices on cloud instances (server)
This commit is contained in:
Jeremy Grossmann 2014-11-12 21:19:15 -07:00
commit e75dde3ebf
4 changed files with 85 additions and 11 deletions

View File

@ -17,6 +17,7 @@
import os
import base64
import ntpath
import time
from gns3server.modules import IModule
from gns3dms.cloud.rackspace_ctrl import get_provider
@ -148,13 +149,15 @@ class VM(object):
else:
if not os.path.exists(self.images_directory):
os.mkdir(self.images_directory)
if request.get("cloud_path", None):
cloud_path = request.get("cloud_path", None)
if cloud_path is not None:
# Download the image from cloud files
cloud_path = request.get("cloud_path")
full_cloud_path = "/".join((cloud_path, image))
_, filename = ntpath.split(image)
src = '{}/{}'.format(cloud_path, filename)
provider = get_provider(self._cloud_settings)
provider.download_file(full_cloud_path, updated_image_path)
log.debug("Downloading file from {} to {}...".format(src, updated_image_path))
provider.download_file(src, updated_image_path)
log.debug("Download of {} complete.".format(src))
image = updated_image_path
try:

View File

@ -21,6 +21,7 @@ IOU server module.
import os
import base64
import ntpath
import stat
import tempfile
import socket
@ -304,13 +305,15 @@ class IOU(IModule):
else:
if not os.path.exists(self.images_directory):
os.mkdir(self.images_directory)
if request.get("cloud_path", None):
cloud_path = request.get("cloud_path", None)
if cloud_path is not None:
# Download the image from cloud files
cloud_path = request.get("cloud_path")
full_cloud_path = "/".join((cloud_path, iou_path))
_, filename = ntpath.split(iou_path)
src = '{}/{}'.format(cloud_path, filename)
provider = get_provider(self._cloud_settings)
provider.download_file(full_cloud_path, updated_iou_path)
log.debug("Downloading file from {} to {}...".format(src, updated_iou_path))
provider.download_file(src, updated_iou_path)
log.debug("Download of {} complete.".format(src))
# Make file executable
st = os.stat(updated_iou_path)
os.chmod(updated_iou_path, st.st_mode | stat.S_IEXEC)

View File

@ -24,6 +24,10 @@ import shutil
import random
import subprocess
import shlex
import ntpath
from gns3server.config import Config
from gns3dms.cloud.rackspace_ctrl import get_provider
from .qemu_error import QemuError
from .adapters.ethernet_adapter import EthernetAdapter
@ -89,6 +93,7 @@ class QemuVM(object):
self._console_host = console_host
self._console_start_port_range = console_start_port_range
self._console_end_port_range = console_end_port_range
self._cloud_path = None
# QEMU settings
self._qemu_path = qemu_path
@ -291,6 +296,27 @@ class QemuVM(object):
log.info("QEMU VM {name} [id={id}] has been deleted (including associated files)".format(name=self._name,
id=self._id))
@property
def cloud_path(self):
"""
Returns the cloud path where images can be downloaded from.
:returns: cloud path
"""
return self._cloud_path
@cloud_path.setter
def cloud_path(self, cloud_path):
"""
Sets the cloud path where images can be downloaded from.
:param cloud_path:
:return:
"""
self._cloud_path = cloud_path
@property
def qemu_path(self):
"""
@ -534,8 +560,46 @@ class QemuVM(object):
if not self.is_running():
if not os.path.isfile(self._qemu_path) or not os.path.exists(self._qemu_path):
found = False
paths = [os.getcwd()] + os.environ["PATH"].split(os.pathsep)
# look for the qemu binary in the current working directory and $PATH
for path in paths:
try:
if self._qemu_path in os.listdir(path) and os.access(os.path.join(path, self._qemu_path), os.X_OK):
self._qemu_path = os.path.join(path, self._qemu_path)
found = True
break
except OSError:
continue
if not found:
raise QemuError("QEMU binary '{}' is not accessible".format(self._qemu_path))
if self.cloud_path is not None:
# Download from Cloud Files
if self.hda_disk_image != "":
_, filename = ntpath.split(self.hda_disk_image)
src = '{}/{}'.format(self.cloud_path, filename)
dst = os.path.join(self.working_dir, filename)
if not os.path.isfile(dst):
cloud_settings = Config.instance().cloud_settings()
provider = get_provider(cloud_settings)
log.debug("Downloading file from {} to {}...".format(src, dst))
provider.download_file(src, dst)
log.debug("Download of {} complete.".format(src))
self.hda_disk_image = dst
if self.hdb_disk_image != "":
_, filename = ntpath.split(self.hdb_disk_image)
src = '{}/{}'.format(self.cloud_path, filename)
dst = os.path.join(self.working_dir, filename)
if not os.path.isfile(dst):
cloud_settings = Config.instance().cloud_settings()
provider = get_provider(cloud_settings)
log.debug("Downloading file from {} to {}...".format(src, dst))
provider.download_file(src, dst)
log.debug("Download of {} complete.".format(src))
self.hdb_disk_image = dst
self._command = self._build_command()
try:
log.info("starting QEMU: {}".format(self._command))

View File

@ -120,6 +120,10 @@ QEMU_UPDATE_SCHEMA = {
"description": "QEMU kernel command line",
"type": "string",
},
"cloud_path": {
"description": "Path to the image in the cloud object store",
"type": "string",
},
"options": {
"description": "additional QEMU options",
"type": "string",