def download(caller_id, name, description, path, disk_controller): """ Downloads specified IsoImage and saves it with specified name and description. @cmview_user @param_post{name,string} @param_post{description,string} @param_post{path,string} HTTP or FTP path to IsoImage to download @param_post{disk_controller} """ user = User.get(caller_id) if not any([path.startswith('http://'), path.startswith('https://'), path.startswith('ftp://')]): path = 'http://' + path.strip() # size value is taken try: connection = urllib.urlopen(path) size = int(connection.info()["Content-Length"]) except IOError: log.exception('Cannot find image') raise CMException('image_not_found') except KeyError: log.exception(caller_id, 'Cannot calculate size') raise CMException('image_calculate_size') user.check_storage(size / (1024 * 1024)) image = IsoImage.create(user=user, description=description, name=name, disk_controller=disk_controller, disk_dev=1) try: image.save() except Exception, e: log.error(caller_id, "Unable to save image to DB: %s" % str(e)) raise CMException('image_create')
def download(caller_id, description, name, path, disk_dev, disk_controller): """ Downloads Image with given path and saves it with specified name and description. @cmview_admin_cm @param_post{description,string} @param_post{name,string} @param_post{path,string} HTTP or FTP path to IsoImage @param_post{disk_dev} @param_post{disk_controller} """ # size value is taken try: connection = urllib.urlopen(path) size = int(connection.info()["Content-Length"]) except IOError: log.exception('Cannot find image') raise CMException('image_not_found') except KeyError: log.exception(caller_id, 'Cannot calculate size') raise CMException('image_calculate_size') user = User.get(caller_id) image = IsoImage.create(name=name, description=description, user=user, disk_dev=disk_dev, disk_controller=disk_controller) try: image.save() except Exception, e: log.error(caller_id, "Unable to save image to DB: %s" % str(e)) raise CMException('image_create')
def download(caller_id, description, name, path, disk_dev, disk_controller): """ Downloads image depending on the \c data parameter. @cmview_admin_cm @parameter{description,string} @parameter{name,string} @parameter{path,string} HTTP or FTP path to image to download @parameter{type,image_types} type of image, automatically set, type is in the URL requested @response{None} """ # size value is taken try: connection = urllib.urlopen(path) size = int(connection.info()["Content-Length"]) except IOError: log.exception('Cannot find image') raise CMException('image_not_found') except KeyError: log.exception(caller_id, 'Cannot calculate size') raise CMException('image_calculate_size') user = User.get(caller_id) image = IsoImage.create(name=name, description=description, user=user, disk_dev=disk_dev, disk_controller=disk_controller) try: image.save() except Exception, e: log.error(caller_id, "Unable to save image to DB: %s" % str(e)) raise CMException('image_create')
def copy(caller_id, src_image_id, dest_user_id): """ Copies selected IsoImage to User's IsoImages pool. @cmview_admin_cm @param_post{src_image_id,int} @param_post{dest_user_id,int} """ src_image = IsoImage.admin_get(src_image_id) dest_user = User.get(dest_user_id) dest_image = IsoImage.create(name=src_image.name, description=src_image.description, user=dest_user, disk_controller=src_image.disk_controller, disk_dev=src_image.disk_dev) try: dest_image.save() except Exception, e: log.error(caller_id, "Unable to commit: %s" % str(e)) raise CMException('image_create')
def download(caller_id, name, description, path, disk_controller): """ Downloads specified IsoImage and saves it with specified name and description. @cmview_user @param_post{name,string} @param_post{description,string} @param_post{path,string} HTTP or FTP path to IsoImage to download @param_post{disk_controller} """ user = User.get(caller_id) if not any([ path.startswith('http://'), path.startswith('https://'), path.startswith('ftp://') ]): path = 'http://' + path.strip() # size value is taken try: connection = urllib.urlopen(path) size = int(connection.info()["Content-Length"]) except IOError: log.exception('Cannot find image') raise CMException('image_not_found') except KeyError: log.exception(caller_id, 'Cannot calculate size') raise CMException('image_calculate_size') user.check_storage(size / (1024 * 1024)) image = IsoImage.create(user=user, description=description, name=name, disk_controller=disk_controller, disk_dev=1) try: image.save() except Exception, e: log.error(caller_id, "Unable to save image to DB: %s" % str(e)) raise CMException('image_create')