ucscsdk/utils/ucscbackup.py
def _backup_or_exportconfig_domain(handle, backup_type, file_dir, file_name,
                                   domain_ip, domain_name, hostname,
                                   preserve_pooled_values, protocol,
                                   username, password, timeout):
    """
    This internal function helps create domain full_state backup or export
    config to remote location
    Note: This is internal function, should use either backup_domain or
    backup_export_config
    Args:
        handle (UcscHandle): UcsCentral Connection handle
        file_dir (str): directory to download ucs backup file to
        file_name (str): name for the backup file
                         (supported file extension is '.tgz')
        backup_type (str): Either full-state or config-all.
        timeout (number) : time in seconds for which method waits
                           for the backUp file to generate before it exits.
        domain_ip(str): IP of domain, set 'None' if domain_name is valid
        domain_name(str): Domain name, valid only if domain_ip is None
        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
        preserve_pooled_values (boolean): True/False,
                                          False - by default

    """
    from ..mometa.mgmt.MgmtBackupOperation import MgmtBackupOperation, \
        MgmtBackupOperationConsts
    from ..mometa.mgmt.MgmtBackup import MgmtBackupConsts
    from .ucscdomain import get_domain, _is_domain_available

    preserve_pooled_values = False

    if not file_dir:
        raise UcscValidationException("Missing file_dir argument")
    if not file_name:
        raise UcscValidationException("Missing file_name argument")
    if not domain_ip:
        raise UcscValidationException("Missing domain_ip argument")

    if backup_type == 'full-state':
        if (not file_name.endswith('.tgz')):
            raise UcscValidationException(
                "file_name must be .tgz format")
    elif backup_type == 'config-all':
        if (not file_name.endswith('.xml')):
            raise UcscValidationException(
                "file_name must be .xml format")
    _validate_remote_host_args(protocol, hostname, username, password)

    domain = get_domain(handle, domain_ip, domain_name)

    if _is_domain_available(handle, domain.id):
        domain_dn = domain.dn
    else:
        raise UcscOperationError("Backup or Export_config",
                                 "Domain with IP %s or name %s not "
                                 "registered or lost visibility "
                                 "with UcsCentral" %
                                 (domain_ip, domain_name))

    file_path = os.path.join(file_dir, file_name)

    mgmt_backup = MgmtBackupOperation(
            parent_mo_or_dn=domain_dn,
            hostname=hostname,
            admin_state=MgmtBackupOperationConsts.ADMIN_STATE_ENABLED,
            proto=protocol,
            type=backup_type,
            remote_file=file_path,
            user=username,
            pwd=password)
    if preserve_pooled_values:
        mgmt_backup.preserve_pooled_values = \
            MgmtBackupOperationConsts.PRESERVE_POOLED_VALUES_YES
    else:
        mgmt_backup.preserve_pooled_values = \
            MgmtBackupOperationConsts.PRESERVE_POOLED_VALUES_NO

    handle.set_mo(mgmt_backup)
    handle.commit()

    log.debug("Triggering Domain Backup ")
    duration = 30
    poll_interval = 2
    backup_status_dn = "extpol/reg/clients/client-" + \
        domain.id + "/backup-" + hostname
    while True:
        backup_status = handle.query_dn(
            dn=backup_status_dn, dme="resource-mgr")
        if backup_status is not None:
            break

        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration - poll_interval))
        if duration == 0:
            raise UcscOperationError(
                "Backup or export config of domain", "not triggered")

    log.debug("Domain Backup Triggered")

    # Checking for the backup to become available.
    log.debug("Waiting for Domain Backup to become available")
    duration = timeout
    poll_interval = 5

    while True:
        backup_status = handle.query_dn(backup_status_dn, dme="resource-mgr")
        if backup_status.over_all_status == \
                MgmtBackupConsts.OVER_ALL_STATUS_ALL_SUCCESS:
            break
        if backup_status.over_all_status != \
                MgmtBackupConsts.OVER_ALL_STATUS_WORK_IN_PROGRESS:
            _fail_and_remove_domain_backup(
                handle, backup_status, 'operation failed')
        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration - poll_interval))
        if duration == 0:
            _fail_and_remove_domain_backup(
                handle, backup_status, 'operation timed out')

    log.debug("Domain backup is available")

    This internal function helps create domain full_state backup or export
    config to remote location
    Note: This is internal function, should use either backup_domain or
    backup_export_config
    Args:
        handle (UcscHandle): UcsCentral Connection handle
        file_dir (str): directory to download ucs backup file to
        file_name (str): name for the backup file
                         (supported file extension is '.tgz')
        backup_type (str): Either full-state or config-all.
        timeout (number) : time in seconds for which method waits
                           for the backUp file to generate before it exits.
        domain_ip(str): IP of domain, set 'None' if domain_name is valid
        domain_name(str): Domain name, valid only if domain_ip is None
        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
        preserve_pooled_values (boolean): True/False,
                                          False - by default

    
This internal function helps create domain full_state backup or export
config to remote location
Note: This is internal function, should use either backup_domain or
backup_export_config
This internal function helps create domain full_state backup or export config to remote location Note : This is internal function should use either backup_domain or backup_export_config
def _backup_or_exportconfig_domain(handle, backup_type, file_dir, file_name,
                                   domain_ip, domain_name, hostname,
                                   preserve_pooled_values, protocol,
                                   username, password, timeout):
    from ..mometa.mgmt.MgmtBackupOperation import MgmtBackupOperation, \
        MgmtBackupOperationConsts
    from ..mometa.mgmt.MgmtBackup import MgmtBackupConsts
    from .ucscdomain import get_domain, _is_domain_available
    preserve_pooled_values = False
    if not file_dir:
        raise UcscValidationException("Missing file_dir argument")
    if not file_name:
        raise UcscValidationException("Missing file_name argument")
    if not domain_ip:
        raise UcscValidationException("Missing domain_ip argument")
    if backup_type == 'full-state':
        if (not file_name.endswith('.tgz')):
            raise UcscValidationException(
                "file_name must be .tgz format")
    elif backup_type == 'config-all':
        if (not file_name.endswith('.xml')):
            raise UcscValidationException(
                "file_name must be .xml format")
    _validate_remote_host_args(protocol, hostname, username, password)
    domain = get_domain(handle, domain_ip, domain_name)
    if _is_domain_available(handle, domain.id):
        domain_dn = domain.dn
    else:
        raise UcscOperationError("Backup or Export_config",
                                 "Domain with IP %s or name %s not "
                                 "registered or lost visibility "
                                 "with UcsCentral" %
                                 (domain_ip, domain_name))
    file_path = os.path.join(file_dir, file_name)
    mgmt_backup = MgmtBackupOperation(
            parent_mo_or_dn=domain_dn,
            hostname=hostname,
            admin_state=MgmtBackupOperationConsts.ADMIN_STATE_ENABLED,
            proto=protocol,
            type=backup_type,
            remote_file=file_path,
            user=username,
            pwd=password)
    if preserve_pooled_values:
        mgmt_backup.preserve_pooled_values = \
            MgmtBackupOperationConsts.PRESERVE_POOLED_VALUES_YES
    else:
        mgmt_backup.preserve_pooled_values = \
            MgmtBackupOperationConsts.PRESERVE_POOLED_VALUES_NO
    handle.set_mo(mgmt_backup)
    handle.commit()
    log.debug("Triggering Domain Backup ")
    duration = 30
    poll_interval = 2
    backup_status_dn = "extpol/reg/clients/client-" + \
        domain.id + "/backup-" + hostname
    while True:
        backup_status = handle.query_dn(
            dn=backup_status_dn, dme="resource-mgr")
        if backup_status is not None:
            break
        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration - poll_interval))
        if duration == 0:
            raise UcscOperationError(
                "Backup or export config of domain", "not triggered")
    log.debug("Domain Backup Triggered")
    log.debug("Waiting for Domain Backup to become available")
    duration = timeout
    poll_interval = 5
    while True:
        backup_status = handle.query_dn(backup_status_dn, dme="resource-mgr")
        if backup_status.over_all_status == \
                MgmtBackupConsts.OVER_ALL_STATUS_ALL_SUCCESS:
            break
        if backup_status.over_all_status != \
                MgmtBackupConsts.OVER_ALL_STATUS_WORK_IN_PROGRESS:
            _fail_and_remove_domain_backup(
                handle, backup_status, 'operation failed')
        time.sleep(min(duration, poll_interval))
        duration = max(0, (duration - poll_interval))
        if duration == 0:
            _fail_and_remove_domain_backup(
                handle, backup_status, 'operation timed out')
    log.debug("Domain backup is available")
def _backup_or_exportconfig_domain ( handle , backup_type , file_dir , file_name , domain_ip , domain_name , hostname , preserve_pooled_values , protocol , username , password , timeout ) : from . . mometa . mgmt . MgmtBackupOperation import MgmtBackupOperation , MgmtBackupOperationConsts from . . mometa . mgmt . MgmtBackup import MgmtBackupConsts from . ucscdomain import get_domain , _is_domain_available preserve_pooled_values = False if not file_dir : raise UcscValidationException ( "Missing file_dir argument" ) if not file_name : raise UcscValidationException ( "Missing file_name argument" ) if not domain_ip : raise UcscValidationException ( "Missing domain_ip argument" ) if backup_type == 'full-state' : if ( not file_name . endswith ( '.tgz' ) ) : raise UcscValidationException ( "file_name must be .tgz format" ) elif backup_type == 'config-all' : if ( not file_name . endswith ( '.xml' ) ) : raise UcscValidationException ( "file_name must be .xml format" ) _validate_remote_host_args ( protocol , hostname , username , password ) domain = get_domain ( handle , domain_ip , domain_name ) if _is_domain_available ( handle , domain . id ) : domain_dn = domain . dn else : raise UcscOperationError ( "Backup or Export_config" , "Domain with IP %s or name %s not " "registered or lost visibility " "with UcsCentral" % ( domain_ip , domain_name ) ) file_path = os . path . join ( file_dir , file_name ) mgmt_backup = MgmtBackupOperation ( parent_mo_or_dn = domain_dn , hostname = hostname , admin_state = MgmtBackupOperationConsts . ADMIN_STATE_ENABLED , proto = protocol , type = backup_type , remote_file = file_path , user = username , pwd = password ) if preserve_pooled_values : mgmt_backup . preserve_pooled_values = MgmtBackupOperationConsts . PRESERVE_POOLED_VALUES_YES else : mgmt_backup . preserve_pooled_values = MgmtBackupOperationConsts . PRESERVE_POOLED_VALUES_NO handle . set_mo ( mgmt_backup ) handle . commit ( ) log . debug ( "Triggering Domain Backup " ) duration = 30 poll_interval = 2 backup_status_dn = "extpol/reg/clients/client-" + domain . id + "/backup-" + hostname while True : backup_status = handle . query_dn ( dn = backup_status_dn , dme = "resource-mgr" ) if backup_status is not None : break time . sleep ( min ( duration , poll_interval ) ) duration = max ( 0 , ( duration - poll_interval ) ) if duration == 0 : raise UcscOperationError ( "Backup or export config of domain" , "not triggered" ) log . debug ( "Domain Backup Triggered" ) log . debug ( "Waiting for Domain Backup to become available" ) duration = timeout poll_interval = 5 while True : backup_status = handle . query_dn ( backup_status_dn , dme = "resource-mgr" ) if backup_status . over_all_status == MgmtBackupConsts . OVER_ALL_STATUS_ALL_SUCCESS : break if backup_status . over_all_status != MgmtBackupConsts . OVER_ALL_STATUS_WORK_IN_PROGRESS : _fail_and_remove_domain_backup ( handle , backup_status , 'operation failed' ) time . sleep ( min ( duration , poll_interval ) ) duration = max ( 0 , ( duration - poll_interval ) ) if duration == 0 : _fail_and_remove_domain_backup ( handle , backup_status , 'operation timed out' ) log . debug ( "Domain backup is available" )
This internal function helps create domain full_state backup or export
config to remote location
Note: This is internal function, should use either backup_domain or
backup_export_config
This internal function helps create domain full_state backup or export config to remote location Note : This is internal function should use either backup_domain or backup_export_config
"""
    This internal function helps create domain full_state backup or export
    config to remote location
    Note: This is internal function, should use either backup_domain or
    backup_export_config
    Args:
        handle (UcscHandle): UcsCentral Connection handle
        file_dir (str): directory to download ucs backup file to
        file_name (str): name for the backup file
                         (supported file extension is '.tgz')
        backup_type (str): Either full-state or config-all.
        timeout (number) : time in seconds for which method waits
                           for the backUp file to generate before it exits.
        domain_ip(str): IP of domain, set 'None' if domain_name is valid
        domain_name(str): Domain name, valid only if domain_ip is None
        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
        preserve_pooled_values (boolean): True/False,
                                          False - by default

    """ # Checking for the backup to become available.
handle
UcsCentral Connection handle
UcsCentral Connection handle
backup_type
Either full-state or config-all.
Either full - state or config - all .
file_dir
directory to download ucs backup file to
directory to download ucs backup file to
file_name
name for the backup file
(supported file extension is '.tgz')
name for the backup file ( supported file extension is ' . tgz ' )
domain_ip
IP of domain, set 'None' if domain_name is valid
IP of domain set ' None ' if domain_name is valid
domain_name
Domain name, valid only if domain_ip is None
Domain name valid only if domain_ip is None
hostname
Hostname/IP for the remote backup
Hostname / IP for the remote backup
preserve_pooled_values
True/False,
False - by default
True / False False - by default
protocol
Transfer protocol for remote backup
['ftp','sftp','tftp','scp']
Transfer protocol for remote backup [ ' ftp ' ' sftp ' ' tftp ' ' scp ' ]
username
Username for remote backup
Username for remote backup
password
Password for remote backup
Password for remote backup
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 .