Skip to content

Commit

Permalink
Merge pull request #55 from martin-belanger/return-native-dbus-data-n…
Browse files Browse the repository at this point in the history
…ot-json

dbus: return native dbus data instead of json when possible.
  • Loading branch information
martin-belanger authored Mar 24, 2022
2 parents 52da2fc + 6438523 commit a708be9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions stacctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def status(args):
bus = SystemMessageBus()
iface = bus.get_proxy(defs.STACD_DBUS_NAME, defs.STACD_DBUS_PATH)
info = json.loads(iface.process_info())
info['controllers'] = json.loads(iface.list_controllers(True))
info['controllers'] = iface.list_controllers(True)
for controller in info['controllers']:
transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn = _extract_cid(controller)
controller.update(json.loads(iface.controller_info(transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn)))
Expand All @@ -42,7 +42,7 @@ def status(args):
def ls(args):
bus = SystemMessageBus()
iface = bus.get_proxy(defs.STACD_DBUS_NAME, defs.STACD_DBUS_PATH)
info = json.loads(iface.list_controllers(args.detailed))
info = iface.list_controllers(args.detailed)
print(pprint.pformat(info, width=120))

PARSER = ArgumentParser(description=f'{defs.STAC_DESCRIPTION} ({defs.STAC_ACRONYM})')
Expand Down
4 changes: 2 additions & 2 deletions stacd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<interface name="%s">
<method name="list_controllers">
<arg direction="in" type="b" name="detailed"/>
<arg direction="out" type="s" name="controller_list_json"/>
<arg direction="out" type="aa{ss}" name="controller_list"/>
</method>
</interface>
</node>
Expand Down Expand Up @@ -160,7 +160,7 @@ def controller_info(self, transport, traddr, trsvcid, host_traddr, host_iface, s
return json.dumps(controller.info()) if controller else '{}'

def list_controllers(self, detailed) -> str: # pylint: disable=no-self-use
return json.dumps([ controller.details() if detailed else controller.controller_id_dict() for controller in STAC.get_controllers() ])
return [ controller.details() if detailed else controller.controller_id_dict() for controller in STAC.get_controllers() ]


#===========================================================================
Expand Down
8 changes: 4 additions & 4 deletions stafctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ def status(args):
bus = SystemMessageBus()
iface = bus.get_proxy(defs.STAFD_DBUS_NAME, defs.STAFD_DBUS_PATH)
info = json.loads(iface.process_info())
info['controllers'] = json.loads(iface.list_controllers(True))
info['controllers'] = iface.list_controllers(True)
for controller in info['controllers']:
transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn = _extract_cid(controller)
controller['log_pages'] = json.loads(iface.get_log_pages(transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn))
controller['log_pages'] = iface.get_log_pages(transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn)
controller.update(json.loads(iface.controller_info(transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn)))

print(pprint.pformat(info, width=120))

def ls(args):
bus = SystemMessageBus()
iface = bus.get_proxy(defs.STAFD_DBUS_NAME, defs.STAFD_DBUS_PATH)
info = json.loads(iface.list_controllers(args.detailed))
info = iface.list_controllers(args.detailed)
print(pprint.pformat(info, width=120))

def dlp(args):
bus = SystemMessageBus()
iface = bus.get_proxy(defs.STAFD_DBUS_NAME, defs.STAFD_DBUS_PATH)
info = json.loads(iface.get_log_pages(args.transport, args.traddr, args.trsvcid, args.host_traddr, args.host_iface, args.nqn))
info = iface.get_log_pages(args.transport, args.traddr, args.trsvcid, args.host_traddr, args.host_iface, args.nqn)
print(pprint.pformat(info, width=120))

def adlp(args):
Expand Down
8 changes: 4 additions & 4 deletions stafd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<interface name="%s">
<method name="list_controllers">
<arg direction="in" type="b" name="detailed"/>
<arg direction="out" type="s" name="controller_list_json"/>
<arg direction="out" type="aa{ss}" name="controller_list"/>
</method>
<method name="get_log_pages">
<arg direction="in" type="s" name="transport"/>
Expand All @@ -44,7 +44,7 @@
<arg direction="in" type="s" name="host_traddr"/>
<arg direction="in" type="s" name="host_iface"/>
<arg direction="in" type="s" name="subsysnqn"/>
<arg direction="out" type="s" name="log_pages_json"/>
<arg direction="out" type="aa{ss}" name="log_pages"/>
</method>
<method name="get_all_log_pages">
<arg direction="in" type="b" name="detailed"/>
Expand Down Expand Up @@ -351,7 +351,7 @@ def controller_info(self, transport, traddr, trsvcid, host_traddr, host_iface, s

def get_log_pages(self, transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn) -> str: # pylint: disable=no-self-use,too-many-arguments
controller = STAF.get_controller(transport, traddr, trsvcid, host_traddr, host_iface, subsysnqn)
return json.dumps(controller.log_pages()) if controller else '[]'
return controller.log_pages() if controller else '[]'

def get_all_log_pages(self, detailed) -> str: # pylint: disable=no-self-use
log_pages = list()
Expand All @@ -363,7 +363,7 @@ def get_all_log_pages(self, detailed) -> str: # pylint: disable=no-self-use
def list_controllers(self, detailed) -> str: # pylint: disable=no-self-use
''' @brief Return the list of discovery controller IDs
'''
return json.dumps([ controller.details() if detailed else controller.controller_id_dict() for controller in STAF.get_controllers() ])
return [ controller.details() if detailed else controller.controller_id_dict() for controller in STAF.get_controllers() ]


#===========================================================================
Expand Down
2 changes: 1 addition & 1 deletion staslib/stas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ def controller_id_dict(self) -> dict:
def details(self) -> dict:
details = self.controller_id_dict()
details.update(UDEV.get_attributes(self.device, ('hostid', 'hostnqn', 'model', 'serial')))
details['connect attempts'] = self._connect_attempts
details['connect attempts'] = str(self._connect_attempts)
details['retry connect timer'] = str(self._retry_connect_tmr)
return details

Expand Down

0 comments on commit a708be9

Please sign in to comment.