本文整理汇总了Python中cloudinit.distros.parsers.hostname.HostnameConf类的典型用法代码示例。如果您正苦于以下问题:Python HostnameConf类的具体用法?Python HostnameConf怎么用?Python HostnameConf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HostnameConf类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _write_hostname
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
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
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)
示例4: _read_hostname_conf
def _read_hostname_conf(self, filename):
conf = HostnameConf(util.load_file(filename))
conf.parse()
return conf