def _deploy(cluster_id): """Deploy the cluster""" deploy_hosts_urls = [] with database.session() as session: cluster_hosts_ids = session.query(ModelClusterHost.id)\ .filter_by(cluster_id=cluster_id).all() if not cluster_hosts_ids: # No host belongs to this cluster error_msg = ('Cannot find any host in cluster id=%s' % cluster_id) return errors.handle_not_exist( errors.ObjectDoesNotExist(error_msg)) for elm in cluster_hosts_ids: host_id = str(elm[0]) progress_url = '/cluster_hosts/%s/progress' % host_id deploy_hosts_urls.append(progress_url) # Lock cluster hosts and its cluster session.query(ModelClusterHost).filter_by(cluster_id=cluster_id)\ .update({'mutable': False}) session.query(ModelCluster).filter_by(id=cluster_id)\ .update({'mutable': False}) celery.send_task("compass.tasks.trigger_install", (cluster_id, )) return util.make_json_response(202, { "status": "OK", "deployment": deploy_hosts_urls })
def _deploy(cluster_id): """Deploy the cluster""" deploy_hosts_urls = [] with database.session() as session: cluster_hosts_ids = session.query(ModelClusterHost.id)\ .filter_by(cluster_id=cluster_id).all() if not cluster_hosts_ids: # No host belongs to this cluster error_msg = ('Cannot find any host in cluster id=%s' % cluster_id) return errors.handle_not_exist( errors.ObjectDoesNotExist(error_msg)) for host_id in cluster_hosts_ids: progress_url = '/cluster_hosts/%s/progress' % str(host_id) deploy_hosts_urls.append(progress_url) # Lock cluster hosts and its cluster session.query(ModelClusterHost).filter_by(cluster_id=cluster_id)\ .update({'mutable': False}) session.query(ModelCluster).filter_by(id=cluster_id)\ .update({'mutable': False}) celery.send_task("compass.tasks.trigger_install", (cluster_id,)) return util.make_json_response( 202, {"status": "OK", "deployment": deploy_hosts_urls})
def pollswitches(switch_ips): """poll switch.""" poll_switch_ips = [] with database.session(): poll_switch_ips = util.update_switch_ips(switch_ips) if flags.OPTIONS.async: for poll_switch_ip in poll_switch_ips: celery.send_task( 'compass.tasks.pollswitch', (poll_switch_ip,) ) else: try: pool = Pool(processes=int(flags.OPTIONS.thread_pool_size)) for poll_switch_ip in poll_switch_ips: pool.apply_async( poll_switch.poll_switch, (poll_switch_ip,) ) pool.close() pool.join() except Exception as error: logging.error('failed to poll switches %s', poll_switch_ips) logging.exception(error)
def main(argv): flags.init() logsetting.init() clusterids = [ int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',') if clusterid ] with database.session() as session: if not clusterids: clusters = session.query(Cluster).all() trigger_clusterids = [cluster.id for cluster in clusters] else: trigger_clusterids = clusterids logging.info('trigger installer for clusters: %s', trigger_clusterids) for clusterid in trigger_clusterids: hosts = session.query( ClusterHost).filter_by( cluster_id=clsuterid).all() hostids = [host.id for host in hosts] if flags.OPTIONS.async: celery.send_task('compass.tasks.trigger_install', (clusterid, hostids)) else: trigger_install.trigger_install(clusterid, hostids)
def progress_update(): """entry function.""" if flags.OPTIONS.async: celery.send_task('compass.tasks.update_progress', ()) else: try: update_progress.update_progress() except Exception as error: logging.error('failed to update progress') logging.exception(error)
def progress_update(): """entry function.""" if flags.OPTIONS. async: celery.send_task('compass.tasks.update_progress', ()) else: try: update_progress.update_progress() except Exception as error: logging.error('failed to update progress') logging.exception(error)
def progress_update(cluster_hosts): """entry function.""" if flags.OPTIONS. async: celery.send_task('compass.tasks.update_progress', (cluster_hosts, )) else: try: update_progress.update_progress(cluster_hosts) except Exception as error: logging.error('failed to update progress for cluster_hosts: %s', cluster_hosts) logging.exception(error)
def progress_update(cluster_hosts): """entry function.""" if flags.OPTIONS.async: celery.send_task('compass.tasks.update_progress', (cluster_hosts,)) else: try: update_progress.update_progress(cluster_hosts) except Exception as error: logging.error('failed to update progress for cluster_hosts: %s', cluster_hosts) logging.exception(error)
def clean_clusters(): """Delete clusters and hosts. .. note:: The clusters and hosts are defined in --clusters. the clusters flag is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = util.get_clusters_from_str(flags.OPTIONS.clusters) if flags.OPTIONS. async: celery.send_task('compass.tasks.clean_deployment', (cluster_hosts, )) else: clean_deployment.clean_deployment(cluster_hosts)
def post(self): """ Insert switch IP and the credential to db. Invoke a task to poll switch at the same time. :param ip: switch IP address :param credential: a dict for accessing the switch """ ip_addr = None credential = None logging.debug('post switch request from curl is %s', request.data) json_data = json.loads(request.data) ip_addr = json_data['switch']['ip'] credential = json_data['switch']['credential'] logging.info('post switch ip_addr=%s credential=%s(%s)', ip_addr, credential, type(credential)) if not util.is_valid_ip(ip_addr): error_msg = "Invalid IP address format!" return errors.handle_invalid_usage( errors.UserInvalidUsage(error_msg) ) new_switch = {} with database.session() as session: switch = session.query(ModelSwitch).filter_by(ip=ip_addr).first() logging.info('switch for ip %s: %s', ip_addr, switch) if switch: error_msg = "IP address '%s' already exists" % ip_addr value = {'failedSwitch': switch.id} return errors.handle_duplicate_object( errors.ObjectDuplicateError(error_msg), value ) switch = ModelSwitch(ip=ip_addr) switch.credential = credential session.add(switch) session.flush() new_switch['id'] = switch.id new_switch['ip'] = switch.ip new_switch['state'] = switch.state link = {'rel': 'self', 'href': '/'.join((self.ENDPOINT, str(switch.id)))} new_switch['link'] = link celery.send_task("compass.tasks.pollswitch", (ip_addr,)) logging.info('new switch added: %s', new_switch) return util.make_json_response( 202, {"status": "accepted", "switch": new_switch} )
def reinstall_clusters(): """Reinstall hosts in clusters. .. note:: The hosts are defined in --clusters. The clusters flag is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = flags.OPTIONS.clusters if flags.OPTIONS.async: celery.send_task('compass.tasks.reinstall', (cluster_hosts,)) else: reinstall.reinstall(cluster_hosts)
def reinstall_clusters(): """Reinstall hosts in clusters. .. note:: The hosts are defined in --clusters. The clusters flag is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = flags.OPTIONS.clusters if flags.OPTIONS. async: celery.send_task('compass.tasks.reinstall', (cluster_hosts, )) else: reinstall.reinstall(cluster_hosts)
def post(self): """ Insert switch IP and the credential to db. Invoke a task to poll switch at the same time. :param ip: switch IP address :param credential: a dict for accessing the switch """ ip_addr = None credential = None logging.debug('post switch request from curl is %s', request.data) json_data = json.loads(request.data) ip_addr = json_data['switch']['ip'] credential = json_data['switch']['credential'] logging.info('post switch ip_addr=%s credential=%s(%s)', ip_addr, credential, type(credential)) if not util.is_valid_ip(ip_addr): error_msg = "Invalid IP address format!" return errors.handle_invalid_usage( errors.UserInvalidUsage(error_msg)) new_switch = {} with database.session() as session: switch = session.query(ModelSwitch).filter_by(ip=ip_addr).first() logging.info('switch for ip %s: %s', ip_addr, switch) if switch: error_msg = "IP address '%s' already exists" % ip_addr value = {'failedSwitch': switch.id} return errors.handle_duplicate_object( errors.ObjectDuplicateError(error_msg), value) switch = ModelSwitch(ip=ip_addr) switch.credential = credential session.add(switch) session.flush() new_switch['id'] = switch.id new_switch['ip'] = switch.ip new_switch['state'] = switch.state link = { 'rel': 'self', 'href': '/'.join((self.ENDPOINT, str(switch.id))) } new_switch['link'] = link celery.send_task("compass.tasks.pollswitch", (ip_addr, )) logging.info('new switch added: %s', new_switch) return util.make_json_response(202, { "status": "accepted", "switch": new_switch })
def deploy_clusters(): """Deploy hosts in clusters. .. note:: The hosts are defined in --clusters. The clusters flag is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = flags.OPTIONS.clusters if flags.OPTIONS.async: celery.send_task('compass.tasks.deploy', (cluster_hosts,)) else: deploy.deploy(cluster_hosts)
def deploy_clusters(): """Deploy hosts in clusters. .. note:: The hosts are defined in --clusters. The clusters flag is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = flags.OPTIONS.clusters if flags.OPTIONS. async: celery.send_task('compass.tasks.deploy', (cluster_hosts, )) else: deploy.deploy(cluster_hosts)
def clean_clusters(): """Delete clusters and hosts. .. note:: The clusters and hosts are defined in --clusters. the clusters flag is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = util.get_clusters_from_str(flags.OPTIONS.clusters) if flags.OPTIONS.async: celery.send_task('compass.tasks.clean_deployment', (cluster_hosts,)) else: clean_deployment.clean_deployment(cluster_hosts)
def clean_installation_progress(): """Clean clusters and hosts installation progress. .. note:: The cluster and hosts is defined in --clusters. The clusters flags is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = util.get_clusters_from_str(flags.OPTIONS.clusters) if flags.OPTIONS.async: celery.send_task('compass.tasks.clean_installing_progress', (cluster_hosts,)) else: clean_installing_progress.clean_installing_progress(cluster_hosts)
def clean_installation_progress(): """Clean clusters and hosts installation progress. .. note:: The cluster and hosts is defined in --clusters. The clusters flags is as clusterid:hostname1,hostname2,...;... """ cluster_hosts = util.get_clusters_from_str(flags.OPTIONS.clusters) if flags.OPTIONS. async: celery.send_task('compass.tasks.clean_installing_progress', (cluster_hosts, )) else: clean_installing_progress.clean_installing_progress(cluster_hosts)
def _deploy(cluster_id, hosts): """Deploy the cluster""" deploy_hosts_info = [] deploy_cluster_info = {} with database.session() as session: if not hosts: # Deploy all hosts in the cluster cluster_hosts = session.query(ModelClusterHost)\ .filter_by(cluster_id=cluster_id).all() if not cluster_hosts: # No host belongs to this cluster error_msg = ('Cannot find any host in cluster id=%s' % cluster_id) return errors.handle_not_exist( errors.ObjectDoesNotExist(error_msg)) for host in cluster_hosts: if not host.mutable: # The host is not allowed to modified error_msg = ("The host id=%s is not allowed to be " "modified now!") % host.id return errors.UserInvalidUsage( errors.UserInvalidUsage(error_msg)) hosts.append(host.id) deploy_cluster_info["cluster_id"] = int(cluster_id) deploy_cluster_info["url"] = '/clusters/%s/progress' % cluster_id for host_id in hosts: host_info = {} progress_url = '/cluster_hosts/%s/progress' % host_id host_info["host_id"] = host_id host_info["url"] = progress_url deploy_hosts_info.append(host_info) # Lock cluster hosts and its cluster session.query(ModelClusterHost).filter_by(cluster_id=cluster_id)\ .update({'mutable': False}) session.query(ModelCluster).filter_by(id=cluster_id)\ .update({'mutable': False}) celery.send_task("compass.tasks.trigger_install", (cluster_id, hosts)) return util.make_json_response( 202, {"status": "accepted", "deployment": { "cluster": deploy_cluster_info, "hosts": deploy_hosts_info }})
def main(argv): global BUSY global KILLED switchids = [int(switchid) for switchid in flags.OPTIONS.switchids.split(',') if switchid] signal.signal(signal.SIGTERM, handle_term) signal.signal(signal.SIGHUP, handle_term) while True: BUSY = True with database.session() as session: switch_ips = {} switches = session.query(Switch).all() for switch in switches: switch_ips[switch.id] = switch.ip if not switchids: poll_switchids = [switch.id for switch in switches] else: poll_switchids = switchids logging.info('poll switches to get machines mac: %s', poll_switchids) for switchid in poll_switchids: if switchid not in switch_ips: logging.error('there is no switch ip for switch %s', switchid) continue if flags.OPTIONS.async: celery.send_task('compass.tasks.pollswitch', (switch_ips[switchid],)) else: try: poll_switch.poll_switch(switch_ips[switchid]) except Exception as error: logging.error('failed to poll switch %s', switch_ips[switchid]) BUSY = False if KILLED: logging.info('exit poll switch loop') break if flags.OPTIONS.once: logging.info('finish poll switch') break if flags.OPTIONS.run_interval > 0: logging.info('will rerun poll switch after %s seconds', flags.OPTIONS.run_interval) time.sleep(flags.OPTIONS.run_interval) else: logging.info('rerun poll switch imediately')
def main(argv): """entry function.""" global BUSY global KILLED clusterids = [ int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',') if clusterid ] signal.signal(signal.SIGINT, handle_term) while True: BUSY = True with database.session() as session: if not clusterids: clusters = session.query(Cluster).all() update_clusterids = [cluster.id for cluster in clusters] else: update_clusterids = clusterids logging.info('update progress for clusters: %s', update_clusterids) for clusterid in update_clusterids: if flags.OPTIONS. async: celery.send_task('compass.tasks.progress_update', (clusterid, )) else: try: progress_update.update_progress(clusterid) except Exception as error: logging.error('failed to update progress for cluster %s', clusterid) logging.exception(error) pass BUSY = False if KILLED: logging.info('exit progress update loop') break if flags.OPTIONS.once: logging.info('trigger installer finsished') break if flags.OPTIONS.run_interval > 0: logging.info('will rerun the trigger install after %s', flags.OPTIONS.run_interval) time.sleep(flags.OPTIONS.run_interval) else: logging.info('rerun the trigger installer immediately')
def main(argv): """entry function.""" global BUSY global KILLED clusterids = [ int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',') if clusterid ] signal.signal(signal.SIGINT, handle_term) while True: BUSY = True with database.session() as session: if not clusterids: clusters = session.query(Cluster).all() update_clusterids = [cluster.id for cluster in clusters] else: update_clusterids = clusterids logging.info('update progress for clusters: %s', update_clusterids) for clusterid in update_clusterids: if flags.OPTIONS.async: celery.send_task('compass.tasks.progress_update', (clusterid,)) else: try: progress_update.update_progress(clusterid) except Exception as error: logging.error('failed to update progress for cluster %s', clusterid) logging.exception(error) pass BUSY = False if KILLED: logging.info('exit progress update loop') break if flags.OPTIONS.once: logging.info('trigger installer finsished') break if flags.OPTIONS.run_interval > 0: logging.info('will rerun the trigger install after %s', flags.OPTIONS.run_interval) time.sleep(flags.OPTIONS.run_interval) else: logging.info('rerun the trigger installer immediately')
def put(self, switch_id): """Update an existing switch information. :param switch_id: the unqiue identifier of the switch """ switch = None with database.session() as session: switch = session.query(ModelSwitch).filter_by(id=switch_id).first() logging.info('PUT switch id is %s: %s', switch_id, switch) if not switch: # No switch is found. error_msg = 'Cannot update a non-existing switch!' return errors.handle_not_exist( errors.ObjectDoesNotExist(error_msg)) credential = None logging.debug('PUT a switch request from curl is %s', request.data) json_data = json.loads(request.data) credential = json_data['switch']['credential'] logging.info('PUT switch id=%s credential=%s(%s)', switch_id, credential, type(credential)) ip_addr = None switch_res = {} with database.session() as session: switch = session.query(ModelSwitch).filter_by(id=switch_id).first() switch.credential = credential switch.state = "not_reached" ip_addr = switch.ip switch_res['id'] = switch.id switch_res['ip'] = switch.ip switch_res['state'] = switch.state link = { 'rel': 'self', 'href': '/'.join((self.ENDPOINT, str(switch.id))) } switch_res['link'] = link celery.send_task("compass.tasks.pollswitch", (ip_addr, )) return util.make_json_response(202, { "status": "accepted", "switch": switch_res })
def delete_clusters(): clusternames = [ clustername for clustername in flags.OPTIONS.clusternames.split(',') if clustername ] user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL) list_cluster_args = {} if clusternames: list_cluster_args['name'] = clusternames clusters = cluster_api.list_clusters( user, **list_cluster_args ) delete_underlying_host = flags.OPTIONS.delete_hosts for cluster in clusters: cluster_id = cluster['id'] hosts = cluster_api.list_cluster_hosts(user, cluster_id) host_id_list = [host['id'] for host in hosts] logging.info( 'delete cluster %s and cluster hosts %s', cluster_id, host_id_list ) logging.info('delete underlying host? %s', delete_underlying_host) if flags.OPTIONS.async: celery.send_task( 'compass.tasks.delete_cluster', ( setting.COMPASS_ADMIN_EMAIL, cluster_id, host_id_list, delete_underlying_host ) ) else: try: delete.delete_cluster( cluster_id, host_id_list, setting.COMPASS_ADMIN_EMAIL, delete_underlying_host ) except Exception as error: logging.error('failed to delete cluster %s', cluster) logging.exception(error)
def put(self, switch_id): """Update an existing switch information. :param switch_id: the unqiue identifier of the switch """ switch = None credential = None logging.debug('PUT a switch request from curl is %s', request.data) ip_addr = None switch_res = {} with database.session() as session: switch = session.query(ModelSwitch).filter_by(id=switch_id).first() logging.info('PUT switch id is %s: %s', switch_id, switch) if not switch: # No switch is found. error_msg = 'Cannot update a non-existing switch!' return errors.handle_not_exist( errors.ObjectDoesNotExist(error_msg)) json_data = json.loads(request.data) credential = json_data['switch']['credential'] logging.info('PUT switch id=%s credential=%s(%s)', switch_id, credential, type(credential)) switch.credential = credential switch.state = "repolling" switch.err_msg = "" ip_addr = switch.ip switch_res['id'] = switch.id switch_res['ip'] = switch.ip switch_res['state'] = switch.state link = {'rel': 'self', 'href': '/'.join((self.ENDPOINT, str(switch.id)))} switch_res['link'] = link celery.send_task("compass.tasks.pollswitch", (ip_addr,)) return util.make_json_response( 202, {"status": "accepted", "switch": switch_res})
def main(argv): flags.init() logsetting.init() clusterids = [ int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',') if clusterid ] with database.session() as session: if not clusterids: clusters = session.query(Cluster).all() trigger_clusterids = [cluster.id for cluster in clusters] else: trigger_clusterids = clusterids logging.info('trigger installer for clusters: %s', trigger_clusterids) for clusterid in trigger_clusterids: if flags.OPTIONS. async: celery.send_task('compass.tasks.trigger_install', (clusterid, )) else: trigger_install.trigger_install(clusterid)
def pollswitches(switch_ips): """poll switch.""" poll_switch_ips = [] with database.session(): poll_switch_ips = util.update_switch_ips(switch_ips) if flags.OPTIONS. async: for poll_switch_ip in poll_switch_ips: celery.send_task('compass.tasks.pollswitch', (poll_switch_ip, )) else: try: pool = Pool(processes=int(flags.OPTIONS.thread_pool_size)) for poll_switch_ip in poll_switch_ips: pool.apply_async(poll_switch.poll_switch, (poll_switch_ip, )) pool.close() pool.join() except Exception as error: logging.error('failed to poll switches %s', poll_switch_ips) logging.exception(error)
def pollswitches(switch_ips): """poll switch.""" user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL) poll_switches = [] all_switches = dict([ (switch['ip'], switch['credentials']) for switch in switch_api.list_switches(user) ]) if switch_ips: poll_switches = dict([ (switch_ip, all_switches[switch_ip]) for switch_ip in switch_ips if switch_ip in all_switches ]) else: poll_switches = all_switches if flags.OPTIONS.async: for switch_ip, switch_credentials in poll_switches.items(): celery.send_task( 'compass.tasks.pollswitch', (user.email, switch_ip, switch_credentials) ) else: try: pool = Pool(processes=flags.OPTIONS.thread_pool_size) for switch_ip, switch_credentials in poll_switches.items(): pool.apply_async( poll_switch.poll_switch, (user.email, switch_ip, switch_credentials) ) pool.close() pool.join() except Exception as error: logging.error('failed to poll switches %s', poll_switches) logging.exception(error)
def pollswitches(switch_ips): """poll switch.""" user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL) poll_switches = [] all_switches = dict([ (switch['ip'], switch['credentials']) for switch in switch_api.list_switches(user=user) ]) if switch_ips: poll_switches = dict([ (switch_ip, all_switches[switch_ip]) for switch_ip in switch_ips if switch_ip in all_switches ]) else: poll_switches = all_switches if flags.OPTIONS.async: for switch_ip, switch_credentials in poll_switches.items(): celery.send_task( 'compass.tasks.pollswitch', (user.email, switch_ip, switch_credentials) ) else: try: pool = Pool(processes=flags.OPTIONS.thread_pool_size) for switch_ip, switch_credentials in poll_switches.items(): pool.apply_async( poll_switch.poll_switch, (user.email, switch_ip, switch_credentials) ) pool.close() pool.join() except Exception as error: logging.error('failed to poll switches %s', poll_switches) logging.exception(error)
def clean_installers(): os_installers = [ os_installer for os_installer in flags.OPTIONS.os_installers.split(',') if os_installer ] package_installers = [ package_installer for package_installer in flags.OPTIONS.package_installers.split(',') if package_installer ] user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL) adapters = adapter_api.list_adapters(user=user) filtered_os_installers = {} filtered_package_installers = {} for adapter in adapters: logging.info( 'got adapter: %s', adapter ) if 'os_installer' in adapter: os_installer = adapter['os_installer'] os_installer_name = os_installer['alias'] if not os_installers or os_installer_name in os_installers: filtered_os_installers[os_installer_name] = os_installer else: logging.info( 'ignore os isntaller %s', os_installer_name ) else: logging.info( 'cannot find os installer in adapter %s', adapter['name'] ) if 'package_installer' in adapter: package_installer = adapter['package_installer'] package_installer_name = package_installer['alias'] if ( not package_installers or package_installer_name in package_installers ): filtered_package_installers[package_installer_name] = ( package_installer ) else: logging.info( 'ignore package installer %s', package_installer_name ) else: logging.info( 'cannot find package installer in adapter %s', adapter['name'] ) logging.info( 'clean os installers: %s', filtered_os_installers.keys() ) logging.info( 'clean package installers: %s', filtered_package_installers.keys() ) if flags.OPTIONS.async: for os_installer_name, os_installer in filtered_os_installers.items(): celery.send_task( 'compass.tasks.clean_os_installer', ( os_installer['name'], os_installer['settings'] ) ) for package_installer_name, package_installer in ( filtered_package_installers.items() ): celery.send_task( 'compass.tasks.clean_package_installer', ( package_installer['name'], package_installer['settings'] ) ) else: for os_installer_name, os_installer in ( filtered_os_installers.items() ): try: clean.clean_os_installer( os_installer['name'], os_installer['settings'] ) except Exception as error: logging.error( 'failed to clean os installer %s', os_installer_name ) logging.exception(error) for package_installer_name, package_installer in ( filtered_package_installers.items() ): try: clean.clean_package_installer( package_installer['name'], package_installer['settings'] ) except Exception as error: logging.error( 'failed to clean package installer %s', package_installer_name ) logging.exception(error)
def clean_installers(): os_installers = [ os_installer for os_installer in flags.OPTIONS.os_installers.split(',') if os_installer ] package_installers = [ package_installer for package_installer in flags.OPTIONS.package_installers.split(',') if package_installer ] user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL) adapters = adapter_api.list_adapters(user=user) filtered_os_installers = {} filtered_package_installers = {} for adapter in adapters: logging.info('got adapter: %s', adapter) if 'os_installer' in adapter: os_installer = adapter['os_installer'] os_installer_name = os_installer['alias'] if not os_installers or os_installer_name in os_installers: filtered_os_installers[os_installer_name] = os_installer else: logging.info('ignore os installer %s', os_installer_name) else: logging.info('cannot find os installer in adapter %s', adapter['name']) if 'package_installer' in adapter: package_installer = adapter['package_installer'] package_installer_name = package_installer['alias'] if (not package_installers or package_installer_name in package_installers): filtered_package_installers[package_installer_name] = ( package_installer) else: logging.info('ignore package installer %s', package_installer_name) else: logging.info('cannot find package installer in adapter %s', adapter['name']) logging.info('clean os installers: %s', filtered_os_installers.keys()) logging.info('clean package installers: %s', filtered_package_installers.keys()) if flags.OPTIONS. async: for os_installer_name, os_installer in filtered_os_installers.items(): celery.send_task('compass.tasks.clean_os_installer', (os_installer['name'], os_installer['settings'])) for package_installer_name, package_installer in ( filtered_package_installers.items()): celery.send_task( 'compass.tasks.clean_package_installer', (package_installer['name'], package_installer['settings'])) else: for os_installer_name, os_installer in ( filtered_os_installers.items()): try: clean.clean_os_installer(os_installer['name'], os_installer['settings']) except Exception as error: logging.error('failed to clean os installer %s', os_installer_name) logging.exception(error) for package_installer_name, package_installer in ( filtered_package_installers.items()): try: clean.clean_package_installer(package_installer['name'], package_installer['settings']) except Exception as error: logging.error('failed to clean package installer %s', package_installer_name) logging.exception(error)