forked from stove/risotto
inventory: add only_server option
This commit is contained in:
parent
33e4b63731
commit
ac035aacf1
1 changed files with 21 additions and 11 deletions
|
@ -41,7 +41,8 @@ class RisottoInventory(object):
|
||||||
parser.add_argument('--nocache', action='store_true')
|
parser.add_argument('--nocache', action='store_true')
|
||||||
parser.add_argument('--debug', action='store_true')
|
parser.add_argument('--debug', action='store_true')
|
||||||
parser.add_argument('--pretty_print', 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()
|
self.args = parser.parse_args()
|
||||||
if self.args.debug:
|
if self.args.debug:
|
||||||
global DEBUG
|
global DEBUG
|
||||||
|
@ -64,7 +65,10 @@ class RisottoInventory(object):
|
||||||
if self.args.list:
|
if self.args.list:
|
||||||
return self.do_inventory(config)
|
return self.do_inventory(config)
|
||||||
elif self.args.host:
|
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')
|
raise Exception('pfff')
|
||||||
|
|
||||||
def do_inventory(self,
|
def do_inventory(self,
|
||||||
|
@ -86,6 +90,7 @@ class RisottoInventory(object):
|
||||||
def get_vars(self,
|
def get_vars(self,
|
||||||
config: Config,
|
config: Config,
|
||||||
host_name: str,
|
host_name: str,
|
||||||
|
only_server_name: str,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
ret = {}
|
ret = {}
|
||||||
rougailconfig = RougailConfig.copy()
|
rougailconfig = RougailConfig.copy()
|
||||||
|
@ -101,14 +106,19 @@ class RisottoInventory(object):
|
||||||
if module_name != 'host' and engine.rougail_variables_dict['general']['host'] != host_name:
|
if module_name != 'host' and engine.rougail_variables_dict['general']['host'] != host_name:
|
||||||
continue
|
continue
|
||||||
ret[server_name] = engine.rougail_variables_dict
|
ret[server_name] = engine.rougail_variables_dict
|
||||||
ret['modules'] = config.information.get('modules')
|
if only_server_name is None:
|
||||||
ret['delete_old_image'] = False
|
ret['modules'] = config.information.get('modules')
|
||||||
ret['configure_host'] = True
|
ret['delete_old_image'] = False
|
||||||
ret['only_machine'] = None
|
ret['configure_host'] = True
|
||||||
ret['copy_templates'] = False
|
ret['only_machine'] = None
|
||||||
ret['copy_tests'] = False
|
ret['copy_templates'] = False
|
||||||
ret['host_install_dir'] = ret[host_name]['general']['host_install_dir']
|
ret['copy_tests'] = False
|
||||||
return dumps(ret, cls=RougailEncoder)
|
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.
|
# Get the inventory.
|
||||||
|
@ -120,7 +130,7 @@ def main():
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from json import loads
|
from json import loads
|
||||||
pprint(loads(values))
|
pprint(loads(values))
|
||||||
elif not inv.args.quite:
|
elif not inv.args.quiet:
|
||||||
print(values)
|
print(values)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
Loading…
Reference in a new issue