def manage_initial_host_status_brok(self, b): data = b.data hname = data['host_name'] inst_id = data['instance_id'] customs = data.get('customs', {}) if customs.get('_TECH') == self.tech: key = CPEKEY_BY_TECH[self.tech] h = Host({}) self.update_element(h, data) # safe_print("TECH Creating a host: %s/%s in instance %d" % (hname, data.get('hostgroups', 'hgs?'), # inst_id)) if key in customs: self.indices[customs.get(key).lower()] = TechCpe( hname, data, self.customs) try: inp_hosts = self.inp_hosts[inst_id] except Exception, exp: # not good. we will cry in theprogram update print "Not good!", exp return # Ok, put in in the in progress hosts inp_hosts[h.id] = h
def setUp(self): from shinken.objects.host import Host self.item = Host()
def bench_host_creation_with_attr(): ################## Becnh host creation with setattr/getattr/hasattr print_title("Bench host creation with attr") ''' def testBit(int_type, offset): mask = 1 << offset return(int_type & mask) def setBit(int_type, offset): mask = 1 << offset return(int_type | mask) N = 10000000 for pos in [20, 256]: t0 = time.time() mask = 1 << pos for i in xrange(N): f = 0 #print "Set pos %d" % pos b = f | mask #print "Is set?", testBit(f, pos) #print type(f) print "Pos:%d %.2f" % (pos, time.time() - t0) ''' if Host is None: print("Shinken is not installed, skip this test") return # Hack fill default, by setting values directly to class cls = Host for prop, entry in cls.properties.items(): if entry.has_default: v = entry.pythonize(entry.default) setattr(cls, prop, v) # print "Pop: %s => %s" % (prop, v) delete_bool = False delete_running = False lst = [] p1 = 0.0 p2 = 0.0 p3 = 0.0 p4 = 0.0 N = 40000 print("Number of elements", N) for i in xrange(N): t0 = time.time() h = Host({ 'host_name': 'blablacar', 'address': '127.0.0.%d' % i, 'active_checks_enabled': '1' }) p1 += (time.time() - t0) # print h.__dict__ # print h.active_checks_enabled t0 = time.time() # h.fill_default() p2 += (time.time() - t0) # print h.__dict__ # print h.active_checks_enabled t0 = time.time() h.pythonize() p3 += (time.time() - t0) # print h.__dict__ # print h.passive_checks_enabled t0 = time.time() nb_delete = 0 nb_fields = 0 properties = Host.properties for (k, e) in properties.items(): nb_fields += 1 if not hasattr(h, k): continue elif delete_bool: if isinstance(getattr(h, k), bool): delattr(h, k) # pass nb_delete += 1 for (k, e) in Host.running_properties.items(): nb_fields += 1 if not hasattr(h, k): continue elif delete_running: delattr(h, k) continue elif delete_bool: if isinstance(getattr(h, k), bool): delattr(h, k) # pass nb_delete += 1 # print cPickle.dumps(h, 0) p4 += (time.time() - t0) # print "Deleted: %d / %d total" % (nb_delete, nb_fields) lst.append(h) t0 = time.time() buf = cPickle.dumps(lst, 2) print("TIME pickle %.2f len=%d" % (time.time() - t0, len(buf))) print("Phases: create=%.2f default=%.2f pythonize=%.2f clean=%.2f" % (p1, p2, p3, p4))