inventory: add only_server option

This commit is contained in:
egarette@silique.fr 2023-08-23 22:44:12 +02:00
parent 33e4b63731
commit ac035aacf1

View file

@ -41,7 +41,8 @@ class RisottoInventory(object):
parser.add_argument('--nocache', action='store_true')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--pretty_print', action='store_true')
parser.add_argument('--quite', action='store_true')
parser.add_argument('--quiet', action='store_true')
parser.add_argument('--server', action='store', default=None)
self.args = parser.parse_args()
if self.args.debug:
global DEBUG
@ -64,7 +65,10 @@ class RisottoInventory(object):
if self.args.list:
return self.do_inventory(config)
elif self.args.host:
return self.get_vars(config, self.args.host)
return self.get_vars(config,
self.args.host,
self.args.server,
)
raise Exception('pfff')
def do_inventory(self,
@ -86,6 +90,7 @@ class RisottoInventory(object):
def get_vars(self,
config: Config,
host_name: str,
only_server_name: str,
) -> dict:
ret = {}
rougailconfig = RougailConfig.copy()
@ -101,14 +106,19 @@ class RisottoInventory(object):
if module_name != 'host' and engine.rougail_variables_dict['general']['host'] != host_name:
continue
ret[server_name] = engine.rougail_variables_dict
ret['modules'] = config.information.get('modules')
ret['delete_old_image'] = False
ret['configure_host'] = True
ret['only_machine'] = None
ret['copy_templates'] = False
ret['copy_tests'] = False
ret['host_install_dir'] = ret[host_name]['general']['host_install_dir']
return dumps(ret, cls=RougailEncoder)
if only_server_name is None:
ret['modules'] = config.information.get('modules')
ret['delete_old_image'] = False
ret['configure_host'] = True
ret['only_machine'] = None
ret['copy_templates'] = False
ret['copy_tests'] = False
ret['host_install_dir'] = ret[host_name]['general']['host_install_dir']
return dumps(ret, cls=RougailEncoder)
else:
if only_server_name not in ret:
raise Exception(f'cannot find server name "{only_server_name}" in {list(ret)}')
return dumps(ret[only_server_name], cls=RougailEncoder)
# Get the inventory.
@ -120,7 +130,7 @@ def main():
from pprint import pprint
from json import loads
pprint(loads(values))
elif not inv.args.quite:
elif not inv.args.quiet:
print(values)
except Exception as err:
if DEBUG: