本文整理汇总了Python中cloudinit.distros.parsers.hostname.HostnameConf.set_hostname方法的典型用法代码示例。如果您正苦于以下问题:Python HostnameConf.set_hostname方法的具体用法?Python HostnameConf.set_hostname怎么用?Python HostnameConf.set_hostname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudinit.distros.parsers.hostname.HostnameConf
的用法示例。
在下文中一共展示了HostnameConf.set_hostname方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _write_hostname
# 需要导入模块: from cloudinit.distros.parsers.hostname import HostnameConf [as 别名]
# 或者: from cloudinit.distros.parsers.hostname.HostnameConf import set_hostname [as 别名]
def _write_hostname(self, your_hostname, out_fn):
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
conf = self._read_hostname_conf(out_fn)
except IOError:
pass
if not conf:
conf = HostnameConf('')
conf.set_hostname(your_hostname)
util.write_file(out_fn, str(conf), 0644)
示例2: _write_hostname
# 需要导入模块: from cloudinit.distros.parsers.hostname import HostnameConf [as 别名]
# 或者: from cloudinit.distros.parsers.hostname.HostnameConf import set_hostname [as 别名]
def _write_hostname(self, your_hostname, out_fn):
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
conf = self._read_hostname_conf(out_fn)
except IOError:
pass
if not conf:
conf = HostnameConf('')
conf.set_hostname(your_hostname)
gentoo_hostname_config = 'hostname="%s"' % conf
gentoo_hostname_config = gentoo_hostname_config.replace('\n', '')
util.write_file(out_fn, gentoo_hostname_config, 0o644)
示例3: _write_hostname
# 需要导入模块: from cloudinit.distros.parsers.hostname import HostnameConf [as 别名]
# 或者: from cloudinit.distros.parsers.hostname.HostnameConf import set_hostname [as 别名]
def _write_hostname(self, hostname, out_fn):
if self.uses_systemd() and out_fn.endswith('/previous-hostname'):
util.write_file(out_fn, hostname)
elif self.uses_systemd():
util.subp(['hostnamectl', 'set-hostname', str(hostname)])
else:
conf = None
try:
# Try to update the previous one
# so lets see if we can read it first.
conf = self._read_hostname_conf(out_fn)
except IOError:
pass
if not conf:
conf = HostnameConf('')
conf.set_hostname(hostname)
util.write_file(out_fn, str(conf), 0o644)