Exemplo n.º 1
0
def http_login(host_name, host_ip, local_ip, tunnel_index):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(
        r'apiv1/hosts/sessions/')

    json_body = json.dumps({
        'host_ident': host_name,
        'host_ip': host_ip,
        'local_ip': local_ip,
        'tunnel_index': tunnel_index
    })
    response = requests.post(f_url,
                             headers={
                                 'Content-Type': 'application/json',
                                 'x-csrftoken': csrf_token
                             },
                             data=json_body,
                             cookies=secure_cookie)

    if http_status.is_success(response.status_code):
        return True
    elif response.status_code == http_status.HTTP_429_TOO_MANY_REQUESTS:
        return False
    else:
        error_description = r'客户端登陆失败:{}'.format(response.status_code)
        error_debug = r'http_login call web api failed. [{}] :{}'.format(
            f_url, response.status_code)
        xlogging.raise_system_error(error_description, error_debug,
                                    response.status_code, _logger)
Exemplo n.º 2
0
def http_query_host_soft_ident(host_name):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(
        r'apiv1/hosts/{}'.format(host_name))

    r = requests.get(f_url,
                     headers={
                         'content-type': 'application/json; charset=utf-8',
                         'x-csrftoken': csrf_token
                     },
                     data='',
                     cookies=secure_cookie)
    if http_status.is_success(r.status_code):
        soft_ident = r.json().get('soft_ident', '')
        if soft_ident:
            return soft_ident
        else:
            xlogging.raise_system_error(r'无效的客户端标识',
                                        r'http_query_host_soft_ident empty', 0,
                                        _logger)
    else:
        error_description = '获取客户端标识失败:{}'.format(r.status_code)
        error_debug = 'http_query_host_soft_ident call web api failed. [{}] :{}'.format(
            f_url, r.status_code)
        xlogging.raise_system_error(error_description, error_debug,
                                    r.status_code, _logger)
Exemplo n.º 3
0
def http_refresh_token(token):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(
        r'apiv1/tokens/{}/'.format(token))

    response = requests.get(f_url,
                            headers={
                                'Content-Type': 'application/json',
                                'x-csrftoken': csrf_token
                            },
                            cookies=secure_cookie)

    if http_status.is_success(response.status_code):
        pass
    else:
        error_description = r'获取Token信息失败,错误代码:{}'.format(response.status_code)
        error_debug = r'http_refresh_token failed. [{}] :{}'.format(
            f_url, response.status_code)
        if xlogging.logger_traffic_control.is_logger_print(
                'http_refresh_token__error', token):
            xlogging.raise_system_error(error_description, error_debug,
                                        response.status_code, _logger)
        else:
            xlogging.raise_system_error_without_logger(error_description,
                                                       error_debug,
                                                       response.status_code)

    if xlogging.logger_traffic_control.is_logger_print(
            'http_refresh_token__debug', token):
        _logger.debug('http_refresh_token, input args: {}'.format(token))
Exemplo n.º 4
0
def http_report_restore_status(token, progress, finished, host_ident=None):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(
        r'apiv1/tokens/{}/'.format(token))

    json_body = json.dumps({
        'remainingBytes': progress.remainingBytes,
        'totalBytes': progress.totalBytes,
        'finished': finished,
        'successful': True,
        'host_ident': host_ident
    })

    response = requests.put(f_url,
                            headers={
                                'Content-Type': 'application/json',
                                'x-csrftoken': csrf_token
                            },
                            data=json_body,
                            cookies=secure_cookie)

    if http_status.is_success(response.status_code):
        return
    else:
        error_description = r'更新还原进度失败,错误代码:{}'.format(response.status_code)
        error_debug = r'http_report_restore_status failed. [{}] :{}'.format(
            f_url, response.status_code)
        xlogging.raise_system_error(error_description, error_debug,
                                    response.status_code, _logger)
Exemplo n.º 5
0
def http_pe_host_login(disk_info_list, remoteAddress, localAddress,
                       boot_disk_id, login_type, tunnel_index, more_info):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(
        r'apiv1/pe_hosts/sessions/')

    disks = list()
    for disk in disk_info_list:
        disks.append(disk.__dict__)
    json_body = json.dumps({
        'disks': disks,
        'remote_ip': remoteAddress,
        'local_ip': localAddress,
        'boot_disk_id': boot_disk_id,
        'login_type': login_type,
        'tunnel_index': tunnel_index,
        'more_info': more_info,
    })

    response = requests.post(f_url,
                             headers={
                                 'Content-Type': 'application/json',
                                 'x-csrftoken': csrf_token
                             },
                             data=json_body,
                             cookies=secure_cookie)

    if http_status.is_success(response.status_code):
        return response.json()['ident']
    else:
        error_description = r'还原目标客户端登陆失败:{}'.format(response.status_code)
        error_debug = r'http_pe_host_login call web api failed. [{}] :{}'.format(
            f_url, response.status_code)
        xlogging.raise_system_error(error_description, error_debug,
                                    response.status_code, _logger)
Exemplo n.º 6
0
def http_report_backup_progress(host_name, progress):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(
        r'apiv1/hosts/sessions/{}/backup/'.format(host_name))
    response = requests.put(f_url,
                            data=json.dumps({
                                'code':
                                progress.code.value,
                                'progressIndex':
                                progress.progressIndex,
                                'progressTotal':
                                progress.progressTotal
                            }),
                            headers={
                                'Content-Type': 'application/json',
                                'x-csrftoken': csrf_token
                            },
                            cookies=secure_cookie)
    if http_status.is_success(response.status_code):
        return
    else:
        error_description = r'提交备份进度失败:{}'.format(response.status_code)
        error_debug = r'http_report_backup_progress call web api failed. [{}] :{}'.format(
            f_url, response.status_code)
        xlogging.raise_system_error(error_description, error_debug,
                                    response.status_code, _logger)
Exemplo n.º 7
0
def http_query_host_name(ident, host_name, user_ident, sysinfo):
    global _logger
    secure_cookie, csrf_token, f_url = authCookies.get(r'apiv1/hosts/')

    json_body = json.dumps({
        'user_ident': user_ident,
        'macs': ident.Hardware,
        'host_name': host_name,
        'sysinfo': sysinfo
    })

    r = requests.post(f_url,
                      headers={
                          'content-type': 'application/json; charset=utf-8',
                          'x-csrftoken': csrf_token
                      },
                      data=json_body,
                      cookies=secure_cookie)
    if http_status.is_success(r.status_code):
        return r.json()['ident']
    else:
        error_description = '获取客户端标识号失败:{}'.format(r.status_code)
        error_debug = 'http_query_host_name call web api failed. [{}] :{}'.format(
            f_url, r.status_code)
        xlogging.raise_system_error(error_description, error_debug,
                                    r.status_code, _logger)
Exemplo n.º 8
0
def refresh(self_call=False):
    global _cookies, _username, _password, _csrftoken, _logger
    _logger.info(r'refresh cookies ...')
    url_login = _url + r'api-auth/login/'
    web_login_get = requests.get(url_login)
    if web_login_get.status_code == http_status.HTTP_200_OK:
        csrftoken = web_login_get.cookies['csrftoken']
        login_data = {
            'username': _username,
            'password': _password,
            'csrfmiddlewaretoken': csrftoken
        }
        login_cookies = dict(csrftoken=web_login_get.cookies['csrftoken'])
        web_login_post = requests.post(url_login,
                                       allow_redirects=False,
                                       data=login_data,
                                       cookies=login_cookies)
        if web_login_post.status_code == http_status.HTTP_302_FOUND:
            _cookies = web_login_post.cookies
            _logger.info('refresh cookies ok')
        elif web_login_post.status_code == http_status.HTTP_200_OK and not self_call:
            _logger.error('refresh cookies failed. super user Not exist!')
            refresh(True)
        else:
            xlogging.raise_system_error('无法通过Web组件验证',
                                        'refresh cookies post failed',
                                        web_login_post.status_code, _logger)
    else:
        xlogging.raise_system_error('无法连接到Web组件', 'refresh cookies get failed',
                                    web_login_get.status_code, _logger)
Exemplo n.º 9
0
    def _start_logic(self, runner_dir):
        self._check_func()
        work_dir = os.path.join(runner_dir, 'agent_application')
        cmd = r'{} application_main.py'.format(self._python_path)
        self.logger.info('fetch_patch cmd : {}       work_dir : {}'.format(
            cmd, work_dir))

        try:
            rc = json.loads(self._get_loader_prx().popen(
                json.dumps({
                    'async': True,
                    'shell': False,
                    'cmd': cmd,
                    'work_dir': work_dir,
                    'timeouts_seconds': None
                })))
        except Exception as e:
            xlogging.raise_system_error(r'启动备份代理失败',
                                        'start_logic {}'.format(e),
                                        1,
                                        logger=self.logger)
            raise  # fix pycharm warn

        logger_msg = r'start_logic rc : {}'.format(rc)
        if not rc['pid']:
            xlogging.raise_system_error(r'启动备份代理失败',
                                        logger_msg,
                                        1,
                                        logger=self.logger)
        else:
            self.logger.info(logger_msg)
Exemplo n.º 10
0
 def pull_file(self, remote_relative_path, local_file_path):
     try:
         sftp = self.ssh.open_sftp()
         sftp.get(self.get_full_path_by_relative(remote_relative_path), local_file_path)
         sftp.close()
     except Exception as e:
         xlogging.raise_system_error(r'获取文件失败', r'push_files failed {}'.format(e), 0, _logger)
Exemplo n.º 11
0
 def create_nbd_device(self):
     if not self._host_params['disksnapshots']:
         xlogging.raise_system_error('参数错误, 无效的磁盘信息', 'no disk info', 3036)
     vnc_address = None
     for disk_info in self._host_params['disksnapshots']:
         _nbd_type = disk_info.get('nbd_type', 'nbdrw')
         nbd_object = nbdrwthread.NbdReadWriteThread()
         _nbd_dev_name, _nbd_dev_number = nbd_object.get_nbd_device_name()
         if _nbd_type == 'nbdrw':
             _cmd_nbd_umount = "/sbin/aio/nbdrw -d {}".format(_nbd_dev_name)
             _cmd_nbd_mount = "/sbin/aio/nbdrw -rw {} {}".format(
                 _nbd_dev_name, disk_info['disk_bytes'])
         elif _nbd_type == 'gznbd':
             _cmd_nbd_umount = "/sbin/aio/gznbd -d {}".format(_nbd_dev_name)
             _cmd_nbd_mount = "/sbin/aio/gznbd -c {}".format(_nbd_dev_name)
         else:
             xlogging.raise_system_error(
                 '未知的nbd类型', 'not support nbd type : {}'.format(_nbd_type),
                 2055)
             return
         for _disk_snapshot in disk_info['images']:
             _cmd_nbd_mount += r' {} {}'.format(_disk_snapshot['path'],
                                                _disk_snapshot['ident'])
         nbd_object.setDaemon(True)
         nbd_object.set_scsi_id(disk_info.get('scsi_id', uuid.uuid4().hex))
         nbd_object.start_and_wait_ready(_cmd_nbd_mount, _cmd_nbd_umount)
         if vnc_address is None:
             if os.path.exists('/dev/shm/debug_vnc'):
                 vnc_address = '0.0.0.0:{}'.format(200 + _nbd_dev_number)
             else:
                 vnc_address = '127.0.0.1:{}'.format(200 + _nbd_dev_number)
         self._nbds.append(nbd_object)
     return vnc_address
Exemplo n.º 12
0
    def start_logic(self, ip, timeout_seconds, runner_dir):
        self._check_quit()
        work_dir = os.path.join(runner_dir, 'FileBackupLogic')
        cmd = r'/usr/bin/python3 FileBackupLogicMain.py'
        self.logger.info('fetch_patch cmd : {}       work_dir : {}'.format(
            cmd, work_dir))

        try:
            rc = json.loads(self._get_loader_prx().popen(
                json.dumps({
                    'async': True,
                    'shell': False,
                    'cmd': cmd,
                    'work_dir': work_dir,
                    'timeouts_seconds': None
                })))
        except Exception as e:
            xlogging.raise_system_error(r'启动备份代理失败',
                                        'start_logic {}'.format(e),
                                        1,
                                        logger=self.logger)
            raise  # fix pycharm warn

        logger_msg = r'start_logic rc : {}'.format(rc)
        if not rc['pid']:
            xlogging.raise_system_error(r'启动备份代理失败',
                                        logger_msg,
                                        1,
                                        logger=self.logger)
        else:
            self.logger.info(logger_msg)

        self._check_connct(ip, timeout_seconds, self._get_prx, False)
        self._set_flag_with_lock('_backup_logic_running')
Exemplo n.º 13
0
 def _check_quit(self):
     with self._locker:
         if self._quit:
             xlogging.raise_system_error(r'用户取消操作',
                                         'self._quit',
                                         1,
                                         logger=self.logger)
Exemplo n.º 14
0
    def _run_kvm(self):

        kvm_cmd = self.__kvm_cmd_mgr.generate_kvm_cmd_line()

        alloc_success = False
        while not alloc_success:
            alloc_success = all_big_mm.CAllocBigMM.try_alloc(self.__kvm_cmd_mgr.get_memory_mbyte())
            if not alloc_success:
                _logger.warning(r'alloc mem for kvm failed,will retry')

        if self.__kvm_cmd_mgr.is_aio_sys_vt_valid():
            cwd = None
        else:
            cwd = r'/sbin/aio/qemu-nokvm'  # 非vt下需要指定工作路径 否则出错

        # shlex.split(kvm_cmd)
        # use exec will not create two process
        self._process = subprocess.Popen('exec ' + kvm_cmd, cwd=cwd, shell=True, stderr=subprocess.PIPE,
                                         stdout=subprocess.PIPE,
                                         universal_newlines=True)
        if self._process.poll() is None:
            _logger.info('KvmHandle start kvm PID:{} {}'.format(self._process.pid, kvm_cmd))
        else:
            msg = 'start kvm error {}|{}|{}'.format(self._process.returncode, *self._process.communicate())
            xlogging.raise_system_error('启动虚拟机失败', msg, 1111)
Exemplo n.º 15
0
def set_root_passwd(passwdinfo):
    cmdline = 'mount -no remount, rw /boot'
    retval = net_common.get_info_from_syscmd(cmdline)
    _logger.debug('remount /boot {} {}'.format(retval[0], retval[1]))
    tmpfile = '/dev/shm/tempstr'
    mpasswd = json.loads(passwdinfo)
    _logger.debug("set root pwd info {}       {}".format(passwdinfo, mpasswd))
    retval = net_common.set_info_to_file(tmpfile, mpasswd, 'w')
    if retval != 0:
        _logger.error('set passwd write file failed,ret {}'.format(retval))
        xlogging.raise_system_error('set passwd failed,{}'.format(retval),
                                    'set passwd failed,{}'.format(retval), -1,
                                    _logger)
    cmdline = 'set_passwd -f {}'.format(tmpfile)
    retval = net_common.get_info_from_syscmd(cmdline)
    if retval[0] != 0:
        _logger.error('set passwd failed,ret {} {}'.format(
            retval[0], retval[1]))
        xlogging.raise_system_error('set passwd failed,{}'.format(retval[0]),
                                    'set passwd failed,{}'.format(retval[0]),
                                    -1, _logger)
    else:
        _logger.debug('set passwd success')

    cmdline = 'umount /boot'
    retval = net_common.get_info_from_syscmd(cmdline)
    _logger.debug('umount /boot {} {}'.format(retval[0], retval[1]))

    cmdline = 'mount -o ro /dev/mapper/boot /boot'
    retval = net_common.get_info_from_syscmd(cmdline)
    _logger.debug('mount /dev/mapper/boot /boot {} {}'.format(
        retval[0], retval[1]))
Exemplo n.º 16
0
    def mount_with_box_service(self, peHostIdent, diskToken, diskBytes):
        try:
            if self.is_mount:
                xlogging.raise_system_error(
                    r'内部错误,重复挂载虚拟磁盘设备',
                    r'mount_with_box_service is_mount {}'.format(
                        self.device_path), self.device_index, _logger)

            nbd_wrapper.check_unused(self.device_name)

            if nbd_wrapper.nbd_read_ok(self.device_path):
                xlogging.raise_system_error(
                    r'内部错误,挂载虚拟磁盘设备重复',
                    r'mount_with_box_service nbd_read_ok {}'.format(
                        self.device_path), self.device_index, _logger)

            cmd_nbd = "{} -b {} {} {} {:d} 5".format(_EXEC_PATH,
                                                     self.device_path,
                                                     peHostIdent, diskToken,
                                                     diskBytes)

            split_nbd_cmd = shlex.split(cmd_nbd)
            with subprocess.Popen(split_nbd_cmd,
                                  stderr=subprocess.PIPE,
                                  universal_newlines=True) as p:
                self.is_mount = True
                _logger.info("mount_with_box_service pid:{} {} ".format(
                    p.pid, cmd_nbd))
                for line in p.stderr:
                    _nbd_logger.debug('{}:{}'.format(p.pid, line.rstrip()))
            _logger.info("mount_with_box_service end : pid:{} - {}".format(
                p.pid, p.returncode))
        finally:
            self.is_mount = False
Exemplo n.º 17
0
    def fetch_patch(self, ip_address):
        self.create_patch_dir()
        if self._logic == 'windows':
            icepatch2client = r'%SYSTEMDRIVE%\icepatch2\icepatch2client'
        else:
            icepatch2client = r'/usr/bin/icepatch2client'
        cmd = r'{icepatch2client} -t' \
              r' --IcePatch2Client.Proxy="IcePatch2/server:tcp -h {ip_address} -p 20090"' \
              r' {patch_dir}'.format(icepatch2client=icepatch2client, ip_address=ip_address, patch_dir=self.patch_dir)

        self.logger.info('fetch_patch cmd : {}'.format(cmd))
        try:
            json.loads(self._get_loader_prx().popen(
                json.dumps({
                    'async': False,
                    'shell': True,
                    'cmd': cmd,
                    'work_dir': None,
                    'timeouts_seconds': 60 * 2
                })))
        except Exception as e:
            self.logger.info('fetch_patch Failed. cmd={},e={}'.format(cmd, e))
            xlogging.raise_system_error(r'配置备份代理失败',
                                        'fetch_patch {}'.format(e),
                                        1,
                                        logger=self.logger)
            raise
Exemplo n.º 18
0
    def mount(self):
        if self._mounted:
            xlogging.raise_system_error(r'内部异常,多次挂载', r'MountNbdLinux mount failed', 1)
        else:
            self._mounted = True

        if self._read_only:
            self.change_gpt_guid()
            self.change_vgs_name_and_uuid()

        mount_params, pvs, swap_devices = self.analyze_mount_params()

        if self._read_only:
            self.change_pvs_uuid(pvs)

        self.activate_lvm()

        if self._read_only:
            self.change_xfs_uuid(mount_params)
            self.change_ext_uuid(mount_params)
            self.change_btrfs_uuid(mount_params)

        self.mount_all(mount_params)

        if self._read_only:
            self.change_chmod_only_read()
        else:
            self.fix_swap(swap_devices)
Exemplo n.º 19
0
 def _create_qcows(self):
     for qcow_file in self._host_params['qcow_files']:
         base_file = qcow_file.get('base')  # 不是必须
         disk_bytes = qcow_file.get('disk_bytes')  # 不是必须
         new_file = qcow_file['new']
         qcow_type = qcow_file['qcow_type']
         self._new_qcow_files.append(new_file)
         _remove_no_exception(new_file)
         if qcow_type == 'with_base':
             assert base_file
             rev = qemuimgcmd.QemuImgCmd().create_qcow2_file_base_old(
                 base_file, new_file)
         elif qcow_type == 'empty':
             assert disk_bytes
             rev = qemuimgcmd.QemuImgCmd().create_qcow2_file_empty(
                 new_file, disk_bytes)
         else:
             xlogging.raise_system_error(
                 '未知的qcow类型',
                 'not support qcow type : {}'.format(qcow_type), 2092)
             return
         if rev[0] != 0:
             xlogging.raise_system_error(
                 '创建虚拟磁盘失败', '_create_qcow failed, rev:{}'.format(rev),
                 2066)
Exemplo n.º 20
0
    def do_work(self, src_ko_file, target_ko_file):

        # 检查文件是不是存在?
        if not os.path.isfile(src_ko_file):
            xlogging.raise_system_error(
                'drv3: file({}) not exist'.format(src_ko_file),
                '文件不存在:{}'.format(src_ko_file), 6, _logger)
        src_bin = get_file_BytesIO(src_ko_file)
        target_bin = copy.copy(src_bin)

        src_elffile = elftools.elf.elffile.ELFFile(src_bin)

        self.check_src_and_include_elf(src_ko_file, src_elffile)

        _src_modinfo_section = src_elffile.get_section_by_name(r'.modinfo')
        _src_version_section = src_elffile.get_section_by_name(r'__versions')

        print_section_info(src_ko_file, _src_modinfo_section)

        src_mod_info = ElfModInfo(src_ko_file, src_bin, _src_modinfo_section)
        self.copy_ver_magic(target_bin, src_mod_info)

        if _src_version_section:
            src_version = ElfVersion(src_bin, _src_version_section,
                                     src_elffile.elfclass)
            self.copy_crc32(target_bin, src_version)

        # 产生新的文件
        self.do_create_target_and_flush(target_bin, target_ko_file)
        return
Exemplo n.º 21
0
    def __init__(self, link_info):

        self.__vm_filename = None
        if 'vm_file' in link_info:
            self.__vm_filename = link_info['vm_file']

        self.__module_sym_file = None
        if 'sym_file' in link_info:
            self.__module_sym_file = link_info['sym_file']

        self.__inc_elf_filename = None
        if 'inc_ko' in link_info:
            self.__inc_elf_filename = link_info['inc_ko']

        self.__target_vermagic = None
        if 'vermagic' in link_info:
            self.__target_vermagic = link_info['vermagic']

        if self.__inc_elf_filename is None and self.__target_vermagic is None:
            xlogging.raise_system_error(r'drv3: no inc.ko or vermagic',
                                        '没有inc.ko或vermagic', 11, _logger)

        if self.__vm_filename is None and self.__module_sym_file is None:
            xlogging.raise_system_error(r'drv3: no vm_file or sym_file',
                                        '没有vmlinux或sym_file', 11, _logger)

        self.__crc32Table = elf_read_crctab.ElfReadCrcTable(
            self.__vm_filename, self.__module_sym_file)
        self.__inc_elf_filename_list = [self.__inc_elf_filename]
        self.__inc_ko = None
        self.init_vermagic()
Exemplo n.º 22
0
def get_device_files(kernel_version, release_version, arch, device):
    """
    得到  设备驱动文件列表 的绝对路径
    :param kernel_version: linux 内核版本
    :param release_version: linux 发行版本
    :param arch: "32" "64" "32_PAE"  x86 or x86_64 or x86_PAE
    :param device: 设备描述
    :return: 成功返回路径数组
    """
    pci_value_list = modget.convert_pci_str_2_pci_value_list(device)
    if not modget.is_pci_value_valid(pci_value_list):
        _logger.error(
            r'modget.is_pci_value_valid False : {}'.format(pci_value_list))
        return None

    db_json = _get_db_json()
    relative_folder, files = _search_db_json(db_json, kernel_version,
                                             release_version, arch,
                                             pci_value_list)
    if relative_folder is None:
        xlogging.raise_system_error(
            r'不支持的设备:{}'.format(device),
            r'get_device_files failed : {} {} {} {}'.format(
                kernel_version, release_version, arch, device), 1)

    result = list()
    for file in files:
        result.append(os.path.join(loadIce.current_dir, relative_folder, file))
    return result
Exemplo n.º 23
0
 def _mount_file_system_to_local(self, mount_point):
     self.logger.info('begin _mount_file_system_to_local')
     self._samba_mount_handle = SAMBAMountHandle(self._samba_params, mount_point)
     self._samba_mount_handle.set_ip(self._guest_ip)
     if not self._samba_mount_handle.mount(self._samba_params['read_only']):
         xlogging.raise_system_error('挂载文件系统失败', 'mount fail', 753)
     self.logger.info('end _mount_file_system_to_local ')
Exemplo n.º 24
0
 def _worker(self, name):
     _logger.info('{} worker begin'.format(name))
     while not self._error:
         params = self._work_params.get()
         tmp_file = '/tmp/cluster_gen_qcow{}.json'.format(uuid.uuid4().hex)
         try:
             if params is self._end_flag:
                 break
             with open(tmp_file, 'w') as f:
                 json.dump(params, f)
             cmd = 'python /sbin/aio/logic_service/generate_cluster_diff_qcow_task.py {}'.format(
                 tmp_file)
             with subprocess.Popen(cmd,
                                   shell=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True) as p:
                 stdout, stderr = p.communicate()
             if p.returncode != 0:
                 xlogging.raise_system_error(
                     '生成QCOW失败',
                     'error:{}|{}|{}'.format(p.returncode, stdout,
                                             stderr), 3073)
         except Exception as e:
             self._error = e
         finally:
             _remove_no_exception(tmp_file)
             self._work_params.task_done()
     _logger.info('{} worker end'.format(name))
Exemplo n.º 25
0
def get_ext_vmlinux(src_vm):

    # 已经是解压缩文件,并且可用。
    try:
        if check_is_elf_file(src_vm):
            if is_include_setion(src_vm):
                with open(src_vm, "rb") as f:
                    return io.BytesIO(f.read())
    except:
        # 忽略错误。
        pass

    try:
        os.makedirs(_TMP_VM_DIR)
    except:
        pass

    exe_sc = os.path.join(loadIce.current_dir, "extract_vmlinux")
    tmp_file = os.path.join(_TMP_VM_DIR, str(uuid.uuid4().hex))

    try:
        # extract-vmlinux >> /tmp/xxxx.bmp
        cmd = "{} {} >> {}".format(exe_sc, src_vm, tmp_file)
        retval, outs, errinfo = net_common.get_info_from_syscmd(cmd)
        _logger.info("drv3: runcmd {} return:{} out:{} errorinfo:{}".format(
            retval, cmd, outs, errinfo))
        if not check_is_elf_file(tmp_file):
            _str = "drv3: 不是标准的elf文件:{}".format(tmp_file)
            _logger.error(_str)
            raise Exception(_str)

        # 有可能没有开始CRC 功能。
        #if not is_include_setion(tmp_file, "__kcrctab"):
        #    _str = "drv3: elf文件:{}不包含__kcrctab".format(tmp_file)
        #    _logger.error(_str)
        #    raise Exception(_str)

        f = open(tmp_file, "rb")
        _vm_iobs = io.BytesIO(f.read())
        f.close()
        os.remove(tmp_file)
        return _vm_iobs

    except Exception as e:
        try:
            os.remove(tmp_file)
        except:
            pass
        xlogging.raise_system_error(
            'drv3: decompress vm ({}) failed{}'.format(src_vm, e),
            '解开({})vm 失败:{}'.format(src_vm, e), 8, _logger)

    try:
        os.remove(tmp_file)
    except:
        pass
    xlogging.raise_system_error(
        'drv3: error vmlinux file ({}) failed'.format(src_vm),
        "错误的vm file({})vm".format(src_vm), 9, _logger)
Exemplo n.º 26
0
 def raise_last_error(self, key, params):
     ins = self._fetch(key)
     if ins and ins.error:
         raise ins.error
     else:
         xlogging.raise_system_error('无效的错误码',
                                     'not found error, ins:{}'.format(ins),
                                     197)
Exemplo n.º 27
0
 def get_snapshot_disk_index(self, disk_ident):
     for info in self._linux_disk_index_info:
         if disk_ident == info['disk_ident']:
             return info['snapshot_disk_index']
     xlogging.raise_system_error(
         r'内部异常,代码3110',
         'get_snapshot_disk_index failed {} not in {}'.format(
             disk_ident, self._linux_disk_index_info), 1)
Exemplo n.º 28
0
 def __init__(self, info):
     self._info = info
     self._meta_data = self._info['meta_data']
     self._media = media_objects.get(self._info['media_uuid'])
     if not self._media:
         xlogging.raise_system_error('获取介质失败', 'get media fail', 138)
     self._logger = merge_hash_core.LoggerAdapter(_logger,
                                                  {'prefix': 'ExportSnapshotsLogic_{}'.format(uuid.uuid4().hex[-6:])})
Exemplo n.º 29
0
 def check_unused(device_name):
     _logger.debug(
         'nbd_wrapper check_unused device_name:{}'.format(device_name))
     if os.path.exists(
             '/dev/{}'.format(device_name)) and nbd_wrapper.nbd_read_ok(
                 '/dev/{}'.format(device_name)):
         xlogging.raise_system_error(
             r'内部错误,虚拟磁盘设备残留',
             r'nbd_wrapper set_used {}'.format(device_name), 2312)
Exemplo n.º 30
0
    def share(self):
        ret = smb_add_user(self.user, self.password, self.read_only)
        if ret[0] != 0:
            xlogging.raise_system_error('SambaShareUser add user fail', 'SambaShareUser add user fail', 131)
        self.add_user = True

        ret = smb_add_hostpath(self.user, self.host_path)
        if ret[0] != 0:
            xlogging.raise_system_error('SambaShareUser add host path fail', 'SambaShareUser add host path fail', 132)
        self.add_host = True