本文整理汇总了Python中resource_management.core.environment.Environment.get_instance_copy方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.get_instance_copy方法的具体用法?Python Environment.get_instance_copy怎么用?Python Environment.get_instance_copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource_management.core.environment.Environment
的用法示例。
在下文中一共展示了Environment.get_instance_copy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: action_create
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_create(self):
with Environment.get_instance_copy() as env:
with tempfile.NamedTemporaryFile() as tmpf:
repo_file_name = format("{repo_file_name}.list", repo_file_name=self.resource.repo_file_name)
repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir=self.repo_dir)
new_content = Template(
self.resource.repo_template,
package_type=self.package_type,
base_url=self.resource.base_url,
components=" ".join(self.resource.components),
).get_content()
old_content = ""
if self.resource.append_to_file and os.path.isfile(repo_file_path):
with open(repo_file_path) as repo_file:
old_content = repo_file.read() + "\n"
File(tmpf.name, content=old_content + new_content)
if not os.path.isfile(repo_file_path) or not filecmp.cmp(tmpf.name, repo_file_path):
File(repo_file_path, content=StaticFile(tmpf.name))
update_cmd_formatted = [format(x) for x in self.update_cmd]
# this is time expensive
retcode, out = checked_call(update_cmd_formatted, sudo=True)
# add public keys for new repos
missing_pkeys = set(re.findall(self.missing_pkey_regex, out))
for pkey in missing_pkeys:
Execute(
format(self.add_pkey_cmd),
timeout=15, # in case we are on the host w/o internet (using localrepo), we should ignore hanging
ignore_failures=True,
)
示例2: action_remove
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_remove(self):
with Environment.get_instance_copy() as env:
repo_file_name = self.resource.repo_file_name
repo_dir = get_repo_dir()
File(format("{repo_dir}/{repo_file_name}.repo"),
action="delete")
示例3: action_create
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_create(self):
with Environment.get_instance_copy() as env:
repo_file_name = self.resource.repo_file_name
repo_dir = get_repo_dir()
new_content = InlineTemplate(self.resource.repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name,
base_url=self.resource.base_url, mirror_list=self.resource.mirror_list)
repo_file_path = format("{repo_dir}/{repo_file_name}.repo")
if os.path.isfile(repo_file_path):
existing_content_str = sudo.read_file(repo_file_path)
new_content_str = new_content.get_content()
if existing_content_str != new_content_str and OSCheck.is_suse_family():
# We need to reset package manager's cache when we replace base urls
# at existing repo. That is a case at least under SLES
Logger.info("Flushing package manager cache since repo file content is about to change")
checked_call(self.update_cmd, sudo=True)
if self.resource.append_to_file:
content = existing_content_str + '\n' + new_content_str
else:
content = new_content_str
else: # If repo file does not exist yet
content = new_content
File(repo_file_path,
content=content
)
示例4: action_create
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_create(self):
filename = self.resource.filename
xml_config_provider_config_dir = self.resource.conf_dir
# |e - for html-like escaping of <,>,',"
config_content = InlineTemplate(''' <configuration>
{% for key, value in configurations_dict|dictsort %}
<property>
<name>{{ key|e }}</name>
<value>{{ resource_management.core.source.InlineTemplate(str(value)).get_content() |e }}</value>
{%- if not configuration_attrs is none -%}
{%- for attrib_name, attrib_occurances in configuration_attrs.items() -%}
{%- for property_name, attrib_value in attrib_occurances.items() -%}
{% if property_name == key and attrib_name %}
<{{attrib_name|e}}>{{attrib_value|e}}</{{attrib_name|e}}>
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endif %}
</property>
{% endfor %}
</configuration>''', extra_imports=[time, resource_management, resource_management.core, resource_management.core.source], configurations_dict=self.resource.configurations,
configuration_attrs=self.resource.configuration_attributes)
xml_config_dest_file_path = os.path.join(xml_config_provider_config_dir, filename)
Logger.info("Generating config: {0}".format(xml_config_dest_file_path))
with Environment.get_instance_copy() as env:
File (xml_config_dest_file_path,
content = config_content,
owner = self.resource.owner,
group = self.resource.group,
mode = self.resource.mode,
encoding = self.resource.encoding
)
示例5: action_remove
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_remove(self):
with Environment.get_instance_copy() as env:
repo_file_name = format("{repo_file_name}.list", repo_file_name=self.resource.repo_file_name)
repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir=self.repo_dir)
if os.path.isfile(repo_file_path):
File(repo_file_path, action="delete")
# this is time expensive
update_cmd_formatted = [format(x) for x in self.update_cmd]
Execute(update_cmd_formatted)
示例6: action_create
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_create(self):
template_tag = self.resource.template_tag
qualified_file_name = self.resource.name
file_name = os.path.basename(qualified_file_name)
if not template_tag:
template_name = format("{file_name}.j2")
else:
template_name = format("{file_name}-{template_tag}.j2")
with Environment.get_instance_copy() as env:
File( qualified_file_name,
owner = self.resource.owner,
group = self.resource.group,
mode = self.resource.mode,
content = Template(template_name, extra_imports=self.resource.extra_imports)
)
示例7: action_create
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_create(self):
filename = self.resource.filename
comment_symbols = self.resource.comment_symbols
delimiter = self.resource.key_value_delimiter
properties = self.resource.properties
unsaved_values = properties.keys()
new_content_lines = []
if sudo.path_isfile(filename):
file_content = sudo.read_file(filename, encoding=self.resource.encoding)
new_content_lines += file_content.split('\n')
Logger.info(format("Modifying existing properties file: {filename}"))
for line_num in range(len(new_content_lines)):
line = new_content_lines[line_num]
if line.lstrip() and not line.lstrip()[0] in comment_symbols and delimiter in line:
in_var_name = line.split(delimiter)[0].strip()
in_var_value = line.split(delimiter)[1].strip()
if in_var_name in properties:
value = InlineTemplate(unicode(properties[in_var_name])).get_content()
new_content_lines[line_num] = u"{0}{1}{2}".format(unicode(in_var_name), delimiter, value)
unsaved_values.remove(in_var_name)
else:
Logger.info(format("Creating new properties file as {filename} doesn't exist"))
for property_name in unsaved_values:
value = InlineTemplate(unicode(properties[property_name])).get_content()
line = u"{0}{1}{2}".format(unicode(property_name), delimiter, value)
new_content_lines.append(line)
with Environment.get_instance_copy() as env:
File (filename,
content = u"\n".join(new_content_lines) + "\n",
owner = self.resource.owner,
group = self.resource.group,
mode = self.resource.mode,
encoding = self.resource.encoding,
)
示例8: action_create
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_create(self):
filename = self.resource.filename
dir = self.resource.dir
if dir == None:
filepath = filename
else:
filepath = os.path.join(dir, filename)
config_content = InlineTemplate('''# Generated by Apache Ambari. {{time.asctime(time.localtime())}}
{% for key, value in properties_dict|dictsort %}
{{key}}{{key_value_delimiter}}{{ resource_management.core.source.InlineTemplate(str(value)).get_content() }}{% endfor %}
''', extra_imports=[time, resource_management, resource_management.core, resource_management.core.source], properties_dict=self.resource.properties, key_value_delimiter=self.resource.key_value_delimiter)
Logger.info(format("Generating properties file: {filepath}"))
with Environment.get_instance_copy() as env:
File (format("{filepath}"),
content = config_content,
owner = self.resource.owner,
group = self.resource.group,
mode = self.resource.mode
)
示例9: action_run
# 需要导入模块: from resource_management.core.environment import Environment [as 别名]
# 或者: from resource_management.core.environment.Environment import get_instance_copy [as 别名]
def action_run(self):
kinit__path_local = self.resource.kinit_path_local
keytab = self.resource.keytab
conf_dir = self.resource.conf_dir
command = self.resource.command
principal = self.resource.principal
if isinstance(command, (list, tuple)):
command = " ".join(quote_bash_args(x) for x in command)
with Environment.get_instance_copy() as env:
if self.resource.security_enabled and not self.resource.kinit_override:
Execute(format("{kinit__path_local} -kt {keytab} {principal}"), path=["/bin"], user=self.resource.user)
Execute(
format("hadoop --config {conf_dir} {command}"),
user=self.resource.user,
tries=self.resource.tries,
try_sleep=self.resource.try_sleep,
logoutput=self.resource.logoutput,
path=self.resource.bin_dir,
environment=self.resource.environment,
)