def recursive_add(self, service, ha): if not services.check_service_cluster(service): m_serv, _ = services.check_service_req_service(service, ha) for serv in m_serv: self.recursive_add(serv, ha) print('Adding "%s"' % service) services.add_service(name=service, ha=ha, cluster=self.c_name) services.auto_assign(service=service, ha=ha, cluster=self.c_name)
def test_add_indep_services_ha(self): print('Test "add_indep_services_ha"') indep_serv = [ s for s in services.config['services'] if not s['requirements']['services']['ha'] ] for s in indep_serv: print('Adding "%s"' % s['name']) services.add_service(name=s['name'], ha=True, cluster=self.c_name) for s in indep_serv: self.assertTrue(services.check_service_cluster(s['name']))
def addservice(ctx, name, cluster, no_auto, ha, recursive): """ Add a service to a cluster and auto-install its components on the best fitting hosts. """ switched = True if cluster else False if not cluster: cluster = ss.svars['cluster'] try: msg = '' auto_installed_count = 0 if recursive: dep_serv = '' dep_comp = '' dependencies = services.get_service_dependencies(name=name, ha=ha, first=True, cluster=cluster) if dependencies['components'] or dependencies['services']: click.echo('The service %s and its dependencies will be' ' installed. Dependencies:' % name) if dependencies['components']: dep_comp = ('Components:\n - %s\n' % '\n - '.join( '{} {}' .format(v, k) for k, v in dependencies['components'].items())) if dependencies['services']: dep_serv = ('Services:\n - %s\n' % '\n - '.join(dependencies['services'])) if click.confirm('{}{}\nDo you want to continue?' .format(dep_comp, dep_serv)): auto_installed_count = services.install_dependencies( dependencies=dependencies, cluster=cluster) msg += 'Auto-installed the dependencies:\n{}{}'.format( dep_comp, dep_serv) else: click.echo('Installation canceled.') return services.add_service(name=name, ha=ha, cluster=cluster) if no_auto: msg += ('No component has been auto-installed (except clients). ' 'Use "addcomp" manually.') else: count = services.auto_assign(service=name, ha=ha, cluster=cluster) msg += ('{} type{} of component{} auto-installed. ' 'Use "listcomponents -a" for details.' .format(count + auto_installed_count, 's' if count > 1 else '', 's' if count > 1 else '')) except ex.LoadError as e: print_with_color(e.message, 'red') switched = False if e.type == 'NotExist': click.echo('Available services:\n - %s' % '\n - '.join(services.get_available_services())) except ex.CreationError as e: print_with_color(e.message, 'red') else: click.echo('Service "{}" and related clients added to cluster "{}".\n' .format(name, cluster) + msg) finally: if switched: set_context(ctx, cluster)