コード例 #1
0
ファイル: ucsfirmware.py プロジェクト: vvb/ucsmsdk_samples
def firmware_add_local(handle, image_dir, image_name):

    from ucsmsdk.ucseventhandler import UcsEventHandle

    file_path = os.path.join(image_dir, image_name)

    if not os.path.exists(file_path):
        raise IOError("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=image_name)
    firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    uri_suffix = "operations/file-%s/image.txt" % image_name
    handle.file_upload(url_suffix=uri_suffix,
                       file_dir=image_dir,
                       file_name=image_name)

    handle.add_mo(firmware_downloader)
    handle.set_dump_xml()
    handle.commit()

    return firmware_downloader
コード例 #2
0
ファイル: ucsfirmware.py プロジェクト: vvb/ucsmsdk_samples
def firmware_add_local(handle, image_dir, image_name):

    from ucsmsdk.ucseventhandler import UcsEventHandle

    file_path = os.path.join(image_dir, image_name)

    if not os.path.exists(file_path):
        raise IOError("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=image_name)
    firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    uri_suffix = "operations/file-%s/image.txt" % image_name
    handle.file_upload(url_suffix=uri_suffix,
                       file_dir=image_dir,
                       file_name=image_name)

    handle.add_mo(firmware_downloader)
    handle.set_dump_xml()
    handle.commit()

    return firmware_downloader
コード例 #3
0
ファイル: ucsfirmware.py プロジェクト: ryaeng/ucsmsdk_samples
def firmware_add_local(handle, image_dir, image_name, timeout=10 * 60):
    """
    Downloads the firmware image on ucsm from local server

    Args:
        image_dir (string): path of download directory
        image_name (string): firmware image name
        timeout (number): timeout in seconds

    Returns:
        FirmwareDownloader: Managed Object

    Raises:
        ValueError if download fail or timeout

    Example:
        firmware_add_local(image_dir="/home/imagedir",
                           image_name="ucs-k9-bundle-c-series.2.2.5b.C.bin")
    """

    file_path = os.path.join(image_dir, image_name)

    if not os.path.exists(file_path):
        raise IOError("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=image_name)
    firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    uri_suffix = "operations/file-%s/image.txt" % image_name
    handle.file_upload(url_suffix=uri_suffix,
                       file_dir=image_dir,
                       file_name=image_name)

    handle.add_mo(firmware_downloader, modify_present=True)
    # handle.set_dump_xml()
    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 Exception("Download of '%s' failed. Error: %s" %
                            (image_name,
                             firmware_downloader.fsm_rmt_inv_err_descr))
        if (datetime.datetime.now() - start).total_seconds() > timeout:
            raise Exception("Download of '%s' timed out" % image_name)

    return firmware_downloader
コード例 #4
0
def firmware_add_local(handle, image_dir, image_name, timeout=10 * 60):
    """
    Downloads the firmware image on ucsm from local server

    Args:
        image_dir (string): path of download directory
        image_name (string): firmware image name
        timeout (number): timeout in seconds

    Returns:
        FirmwareDownloader: Managed Object

    Raises:
        ValueError if download fail or timeout

    Example:
        firmware_add_local(image_dir="/home/imagedir",
                           image_name="ucs-k9-bundle-c-series.2.2.5b.C.bin")
    """

    file_path = os.path.join(image_dir, image_name)

    if not os.path.exists(file_path):
        raise IOError("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=image_name)
    firmware_downloader.server = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.protocol = FirmwareDownloaderConsts.PROTOCOL_LOCAL
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    uri_suffix = "operations/file-%s/image.txt" % image_name
    handle.file_upload(url_suffix=uri_suffix,
                       file_dir=image_dir,
                       file_name=image_name)

    handle.add_mo(firmware_downloader, modify_present=True)
    # handle.set_dump_xml()
    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 Exception("Download of '%s' failed. Error: %s" %
                            (image_name,
                             firmware_downloader.fsm_rmt_inv_err_descr))
        if (datetime.datetime.now() - start).total_seconds() > timeout:
            raise Exception("Download of '%s' timed out" % image_name)

    return firmware_downloader
コード例 #5
0
ファイル: ucsfirmware.py プロジェクト: vvb/ucsmsdk_samples
def firmware_add_remote(handle,
                        file_name,
                        remote_path,
                        protocol,
                        server,
                        user="",
                        pwd=""):

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

    if not os.path.exists(file_path):
        raise IOError("Image does not exist")

    if protocol is not FirmwareDownloaderConsts.PROTOCOL_TFTP:
        if not user:
            raise ValueError("Provide user")
        if not pwd:
            raise ValueError("Provide pwd")

    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.remote_path = remote_path
    firmware_downloader.protocol = protocol
    firmware_downloader.server = server
    firmware_downloader.user = user
    firmware_downloader.pwd = pwd
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    handle.add_mo(firmware_downloader)
    handle.set_dump_xml()
    handle.commit()
コード例 #6
0
def firmware_remove(handle, image_name):
    """
    Removes firmware image from  ucsm

    Args:
        handle (UcsHandle)
        image_name (string): firmware image name

    Returns:
        None

    Raises:
        ValueError if image not available on ucsm

    Example:
        firmware_add_remote(handle,
                            file_name="ucs-k9-bundle-c-series.2.2.5b.C.bin")
    """

    top_system = TopSystem()
    firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system)
    firmware_downloader = FirmwareDownloader(
        parent_mo_or_dn=firmware_catalogue, file_name=image_name)

    dn = firmware_downloader.dn
    mo = handle.query_dn(dn)
    if mo is None:
        raise ValueError("Image not available on UCSM.")

    handle.remove_mo(mo)
    # handle.set_dump_xml()
    handle.commit()
コード例 #7
0
def firmware_add_remote(handle, file_name, remote_path, protocol, server,
                        user="", pwd=""):
    """
    Downloads the firmware image on ucsm from remote server

    Args:
        handle (UcsHandle)
        file_name (string): firmware image name
        remote_path (string): path of image directory
        protocol (string): protocol
        server (string): remote server ip address
        user (string): remote server username
        pwd (string): remote server password

    Returns:
        FirmwareDownloader: Managed Object

    Raises:
        ValueError if image not available or incorrect credential

    Example:
        firmware_add_remote(handle,
                            file_name="ucs-k9-bundle-c-series.2.2.5b.C.bin",
                            remote_path="/home/imagedir",
                            protocol="nfs",
                            server="10.65.1.2,
                            user="******", pwd="pwd")
    """

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

    if not os.path.exists(file_path):
        raise IOError("Image does not exist")

    if protocol is not FirmwareDownloaderConsts.PROTOCOL_TFTP:
        if not user:
            raise ValueError("Provide user")
        if not pwd:
            raise ValueError("Provide pwd")

    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.remote_path = remote_path
    firmware_downloader.protocol = protocol
    firmware_downloader.server = server
    firmware_downloader.user = user
    firmware_downloader.pwd = pwd
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    handle.add_mo(firmware_downloader)
    # handle.set_dump_xml()
    handle.commit()
    return firmware_downloader
コード例 #8
0
ファイル: ucsfirmware.py プロジェクト: vvb/ucsmsdk_samples
def firmware_add_remote(handle, file_name, remote_path, protocol, server,
                            user="", pwd=""):

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

    if not os.path.exists(file_path):
        raise IOError("Image does not exist")

    if protocol is not FirmwareDownloaderConsts.PROTOCOL_TFTP:
        if not user:
            raise ValueError("Provide user")
        if not pwd:
            raise ValueError("Provide pwd")

    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.remote_path = remote_path
    firmware_downloader.protocol = protocol
    firmware_downloader.server = server
    firmware_downloader.user = user
    firmware_downloader.pwd = pwd
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    handle.add_mo(firmware_downloader)
    handle.set_dump_xml()
    handle.commit()
コード例 #9
0
ファイル: ucsfirmware.py プロジェクト: ryaeng/ucsmsdk_samples
def firmware_add_remote(handle, file_name, remote_path, protocol, server,
                        user="", pwd=""):
    """
    Downloads the firmware image on ucsm from remote server

    Args:
        handle (UcsHandle)
        file_name (string): firmware image name
        remote_path (string): path of image directory
        protocol (string): protocol
        server (string): remote server ip address
        user (string): remote server username
        pwd (string): remote server password

    Returns:
        FirmwareDownloader: Managed Object

    Raises:
        ValueError if image not available or incorrect credential

    Example:
        firmware_add_remote(handle,
                            file_name="ucs-k9-bundle-c-series.2.2.5b.C.bin",
                            remote_path="/home/imagedir",
                            protocol="nfs",
                            server="10.65.1.2,
                            user="******", pwd="pwd")
    """

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

    if not os.path.exists(file_path):
        raise IOError("Image does not exist")

    if protocol is not FirmwareDownloaderConsts.PROTOCOL_TFTP:
        if not user:
            raise ValueError("Provide user")
        if not pwd:
            raise ValueError("Provide pwd")

    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.remote_path = remote_path
    firmware_downloader.protocol = protocol
    firmware_downloader.server = server
    firmware_downloader.user = user
    firmware_downloader.pwd = pwd
    firmware_downloader.admin_state = \
        FirmwareDownloaderConsts.ADMIN_STATE_RESTART

    handle.add_mo(firmware_downloader)
    # handle.set_dump_xml()
    handle.commit()
    return firmware_downloader
コード例 #10
0
ファイル: ucsfirmware.py プロジェクト: vvb/ucsmsdk_samples
def firmware_remove(handle, image_name):

    top_system = TopSystem()
    firmware_catalogue = FirmwareCatalogue(parent_mo_or_dn=top_system)
    firmware_downloader = FirmwareDownloader(
        parent_mo_or_dn=firmware_catalogue, file_name=image_name)

    dn = firmware_downloader.dn
    mo = handle.query_dn(dn)
    if mo is None:
        raise ValueError("Image not available on UCSM.")

    handle.remove_mo(mo)
    handle.set_dump_xml()
    handle.commit()