def hostPreferences(self): prefs = ObjectPreferences(True) for h in hosts.getAll(self.hostgroup): if h.enabled: prefs.add(h, 1.0 - len(h.device_set.all())/100.0) #print "Host preferences for %s: %s" % (self, prefs) return prefs
def forwards(self, orm): for host in hosts.getAll(): for type in resources.TYPES: resources.createPool(host, type, host.getAttribute("%s_start" % type), host.getAttribute("%s_count" % type)) host.deleteAttribute("%s_start" % type) host.deleteAttribute("%s_count" % type) for obj in m.EmulatedConnection.objects.all(): if obj.getAttribute("capture_port"): host = obj.interface.device.host obj.live_capture_port = resources.take(host, "port", obj, obj.LIVE_CAPTURE_PORT_SLOT, obj.getAttribute("capture_port")) obj.deleteAttribute("capture_port") if not obj.getAttribute("ifb_id") is None: host = obj.interface.device.host obj.ifb_id = resources.take(host, "ifb", obj, obj.IFB_ID_SLOT, obj.getAttribute("ifb_id")) obj.deleteAttribute("ifb_id") obj.save() for obj in orm.TincConnector.objects.all(): if obj.getAttribute("external_access_port"): port = obj.getAttribute("external_access_port") obj.deleteAttribute("external_access_port") cname = obj.getAttribute("external_access_con") obj.deleteAttribute("external_access_con") con = obj.topology.interfacesGet(cname).connection host = con.interface.device.host obj.external_access_port = resources.take(host, "port", obj, obj.EXTERNAL_ACCESS_PORT_SLOT, port) obj.save() for obj in orm.TincConnection.objects.all(): host = obj.interface.device.host if obj.tinc_port and host: pool = orm.ResourcePool.objects.get(host=host, type="port") obj.tinc_port_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="c", owner_id=obj.id, slot="tinc", num=obj.tinc_port) if obj.bridge_id and host: pool = orm.ResourcePool.objects.get(host=host, type="bridge") obj.bridge_id_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="c", owner_id=obj.id, slot="b", num=obj.bridge_id) obj.save() for obj in orm.KVMDevice.objects.all(): if obj.vmid and obj.host: pool = orm.ResourcePool.objects.get(host=obj.host, type="vmid") obj.vmid_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="D", owner_id=obj.id, slot="vmid", num=obj.vmid) if obj.vnc_port and obj.host: pool = orm.ResourcePool.objects.get(host=obj.host, type="port") obj.vnc_port_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="D", owner_id=obj.id, slot="vnc", num=obj.vnc_port) obj.save() for obj in orm.OpenVZDevice.objects.all(): if obj.vmid and obj.host: pool = orm.ResourcePool.objects.get(host=obj.host, type="vmid") obj.vmid_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="D", owner_id=obj.id, slot="vmid", num=obj.vmid) if obj.vnc_port and obj.host: pool = orm.ResourcePool.objects.get(host=obj.host, type="port") obj.vnc_port_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="D", owner_id=obj.id, slot="vnc", num=obj.vnc_port) obj.save() for obj in orm.ProgDevice.objects.all(): if obj.vnc_port and obj.host: pool = orm.ResourcePool.objects.get(host=obj.host, type="port") obj.vnc_port_ref = orm.ResourceEntry.objects.create(pool=pool, owner_type="D", owner_id=obj.id, slot="vnc", num=obj.vnc_port) obj.save()
def hostPreferences(self): prefs = ObjectPreferences() # keep it local for c in self.connectionSetAll(): dev = c.interface.device if dev.host: prefs.add(dev.host, -0.1) for h in hosts.getAll(dev.host.group): prefs.add(h, 0.01) #print "Host preferences for %s: %s" % (self, prefs) return prefs
def hostPreferences(self): prefs = ObjectPreferences() # keep it local sites={} for c in self.connectionSetAll(): dev = c.interface.device if dev.host: #discourage devices on the same host prefs.add(dev.host, -0.05) sites[dev.host.group] = sites.get(dev.host.group, 0.0) + 1.0 for site, num in sites.iteritems(): val = 0.05 * num/(num+10) # value increases with hosts already at that site # value is bounded by 0.01 for h in hosts.getAll(site): prefs.add(h, val) #print "Host preferences for %s: %s" % (self, prefs) return prefs