ucscsdk/utils/ucscfirmware.py
def firmware_add_local(handle, local_path, file_name,
                       timeout=15 * 60, progress=Progress()):
    '''
    Import the firmware to UcsCentral from local drive

    Args:
        local_path (str): Local directory where image resides
        file_name (str): Name of the image in the local directory
        timeout (number): Timeout in seconds for the image to get uploaded to
                          ucs central
    Example:
        firmware_add_local(handle,"/Users/guest/Downloads/",
                                  "ucs-k9-bundle-b-series.3.1.1h.B.bin")
    '''
    if not local_path:
        raise UcscValidationException("Missing local_path argument")
    if not file_name:
        raise UcscValidationException("Missing file_name argument")

    file_path = os.path.join(local_path, file_name)
    if not os.path.exists(file_path):
        raise UcscValidationException("File does not exist")

    top_system = TopSystem()
    firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system)
    firmware_downloader = FirmwareDownloader(
        parent_mo_or_dn=firmware_catalogue,
        file_name=file_name)
    firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    try:
        log.debug("Start uploading firmware")
        uri_suffix = "operations/file-%s/image.txt?Cookie=%s" % (
            file_name, handle.cookie)
        handle.file_upload(url_suffix=uri_suffix,
                           file_dir=local_path,
                           file_name=file_name,
                           progress=progress)

    except Exception as err:
        UcscWarning(str(err))
        raise UcscOperationError("Upload firmware", "upload failed")

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

    start = datetime.datetime.now()
    while not firmware_downloader.transfer_state == \
            FirmwareDownloaderConsts.TRANSFER_STATE_DOWNLOADED:
        firmware_downloader = handle.query_dn(firmware_downloader.dn)
        if firmware_downloader.transfer_state == \
                FirmwareDownloaderConsts.TRANSFER_STATE_FAILED:
            raise UcscOperationError(
                    "Import of %s " % file_name,
                    "%s" % firmware_downloader.fsm_rmt_inv_err_descr)
        if (datetime.datetime.now() - start).total_seconds() > timeout:
            raise UcscOperationError(
                "Import of %s" % file_name,  "operation timed out")
        time.sleep(1)

    return firmware_downloader

    Import the firmware to UcsCentral from local drive

    Args:
        local_path (str): Local directory where image resides
        file_name (str): Name of the image in the local directory
        timeout (number): Timeout in seconds for the image to get uploaded to
                          ucs central
    Example:
        firmware_add_local(handle,"/Users/guest/Downloads/",
                                  "ucs-k9-bundle-b-series.3.1.1h.B.bin")
    
Import the firmware to UcsCentral from local drive
Import the firmware to UcsCentral from local drive
def firmware_add_local(handle, local_path, file_name,
                       timeout=15 * 60, progress=Progress()):
    if not local_path:
        raise UcscValidationException("Missing local_path argument")
    if not file_name:
        raise UcscValidationException("Missing file_name argument")
    file_path = os.path.join(local_path, file_name)
    if not os.path.exists(file_path):
        raise UcscValidationException("File does not exist")
    top_system = TopSystem()
    firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system)
    firmware_downloader = FirmwareDownloader(
        parent_mo_or_dn=firmware_catalogue,
        file_name=file_name)
    firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART
    try:
        log.debug("Start uploading firmware")
        uri_suffix = "operations/file-%s/image.txt?Cookie=%s" % (
            file_name, handle.cookie)
        handle.file_upload(url_suffix=uri_suffix,
                           file_dir=local_path,
                           file_name=file_name,
                           progress=progress)
    except Exception as err:
        UcscWarning(str(err))
        raise UcscOperationError("Upload firmware", "upload failed")
    handle.add_mo(firmware_downloader, modify_present=True)
    handle.commit()
    start = datetime.datetime.now()
    while not firmware_downloader.transfer_state == \
            FirmwareDownloaderConsts.TRANSFER_STATE_DOWNLOADED:
        firmware_downloader = handle.query_dn(firmware_downloader.dn)
        if firmware_downloader.transfer_state == \
                FirmwareDownloaderConsts.TRANSFER_STATE_FAILED:
            raise UcscOperationError(
                    "Import of %s " % file_name,
                    "%s" % firmware_downloader.fsm_rmt_inv_err_descr)
        if (datetime.datetime.now() - start).total_seconds() > timeout:
            raise UcscOperationError(
                "Import of %s" % file_name,  "operation timed out")
        time.sleep(1)
    return firmware_downloader
def firmware_add_local ( handle , local_path , file_name , timeout = 15 * 60 , progress = Progress ( ) ) : if not local_path : raise UcscValidationException ( "Missing local_path argument" ) if not file_name : raise UcscValidationException ( "Missing file_name argument" ) file_path = os . path . join ( local_path , file_name ) if not os . path . exists ( file_path ) : raise UcscValidationException ( "File does not exist" ) top_system = TopSystem ( ) firmware_catalogue = FirmwareCatalogue ( parent_mo_or_dn = top_system ) firmware_downloader = FirmwareDownloader ( parent_mo_or_dn = firmware_catalogue , file_name = file_name ) firmware_downloader . server = FirmwareDownloaderConsts . PROTOCOL_LOCAL firmware_downloader . protocol = FirmwareDownloaderConsts . PROTOCOL_LOCAL firmware_downloader . admin_state = FirmwareDownloaderConsts . ADMIN_STATE_RESTART try : log . debug ( "Start uploading firmware" ) uri_suffix = "operations/file-%s/image.txt?Cookie=%s" % ( file_name , handle . cookie ) handle . file_upload ( url_suffix = uri_suffix , file_dir = local_path , file_name = file_name , progress = progress ) except Exception as err : UcscWarning ( str ( err ) ) raise UcscOperationError ( "Upload firmware" , "upload failed" ) handle . add_mo ( firmware_downloader , modify_present = True ) handle . commit ( ) start = datetime . datetime . now ( ) while not firmware_downloader . transfer_state == FirmwareDownloaderConsts . TRANSFER_STATE_DOWNLOADED : firmware_downloader = handle . query_dn ( firmware_downloader . dn ) if firmware_downloader . transfer_state == FirmwareDownloaderConsts . TRANSFER_STATE_FAILED : raise UcscOperationError ( "Import of %s " % file_name , "%s" % firmware_downloader . fsm_rmt_inv_err_descr ) if ( datetime . datetime . now ( ) - start ) . total_seconds ( ) > timeout : raise UcscOperationError ( "Import of %s" % file_name , "operation timed out" ) time . sleep ( 1 ) return firmware_downloader
Import the firmware to UcsCentral from local drive
Import the firmware to UcsCentral from local drive
'''
    Import the firmware to UcsCentral from local drive

    Args:
        local_path (str): Local directory where image resides
        file_name (str): Name of the image in the local directory
        timeout (number): Timeout in seconds for the image to get uploaded to
                          ucs central
    Example:
        firmware_add_local(handle,"/Users/guest/Downloads/",
                                  "ucs-k9-bundle-b-series.3.1.1h.B.bin")
    '''
handle
local_path
Local directory where image resides
Local directory where image resides
file_name
Name of the image in the local directory
Name of the image in the local directory
timeout
Timeout in seconds for the image to get uploaded to
ucs central
Timeout in seconds for the image to get uploaded to ucs central
progress
examples
None