Пример #1
0
    def _bind_mc(self, filespace, highlevel, lowlevel):
        """
        The dsmBindMC function call associates, or binds, a management class to the passed object.
        The object is passed through the Include-Exclude list that is pointed to in the options file.
        If a match is not found in the Include list for a specific management class,
        the default management class is assigned.
        The Exclude list can prevent objects from a backup but not from an archive.
        :param filespace: The filespace name associated for this object
        :param highlevel: The highlevel name associated for this object
        :param lowlevel: The lowlevel name associated for this object
        """
        assert filespace is not None
        assert highlevel is not None
        assert lowlevel is not None

        dsm_obj_name = dsmObjName()
        dsm_obj_name.fs = str_to_bytes(filespace)
        dsm_obj_name.hl = str_to_bytes(highlevel)
        dsm_obj_name.ll = str_to_bytes(lowlevel)
        dsm_obj_name.objType = DSM_OBJ_FILE
        mc_bind_key = mcBindKey()
        mc_bind_key.stVersion = mcBindKeyVersion

        self.method_proxy.dsmBindMC.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmBindMC(self.dsm_handle,
                                         ctypes.byref(dsm_obj_name),
                                         dsmSendTypeEnum.stArchive,
                                         ctypes.byref(mc_bind_key))
        self._raise_err_on_rc(rc)
        return dsm_obj_name
Пример #2
0
    def _bind_mc(self, filespace, highlevel, lowlevel):
        """
        The dsmBindMC function call associates, or binds, a management class to the passed object.
        The object is passed through the Include-Exclude list that is pointed to in the options file.
        If a match is not found in the Include list for a specific management class,
        the default management class is assigned.
        The Exclude list can prevent objects from a backup but not from an archive.
        :param filespace: The filespace name associated for this object
        :param highlevel: The highlevel name associated for this object
        :param lowlevel: The lowlevel name associated for this object
        """
        assert filespace is not None
        assert highlevel is not None
        assert lowlevel is not None

        dsm_obj_name = dsmObjName()
        dsm_obj_name.fs = str_to_bytes(filespace)
        dsm_obj_name.hl = str_to_bytes(highlevel)
        dsm_obj_name.ll = str_to_bytes(lowlevel)
        dsm_obj_name.objType = DSM_OBJ_FILE
        mc_bind_key = mcBindKey()
        mc_bind_key.stVersion = mcBindKeyVersion

        self.method_proxy.dsmBindMC.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmBindMC(self.dsm_handle, ctypes.byref(dsm_obj_name), dsmSendTypeEnum.stArchive,
                                         ctypes.byref(mc_bind_key))
        self._raise_err_on_rc(rc)
        return dsm_obj_name
Пример #3
0
    def _register_fs(self, fs_name, fs_type, fs_info):
        """
        The dsmRegisterFS function call registers a new file space with the Tivoli Storage Manager server.
        Register a file space first before you can back up any data to it.
        :param fs_name: Filespace name to create
        :param fs_type: Filespace type: eg. UNIX
        :param fs_info: Descriptive info data
        """
        assert fs_name is not None
        assert fs_type is not None
        assert fs_info is not None
        dsm_reg_fs_data = regFSData()
        dsm_reg_fs_data.stVersion = regFSDataVersion
        dsm_reg_fs_data.fsName = str_to_bytes(fs_name)
        dsm_reg_fs_data.fsType = str_to_bytes(fs_type)
        dsm_reg_fs_data.fsAttr.unixFSAttr.fsInfo = str_to_bytes(fs_info)
        dsm_reg_fs_data.fsAttr.unixFSAttr.fsInfoLength = len(
            dsm_reg_fs_data.fsAttr.unixFSAttr.fsInfo)

        self.method_proxy.dsmRegisterFS.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmRegisterFS(self.dsm_handle, dsm_reg_fs_data)
        if rc == DSM_RC_FS_ALREADY_REGED:
            logger.info('filespace: {0} is already registered'.format(fs_name))
        else:
            self._raise_err_on_rc(rc)
Пример #4
0
    def log(self,
            msg: str,
            app_msg_id: str = '',
            app_name: str = '',
            severity: int = dsmLogSeverityEnum.logSevInfo,
            log_type: int = dsmLogTypeEnum.logServer):
        """
        The dsmLogEventEx function call logs a user message to the server log file, to the local error log,
        or to both. This call must be performed while at InSession state inside a session.
        Do not perform it within a send, get, or query. See Figure 20.
        The severity determines the Tivoli Storage Manager message number.
        To view messages that are logged on the server, use the query actlog command through the Administrative Client.
        Use the Tivoli Storage Manager client option, errorlogretention,
        to prune the client error log file if the application generates numerous client messages written to the client
        log (dsmLogType either logLocal or logBoth). Refer to the Tivoli Storage Manager Administrator's Reference for
        more information.
        :param msg: This parameter is the text of the event message to log. This must be a null-ended string.
        The maximum length is DSM_MAX_RC_MSG_LENGTH
        :param app_msg_id: This parameter is a string to identify the specific application message.
        The format we recommend is three characters that are followed by four numbers. For example DSM0250
        :param app_name:
        :param severity: This parameter is the event severity. The possible values are:
            logSevInfo,       /* information ANE4990 */
            logSevWarning,    /* warning     ANE4991 */
            logSevError,      /* Error       ANE4992 */
            logSevSevere      /* severe      ANE4993 */
        :param log_type: This parameter specifies where to direct the event.
            The possible values include: logServer, logLocal, or logBoth.
        :return:
        """
        assert msg is not None

        self.connect()

        dsm_log_ex_in = dsmLogExIn_t()
        dsm_log_ex_in.stVersion = dsmLogExInVersion
        dsm_log_ex_in.severity = severity
        dsm_log_ex_in.appMsgID = str_to_bytes(app_msg_id)
        dsm_log_ex_in.logType = log_type
        dsm_log_ex_in.appName = str_to_bytes(app_name)
        dsm_log_ex_in.message = str_to_bytes(msg)

        dsm_log_ex_out = dsmLogExOut_t()
        rc = self.method_proxy.dsmLogEventEx(self.dsm_handle,
                                             ctypes.byref(dsm_log_ex_in),
                                             ctypes.byref(dsm_log_ex_out))
        self._raise_err_on_rc(rc)
Пример #5
0
    def _begin_query(self, filespace, highlevel, lowlevel):
        """
        The dsmBeginQuery function call starts a query request to the server for information
        about one of the following items:

        Archived data
        Backed-up data
        Active backed-up data
        File spaces
        Management classes.
        :param filespace: The filespace name associated for this object
        :param highlevel: The highlevel name associated for this object
        :param lowlevel: The lowlevel name associated for this object
        """
        assert filespace is not None
        assert highlevel is not None
        assert lowlevel is not None

        obj_name = dsmObjName()
        obj_name.fs = str_to_bytes(filespace)
        obj_name.hl = str_to_bytes(highlevel)
        obj_name.ll = str_to_bytes(lowlevel)
        obj_name.objType = DSM_OBJ_FILE

        archive_data = qryArchiveData()
        archive_data.stVersion = qryArchiveDataVersion
        archive_data.objName = ctypes.pointer(obj_name)
        archive_data.insDateLowerBound.year = DATE_MINUS_INFINITE
        archive_data.insDateUpperBound.year = DATE_PLUS_INFINITE
        archive_data.expDateLowerBound.year = DATE_MINUS_INFINITE
        archive_data.expDateUpperBound.year = DATE_PLUS_INFINITE
        archive_data_p = ctypes.pointer(archive_data)

        logger.info(
            'querying for DSM_OBJ_FILE, DATE_MINUS_INFINITE - DATE_PLUS_INFINITE: fs={0}, hl={1}, '
            'll={2}...'.format(filespace, highlevel, lowlevel))

        self.method_proxy.dsmBeginQuery.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmBeginQuery(self.dsm_handle,
                                             dsmQueryTypeEnum.qtArchive,
                                             archive_data_p)
        self._raise_err_on_rc(rc)
Пример #6
0
    def log(self, msg: str, app_msg_id: str = '', app_name: str = '',
            severity: int = dsmLogSeverityEnum.logSevInfo,
            log_type: int = dsmLogTypeEnum.logServer):
        """
        The dsmLogEventEx function call logs a user message to the server log file, to the local error log,
        or to both. This call must be performed while at InSession state inside a session.
        Do not perform it within a send, get, or query. See Figure 20.
        The severity determines the Tivoli Storage Manager message number.
        To view messages that are logged on the server, use the query actlog command through the Administrative Client.
        Use the Tivoli Storage Manager client option, errorlogretention,
        to prune the client error log file if the application generates numerous client messages written to the client
        log (dsmLogType either logLocal or logBoth). Refer to the Tivoli Storage Manager Administrator's Reference for
        more information.
        :param msg: This parameter is the text of the event message to log. This must be a null-ended string.
        The maximum length is DSM_MAX_RC_MSG_LENGTH
        :param app_msg_id: This parameter is a string to identify the specific application message.
        The format we recommend is three characters that are followed by four numbers. For example DSM0250
        :param app_name:
        :param severity: This parameter is the event severity. The possible values are:
            logSevInfo,       /* information ANE4990 */
            logSevWarning,    /* warning     ANE4991 */
            logSevError,      /* Error       ANE4992 */
            logSevSevere      /* severe      ANE4993 */
        :param log_type: This parameter specifies where to direct the event.
            The possible values include: logServer, logLocal, or logBoth.
        :return:
        """
        assert msg is not None

        self.connect()

        dsm_log_ex_in = dsmLogExIn_t()
        dsm_log_ex_in.stVersion = dsmLogExInVersion
        dsm_log_ex_in.severity = severity
        dsm_log_ex_in.appMsgID = str_to_bytes(app_msg_id)
        dsm_log_ex_in.logType = log_type
        dsm_log_ex_in.appName = str_to_bytes(app_name)
        dsm_log_ex_in.message = str_to_bytes(msg)

        dsm_log_ex_out = dsmLogExOut_t()
        rc = self.method_proxy.dsmLogEventEx(self.dsm_handle, ctypes.byref(dsm_log_ex_in), ctypes.byref(dsm_log_ex_out))
        self._raise_err_on_rc(rc)
Пример #7
0
    def _init_session(self):
        """
        Starts an API session using the additional parameters that permit extended verification.
        """
        api_appl_ver = dsmApiVersionEx()
        api_appl_ver.stVersion = apiVersionExVer
        api_appl_ver.version = DSM_API_VERSION
        api_appl_ver.release = DSM_API_RELEASE
        api_appl_ver.level = DSM_API_LEVEL
        api_appl_ver.subLevel = DSM_API_SUBLEVEL
        api_appl_ver_p = ctypes.pointer(api_appl_ver)

        app_ver = dsmAppVersion()
        app_ver.applicationVersion = DSM_API_VERSION
        app_ver.applicationRelease = DSM_API_RELEASE
        app_ver.applicationLevel = DSM_API_LEVEL
        app_ver.applicationSubLevel = DSM_API_SUBLEVEL

        init_in = dsmInitExIn_t()
        init_in.stVersion = dsmInitExInVersion
        init_in.apiVersionExP = api_appl_ver_p
        # Es wird die dsm.sys verwendet, gesetzt durch env variablen DSM_DIR usw.
        # initIn.clientNodeNameP     = ''
        # initIn.clientOwnerNameP    = ''
        # initIn.clientPasswordP     = ''
        init_in.applicationTypeP = str_to_bytes(self.filespace_type)
        # init_in.configfile = ''
        # initIn.options             = ''

        # initIn.userNameP           = ''
        # initIn.userPasswordP       = ''
        # initIn.dirDelimiter        = '\0'
        # initIn.useUnicode          = dsmFalse
        # initIn.bEncryptKeyEnabled  = dsmFalse
        # initIn.encryptionPasswordP = ''
        # initIn.appVersionP         = appVer

        initout = dsmInitExOut_t()
        initout.stVersion = dsmInitExOutVersion

        local_handle = dsUint32_t()
        self.method_proxy.dsmInitEx.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmInitEx(ctypes.byref(local_handle),
                                         ctypes.byref(init_in),
                                         ctypes.byref(initout))
        self._raise_err_on_rc(rc)
        logger.info('dsmInitEx')
        logger.info(
            'Connected to server: {server}, ver/rel/lev {ver}/{rel}/{lev}'.
            format(server=initout.adsmServerName,
                   ver=initout.serverVer,
                   rel=initout.serverRel,
                   lev=initout.serverLev))
        return local_handle
Пример #8
0
    def _begin_query(self, filespace, highlevel, lowlevel):
        """
        The dsmBeginQuery function call starts a query request to the server for information
        about one of the following items:

        Archived data
        Backed-up data
        Active backed-up data
        File spaces
        Management classes.
        :param filespace: The filespace name associated for this object
        :param highlevel: The highlevel name associated for this object
        :param lowlevel: The lowlevel name associated for this object
        """
        assert filespace is not None
        assert highlevel is not None
        assert lowlevel is not None

        obj_name = dsmObjName()
        obj_name.fs = str_to_bytes(filespace)
        obj_name.hl = str_to_bytes(highlevel)
        obj_name.ll = str_to_bytes(lowlevel)
        obj_name.objType = DSM_OBJ_FILE

        archive_data = qryArchiveData()
        archive_data.stVersion = qryArchiveDataVersion
        archive_data.objName = ctypes.pointer(obj_name)
        archive_data.insDateLowerBound.year = DATE_MINUS_INFINITE
        archive_data.insDateUpperBound.year = DATE_PLUS_INFINITE
        archive_data.expDateLowerBound.year = DATE_MINUS_INFINITE
        archive_data.expDateUpperBound.year = DATE_PLUS_INFINITE
        archive_data_p = ctypes.pointer(archive_data)

        logger.info('querying for DSM_OBJ_FILE, DATE_MINUS_INFINITE - DATE_PLUS_INFINITE: fs={0}, hl={1}, '
                    'll={2}...'.format(filespace, highlevel, lowlevel))

        self.method_proxy.dsmBeginQuery.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmBeginQuery(self.dsm_handle, dsmQueryTypeEnum.qtArchive, archive_data_p)
        self._raise_err_on_rc(rc)
Пример #9
0
    def _init_session(self):
        """
        Starts an API session using the additional parameters that permit extended verification.
        """
        api_appl_ver = dsmApiVersionEx()
        api_appl_ver.stVersion = apiVersionExVer
        api_appl_ver.version = DSM_API_VERSION
        api_appl_ver.release = DSM_API_RELEASE
        api_appl_ver.level = DSM_API_LEVEL
        api_appl_ver.subLevel = DSM_API_SUBLEVEL
        api_appl_ver_p = ctypes.pointer(api_appl_ver)

        app_ver = dsmAppVersion()
        app_ver.applicationVersion = DSM_API_VERSION
        app_ver.applicationRelease = DSM_API_RELEASE
        app_ver.applicationLevel = DSM_API_LEVEL
        app_ver.applicationSubLevel = DSM_API_SUBLEVEL

        init_in = dsmInitExIn_t()
        init_in.stVersion = dsmInitExInVersion
        init_in.apiVersionExP = api_appl_ver_p
        # Es wird die dsm.sys verwendet, gesetzt durch env variablen DSM_DIR usw.
        # initIn.clientNodeNameP     = ''
        # initIn.clientOwnerNameP    = ''
        # initIn.clientPasswordP     = ''
        init_in.applicationTypeP = str_to_bytes(self.filespace_type)
        # init_in.configfile = ''
        # initIn.options             = ''

        # initIn.userNameP           = ''
        # initIn.userPasswordP       = ''
        # initIn.dirDelimiter        = '\0'
        # initIn.useUnicode          = dsmFalse
        # initIn.bEncryptKeyEnabled  = dsmFalse
        # initIn.encryptionPasswordP = ''
        # initIn.appVersionP         = appVer

        initout = dsmInitExOut_t()
        initout.stVersion = dsmInitExOutVersion

        local_handle = dsUint32_t()
        self.method_proxy.dsmInitEx.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmInitEx(ctypes.byref(local_handle), ctypes.byref(init_in), ctypes.byref(initout))
        self._raise_err_on_rc(rc)
        logger.info('dsmInitEx')
        logger.info(
            'Connected to server: {server}, ver/rel/lev {ver}/{rel}/{lev}'.format(server=initout.adsmServerName,
                                                                                  ver=initout.serverVer,
                                                                                  rel=initout.serverRel,
                                                                                  lev=initout.serverLev))
        return local_handle
Пример #10
0
    def _register_fs(self, fs_name, fs_type, fs_info):
        """
        The dsmRegisterFS function call registers a new file space with the Tivoli Storage Manager server.
        Register a file space first before you can back up any data to it.
        :param fs_name: Filespace name to create
        :param fs_type: Filespace type: eg. UNIX
        :param fs_info: Descriptive info data
        """
        assert fs_name is not None
        assert fs_type is not None
        assert fs_info is not None
        dsm_reg_fs_data = regFSData()
        dsm_reg_fs_data.stVersion = regFSDataVersion
        dsm_reg_fs_data.fsName = str_to_bytes(fs_name)
        dsm_reg_fs_data.fsType = str_to_bytes(fs_type)
        dsm_reg_fs_data.fsAttr.unixFSAttr.fsInfo = str_to_bytes(fs_info)
        dsm_reg_fs_data.fsAttr.unixFSAttr.fsInfoLength = len(dsm_reg_fs_data.fsAttr.unixFSAttr.fsInfo)

        self.method_proxy.dsmRegisterFS.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmRegisterFS(self.dsm_handle, dsm_reg_fs_data)
        if rc == DSM_RC_FS_ALREADY_REGED:
            logger.info('filespace: {0} is already registered'.format(fs_name))
        else:
            self._raise_err_on_rc(rc)
Пример #11
0
    def _send_obj(self, dsm_obj_name, filename):
        """
        The dsmSendObj function call starts a request to send a single object to storage. +Multiple dsmSendObj calls
        and associated dsmSendData calls can be made within the bounds of a transaction for performance reasons.

        :param dsm_obj_name: Object returned from bind_mc function
        :param filename: The file to be sent
        """
        assert dsm_obj_name is not None
        assert os.path.exists(filename)

        obj_attr = ObjAttr()
        obj_attr.stVersion = ObjAttrVersion

        size = os.path.getsize(filename)
        if size == 0:
            raise TSMError('size of: {0} is 0 bytes.'.format(filename),
                           rc=None)

        hi, lo = convert_size_to_hi_lo(size)
        logger.info('obj size={0} => hi={1}, low={2}'.format(size, hi, lo))
        obj_attr.sizeEstimate.hi = hi
        obj_attr.sizeEstimate.lo = lo
        obj_attr.objCompressed = dsmFalse
        obj_attr.objInfoLength = 17  # todo
        obj_attr.objInfo = str_to_bytes('test-api-objinfo')

        snd_arch_data = sndArchiveData()
        snd_arch_data.stVersion = sndArchiveDataVersion

        data_blk = DataBlk()
        data_blk.stVersion = DataBlkVersion

        self.method_proxy.dsmSendObj.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmSendObj(self.dsm_handle,
                                          dsmSendTypeEnum.stArchive,
                                          ctypes.byref(snd_arch_data),
                                          ctypes.byref(dsm_obj_name),
                                          ctypes.byref(obj_attr),
                                          ctypes.byref(data_blk))
        if rc == DSM_RC_WILL_ABORT:
            self._end_send_obj()
            self._end_tx()
        else:
            self._raise_err_on_rc(rc)
Пример #12
0
    def _send_obj(self, dsm_obj_name, filename):
        """
        The dsmSendObj function call starts a request to send a single object to storage. +Multiple dsmSendObj calls
        and associated dsmSendData calls can be made within the bounds of a transaction for performance reasons.

        :param dsm_obj_name: Object returned from bind_mc function
        :param filename: The file to be sent
        """
        assert dsm_obj_name is not None
        assert os.path.exists(filename)

        obj_attr = ObjAttr()
        obj_attr.stVersion = ObjAttrVersion

        size = os.path.getsize(filename)
        if size == 0:
            raise TSMError('size of: {0} is 0 bytes.'.format(filename), rc=None)

        hi, lo = convert_size_to_hi_lo(size)
        logger.info('obj size={0} => hi={1}, low={2}'.format(size, hi, lo))
        obj_attr.sizeEstimate.hi = hi
        obj_attr.sizeEstimate.lo = lo
        obj_attr.objCompressed = dsmFalse
        obj_attr.objInfoLength = 17  # todo
        obj_attr.objInfo = str_to_bytes('test-api-objinfo')

        snd_arch_data = sndArchiveData()
        snd_arch_data.stVersion = sndArchiveDataVersion

        data_blk = DataBlk()
        data_blk.stVersion = DataBlkVersion

        self.method_proxy.dsmSendObj.errcheck = self.log_dsm_rc_msg()
        rc = self.method_proxy.dsmSendObj(self.dsm_handle,
                                          dsmSendTypeEnum.stArchive,
                                          ctypes.byref(snd_arch_data),
                                          ctypes.byref(dsm_obj_name),
                                          ctypes.byref(obj_attr),
                                          ctypes.byref(data_blk))
        if rc == DSM_RC_WILL_ABORT:
            self._end_send_obj()
            self._end_tx()
        else:
            self._raise_err_on_rc(rc)