def get_hosts_and_effective_roles(self, arg_hosts, arg_roles, arg_exclude_hosts, env=None): """ Return a tuple containing the host list the given task should be using and the roles being used. See :ref:`host-lists` for detailed documentation on how host lists are set. .. versionchanged:: 1.9 """ env = env or {'hosts': [], 'roles': [], 'exclude_hosts': []} roledefs = env.get('roledefs', {}) # Command line per-task takes precedence over anything else. if arg_hosts or arg_roles: return merge(arg_hosts, arg_roles, arg_exclude_hosts, roledefs), arg_roles # Decorator-specific hosts/roles go next func_hosts = getattr(self, 'hosts', []) func_roles = getattr(self, 'roles', []) if func_hosts or func_roles: return merge(func_hosts, func_roles, arg_exclude_hosts, roledefs), func_roles # Finally, the env is checked (which might contain globally set lists # from the CLI or from module-level code). This will be the empty list # if these have not been set -- which is fine, this method should # return an empty list if no hosts have been set anywhere. env_vars = list( map(_get_list(env), "hosts roles exclude_hosts".split())) env_vars.append(roledefs) return merge(*env_vars), env.get('roles', [])
def get_hosts_and_effective_roles(self, arg_hosts, arg_roles, arg_exclude_hosts, env=None): """ Return a tuple containing the host list the given task should be using and the roles being used. See :ref:`host-lists` for detailed documentation on how host lists are set. .. versionchanged:: 1.9 """ env = env or {'hosts': [], 'roles': [], 'exclude_hosts': []} roledefs = env.get('roledefs', {}) # Command line per-task takes precedence over anything else. if arg_hosts or arg_roles: return merge(arg_hosts, arg_roles, arg_exclude_hosts, roledefs), arg_roles # Decorator-specific hosts/roles go next func_hosts = getattr(self, 'hosts', []) func_roles = getattr(self, 'roles', []) if func_hosts or func_roles: return merge(func_hosts, func_roles, arg_exclude_hosts, roledefs), func_roles # Finally, the env is checked (which might contain globally set lists # from the CLI or from module-level code). This will be the empty list # if these have not been set -- which is fine, this method should # return an empty list if no hosts have been set anywhere. env_vars = list(map(_get_list(env), "hosts roles exclude_hosts".split())) env_vars.append(roledefs) return merge(*env_vars), env.get('roles', [])
def get_hosts(self, arg_hosts, arg_roles, arg_exclude_hosts, env=None): """Get hosts by priority :param arg_hosts: user command line specifed hosts :type arg_hosts: list :param arg_roles: user commend line specifed roles :type arg_roles: list :param arg_exclude_hosts: user command line specifed hosts to exclude :type arg_exclude_hosts: list :param env: :class:`~fabric.utils._AttributeDict` object with env :type env: `~fabric.utils._AttributeDict` """ env = env or {'hosts': [], 'roles': [], 'exclude_hosts': []} roledefs = env.get('roledefs', {}) # Command line per-task takes precedence over anything else. if arg_hosts or arg_roles: return merge(arg_hosts, arg_roles, arg_exclude_hosts, roledefs) # Use recipe configured roles module_roles = get_module_roles(self.wrapped.__module__) module_hosts = get_module_hosts(self.wrapped.__module__) if module_roles or module_hosts: return merge(module_hosts, module_roles, arg_exclude_hosts, roledefs) # Decorator-specific hosts/roles go next func_hosts = getattr(self, 'hosts', []) func_roles = getattr(self, 'roles', []) if func_hosts or func_roles: return merge(func_hosts, func_roles, arg_exclude_hosts, roledefs) # Finally, the env is checked (which might contain globally set lists # from the CLI or from module-level code). This will be the empty list # if these have not been set -- which is fine, this method should # return an empty list if no hosts have been set anywhere. env_vars = map(_get_list(env), "hosts roles exclude_hosts".split()) env_vars.append(roledefs) return merge(*env_vars)
def get_hosts(self, arg_hosts, arg_roles, arg_exclude_hosts, env=None): """ Return the host list the given task should be using. See :ref:`host-lists` for detailed documentation on how host lists are set. """ env = env or {'hosts': [], 'roles': [], 'exclude_hosts': []} roledefs = env.get('roledefs', {}) # Command line per-task takes precedence over anything else. if arg_hosts or arg_roles: return merge(arg_hosts, arg_roles, arg_exclude_hosts, roledefs) # Decorator-specific hosts/roles go next if self.hosts or self.roles: return merge(self.hosts, self.roles, arg_exclude_hosts, roledefs) # Finally, the env is checked (which might contain globally set lists # from the CLI or from module-level code). This will be the empty list # if these have not been set -- which is fine, this method should # return an empty list if no hosts have been set anywhere. env_vars = [env.get(k, []) for k in ['hosts', 'roles', 'exclude_hosts']] env_vars.append(roledefs) return merge(*env_vars)
def test_aborts_on_nonexistent_roles(): """ Aborts if any given roles aren't found """ merge([], ['badrole'], [], {})
def test_accepts_non_list_hosts(): """ Coerces given host string to a one-item list """ assert merge('badhosts', [], [], {}) == ['badhosts']
def test_accepts_non_list_hosts(): """ Aborts if hosts is a string, not a list """ assert merge('badhosts', [], [], {}) == ['badhosts']
env.my_dir_path = os.path.expanduser("/home/{0}/{1}".format( env.user, MY_DIR_NAME)) env.zookeeper_dir = os.path.join(env.my_dir_path, re.sub(r'\.tar\.gz$', '', env.zookeeper_tgz)) env.solr_dir = os.path.join(env.my_dir_path, re.sub(r'\.tgz$', '', env.solr_tgz)) # names for upstart services. Use a prefix to prevent accidentally overwriting a system package env.zookeeper_service = 'my_zookeeper' env.solr_service = 'my_solr' env.solr_home = 'solr' #If you plan to use multicore. Run: fab stop_solr, fab bootstrap_multicore_solrcloud and fab start_solr env.solr_port = 8983 #Note if you modfiy this, please update example/etc/jetty.xml # create an 'all' role containing all hosts env.roledefs.update( {'all': merge([], ['zookeeper', 'solr'], [], env.roledefs)}) env.first_solr = env.roledefs['solr'][0] env.first_zookeeper = env.roledefs['zookeeper'][0] # local jinja2 templates directory TEMPLATES = "./templates" @roles('all') def test_ssh(): """ Run 'hostname' on all hosts, to test ssh. """ run("hostname") @roles('all')
env.solr_tgz = os.path.basename(env.solr_url) env.tomcat_tgz = os.path.basename(env.tomcat_url) # prepare remote directory names for extracted distributions env.my_dir_path = os.path.expanduser("/home/{0}/{1}".format(env.user, MY_DIR_NAME)) env.zookeeper_dir = os.path.join(env.my_dir_path, re.sub(r'\.tar\.gz$', '', env.zookeeper_tgz)) env.solr_dir = os.path.join(env.my_dir_path, re.sub(r'\.tgz$', '', env.solr_tgz)) env.tomcat_dir = os.path.join(env.my_dir_path, re.sub(r'\.tar\.gz$', '', env.tomcat_tgz)) # names for upstart services. Use a prefix to prevent accidentally overwriting a system package env.zookeeper_service = 'my_zookeeper' env.solr_service = 'my_solr' env.tomcat_service = 'my_tomcat' # create an 'all' role containing all hosts env.roledefs.update({ 'all': merge([], ['zookeeper', 'solr'], [], env.roledefs) }) env.first_solr = env.roledefs['solr'][0] env.first_zookeeper = env.roledefs['zookeeper'][0] # local jinja2 templates directory TEMPLATES = "./templates" @roles('all') def test_ssh(): """ Run 'hostname' on all hosts, to test ssh. """ run("hostname") @roles('all') def test_ping(): """ Run 'ping' on all hosts, to test hostname resolution. """