示例#1
0
def CollectInventory(arglist):
    parser = ArgumentParser(description='Inventory Collector')
    parser.add_argument('-u', '--user', 
        action="store", dest="user", type=str, nargs='?',
        default='root', help="Username to use for iDRAC")
    parser.add_argument('-p', '--password', 
        action="store", dest="password", type=str,
        default='calvin', help="Password to use for iDRAC")
    parser.add_argument('-i', '--ipaddress',
        action="store", dest="idrac_ip", nargs='+',
        help="ipaddress of iDRAC")
    parser.add_argument('-f', '--folder', 
        action="store", dest="folder", type=str,
        help="folder from where inventory is serialized")

    options = parser.parse_args(arglist)

    if options.password is None:
        print("password must be provided")
        return -1
    if options.user is None:
        print("user must be provided")
        return -1
    if options.folder is None:
        print("Folder must be provided")
        return -1
    if options.idrac_ip is None or len(options.idrac_ip) <= 0:
        print("iDRAC ip addresses must be provided")
        return -1


    updshare = LocalFile(local = options.folder, isFolder=True)
    if not updshare.IsValid:
        print("Folder is not writable!")
        return -2

    print("Configuring Update Share...")
    UpdateManager.configure(updshare)

    sd = sdkinfra()
    sd.importPath()
    creds = UserCredentials(options.user, options.password)
    for ipaddr in options.idrac_ip:
        try:
            print("Connecting to " + ipaddr + " ... ")
            idrac = sd.get_driver(sd.driver_enum.iDRAC, ipaddr, creds)
            if idrac:
                print("    ... saving firmware!")
                UpdateHelper.save_firmware_inventory(idrac)
                idrac.disconnect()
            else:
                print("    failed to connect to iDRAC")
        except Exception as ex:
            print(str(ex))
示例#2
0
def sw_inventory(idrac, module):
    """
    Get Firmware Inventory

    Keyword arguments:
    idrac  -- iDRAC handle
    module -- Ansible module
    """

    msg = {}
    msg['changed'] = False
    msg['failed'] = False
    msg['msg'] = {}
    error = False

    try:
        if module.params['choice'] == "all":
            msg['msg'] = idrac.update_mgr.get_swidentity()
        elif module.params['choice'] == "installed":
            msg['msg'] = idrac.update_mgr.InstalledFirmware

        if module.params['serialize']:
            fw_inv_path = LocalFile(local=module.params['share_mnt'],
                                    isFolder=True)

            if fw_inv_path.IsValid:
                UpdateManager.configure(fw_inv_path)
                msg['msg'] = UpdateHelper.save_firmware_inventory(idrac)

                if "Status" in msg['msg'] and msg['msg']['Status'] != "Success":
                    msg['failed'] = True
            else:
                msg['msg'] = "Error: Network share is not valid"
                msg['failed'] = True

    except Exception as err:
        error = True
        msg['msg'] = "Error: %s" % str(err)
        msg['exception'] = traceback.format_exc()
        msg['failed'] = True

    return msg, error
示例#3
0
def CompareInventory(arglist):
    parser = ArgumentParser(description='Compare Inventory')
    # parser.add_argument('-u', '--user',
    #    action="store", dest="user", type=str, nargs='?',
    #    default='tempuser', help="Username to use for iDRAC")
    # parser.add_argument('-p', '--password',
    #    action="store", dest="password", type=str,
    #    default='temppwd', help="Password to use for iDRAC")
    # parser.add_argument('-i', '--ipaddress',
    #    action="store", dest="idrac_ip", nargs='+',
    #    help="ipaddress of iDRAC")
    parser.add_argument('-f',
                        '--folder',
                        action="store",
                        dest="folder",
                        type=str,
                        help="folder from where inventory is serialized")
    parser.add_argument('-C',
                        '--catalog',
                        action="store",
                        dest="catalog",
                        type=str,
                        nargs='?',
                        default='Catalog',
                        help="Catalog to load")

    parser.add_argument('-o',
                        '--output',
                        action="store",
                        dest="output",
                        type=str,
                        nargs='?',
                        default='csv',
                        help="Catalog to load")

    options = parser.parse_args(arglist)

    # if options.password is None:
    #    print("password must be provided")
    #    return -1
    # if options.user is None:
    #    print("user must be provided")
    #    return -1
    # if options.idrac_ip is None or len(options.idrac_ip) <= 0:
    #    print("iDRAC ip addresses must be provided")
    #    return -1
    if options.folder is None:
        print("Folder must be provided")
        return -1
    if options.catalog is None:
        options.catalog = 'Catalog'
    if options.output is None:
        options.output = 'csv'

    updshare = LocalFile(local=options.folder, isFolder=True)
    if not updshare.IsValid:
        print("Folder is not writable!")
        return -2

    UpdateManager.configure(updshare)
    rjson = UpdateHelper.get_firmware_inventory()
    dev_fw = {}
    if rjson['Status'] == 'Success':
        dev_fw = rjson['retval']

    updmgr = UpdateManager.get_instance()
    (ignore, cache_cat) = updmgr.getCatalogScoper(options.catalog)
    devcompare = {}
    for dev in dev_fw:
        swidentity = dev_fw[dev]
        devcompare[dev] = cache_cat.compare(swidentity['Model_Hex'],
                                            swidentity)
        print('{0},{1},{2},{3},{4},{5},{6},"{7}"'.format(
            'Device', 'Component', 'UpdateNeeded', 'UpdatePackage',
            'UpdateType', 'Server.Version', 'Catalog.Version',
            'Reboot Required'))
        for fqdd in devcompare[dev]:
            for fw in devcompare[dev][fqdd]:
                print('{0},"{1}",{2},{3},{4},"{5}","{6}",{7}'.format(
                    str(dev), str(fw.get('ElementName')),
                    str(TypeHelper.resolve(fw.get('UpdateNeeded'))),
                    str(TypeHelper.resolve(fw.get('UpdatePackage'))),
                    str(TypeHelper.resolve(fw.get('UpdateType'))),
                    str(fw.get('Server.Version')),
                    str(fw.get('Catalog.Version', 'Not Available')),
                    str(fw.get('Catalog.rebootRequired', ''))))
示例#4
0
def RepoBuilder(arglist):
    parser = ArgumentParser(description='Local Repository Builder')
    parser.add_argument(
        '-C',
        '--catalog',
        action="store",
        dest="catalog",
        nargs='?',
        default='Catalog',
        type=str,
        help="Name of the Catalog file that contains the info about needed DUPs"
    )
    parser.add_argument('-f',
                        '--folder',
                        action="store",
                        dest="folder",
                        type=str,
                        help="folder from where repository is built")
    parser.add_argument('-c',
                        '--components',
                        action="store",
                        dest="component",
                        nargs='+',
                        help="components for which the DUPs are requested.")
    parser.add_argument('-s',
                        '--site',
                        action="store",
                        dest="site",
                        type=str,
                        nargs='?',
                        default='downloads.dell.com',
                        help="models for which the DUPs are requested.")
    parser.add_argument('-p',
                        '--protocol',
                        action="store",
                        dest="protocol",
                        nargs='?',
                        default='HTTP',
                        choices=['HTTP', 'FTP', 'NoOp', 'HashCheck'],
                        help="models for which the DUPs are requested.")
    parser.add_argument('-v',
                        '--verbose',
                        action="store_true",
                        help="verbose mode")
    parser.add_argument('-D',
                        '--download-dups',
                        action="store_true",
                        dest="dld_dups",
                        help="download DUPs")
    parser.add_argument('-l',
                        '--download-catalog',
                        action="store_true",
                        dest="dld_catalog",
                        help="download catalog")
    parser.add_argument('-b',
                        '--build-catalog',
                        action="store_true",
                        dest="build_catalog",
                        help="build catalog")
    parser.add_argument('-i',
                        '--download-index',
                        action="store_true",
                        dest="dld_index",
                        help="build index")

    options = parser.parse_args(arglist)
    if not options.component:
        options.component = []

    if options.folder is None:
        print("Folder must be provided")
        return -1

    if options.verbose is None:
        options.verbose = False

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    if not options.dld_dups and not options.build_catalog and \
       not options.dld_catalog:
        options.dld_catalog = True
        options.build_catalog = True
        options.dld_dups = True

    options.protocol = TypeHelper.convert_to_enum(options.protocol,
                                                  DownloadProtocolEnum)

    updshare = LocalFile(local=options.folder, isFolder=True)
    if not updshare.IsValid:
        print("Folder is not writable!")
        return -2

    if options.protocol != DownloadProtocolEnum.HashCheck:
        print("Configuring Update Share...")
    UpdateManager.configure(updshare,
                            site=options.site,
                            protocol=options.protocol)

    if options.dld_catalog:
        if options.protocol != DownloadProtocolEnum.HashCheck:
            print("Updating Catalog from downloads.dell.com...")
        UpdateManager.update_catalog()
    if options.build_catalog:
        if options.protocol != DownloadProtocolEnum.HashCheck:
            print("Building Repository Catalog ....")
            UpdateHelper.build_repo(options.catalog, True, *options.component)
    if options.dld_index:
        if options.protocol != DownloadProtocolEnum.HashCheck:
            print("Updating index from downloads.dell.com...")
        UpdateManager.update_index()

    if options.dld_dups:
        if options.protocol != DownloadProtocolEnum.HashCheck:
            print("Downloading DUPs ...")
        UpdateManager.update_cache(options.catalog)
示例#5
0
ipaddr = get_args(argsinfo, 'ipaddr')
driver = get_optional(argsinfo, 'driver')
uname = get_optional(argsinfo, 'user.name')
upass = get_optional(argsinfo, 'user.password', '')
pref = get_optional(argsinfo, 'protocol', 'WSMAN')
nshare = get_optional(argsinfo, 'share')
nsharename = get_optional(argsinfo, 'share.user.name')
nsharepass = get_optional(argsinfo, 'share.user.password', '')
creds = UserCredentials(uname, upass)

@property
def not_implemented():
    print("===== not implemented ====")


myshare = LocalFile(local='C:\\Users\\vaideeswaran_ganesan\\Work\\omsdk', isFolder=True)
updshare = myshare.makedirs('DD')

UpdateManager.configure(updshare)
if updshare.IsValid:
    sd = sdkinfra()
    sd.importPath()
    idrac = sd.get_driver(sd.driver_enum.iDRAC, ipaddr, creds)
    UpdateHelper.save_firmware_inventory(idrac)
    idrac.disconnect()

    UpdateManager.update_catalog()
    print("Building repo....")
    UpdateHelper.build_repo_catalog('NIC')