def store_status_locally(ignored, components): for component in components.values(): if hasattr(component, "logger"): component.logger = None def _open_component_file(component_type): return open(os.path.join(yadtshell.settings.OUT_DIR, component_type), "w") component_files = { yadtshell.settings.ARTEFACT: _open_component_file("artefacts"), yadtshell.settings.SERVICE: _open_component_file("services"), yadtshell.settings.HOST: _open_component_file("hosts"), } for component in components.values(): component_files[component.type].write(component.uri + "\n") for f in component_files.values(): f.close() f = _open_component_file("current_state.components") pickle.dump(components, f, pickle.HIGHEST_PROTOCOL) f.close() groups = [] he = HostExpander() for grouped_hosts in yadtshell.settings.TARGET_SETTINGS["original_hosts"]: hosts = [] for hostname in he.expand(grouped_hosts): services = [] host = components["host://%s" % hostname] host_services = getattr(host, "defined_services", []) host_services.sort(key=lambda s: s.dependency_score) for service in host_services: services.append({"uri": service.uri, "name": service.name, "state": service.state}) artefacts = [] for artefact in sorted(getattr(host, "handled_artefacts", [])): name, version = artefact.split("/") artefacts.append({"uri": "artefact://%s/%s" % (hostname, name), "name": name, "current": version}) host = {"name": hostname, "services": services, "artefacts": artefacts} hosts.append(host) groups.append(hosts) yadtshell.settings.ybc.sendFullUpdate(groups, tracking_id=yadtshell.settings.tracking_id) status_line = yadtshell.util.get_status_line(components) logger.debug("status: %s" % status_line) print(status_line) f = open(os.path.join(yadtshell.settings.OUT_DIR, "statusline"), "w") f.write("\n".join(["", status_line])) f.close()
def store_status_locally(ignored, components): def _open_component_file(component_type): return open(os.path.join(yadtshell.settings.OUT_DIR, component_type), 'w') component_files = { yadtshell.settings.ARTEFACT: _open_component_file('artefacts'), yadtshell.settings.SERVICE: _open_component_file('services'), yadtshell.settings.HOST: _open_component_file('hosts'), } for component in components.values(): component_files[component.type].write(component.uri + "\n") for f in component_files.values(): f.close() f = _open_component_file('current_state.components') pickle.dump(components, f, pickle.HIGHEST_PROTOCOL) f.close() groups = [] he = HostExpander() for grouped_hosts in yadtshell.settings.TARGET_SETTINGS['original_hosts']: hosts = [] for hostname in he.expand(grouped_hosts): services = [] host = components['host://%s' % hostname] host_services = getattr(host, 'defined_services', []) host_services.sort(key=lambda s: s.dependency_score) for service in host_services: services.append({ 'uri': service.uri, 'name': service.name, 'state': service.state }) artefacts = [] for artefact in sorted(getattr(host, 'handled_artefacts', [])): name, version = artefact.split('/') artefacts.append({ 'uri': 'artefact://%s/%s' % (hostname, name), 'name': name, 'current': version }) host = { 'name': hostname, 'services': services, 'artefacts': artefacts } hosts.append(host) groups.append(hosts) yadtshell.settings.ybc.sendFullUpdate( groups, tracking_id=yadtshell.settings.tracking_id) status_line = yadtshell.util.get_status_line(components) logger.debug('status: %s' % status_line) print(status_line) f = open(os.path.join(yadtshell.settings.OUT_DIR, 'statusline'), 'w') f.write('\n'.join(['', status_line])) f.close()
def store_status_locally(ignored, components): for component in components.values(): if hasattr(component, "logger"): component.logger = None def _open_component_file(component_type): return open( os.path.join(yadtshell.settings.OUT_DIR, component_type), 'w') component_files = { yadtshell.settings.ARTEFACT: _open_component_file('artefacts'), yadtshell.settings.SERVICE: _open_component_file('services'), yadtshell.settings.HOST: _open_component_file('hosts'), } for component in components.values(): component_files[component.type].write(component.uri + "\n") for f in component_files.values(): f.close() f = _open_component_file('current_state.components') pickle.dump(components, f, pickle.HIGHEST_PROTOCOL) f.close() groups = [] he = HostExpander() for grouped_hosts in yadtshell.settings.TARGET_SETTINGS[ 'original_hosts']: hosts = [] for hostname in he.expand(grouped_hosts): services = [] host = components['host://%s' % hostname] host_services = getattr(host, 'defined_services', []) host_services.sort(key=lambda s: s.dependency_score) for service in host_services: services.append({ 'uri': service.uri, 'name': service.name, 'state': service.state }) artefacts = [] for artefact in sorted(getattr(host, 'handled_artefacts', [])): name, version = artefact.split('/') artefacts.append({ 'uri': 'artefact://%s/%s' % (hostname, name), 'name': name, 'current': version }) host = { 'name': hostname, 'services': services, 'artefacts': artefacts } hosts.append(host) groups.append(hosts) yadtshell.settings.ybc.sendFullUpdate( groups, tracking_id=yadtshell.settings.tracking_id) status_line = yadtshell.util.get_status_line(components) logger.debug('status: %s' % status_line) print(status_line) f = open(os.path.join(yadtshell.settings.OUT_DIR, 'statusline'), 'w') f.write('\n'.join(['', status_line])) f.close()
yadtshell.settings.ARTEFACT: _open_component_file('artefacts'), yadtshell.settings.SERVICE: _open_component_file('services'), yadtshell.settings.HOST: _open_component_file('hosts'), } for component in components.values(): print >> component_files[component.type], component.uri for f in component_files.values(): f.close() f = _open_component_file('current_state.components') pickle.dump(components, f) f.close() groups = [] he = HostExpander() for grouped_hosts in yadtshell.settings.TARGET_SETTINGS['original_hosts']: hosts = [] for hostname in he.expand(grouped_hosts): services = [] host = components['host://%s' % hostname] for service in getattr(host, 'defined_services', []): services.append({ 'uri': service.uri, 'name': service.name, 'state': service.state }) artefacts = [] for artefact in sorted(getattr(host, 'handled_artefacts', [])): name, version = artefact.split('/')