def signIn(self, ip, info): is_virtual = info.get("virtual") virt_type = info.get("virt_type") if not is_virtual: id = ID.host_id_gen(ip) host_type = "Host" session = self.session #host = session.getResource(host_type, id) host = session.getResource("all", id) if host is None: host = Host(ip) host.id = id else: logger.debug("retrieve object %s from db" % host) host.is_virtual = is_virtual host.virt_type = virt_type host.ip = ip components = info.get("components") cpuinfo = components.get("cpu") cpu = CPU(**cpuinfo) host.hasOne("cpu", cpu) disksinfo = components.get("filesystem")["local"] for dn, di in disksinfo.iteritems(): if di.has_key("disk"): diskname = di.get("disk") diskinfo = disksinfo.get(diskname) disk = Disk(**diskinfo) disk.update({"name": diskname}) partition = Partition(**di) partition.update({"name": dn}) disk.addOne("partitions", dn, partition) host.addOne("disks", diskname, disk) else: continue meminfo = components.get("memory") host.update(meminfo) ifsinfo = components.get("network") for ifn, ifi in ifsinfo.iteritems(): if ifn not in ("lo",): network_interface = NetworkInterface(**ifi) network_interface.update({"name": ifn}) host.addOne("network_interfaces", ifn, network_interface) host.metric_list = info["metric_groups"] host.last_arrival = time.time() session.setResource("all", host.id, host) session.setResource(host.__class__.__name__, host.id, host) session.setResource("active", host.ip, host) #session.root._p_changed = 1 session.commit() logger.info("%s(%s) signed in" % (host.id, host.ip))
def sign_in_handler(ip, info): is_virtual = info.get('virtual') virt_type = info.get('virt_type') if not is_virtual: id = ID.host_id_gen(ip) host_type = 'Host' global modeldb session = modeldb.openSession() host = session.getResource(host_type, id) if host is None: host = Host(ip) host.id = id else: logger.debug('retieve object %s from db' % host) host.is_virtual = is_virtual host.virt_type = virt_type components = info.get('components') cpuinfo = components.get('cpu') cpu = CPU(**cpuinfo) host.hasOne('cpu', cpu) disksinfo = components.get('filesystem')['local'] for dn, di in disksinfo.iteritems(): if di.has_key('disk'): diskname = di.get('disk') diskinfo= disksinfo.get(diskname) disk = Disk(**diskinfo) disk.update({'name': diskname}) partition = Partition(**di) partition.update({'name': dn}) disk.addOne('partitions', dn, partition) host.addOne('disks', diskname, disk) else: continue meminfo = components.get('memory') host.update(meminfo) ifsinfo = components.get('network') for ifn, ifi in ifsinfo.iteritems(): if ifn not in ('lo',): network_interface = NetworkInterface(**ifi) network_interface.update({'name': ifn}) host.addOne('network_interfaces', ifn, network_interface) #if virt_type is not None: #host.virt_type = virt_type host.metric_list = info['metric_groups'] session.setResource(host.__class__.__name__, host.id, host) session.setResource('active', host.ip, host) session.commit() session.close()