cli/info: better output of connection parameters
before: $ slapos service info slapos-sr-testing Software Release URL: /srv/slapgrid/slappart15/srv/project/slapos/software/slapos-sr-testing/software.cfg Instance state: busy Instance parameters: {} Connection parameters: ("<?xml version='1.0' encoding='utf-8'?>\n" '<instance>\n' ' <parameter ' 'id="environment-script">/srv/slapgrid/slappart15/srv/runner/instance/slappart7/etc/slapos-local-development-environment.sh</parameter>\n' after: $ slapos service info slapos-sr-testing Software Release URL: /srv/slapgrid/slappart15/srv/project/slapos/software/slapos-sr-testing/software.cfg Instance state: busy Instance parameters: {} Connection parameters: {'environment-script': '/srv/slapgrid/slappart15/srv/runner/instance/slappart7/etc/slapos-local-development-environment.sh'}
Showing
... | @@ -27,6 +27,7 @@ | ... | @@ -27,6 +27,7 @@ |
# | # | ||
############################################################################## | ############################################################################## | ||
import json | |||
import pprint | import pprint | ||
import sys | import sys | ||
... | @@ -35,6 +36,14 @@ from slapos.cli.config import ClientConfigCommand | ... | @@ -35,6 +36,14 @@ from slapos.cli.config import ClientConfigCommand |
from slapos.client import init, ClientConfig | from slapos.client import init, ClientConfig | ||
from slapos.slap import ResourceNotReady, NotFoundError | from slapos.slap import ResourceNotReady, NotFoundError | ||
from slapos.util import ( | |||
SoftwareReleaseSchema, | |||
SoftwareReleaseSerialisation, | |||
StrPrettyPrinter, | |||
UndefinedSerializationError, | |||
xml2dict, | |||
) | |||
class InfoCommand(ClientConfigCommand): | class InfoCommand(ClientConfigCommand): | ||
"""get status, software_release and parameters of an instance""" | """get status, software_release and parameters of an instance""" | ||
... | @@ -70,10 +79,21 @@ def do_info(logger, conf, local): | ... | @@ -70,10 +79,21 @@ def do_info(logger, conf, local): |
logger.warning('Instance %s does not exist.', conf.reference) | logger.warning('Instance %s does not exist.', conf.reference) | ||
return(2) | return(2) | ||
software_schema = SoftwareReleaseSchema( | |||
instance._software_release_url, | |||
getattr(instance, '_software_type', None)) | |||
connection_parameter_dict = xml2dict(instance._connection_dict) | |||
|
|||
try: | |||
software_serialisation = software_schema.getSerialisation() | |||
except UndefinedSerializationError: | |||
software_serialisation = SoftwareReleaseSerialisation.JsonInXml | |||
if software_serialisation == SoftwareReleaseSerialisation.JsonInXml: | |||
if '_' in connection_parameter_dict: | |||
connection_parameter_dict = json.loads(connection_parameter_dict['_']) | |||
logger.info('Software Release URL: %s', instance._software_release_url) | logger.info('Software Release URL: %s', instance._software_release_url) | ||
logger.info('Instance state: %s', instance._requested_state) | logger.info('Instance state: %s', instance._requested_state) | ||
logger.info('Instance parameters:') | logger.info('Instance parameters:') | ||
logger.info(pprint.pformat(instance._parameter_dict)) | logger.info(StrPrettyPrinter().pformat(instance._parameter_dict)) | ||
logger.info('Connection parameters:') | logger.info('Connection parameters:') | ||
logger.info(pprint.pformat(instance._connection_dict)) | logger.info(StrPrettyPrinter().pformat(connection_parameter_dict)) | ||