Move image path manipulation to server side

This commit is contained in:
Jerry Seutter 2014-11-10 11:28:19 -07:00
parent faa3ef8cb4
commit 5b73786653
3 changed files with 28 additions and 18 deletions

View File

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

View File

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

View File

@ -577,21 +577,25 @@ class QemuVM(object):
if self.hda_disk_image != "": if self.hda_disk_image != "":
_, filename = ntpath.split(self.hda_disk_image) _, filename = ntpath.split(self.hda_disk_image)
src = '{}/{}'.format(self.cloud_path, filename) src = '{}/{}'.format(self.cloud_path, filename)
dest = os.path.join(self.working_dir, filename) dst = os.path.join(self.working_dir, filename)
if not os.path.isfile(dest): if not os.path.isfile(dst):
cloud_settings = Config.instance().cloud_settings() cloud_settings = Config.instance().cloud_settings()
provider = get_provider(cloud_settings) provider = get_provider(cloud_settings)
provider.download_file(src, dest) log.debug("Downloading file from {} to {}...".format(src, dst))
self.hda_disk_image = dest provider.download_file(src, dst)
log.debug("Download of {} complete.".format(src))
self.hda_disk_image = dst
if self.hdb_disk_image != "": if self.hdb_disk_image != "":
_, filename = ntpath.split(self.hdb_disk_image) _, filename = ntpath.split(self.hdb_disk_image)
src = '{}/{}'.format(self.cloud_path, filename) src = '{}/{}'.format(self.cloud_path, filename)
dest = os.path.join(self.working_dir, filename) dst = os.path.join(self.working_dir, filename)
if not os.path.isfile(dest): if not os.path.isfile(dst):
cloud_settings = Config.instance().cloud_settings() cloud_settings = Config.instance().cloud_settings()
provider = get_provider(cloud_settings) provider = get_provider(cloud_settings)
provider.download_file(src, dest) log.debug("Downloading file from {} to {}...".format(src, dst))
self.hdb_disk_image = dest provider.download_file(src, dst)
log.debug("Download of {} complete.".format(src))
self.hdb_disk_image = dst
self._command = self._build_command() self._command = self._build_command()
try: try: