DMTF / Redfish-Interface-Emulator

The Redfish Interface Emulator can emulate a Redfish-based interface statically (GET) or dynamically (POST, PATCH, DELETE)
Other
59 stars 24 forks source link

sample redfish emulator implementing .is it correct? #84

Closed chandra0293 closed 5 years ago

chandra0293 commented 5 years ago

from flask import Flask from flask_restful import Resource, Api import sys, traceback import copy import strgen from utils import replace_recurse

from Acclipc.mdc_webtask import *

BASE_PATH = "/redfish/v1/"

app = Flask(name) api = Api(app)

class ResourceCollection(Resource): def init(self): self.rest_base = BASE_PATH self.uuid = ""

def get(self):
    """
    Configuration property - Service Root
    """
    config = {
        '@odata.context': self.rest_base + '$metadata#ServiceRoot',
        '@odata.type': '#ServiceRoot.1.0.0.ServiceRoot',
        '@odata.id': self.rest_base,
        'Id': 'RootService',
        'Name': 'Root Service',
        'ServiceVersion': '1.0.0',
        'UUID': self.uuid,
        'Links': {
            'Chassis': {'@odata.id': self.rest_base + 'Chassis'}
        }
    }

    return config

class Chassis(Resource):

def __init__(self):
    self.rb = BASE_PATH
    self.config = {
        '@odata.context': self.rb + '$metadata#ChassisCollection.ChassisCollection',
        '@odata.id': self.rb + 'Chassis',
        '@odata.type': '#ChassisCollection.1.0.0.ChassisCollection',
        'Name': 'Chassis Collection',
        'Member@odata.count': 1,
        'Member' : self.rb + 'Chassis/Chassis-1',
        }   

def get(self):
    try:
        resp = self.config, 200
    except Exception:
        traceback.print_exc()
        resp = INTERNAL_ERROR
    return resp

class Chassisinfo(Resource):

def __init__(self):
    self.rb = BASE_PATH
    self.config = {
        "@odata.context": self.rb +"$metadata#Chassis.Chassis",
        "@odata.id": self.rb + "Chassis",
        "@odata.type": "#Chassis.v1_0_0.Chassis",
        'Name': 'MDC System Chassis',
        "ChassisType": "RackMount",
        "SerialNumber": "",
        "PartNumber": "",
        "MaxPower": "",
        "Chassis ID": "",
        "AssetTag": "",
        "Oem": {
            "Links": {
                "Cartridge": [ 
                    {
                        "@odata.id": self.rb +"Chassis/Chassis-1/Cartridge"
                    }
                ],
                "Switch": [ 
                    {
                        "@odata.id": self.rb +"Chassis/Chassis-1/Switch"
                    }
                ]
            }
        }
        }

def get(self,ident):
    global wildcards
    res = login("accl","accl")
    result = chassisinfo()
    self.config['@odata.id']= self.rb + ident
    self.config['PartNumber']= result[0]
    self.config['SerialNumber']= result[1]
    self.config['MaxPower']= result[2]
    self.config['Chassis ID']= result[3]
    self.config['AssetTag']= result[4]
    return self.config, 200

class CartridgeCollection(Resource):

def __init__(self):
    self.rb = BASE_PATH
    self.cartridge = "Cartridge"
    self.switch = "Switch"
    self.config = {
        '@odata.context': self.rb + '$metadata#cartridgeCollection.cartridgeCollection',
        '@odata.id': self.rb + 'Cartridge',
        '@odata.type': '#cartridgeCollection.1.0.0.cartridgeCollection',
        'Name': 'Cartridge Collection',
        'Links': {}
    }
    self.config['Links']['Member@odata.count'] = ''
    self.config['Links']['Members'] = ''

def get(self,ident1,ident2):
    if ident2 == self.cartridge:
        self.config['Name']=self.cartridge + " Collection"
        self.config['Links']['Member@odata.count'] = 12
        self.config['Links']['Members'] = ''
        return self.config, 200
    elif ident2 == self.switch:
        self.config['Name']=self.switch + " Collection"
        self.config['Links']['Member@odata.count'] = 2
        self.config['Links']['Members'] = ''
        return self.config, 200

api.add_resource(ResourceCollection, '/redfish/v1') api.add_resource(Chassis, '/redfish/v1/Chassis') api.add_resource(Chassisinfo, '/redfish/v1/Chassis/') api.add_resource(CartridgeCollection, '/redfish/v1/Chassis//')

if name == 'main': app.run('0.0.0.0', debug=True)

jcleung5549 commented 5 years ago

You should follow the instructions in the README section "Dynamic Emulation".

  1. Create an API file (resource_api.py) file
  2. Create a template file (resource.py)
  3. If replacing a resource subordinate to the ServiceRoot, edit resource_emulator.py

To make things easier, the following examples exist in the repository

jcleung5549 commented 5 years ago

The code fragment you include has calls the Flask(), app.run and api.add_resource. These fragments are in the emulator_api.py file. You shouldn't need to touch this or extract any code from it.

chandra0293 commented 5 years ago

thank you

On Wed, Aug 14, 2019 at 1:59 AM John Leung notifications@github.com wrote:

The code fragment you include has calls the Flask(), app.run and api.add_resource. These fragments are in the emulator_api.py file. You shouldn't need to touch this or extract any code from it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DMTF/Redfish-Interface-Emulator/issues/84?email_source=notifications&email_token=AL5RIWUOOQWWGGDZ5IYN2JLQEMKS7A5CNFSM4ILJEUHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4G4NWY#issuecomment-520996571, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5RIWSZTQIAI2QLLNIPTFDQEMKS7ANCNFSM4ILJEUHA .

chandra0293 commented 5 years ago

in this file populate-config.json chassis count 13 can i change this count to 1.

chassis contain 12 cartridges(here cartridges are Server,storage ,NIC ,FPGA,GPU) or 24 cartridge, 2 switch card

each cartridge(server ) have 2 nodes

On Wed, Aug 14, 2019 at 11:02 AM Chandra Tejaswini < mandhalatejaswini@gmail.com> wrote:

thank you

On Wed, Aug 14, 2019 at 1:59 AM John Leung notifications@github.com wrote:

The code fragment you include has calls the Flask(), app.run and api.add_resource. These fragments are in the emulator_api.py file. You shouldn't need to touch this or extract any code from it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DMTF/Redfish-Interface-Emulator/issues/84?email_source=notifications&email_token=AL5RIWUOOQWWGGDZ5IYN2JLQEMKS7A5CNFSM4ILJEUHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4G4NWY#issuecomment-520996571, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5RIWSZTQIAI2QLLNIPTFDQEMKS7ANCNFSM4ILJEUHA .

chandra0293 commented 5 years ago

how to change this populate-config.json file based on my requirements? Chassis Count -1 Cartridge Count -12 or 24 (Server , storage,NIC,FPGA ,GPU) Each Cartridge node count -2 or 4 (if cartridge is server) SwitchCard count -2 Each SwitchCard Device count -2 (Storage ,NIC ,FPGA,GPU)

On Wed, Aug 14, 2019 at 11:24 AM Chandra Tejaswini < mandhalatejaswini@gmail.com> wrote:

in this file populate-config.json chassis count 13 can i change this count to 1.

chassis contain 12 cartridges(here cartridges are Server,storage ,NIC ,FPGA,GPU) or 24 cartridge, 2 switch card

each cartridge(server ) have 2 nodes

  • each switch having 2 devices (Device are NIC ,Storage ,FPGA,GPU ) *

On Wed, Aug 14, 2019 at 11:02 AM Chandra Tejaswini < mandhalatejaswini@gmail.com> wrote:

thank you

On Wed, Aug 14, 2019 at 1:59 AM John Leung notifications@github.com wrote:

The code fragment you include has calls the Flask(), app.run and api.add_resource. These fragments are in the emulator_api.py file. You shouldn't need to touch this or extract any code from it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DMTF/Redfish-Interface-Emulator/issues/84?email_source=notifications&email_token=AL5RIWUOOQWWGGDZ5IYN2JLQEMKS7A5CNFSM4ILJEUHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4G4NWY#issuecomment-520996571, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5RIWSZTQIAI2QLLNIPTFDQEMKS7ANCNFSM4ILJEUHA .

jcleung5549 commented 5 years ago

Before using Infragen, have you verified that you can manual create the dynamic resources? This can be done by doing a HTTP POST to the new resource instances. You should be able to manually POST each resource to verify each dynamic resource is operational.

(BTW, I did not write the Infragen code. It was contributed to the repository by another developer. So I will not be of much help in crafting an emulator-config.json file for your purposes.)

chandra0293 commented 5 years ago

yes manually created dynamic resources its working thank you.

On Wed, Aug 14, 2019 at 2:49 PM John Leung notifications@github.com wrote:

Before using Infragen, have you verified that you can manual create the dynamic resources? This can be done by doing a HTTP POST to the new resource instances. You should be able to manually POST each resource to verify each dynamic resource is operational.

(BTW, I did not write the Infragen code. It was contributed to the repository by another developer. So I will not be of much help in crafting an emulator-config.json file for your purposes.)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DMTF/Redfish-Interface-Emulator/issues/84?email_source=notifications&email_token=AL5RIWU2RAZTYTCDDZ6DRCTQEPE2NA5CNFSM4ILJEUHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4IGZDY#issuecomment-521170063, or mute the thread https://github.com/notifications/unsubscribe-auth/AL5RIWSFNLJAOVRKAU4P4PLQEPE2NANCNFSM4ILJEUHA .