ucscsdk/utils/ucscbackup.py
def _export_config(handle, file_dir, file_name, timeout=600,
                   remote_enabled=False, protocol=None,
                   hostname="localhost", username=None, password="",
                   remove_from_ucsc=False,
                   preserve_pooled_values=False):
    """
    _export_config internal method helps export UcsCentral config-all backup
    and download it locally or to remote location.

    Args:
        handle (UcscHandle): UcsCentral Connection handle
        file_dir (str): directory to download ucs backup file to
        file_name (str): name for the backup file
        timeout (number) : time in seconds for which method waits
                              for the backUp file to generate before it exits.
        remote_enabled (boolean): True if Remote backup is enabled
                                  False - by default
        protocol (str): Transfer protocol for remote backup
                        ['ftp','sftp','tftp','scp']
        hostname (str): Hostname/IP for the remote backup
        username (str): Username for remote backup
        password (str): Password for remote backup
        remove_from_ucsc (boolean): True/False, False - by default
        preserve_pooled_values (boolean): True/False, False - by default

    Example:
        file_dir = "/home/user/backup"\n
        file_name = "export_config.tgz"\n
        _export_config(handle, file_dir=test_support,
                       file_name=file_name)\n

        _export_config(handle, file_dir=test_support,
                    file_name=file_name,remote_enabled=True,
                    protocol='scp',hostname='192.168.1.1',
                    username='admin',password='password')\n

    """
    from ..mometa.mgmt.MgmtDataExporter import MgmtDataExporter, \
        MgmtDataExporterConsts
    from ..mometa.top.TopSystem import TopSystem

    backup_type = "config-all"
    if not file_dir:
        raise UcscValidationException("Missing file_dir argument")
    if not file_name:
        raise UcscValidationException("Missing file_name argument")

    top_system = TopSystem()

    if remote_enabled:
        _validate_remote_host_args(protocol, hostname, username, password)
        if (not file_name.endswith('.tgz')):
            raise UcscValidationException(
                "file_name must be .tgz format")

        file_path = os.path.join(file_dir, file_name)
        mgmt_export = MgmtDataExporter(
                parent_mo_or_dn=top_system,
                hostname=hostname,
                admin_state=MgmtDataExporterConsts.ADMIN_STATE_ENABLED,
                proto=protocol,
                type=backup_type,
                remote_file=file_path,
                user=username,
                pwd=password)
    else:
        if not os.path.exists(file_dir):
            os.makedirs(file_dir)

        file_string = platform.node().lower() \
            + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        file_path = "/" + file_string + "_" + backup_type + "_backup.tgz"

        mgmt_export = MgmtDataExporter(
                parent_mo_or_dn=top_system,
                hostname=hostname,
                admin_state=MgmtDataExporterConsts.ADMIN_STATE_ENABLED,
                proto=MgmtDataExporterConsts.PROTO_HTTP,
                type=backup_type,
                remote_file=file_path)

    if preserve_pooled_values:
        mgmt_export.preserve_pooled_values = \
            MgmtDataExporterConsts.PRESERVE_POOLED_VALUES_YES
    else:
        mgmt_export.preserve_pooled_values = \
            MgmtDataExporterConsts.PRESERVE_POOLED_VALUES_NO

    handle.add_mo(mgmt_export, modify_present=True)
    handle.commit()

    mgmt_export = handle.query_dn(dn=mgmt_export.dn)
    admin_state_temp = mgmt_export.admin_state
    log.debug("Starting export config")
    # Checking for the backup to compete.
    duration = timeout
    poll_interval = 2

    while True:
        mgmt_export = handle.query_dn(dn=mgmt_export.dn)
        admin_state_temp = mgmt_export.admin_state

        # Break condition:- if state id disabled then break
        if admin_state_temp == MgmtDataExporterConsts.ADMIN_STATE_DISABLED:
            break

        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration - poll_interval))
        if duration == 0:
            handle.remove_mo(mgmt_export)
            handle.commit()
            raise UcscOperationError(
                "Config Export UcsCentral", "operation timed out")

    if remote_enabled:
        if mgmt_export.over_all_status == \
                MgmtDataExporterConsts.OVER_ALL_STATUS_FAILED:
            log.debug("Config exported failed")
            handle.remove_mo(mgmt_export)
            handle.commit()
            raise UcscOperationError(
                "Config Export UcsCentral", "%s" % mgmt_export.fsm_rmt_inv_err_descr)

    if not remote_enabled:
        file_source = "backupfile" + file_path
        if handle.is_local_download_supported():
            try:
                log.debug("Starting download")
                handle.file_download(url_suffix=file_source,
                                     file_dir=file_dir,
                                     file_name=file_name)
            except Exception as err:
                log.debug("Download export config Failed")
                UcscWarning(str(err))
        else:
            log.error("Local download not supported from sdk for this "
                      "version of UcsCentral, skipping it")

    if remove_from_ucsc:
        # remove backup from UcsCentral
        log.debug("Removing export config from UcsCentral")
        handle.remove_mo(mgmt_export)
        handle.commit()

    _export_config internal method helps export UcsCentral config-all backup
    and download it locally or to remote location.

    Args:
        handle (UcscHandle): UcsCentral Connection handle
        file_dir (str): directory to download ucs backup file to
        file_name (str): name for the backup file
        timeout (number) : time in seconds for which method waits
                              for the backUp file to generate before it exits.
        remote_enabled (boolean): True if Remote backup is enabled
                                  False - by default
        protocol (str): Transfer protocol for remote backup
                        ['ftp','sftp','tftp','scp']
        hostname (str): Hostname/IP for the remote backup
        username (str): Username for remote backup
        password (str): Password for remote backup
        remove_from_ucsc (boolean): True/False, False - by default
        preserve_pooled_values (boolean): True/False, False - by default

    Example:
        file_dir = "/home/user/backup"\n
        file_name = "export_config.tgz"\n
        _export_config(handle, file_dir=test_support,
                       file_name=file_name)\n

        _export_config(handle, file_dir=test_support,
                    file_name=file_name,remote_enabled=True,
                    protocol='scp',hostname='192.168.1.1',
                    username='admin',password='password')\n

    
_export_config internal method helps export UcsCentral config-all backup
and download it locally or to remote location.
_export_config internal method helps export UcsCentral config - all backup and download it locally or to remote location .
def _export_config(handle, file_dir, file_name, timeout=600,
                   remote_enabled=False, protocol=None,
                   hostname="localhost", username=None, password="",
                   remove_from_ucsc=False,
                   preserve_pooled_values=False):
    from ..mometa.mgmt.MgmtDataExporter import MgmtDataExporter, \
        MgmtDataExporterConsts
    from ..mometa.top.TopSystem import TopSystem
    backup_type = "config-all"
    if not file_dir:
        raise UcscValidationException("Missing file_dir argument")
    if not file_name:
        raise UcscValidationException("Missing file_name argument")
    top_system = TopSystem()
    if remote_enabled:
        _validate_remote_host_args(protocol, hostname, username, password)
        if (not file_name.endswith('.tgz')):
            raise UcscValidationException(
                "file_name must be .tgz format")
        file_path = os.path.join(file_dir, file_name)
        mgmt_export = MgmtDataExporter(
                parent_mo_or_dn=top_system,
                hostname=hostname,
                admin_state=MgmtDataExporterConsts.ADMIN_STATE_ENABLED,
                proto=protocol,
                type=backup_type,
                remote_file=file_path,
                user=username,
                pwd=password)
    else:
        if not os.path.exists(file_dir):
            os.makedirs(file_dir)
        file_string = platform.node().lower() \
            + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        file_path = "/" + file_string + "_" + backup_type + "_backup.tgz"
        mgmt_export = MgmtDataExporter(
                parent_mo_or_dn=top_system,
                hostname=hostname,
                admin_state=MgmtDataExporterConsts.ADMIN_STATE_ENABLED,
                proto=MgmtDataExporterConsts.PROTO_HTTP,
                type=backup_type,
                remote_file=file_path)
    if preserve_pooled_values:
        mgmt_export.preserve_pooled_values = \
            MgmtDataExporterConsts.PRESERVE_POOLED_VALUES_YES
    else:
        mgmt_export.preserve_pooled_values = \
            MgmtDataExporterConsts.PRESERVE_POOLED_VALUES_NO
    handle.add_mo(mgmt_export, modify_present=True)
    handle.commit()
    mgmt_export = handle.query_dn(dn=mgmt_export.dn)
    admin_state_temp = mgmt_export.admin_state
    log.debug("Starting export config")
    duration = timeout
    poll_interval = 2
    while True:
        mgmt_export = handle.query_dn(dn=mgmt_export.dn)
        admin_state_temp = mgmt_export.admin_state
        if admin_state_temp == MgmtDataExporterConsts.ADMIN_STATE_DISABLED:
            break
        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration - poll_interval))
        if duration == 0:
            handle.remove_mo(mgmt_export)
            handle.commit()
            raise UcscOperationError(
                "Config Export UcsCentral", "operation timed out")
    if remote_enabled:
        if mgmt_export.over_all_status == \
                MgmtDataExporterConsts.OVER_ALL_STATUS_FAILED:
            log.debug("Config exported failed")
            handle.remove_mo(mgmt_export)
            handle.commit()
            raise UcscOperationError(
                "Config Export UcsCentral", "%s" % mgmt_export.fsm_rmt_inv_err_descr)
    if not remote_enabled:
        file_source = "backupfile" + file_path
        if handle.is_local_download_supported():
            try:
                log.debug("Starting download")
                handle.file_download(url_suffix=file_source,
                                     file_dir=file_dir,
                                     file_name=file_name)
            except Exception as err:
                log.debug("Download export config Failed")
                UcscWarning(str(err))
        else:
            log.error("Local download not supported from sdk for this "
                      "version of UcsCentral, skipping it")
    if remove_from_ucsc:
        log.debug("Removing export config from UcsCentral")
        handle.remove_mo(mgmt_export)
        handle.commit()
def _export_config ( handle , file_dir , file_name , timeout = 600 , remote_enabled = False , protocol = None , hostname = "localhost" , username = None , password = "" , remove_from_ucsc = False , preserve_pooled_values = False ) : from . . mometa . mgmt . MgmtDataExporter import MgmtDataExporter , MgmtDataExporterConsts from . . mometa . top . TopSystem import TopSystem backup_type = "config-all" if not file_dir : raise UcscValidationException ( "Missing file_dir argument" ) if not file_name : raise UcscValidationException ( "Missing file_name argument" ) top_system = TopSystem ( ) if remote_enabled : _validate_remote_host_args ( protocol , hostname , username , password ) if ( not file_name . endswith ( '.tgz' ) ) : raise UcscValidationException ( "file_name must be .tgz format" ) file_path = os . path . join ( file_dir , file_name ) mgmt_export = MgmtDataExporter ( parent_mo_or_dn = top_system , hostname = hostname , admin_state = MgmtDataExporterConsts . ADMIN_STATE_ENABLED , proto = protocol , type = backup_type , remote_file = file_path , user = username , pwd = password ) else : if not os . path . exists ( file_dir ) : os . makedirs ( file_dir ) file_string = platform . node ( ) . lower ( ) + datetime . datetime . now ( ) . strftime ( "%Y%m%d%H%M%S" ) file_path = "/" + file_string + "_" + backup_type + "_backup.tgz" mgmt_export = MgmtDataExporter ( parent_mo_or_dn = top_system , hostname = hostname , admin_state = MgmtDataExporterConsts . ADMIN_STATE_ENABLED , proto = MgmtDataExporterConsts . PROTO_HTTP , type = backup_type , remote_file = file_path ) if preserve_pooled_values : mgmt_export . preserve_pooled_values = MgmtDataExporterConsts . PRESERVE_POOLED_VALUES_YES else : mgmt_export . preserve_pooled_values = MgmtDataExporterConsts . PRESERVE_POOLED_VALUES_NO handle . add_mo ( mgmt_export , modify_present = True ) handle . commit ( ) mgmt_export = handle . query_dn ( dn = mgmt_export . dn ) admin_state_temp = mgmt_export . admin_state log . debug ( "Starting export config" ) duration = timeout poll_interval = 2 while True : mgmt_export = handle . query_dn ( dn = mgmt_export . dn ) admin_state_temp = mgmt_export . admin_state if admin_state_temp == MgmtDataExporterConsts . ADMIN_STATE_DISABLED : break time . sleep ( min ( duration , poll_interval ) ) duration = max ( 0 , ( duration - poll_interval ) ) if duration == 0 : handle . remove_mo ( mgmt_export ) handle . commit ( ) raise UcscOperationError ( "Config Export UcsCentral" , "operation timed out" ) if remote_enabled : if mgmt_export . over_all_status == MgmtDataExporterConsts . OVER_ALL_STATUS_FAILED : log . debug ( "Config exported failed" ) handle . remove_mo ( mgmt_export ) handle . commit ( ) raise UcscOperationError ( "Config Export UcsCentral" , "%s" % mgmt_export . fsm_rmt_inv_err_descr ) if not remote_enabled : file_source = "backupfile" + file_path if handle . is_local_download_supported ( ) : try : log . debug ( "Starting download" ) handle . file_download ( url_suffix = file_source , file_dir = file_dir , file_name = file_name ) except Exception as err : log . debug ( "Download export config Failed" ) UcscWarning ( str ( err ) ) else : log . error ( "Local download not supported from sdk for this " "version of UcsCentral, skipping it" ) if remove_from_ucsc : log . debug ( "Removing export config from UcsCentral" ) handle . remove_mo ( mgmt_export ) handle . commit ( )
_export_config internal method helps export UcsCentral config-all backup
and download it locally or to remote location.
_export_config internal method helps export UcsCentral config - all backup and download it locally or to remote location .
"""
    _export_config internal method helps export UcsCentral config-all backup
    and download it locally or to remote location.

    Args:
        handle (UcscHandle): UcsCentral Connection handle
        file_dir (str): directory to download ucs backup file to
        file_name (str): name for the backup file
        timeout (number) : time in seconds for which method waits
                              for the backUp file to generate before it exits.
        remote_enabled (boolean): True if Remote backup is enabled
                                  False - by default
        protocol (str): Transfer protocol for remote backup
                        ['ftp','sftp','tftp','scp']
        hostname (str): Hostname/IP for the remote backup
        username (str): Username for remote backup
        password (str): Password for remote backup
        remove_from_ucsc (boolean): True/False, False - by default
        preserve_pooled_values (boolean): True/False, False - by default

    Example:
        file_dir = "/home/user/backup"\n
        file_name = "export_config.tgz"\n
        _export_config(handle, file_dir=test_support,
                       file_name=file_name)\n

        _export_config(handle, file_dir=test_support,
                    file_name=file_name,remote_enabled=True,
                    protocol='scp',hostname='192.168.1.1',
                    username='admin',password='password')\n

    """ # Checking for the backup to compete. # Break condition:- if state id disabled then break # remove backup from UcsCentral
handle
UcsCentral Connection handle
UcsCentral Connection handle
file_dir
directory to download ucs backup file to
directory to download ucs backup file to
file_name
name for the backup file
name for the backup file
timeout
time in seconds for which method waits
for the backUp file to generate before it exits.
time in seconds for which method waits for the backUp file to generate before it exits .
remote_enabled
True if Remote backup is enabled
False - by default
True if Remote backup is enabled False - by default
protocol
Transfer protocol for remote backup
['ftp','sftp','tftp','scp']
Transfer protocol for remote backup [ ' ftp ' ' sftp ' ' tftp ' ' scp ' ]
hostname
Hostname/IP for the remote backup
Hostname / IP for the remote backup
username
Username for remote backup
Username for remote backup
password
Password for remote backup
Password for remote backup
remove_from_ucsc
True/False, False - by default
True / False False - by default
preserve_pooled_values
True/False, False - by default
True / False False - by default
examples


_export_config(handle, file_dir=test_support,
file_name=file_name,remote_enabled=True,
protocol='scp',hostname='192.168.1.1',
username='admin',password='password')\n
_export_config ( handle file_dir = test_support file_name = file_name remote_enabled = True protocol = ' scp ' hostname = ' 192 . 168 . 1 . 1 ' username = ' admin ' password = ' password ' ) \ n