本文整理汇总了Python中socket.getfqdn函数的典型用法代码示例。如果您正苦于以下问题:Python getfqdn函数的具体用法?Python getfqdn怎么用?Python getfqdn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getfqdn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, sa, argv):
import socket
self.sa = sa
self.env = Path(self.sa.env)
self.argv = argv
self.defaults = {
'svn_dir': Path('svn'),
'git_dir': Path('git'),
'trac_dir': Path('trac'),
'http_base': Path('/'),
'http_vhost': socket.getfqdn(),
'trac_url': Path('trac'),
'submin_url': Path('submin'),
'svn_url': Path('svn'),
'create_user': 'yes',
'enable_features': 'svn, git, apache, nginx',
'smtp_from': 'Submin <[email protected]%s>' % socket.getfqdn(),
}
self.init_vars = {
'conf_dir': Path('conf'),
'hooks_dir': Path('hooks'),
}
self.init_vars.update({
'authz': self.init_vars['conf_dir'] + Path('authz'),
'htpasswd': self.init_vars['conf_dir'] + Path('htpasswd'),
})
self.email = None
示例2: get_user_dns
def get_user_dns():
try:
domain = '.'.join(getfqdn().split('.')[1:])
user_dns = getfqdn(domain).split('.')[0]
except:
user_dns = ''
return user_dns
示例3: check_size
def check_size(file_size, file_name, platform):
""" compare file size with available size on sftpsite """
ssh_key = '/home/encryptonator/.ssh/{}'.format(platform)
df_batch = '/home/encryptonator/df'
if 'ix5' in socket.getfqdn():
squid = 'proxy001.ix5.ops.prod.st.ecg.so'
elif 'esh' in socket.getfqdn():
squid = 'proxy001.esh.ops.prod.st.ecg.so'
with open(df_batch, 'w') as df_file:
df_file.write('df')
df_file.close()
sftp_cmd = "/usr/bin/sftp -b {0} -i {1} -o ProxyCommand='/bin/nc -X connect -x {2}:3128 %h %p' {3}@88.211.136.242".format(df_batch, ssh_key, squid, platform)
proc_sftp = sp.Popen(sftp_cmd, shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)
proc_out = proc_sftp.communicate()[0]
retcode = proc_sftp.returncode
if retcode is not 0:
notify_nagios('Team {} cannot connect to Sftp Site'.format(platform))
return 'noconnection'
else:
proc_out = proc_out.split('\n')[-2] # take last but one row
disk_avail = int(proc_out.split()[-3].replace('%', ''))
if file_size >= disk_avail:
mb_file_size = file_size / 1024
mb_disk_avail = disk_avail / 1024
notify_nagios('The file size to backup ({0} MB) exceeds the space available ({1} MB) on Sftp Site'.format(mb_file_size, mb_disk_avail))
notify_nagios('The file {} will be removed'.format(file_name))
return 'nospace'
示例4: normalizeURL
def normalizeURL(self, url):
"""
Takes a URL (as returned by absolute_url(), for example) and
replaces the hostname with the actual, fully-qualified
hostname.
"""
url_parts = urlsplit(url)
hostpart = url_parts[1]
port = ''
if hostpart.find(':') != -1:
(hostname, port) = split(hostpart, ':')
else:
hostname = hostpart
if hostname == 'localhost' or hostname == '127.0.0.1':
hostname = getfqdn(gethostname())
else:
hostname = getfqdn(hostname)
if port:
hostpart = join((hostname, port), ':')
url = urlunsplit((url_parts[0], hostpart, \
url_parts[2], url_parts[3], url_parts[4]))
return url
示例5: sendPing
def sendPing(self, tasks, isReboot=False):
# Update the values (calls subclass impl)
self.update()
if conf.NETWORK_DISABLED:
return
# Create the hardware profile
hw = ttypes.Hardware()
hw.physicalCpus = self.physicalCpus
hw.logicalCpus = self.logicalCpus
hw.totalRamMb = self.totalRamMb
hw.freeRamMb = self.freeRamMb
hw.totalSwapMb = self.totalSwapMb
hw.freeSwapMb = self.freeSwapMb
hw.cpuModel = self.cpuModel
hw.platform = self.platform
hw.load = self.load
# Create a ping
ping = ttypes.Ping()
ping.hostname = socket.getfqdn()
ping.ipAddr = socket.gethostbyname(socket.getfqdn())
ping.isReboot = isReboot
ping.bootTime = self.bootTime
ping.hw = hw
ping.tasks = tasks
logger.info("Sending ping: %s" % ping)
try:
service, transport = client.getPlowConnection()
service.sendPing(ping)
transport.close()
except Exception, e:
logger.warn("Unable to send ping to plow server, %s" % e)
示例6: hostInfo
def hostInfo():
hostName = socket.gethostname()
print hostName
print socket.gethostbyname(hostName)
print socket.gethostbyname_ex(hostName)
print socket.getfqdn(hostName)
print socket.getaddrinfo("www.baidu.com", 80)
示例7: is_me
def is_me(self, lookup_name):
logger.info("And arbiter is launched with the hostname:%s "
"from an arbiter point of view of addr:%s", self.host_name, socket.getfqdn())
if lookup_name:
return lookup_name == self.get_name()
else:
return self.host_name == socket.getfqdn() or self.host_name == socket.gethostname()
示例8: _localhosts_aggressive
def _localhosts_aggressive():
answ={}
stack=['localhost', '127.0.0.1', socket.getfqdn(), socket.gethostname()]
def lh_add(*hs):
for h in hs:
if answ.has_key(h):
continue
stack.append(h)
while stack:
h = stack.pop()
if answ.has_key(h):
continue
answ[h] = True
lh_add(socket.getfqdn(h))
try:
lh_add(socket.gethostbyname(h))
except:
pass
try:
fqdn, aliases, ip_addresses = socket.gethostbyname_ex(h)
lh_add(fqdn, *aliases)
lh_add(*ip_addresses)
except:
pass
try:
fqdn, aliases, ip_addresses = socket.gethostbyaddr(h)
lh_add(fqdn, *aliases)
lh_add(*ip_addresses)
except:
pass
return answ
示例9: send_problem_report
def send_problem_report(problem):
"""Send a problem report to OCF staff."""
def format_frame(frame):
_, filename, line, funcname, _, _ = frame
return '{}:{} ({})'.format(filename, line, funcname)
callstack = '\n by '.join(map(format_frame, inspect.stack()))
body = \
"""A problem was encountered and reported via ocflib:
{problem}
====
Hostname: {hostname}
Callstack:
at {callstack}
""".format(problem=problem, hostname=socket.getfqdn(), callstack=callstack)
send_mail(
constants.MAIL_ROOT,
'[ocflib] Problem report from ' + socket.getfqdn(),
body,
sender='ocflib <[email protected]>',
)
示例10: get_hostname
def get_hostname(self):
"""
Returns a hostname as configured by the user
"""
if 'hostname' in self.config:
return self.config['hostname']
if ('hostname_method' not in self.config
or self.config['hostname_method'] == 'fqdn_short'):
return socket.getfqdn().split('.')[0]
if self.config['hostname_method'] == 'fqdn':
return socket.getfqdn().replace('.', '_')
if self.config['hostname_method'] == 'fqdn_rev':
hostname = socket.getfqdn().split('.')
hostname.reverse()
hostname = '.'.join(hostname)
return hostname
if self.config['hostname_method'] == 'uname_short':
return os.uname()[1].split('.')[0]
if self.config['hostname_method'] == 'uname_rev':
hostname = os.uname()[1].split('.')
hostname.reverse()
hostname = '.'.join(hostname)
return hostname
if self.config['hostname_method'].lower() == 'none':
return None
raise NotImplementedError(self.config['hostname_method'])
示例11: __init__
def __init__(self,cp):
global has_gratia
global Gratia
global StorageElement
global StorageElementRecord
if not has_gratia:
try:
Gratia = __import__("Gratia")
StorageElement = __import__("StorageElement")
StorageElementRecord = __import__("StorageElementRecord")
has_gratia = True
except:
raise
if not has_gratia:
print "Unable to import Gratia and Storage modules!"
sys.exit(1)
Gratia.Initialize()
try:
if Gratia.Config.get_SiteName().lower().find('generic') >= 0:
Gratia.Config.setSiteName(socket.getfqdn())
except:
pass
try:
if Gratia.Config.get_ProbeName().lower().find('generic') >= 0:
Gratia.Config.setProbeName('dCache-storage:%s' % socket.getfqdn())
except:
pass
示例12: submit
def submit(nworker, nserver, fun_submit, hostIP = 'auto', pscmd = None):
if hostIP == 'auto':
hostIP = 'ip'
if hostIP == 'dns':
hostIP = socket.getfqdn()
elif hostIP == 'ip':
hostIP = socket.gethostbyname(socket.getfqdn())
if nserver == 0:
pscmd = None
envs = {'DMLC_NUM_WORKER' : nworker,
'DMLC_NUM_SERVER' : nserver}
rabit = RabitTracker(hostIP = hostIP, nslave = nworker)
pserver = PSTracker(hostIP = hostIP, cmd = pscmd, envs = envs)
envs.update(rabit.slave_envs())
envs.update(pserver.slave_envs())
rabit.start(nworker)
fun_submit(nworker, nserver, envs)
pserver.join()
# start rabit tracker in another thread
if nserver == 0:
rabit.join()
示例13: process
def process(mysettings, key, logentries, fulltext):
if "PORTAGE_ELOG_MAILURI" in mysettings:
myrecipient = mysettings["PORTAGE_ELOG_MAILURI"].split()[0]
else:
myrecipient = "[email protected]"
myfrom = mysettings["PORTAGE_ELOG_MAILFROM"]
myfrom = myfrom.replace("${HOST}", socket.getfqdn())
mysubject = mysettings["PORTAGE_ELOG_MAILSUBJECT"]
mysubject = mysubject.replace("${PACKAGE}", key)
mysubject = mysubject.replace("${HOST}", socket.getfqdn())
# look at the phases listed in our logentries to figure out what action was performed
action = _("merged")
for phase in logentries:
# if we found a *rm phase assume that the package was unmerged
if phase in ["postrm", "prerm"]:
action = _("unmerged")
# if we think that the package was unmerged, make sure there was no unexpected
# phase recorded to avoid misinformation
if action == _("unmerged"):
for phase in logentries:
if phase not in ["postrm", "prerm", "other"]:
action = _("unknown")
mysubject = mysubject.replace("${ACTION}", action)
mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject, fulltext)
try:
portage.mail.send_mail(mysettings, mymessage)
except PortageException as e:
writemsg("%s\n" % str(e), noiselevel=-1)
return
示例14: find
def find(self, all=False):
'''
If the sll parameter is True, then all methods will be tries and a
list of all RPR's found will be returned.
'''
if self.verbose: print "\tSearching for a BERT-Remote Procedure Repository"
# First try the local machine.
if self.verbose: print "\tTrying the local machine"
if self.search((socket.getfqdn(), self.port)):
if self.verbose: print "\tRPR located: %s:%s" % (socket.getfqdn(), self.port)
if not all: return self.Registries
# First try the supplied places (if any)
if self.verbose and self.places: print "\tTrying supplied places",
elif self.verbose and not self.places: print "\tNo places supplied"
for place in self.places:
if self.verbose: print "\tTrying %s" % (str(place))
if self.search(place):
if self.verbose: print "\tRPR located: %s:%s" % place
if not all: return self.Registries
# Next broadcast for places
if self.verbose: print "\tBroadcasting for an RPR"
for place in self.broadcastForPlaces():
if self.verbose: print "\tResponse from %s:%s" % place
if self.search(place):
if self.verbose: print "\tRPR located: %s:%s" % place
if not all: return self.Registries
if self.verbose: print "\t%s RPR's found" % (len(self.Registries))
return self.Registries
示例15: is_me
def is_me(self):
logger.log(
"And arbiter is launched with the hostname:%s from an arbiter point of view of addr :%s"
% (self.host_name, socket.getfqdn()),
print_it=False,
)
return self.host_name == socket.getfqdn() or self.host_name == socket.gethostname()