xenanetworks / open-automation-chimera-core

XOA Chimera Core
https://docs.xenanetworks.com/projects/xoa-chimera-core
Apache License 2.0
0 stars 0 forks source link

Improve resource reservation and free #16

Open leonardhyu opened 1 year ago

leonardhyu commented 1 year ago

Please improve resource reservation (similar functionalities are implemented in HLFUNC.mgmt but chimera-core doesn't work with xoa-driver.hlfunc, therefore, please improve as shown below)

resource.free(flag)

def free_port():
  if port is reserved by others:
    relinquish the port
  elif port is reserved by you:
    release the port

def free_module(should_free_ports: bool):
  if module is reserved by others:
    relinquish the module
  elif module is reserved by you:
    release the module
  if should_free_ports == True:
    free all ports of the module

def free_tester(should_free_modules_and_ports: bool):
  if tester is reserved by others:
    relinquish the tester
  elif tester is reserved by you:
    release the tester
  if should_free_modules_and_ports == True:
    free all modules of the tester
    free all ports of each module

def free(should_free_sub_resources: bool):
  if resource is tester:
    free_tester(should_free_sub_resources)
  if resource is module:
    free_module(should_free_sub_resources)
  if resource is port:
    free_port()

resource.reserve()

def reserve_port():
  if port is NOT reserved by you:
    free_port()
    reserve the port

def reserve_module():
  if module is NOT reserved by you:
    free_module(True)
    reserve the module

def reserve_tester():
  if tester is NOT reserved by you:
    for each module:
      free_module(True)
    reserve the tester

def reserve():
  if resource is tester:
    reserve_tester()
  if resource is module:
    reserve_module()
  if resource is port:
    reserve_port()

I guess it should be updated here? image

so we can do this: image

fpfeng commented 1 year ago

done by 6f145b881c842918865938fce10a411fa187cc15

leonardhyu commented 1 year ago

Module and all its ports are reserved by others. Got the error using the code below:

async def my_awesome_func(stop_event: asyncio.Event):

    # create credential object
    credentials = dataset.Credentials(
        product=dataset.EProductType.VALKYRIE,
        host=CHASSIS_IP)

    # create chimera core controller object
    controller = await MainController()

    # add chimera emulator into the chassis inventory and get the ID
    tester_id = await controller.add_tester(credentials=credentials)

    # create tester object
    tester = await controller.use(tester_id, username=USERNAME, reserve=False, debug=False)

    # create module object
    module = await tester.use_module(module_id=MODULE_IDX, reserve=False)

    # free the module in case it is reserved by others
    await module.free(should_free_sub_resources=True)
    await module.reserve()

    # create port object and reserver the port
    port = await tester.use_port(module_id=MODULE_IDX, port_id=PORT_IDX, reserve=False)

    # reserve the port
    await port.reserve()

    # reset port
    await port.reset()
    return

image

leonardhyu commented 1 year ago

@fpfeng got some errors

fpfeng commented 1 year ago

@leonardhyu the image are not loading, dead link maybe?