def create_root_volume_from_template(self, req):
     cmd = jsonobject.loads(req[http.REQUEST_BODY])
     rsp = CreateRootVolumeFromTemplateResponse()
     if not os.path.exists(cmd.templatePathInCache):
         rsp.error = self.ERR_UNABLE_TO_FIND_IMAGE_IN_CACHE
         rsp.success = False
         return jsonobject.dumps(rsp)
         
     try:
         dirname = os.path.dirname(cmd.installUrl)
         if not os.path.exists(dirname):
             os.makedirs(dirname, 0775)
             
         linux.qcow2_clone(cmd.templatePathInCache, cmd.installUrl)
         logger.debug('successfully create root volume[%s] from template in cache[%s]' % (cmd.installUrl, cmd.templatePathInCache))
         meta = VolumeMeta()
         meta.account_uuid = cmd.accountUuid
         meta.hypervisor_type = cmd.hypervisorType
         meta.name = cmd.name
         meta.uuid = cmd.volumeUuid
         meta.size = os.path.getsize(cmd.templatePathInCache)
         meta_path = self._json_meta_file_name(cmd.installUrl)
         with open(meta_path, 'w') as fd:
             fd.write(jsonobject.dumps(meta, pretty=True))
         self._set_capacity_to_response(cmd.uuid, rsp)
         logger.debug('successfully create root volume[%s] from template in cache[%s]' % (cmd.installUrl, cmd.templatePathInCache))
     except Exception as e:
         content = traceback.format_exc()
         logger.warn(content)
         err = 'unable to clone qcow2 template[%s] to %s' % (cmd.templatePathInCache, cmd.installUrl)
         rsp.error = err
         rsp.success = False
         
     return jsonobject.dumps(rsp)
    def create_root_volume_from_template(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = CreateRootVolumeFromTemplateResponse()
        if not os.path.exists(cmd.templatePathInCache):
            rsp.error = self.ERR_UNABLE_TO_FIND_IMAGE_IN_CACHE
            rsp.success = False
            return jsonobject.dumps(rsp)
            
        try:
            dirname = os.path.dirname(cmd.installUrl)
            if not os.path.exists(dirname):
                os.makedirs(dirname, 0775)
                
            linux.qcow2_clone(cmd.templatePathInCache, cmd.installUrl)
            logger.debug('successfully create root volume[%s] from template in cache[%s]' % (cmd.installUrl, cmd.templatePathInCache))
            meta = VolumeMeta()
            meta.account_uuid = cmd.accountUuid
            meta.hypervisor_type = cmd.hypervisorType
            meta.name = cmd.name
            meta.uuid = cmd.volumeUuid
            meta.size = os.path.getsize(cmd.templatePathInCache)
            meta_path = self._json_meta_file_name(cmd.installUrl)
            with open(meta_path, 'w') as fd:
                fd.write(jsonobject.dumps(meta, pretty=True))
            self._set_capacity_to_response(cmd.uuid, rsp)
            logger.debug('successfully create root volume[%s] from template in cache[%s]' % (cmd.installUrl, cmd.templatePathInCache))
        except Exception as e:
            content = traceback.format_exc()
            logger.warn(content)
            err = 'unable to clone qcow2 template[%s] to %s' % (cmd.templatePathInCache, cmd.installUrl)
            rsp.error = err
            rsp.success = False
            

        return jsonobject.dumps(rsp)
Beispiel #3
0
    def create_root_volume_from_template(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentResponse()

        if not os.path.exists(cmd.templatePathInCache):
            rsp.error = "UNABLE_TO_FIND_IMAGE_IN_CACHE"
            rsp.success = False
            logger.debug('error: %s: %s' %
                         (rsp.error, cmd.templatePathInCache))
            return jsonobject.dumps(rsp)

        dirname = os.path.dirname(cmd.installUrl)
        logger.debug(
            '--------------------------------------------CREATE_ROOT_VOLUME_PATH:%s'
            % dirname)

        if not os.path.exists(dirname):
            os.makedirs(dirname, 0775)
            logger.debug(
                '--------------------------------------------CREATE_ROOT_VOLUME_PATH_OVER:%s'
                % dirname)

        linux.qcow2_clone(cmd.templatePathInCache, cmd.installUrl)
        rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity()
        return jsonobject.dumps(rsp)
Beispiel #4
0
 def take_full_snapshot_by_qemu_img_convert(previous_install_path, install_path):
     makedir_if_need(install_path)
     linux.qcow2_create_template(previous_install_path, install_path)
     new_volume_path = os.path.join(os.path.dirname(install_path), '{0}.qcow2'.format(uuidhelper.uuid()))
     makedir_if_need(new_volume_path)
     linux.qcow2_clone(install_path, new_volume_path)
     return install_path, new_volume_path
Beispiel #5
0
 def take_delta_snapshot_by_qemu_img_convert(previous_install_path,
                                             install_path):
     new_volume_path = os.path.join(
         os.path.dirname(install_path),
         '{0}.qcow2'.format(uuidhelper.uuid()))
     makedir_if_need(new_volume_path)
     linux.qcow2_clone(previous_install_path, new_volume_path)
     return previous_install_path, new_volume_path
    def revert_volume_from_snapshot(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = RevertVolumeFromSnapshotRsp()

        install_path = cmd.snapshotInstallPath
        new_volume_path = os.path.join(os.path.dirname(install_path), '{0}.qcow2'.format(uuidhelper.uuid()))
        linux.qcow2_clone(install_path, new_volume_path)
        rsp.newVolumeInstallPath = new_volume_path
        return jsonobject.dumps(rsp)
Beispiel #7
0
    def revert_snapshot(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = RevertVolumeFromSnapshotRsp()

        install_path = cmd.snapshotInstallPath
        new_volume_path = os.path.join(os.path.dirname(install_path), '{0}.qcow2'.format(uuidhelper.uuid()))
        linux.qcow2_clone(install_path, new_volume_path)
        rsp.newVolumeInstallPath = new_volume_path
        return jsonobject.dumps(rsp)
Beispiel #8
0
    def revert_volume_from_snapshot(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = RevertVolumeFromSnapshotResponse()

        install_path = cmd.snapshotInstallPath
        new_volume_path = os.path.join(os.path.dirname(install_path),
                                       '{0}.qcow2'.format(uuidhelper.uuid()))
        linux.qcow2_clone(install_path, new_volume_path)
        rsp.newVolumeInstallPath = new_volume_path
        size = linux.qcow2_virtualsize(new_volume_path)
        rsp.size = size
        self._set_capacity_to_response(cmd.uuid, rsp)
        return jsonobject.dumps(rsp)
    def reinit_image(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = ReinitImageRsp()

        install_path = cmd.imageInstallPath
        dirname = os.path.dirname(cmd.volumeInstallPath)
        if not os.path.exists(dirname):
            os.makedirs(dirname, 0775)

        new_volume_path = os.path.join(dirname, '{0}.qcow2'.format(uuidhelper.uuid()))
        linux.qcow2_clone(install_path, new_volume_path)
        rsp.newVolumeInstallPath = new_volume_path
        return jsonobject.dumps(rsp)
Beispiel #10
0
    def create_root_volume_from_template(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentResponse()

        if not os.path.exists(cmd.templatePathInCache):
            rsp.error = "UNABLE_TO_FIND_IMAGE_IN_CACHE"
            rsp.success = False
            return jsonobject.dumps(rsp)

        dirname = os.path.dirname(cmd.installUrl)
        if not os.path.exists(dirname):
            os.makedirs(dirname, 0775)

        linux.qcow2_clone(cmd.templatePathInCache, cmd.installUrl)
        return jsonobject.dumps(rsp)
    def create_root_volume(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()

        if not os.path.exists(cmd.templatePathInCache):
            rsp.error = "UNABLE_TO_FIND_IMAGE_IN_CACHE"
            rsp.success = False
            return jsonobject.dumps(rsp)

        dirname = os.path.dirname(cmd.installPath)
        if not os.path.exists(dirname):
            os.makedirs(dirname, 0775)

        linux.qcow2_clone(cmd.templatePathInCache, cmd.installPath)
        rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity()
        return jsonobject.dumps(rsp)
    def create_root_volume(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()

        if not os.path.exists(cmd.templatePathInCache):
            rsp.error = "UNABLE_TO_FIND_IMAGE_IN_CACHE"
            rsp.success = False
            return jsonobject.dumps(rsp)

        dirname = os.path.dirname(cmd.installPath)
        if not os.path.exists(dirname):
            os.makedirs(dirname, 0775)

        linux.qcow2_clone(cmd.templatePathInCache, cmd.installPath)
        rsp.totalCapacity, rsp.availableCapacity = self._get_disk_capacity()
        return jsonobject.dumps(rsp)