def _update(hostname, ipaddr): ipaddr = str( ipaddr ) # XXX bug in dnspython: crashes if ipaddr is unicode, wants a str! hosts = Host.filter_by_fqdn(hostname) num_hosts = len(hosts) if num_hosts == 0: return False if num_hosts > 1: logging.error("fqdn %s has multiple entries" % hostname) return False hosts[0].poke() try: update(hostname, ipaddr) logger.info('%s - received good update -> ip: %s' % ( hostname, ipaddr, )) return Response('good %s' % ipaddr) except SameIpError: logger.warning('%s - received no-change update, ip: %s' % ( hostname, ipaddr, )) return Response('nochg %s' % ipaddr)
def _update(hostname, ipaddr): ipaddr = str( ipaddr ) # XXX bug in dnspython: crashes if ipaddr is unicode, wants a str! hosts = Host.filter_by_fqdn(hostname) num_hosts = len(hosts) if num_hosts == 0: return HttpResponseBadRequest('Invalid hostname') if num_hosts > 1: logging.error("fqdn %s has multiple entries" % hostname) return HttpResponseBadRequest('Invalid hostname') hosts[0].poke() increment_ip_update_count() try: update(hostname, ipaddr, origin=hosts[0].domain.domain) logger.info('%s - received good update -> ip: %s' % ( hostname, ipaddr, )) return Response('good %s' % ipaddr) except SameIpError: logger.warning('%s - received no-change update, ip: %s' % ( hostname, ipaddr, )) return Response('nochg %s' % ipaddr)
def check_session_auth(user, hostname): """ Check our database whether the hostname is owned by the user. :param user: django user object :param hostname: fqdn :return: True if hostname is owned by this user, False otherwise. """ fqdn = hostname hosts = Host.filter_by_fqdn(fqdn, created_by=user) num_hosts = len(hosts) if num_hosts == 0: return False if num_hosts > 1: logging.error("fqdn %s has multiple entries" % fqdn) return False return True
def _update(hostname, ipaddr): ipaddr = str(ipaddr) # XXX bug in dnspython: crashes if ipaddr is unicode, wants a str! hosts = Host.filter_by_fqdn(hostname) num_hosts = len(hosts) if num_hosts == 0: return False if num_hosts > 1: logging.error("fqdn %s has multiple entries" % hostname) return False hosts[0].poke() try: update(hostname, ipaddr) logger.info('%s - received good update -> ip: %s' % (hostname, ipaddr, )) return Response('good %s' % ipaddr) except SameIpError: logger.warning('%s - received no-change update, ip: %s' % (hostname, ipaddr, )) return Response('nochg %s' % ipaddr)
def check_api_auth(username, password): """ Check username and password against our database. :param username: http basic auth username (== fqdn) :param password: update password :return: True if authenticated, False otherwise. """ fqdn = username hosts = Host.filter_by_fqdn(fqdn) num_hosts = len(hosts) if num_hosts == 0: return False if num_hosts > 1: logging.error("fqdn %s has multiple entries" % fqdn) return False password_hash = hosts[0].update_secret return check_password(password, password_hash)
def _update(hostname, ipaddr): ipaddr = str(ipaddr) # XXX bug in dnspython: crashes if ipaddr is unicode, wants a str! hosts = Host.filter_by_fqdn(hostname) num_hosts = len(hosts) if num_hosts == 0: return HttpResponseBadRequest('Invalid hostname') if num_hosts > 1: logging.error("fqdn %s has multiple entries" % hostname) return HttpResponseBadRequest('Invalid hostname') hosts[0].poke() increment_ip_update_count() try: update(hostname, ipaddr, origin=hosts[0].domain.domain) logger.info('%s - received good update -> ip: %s' % (hostname, ipaddr, )) return Response('good %s' % ipaddr) except SameIpError: logger.warning('%s - received no-change update, ip: %s' % (hostname, ipaddr, )) return Response('nochg %s' % ipaddr)
logger.error("YAMLError", exc) return HttpResponseRedirect('/exec/') sys_scale = int(request.POST['scale']) noarea = int(request.POST['noarea']) bconf['scale'] = sys_scale bconf['num_of_areas'] = noarea mdb_host_id = -1 mdb_host = None mdb_hosts = Host.objects.filter(name__exact=bconf['store_mongo_db']['host']) if len(mdb_hosts) == 0: mdb_host = Host(name=bconf['store_mongo_db']['host'], ipaddr=bconf['store_mongo_db']['host'], # if_worker = False, # if_result_store = True ) mdb_host.save() mdb_host_id = mdb_host.id else: mdb_host = mdb_hosts[0] mdb_host_id = mdb_host.id mdb_id = 0 mdb = None mdbs = ResultSourceMongodb.objects.filter(host_id__exact=mdb_host_id, port__exact=bconf['store_mongo_db']['port']) if len(mdbs) == 0: # add entry mdb = ResultSourceMongodb(host=mdb_host,