How to use the redfish.ris.JSONEncoder function in redfish

To help you get started, we’ve selected a few redfish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DMTF / python-redfish-utility / src / extensions / RAW COMMANDS / RawHeadCommand.py View on Github external
content = results._http_response.msg.headers
            else:
                content = results._headers

            for item in content:
                if isinstance(item, dict):
                    for key, value in item.items():
                        tempdict[key] = value
                else:
                    item = item.replace(": ", ":").replace("\r\n", "").\
                                                                split(":", 1)
                    tempdict[item[0]] = item[1]

            if options.filename:
                output = json.dumps(tempdict, indent=2, \
                                                    cls=redfish.ris.JSONEncoder)
                filehndl = open(options.filename[0], "w")
                filehndl.write(output)
                filehndl.close()

                sys.stdout.write("Results written out to '%s'.\n" % \
                                                            options.filename[0])
            else:
                UI().print_out_json(tempdict)
        else:
            return ReturnCodes.NO_CONTENTS_FOUND_FOR_OPERATION

        #Return code
        return ReturnCodes.SUCCESS
github DMTF / python-redfish-utility / src / rdmc_helper.py View on Github external
def print_out_json(self, content):
        """ Print out json content to std.out

        :param content: content to be printed out
        :type content: str.
        """
        sys.stdout.write(json.dumps(content, indent=2, \
                                                cls=redfish.ris.JSONEncoder))
        sys.stdout.write('\n')
github DMTF / python-redfish-utility / src / extensions / COMMANDS / SaveCommand.py View on Github external
tempcontents[typeselector] = {pathselector: values}
                        else:
                            raise InvalidFileFormattingError("Missing path or" \
                                                     " selector in input file.")

                    templist.append(tempcontents)
            contents = templist

        if not contents:
            raise redfish.ris.NothingSelectedError
        else:
            contents = self.add_save_file_header(contents)

        outfile = open(self.filename, 'w')
        outfile.write(json.dumps(contents, indent=2, \
                                                cls=redfish.ris.JSONEncoder))
        outfile.close()
        sys.stdout.write("Configuration saved to: %s\n" % self.filename)

        if options.logout:
            self.logoutobj.logoutfunction("")

        #Return code
        return ReturnCodes.SUCCESS
github DMTF / python-redfish-utility / src / extensions / RAW COMMANDS / RawGetCommand.py View on Github external
filehndl = open(options.binfile[0], "wb")
            filehndl.write(output)
            filehndl.close()

        elif results and returnresponse:
            if options.getheaders:
                sys.stdout.write(json.dumps(dict(\
                                 results._http_response.getheaders())) + "\n")

            if options.response:
                sys.stdout.write(results.text)
        elif results and results.status == 200:
            if results.dict:
                if options.filename:
                    output = json.dumps(results.dict, indent=2, \
                                                    cls=redfish.ris.JSONEncoder)

                    filehndl = open(options.filename[0], "w")
                    filehndl.write(output)
                    filehndl.close()

                    sys.stdout.write("Results written out to '%s'.\n" % \
                                                            options.filename[0])
                else:
                    UI().print_out_json(results.dict)
        else:
            return ReturnCodes.NO_CONTENTS_FOUND_FOR_OPERATION

        #Return code
        return ReturnCodes.SUCCESS
github DMTF / python-redfish-library / examples / quickstart_rmc.py View on Github external
RMCOBJ.logout


# Login into the server and create a session
RMCOBJ.login(username=login_account, password=login_password, \
                                                        base_url=login_host)

# Select ComputerSystems
RMCOBJ.select(['ComputerSystem.'])

# Get selected type
response = RMCOBJ.get()

# Print out the response
for item in response:
    sys.stdout.write(json.dumps(item, indent=2, cls=JSONEncoder))
    sys.stdout.write('\n')

# Logout of the current session
RMCOBJ.logout()