def _check_hostname(self): hostname = shell.call('hostname') if 'localhost' in hostname: raise zstacksetting.SettingError(("this machine has not been configured with a meaningful hostname, " "current hostname[%s] will confuse puppet agent when zstack management " "deploying its agents. you can either use 'zstack-setting setHostName' or " "manually change it to a name without 'localhost' in" % hostname))
def _set_puppet(self, args): puppet_conf = vars(args)[self.ARG_PUPPET_CONF] if not os.path.exists(puppet_conf): raise zstacksetting.SettingError('cannot find %s' % puppet_conf) hostname = shell.call('hostname') resource_tmpt = zstacksetting.get_resource_file('puppet.conf', self.PUPPET_RESOURCE_DIR) with open(resource_tmpt, 'r') as fd: content = fd.read() zstacksetting.backup_file(puppet_conf, self.PUPPET_BACKUP_SUB_DIR) tmpt = string.Template(content) d = {'server_host_name' : hostname} content = tmpt.safe_substitute(d) with open(puppet_conf, 'w') as fd: fd.write(content) zstacksetting.report_system_change(puppet_conf) puppet_dir = os.path.dirname(puppet_conf) autosign = os.path.join(puppet_dir, 'autosign.conf') if os.path.exists(autosign): zstacksetting.backup_file(autosign, self.PUPPET_BACKUP_SUB_DIR) with open(autosign, 'w') as fd: fd.write('*') zstacksetting.report_system_change(autosign)
def _set_hostname(self, args): hostname = vars(args)[self.ARG_HOSTNAME] if os.path.exists(self.DEBIAN_HOSTNAME): self._set_debian_hostname(hostname) elif os.path.exists(self.REDHAT_HOSTNAME): self._set_redhat_hostname(hostname) else: raise zstacksetting.SettingError("cannot find %s and %s, the system is neither debian based nor redhat based" % (self.REDHAT_HOSTNAME, self.DEBIAN_HOSTNAME)) shell.call('hostname %s' % hostname) print 'set hostname to %s' % hostname