我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用params.config()。
def configure(self, env, isInstall=False): import params env.set_params(params) drill_override_content=InlineTemplate(params.drill_override_content) drill_env_content=InlineTemplate(params.drill_env_content) if isInstall: Execute('chown -R ' + params.drill_user + ':' + params.drill_group + ' ' + params.drill_install_dir) File(params.drill_install_dir + '/apache-drill-1.6.0/conf/drill-override.conf', content=drill_override_content, owner=params.drill_user, group=params.drill_group) File(params.drill_install_dir + '/apache-drill-1.6.0/conf/drill-env.sh', content=drill_env_content, owner=params.drill_user, group=params.drill_group) XmlConfig("hdfs-site.xml", conf_dir=params.drill_install_dir + '/apache-drill-1.6.0/conf', configurations=params.config['configurations']['hdfs-site'], configuration_attributes=params.config['configuration_attributes']['hdfs-site'], owner=params.drill_user, group=params.drill_group, mode=0644) XmlConfig("core-site.xml", conf_dir=params.drill_install_dir + '/apache-drill-1.6.0/conf', configurations=params.config['configurations']['core-site'], configuration_attributes=params.config['configuration_attributes']['core-site'], owner=params.drill_user, group=params.drill_group, mode=0644) Execute('hdfs dfs -mkdir -p ' + params.sys_store_provider_zk_blobroot, user='hdfs') Execute('hdfs dfs -chown -R ' + params.drill_user + ':' + params.drill_group + ' ' + params.sys_store_provider_zk_blobroot, user='hdfs')
def configure(self, env): # Import properties defined in -config.xml file from the params class import params # This allows us to access the params.elastic_pid_file property as # format('{elastic_pid_file}') env.set_params(params) configurations = params.config['configurations']['elastic-config'] File(format("{elastic_conf_dir}/elasticsearch.yml"), content=Template("elasticsearch.yml.j2", configurations=configurations), owner=params.elastic_user, group=params.elastic_group ) # Install HEAD and HQ puglins - these plugins are not currently supported by ES 5.x #cmd = format("{elastic_base_dir}/bin/elasticsearch-plugin install mobz/elasticserach-head") #Execute(cmd) # Attempt to remove X-Pack plugin cmd = format("{elastic_base_dir}/bin/elasticsearch-plugin remove x-pack") Execute(cmd) # Install X-Pack plugin cmd = format("{elastic_base_dir}/bin/elasticsearch-plugin install x-pack") Execute(cmd) # Ensure all files owned by elasticsearch user cmd = format("chown -R {elastic_user}:{elastic_group} {elastic_base_dir}") Execute(cmd) Execute('echo "Configuration complete"')
def stop(self, env): # Import properties defined in -config.xml file from the params class import params # Import properties defined in -env.xml file from the status_params class import status_params # This allows us to access the params.elastic_pid_file property as # format('{elastic_pid_file}') env.set_params(params) # Stop Elasticsearch kill_process(params.elastic_pid_file, params.elastic_user, params.elastic_log_dir) #cmd = format("kill `cat {elastic_pid_file}`") #Execute(cmd, user=params.elastic_user, only_if=format("test -f {elastic_pid_file}"))
def start(self, env): # Import properties defined in -config.xml file from the params class import params # This allows us to access the params.elastic_pid_file property as # format('{elastic_pid_file}') env.set_params(params) # Configure Elasticsearch self.configure(env) # Start Elasticsearch cmd = format("{elastic_base_dir}/bin/elasticsearch -d -p {elastic_pid_file}") Execute(cmd, user=params.elastic_user)
def slave(): import params User(params.elastic_user, action = "create", groups = params.elastic_group) params.path_data = params.path_data.replace('"', '') data_path = params.path_data.replace(' ', '').split(',') data_path[:] = [x.replace('"', '') for x in data_path] directories = [params.log_dir, params.pid_dir, params.conf_dir] directories = directories + data_path Directory(directories, create_parents=True, mode=0755, owner=params.elastic_user, group=params.elastic_group, cd_access="a" ) File("{0}/elastic-env.sh".format(params.conf_dir), owner=params.elastic_user, content=InlineTemplate(params.elastic_env_sh_template) ) configurations = params.config['configurations']['elastic-site'] File("{0}/elasticsearch.yml".format(params.conf_dir), content=Template( "elasticsearch.slave.yaml.j2", configurations=configurations), owner=params.elastic_user, group=params.elastic_group ) print "Master sysconfig: /etc/sysconfig/elasticsearch" File(format("/etc/sysconfig/elasticsearch"), owner="root", group="root", content=InlineTemplate(params.sysconfig_template) )
def slave(): import params params.path_data = params.path_data.replace('"', '') data_path = params.path_data.replace(' ', '').split(',') data_path[:] = [x.replace('"', '') for x in data_path] directories = [params.log_dir, params.pid_dir, params.conf_dir] directories = directories + data_path Directory(directories, create_parents=True, mode=0755, owner=params.elastic_user, group=params.elastic_user, cd_access="a" ) File("{0}/elastic-env.sh".format(params.conf_dir), owner=params.elastic_user, content=InlineTemplate(params.elastic_env_sh_template) ) configurations = params.config['configurations']['elastic-site'] File("{0}/elasticsearch.yml".format(params.conf_dir), content=Template( "elasticsearch.slave.yaml.j2", configurations=configurations), owner=params.elastic_user, group=params.elastic_user ) print "Master sysconfig: /etc/sysconfig/elasticsearch" File(format("/etc/sysconfig/elasticsearch"), owner="root", group="root", content=InlineTemplate(params.sysconfig_template) )
def install(self, env): # Import properties defined in -config.xml file from the params class import params # This allows us to access the params.elastic_pid_file property as # format('{elastic_pid_file}') env.set_params(params) # Install dependent packages self.install_packages(env) # Create user and group for Elasticsearch if they don't exist try: grp.getgrnam(params.elastic_group) except KeyError: Group(group_name=params.elastic_group) try: pwd.getpwnam(params.elastic_user) except KeyError: User(username=params.elastic_user, gid=params.elastic_group, groups=[params.elastic_group], ignore_failures=True ) # Create Elasticsearch directories Directory([params.elastic_base_dir, params.elastic_log_dir, params.elastic_pid_dir], mode=0755, cd_access='a', owner=params.elastic_user, group=params.elastic_group, create_parents=True ) # Create empty Elasticsearch install log File(params.elastic_install_log, mode=0644, owner=params.elastic_user, group=params.elastic_group, content='' ) # Download Elasticsearch cmd = format("cd {elastic_base_dir}; wget {elastic_download} -O elasticsearch.tar.gz -a {elastic_install_log}") Execute(cmd, user=params.elastic_user) # Install Elasticsearch cmd = format("cd {elastic_base_dir}; tar -xf elasticsearch.tar.gz --strip-components=1") Execute(cmd, user=params.elastic_user) # Ensure all files owned by elasticsearch user cmd = format("chown -R {elastic_user}:{elastic_group} {elastic_base_dir}") Execute(cmd) # Remove Elasticsearch installation file cmd = format("cd {elastic_base_dir}; rm elasticsearch.tar.gz") Execute(cmd, user=params.elastic_user) Execute('echo "Install complete"')
def elastic(): import params User(params.elastic_user, action = "create", groups = params.elastic_group) params.path_data = params.path_data.replace('"', '') data_path = params.path_data.replace(' ', '').split(',') data_path[:] = [x.replace('"', '') for x in data_path] directories = [params.log_dir, params.pid_dir, params.conf_dir] directories = directories + data_path + ["{0}/scripts".format(params.conf_dir)] Directory(directories, create_parents=True, mode=0755, owner=params.elastic_user, group=params.elastic_group ) print "Master env: ""{0}/elastic-env.sh".format(params.conf_dir) File("{0}/elastic-env.sh".format(params.conf_dir), owner=params.elastic_user, group=params.elastic_group, content=InlineTemplate(params.elastic_env_sh_template) ) configurations = params.config['configurations']['elastic-site'] print "Master yml: ""{0}/elasticsearch.yml".format(params.conf_dir) File("{0}/elasticsearch.yml".format(params.conf_dir), content=Template( "elasticsearch.master.yaml.j2", configurations=configurations), owner=params.elastic_user, group=params.elastic_group ) print "Master sysconfig: /etc/sysconfig/elasticsearch" File("/etc/sysconfig/elasticsearch", owner="root", group="root", content=InlineTemplate(params.sysconfig_template) )
def elastic(): print "INSIDE THE %s" % __file__ import params params.path_data = params.path_data.replace('"', '') data_path = params.path_data.replace(' ', '').split(',') data_path[:] = [x.replace('"', '') for x in data_path] directories = [params.log_dir, params.pid_dir, params.conf_dir] directories = directories + data_path Directory(directories, create_parents=True, # recursive=True, mode=0755, owner=params.elastic_user, group=params.elastic_user ) print "Master env: ""{0}/elastic-env.sh".format(params.conf_dir) File("{0}/elastic-env.sh".format(params.conf_dir), owner=params.elastic_user, content=InlineTemplate(params.elastic_env_sh_template) ) configurations = params.config['configurations']['elastic-site'] print "Master yml: ""{0}/elasticsearch.yml".format(params.conf_dir) File("{0}/elasticsearch.yml".format(params.conf_dir), content=Template( "elasticsearch.master.yaml.j2", configurations=configurations), owner=params.elastic_user, group=params.elastic_user ) print "Master sysconfig: /etc/sysconfig/elasticsearch" File(format("/etc/sysconfig/elasticsearch"), owner="root", group="root", content=InlineTemplate(params.sysconfig_template) )