Noam Slomianko has uploaded a new change for review. Change subject: Samples: score by similar os for ksm ......................................................................
Samples: score by similar os for ksm Score each host by how many of its vms have the same os as the requested vm. Change-Id: Idfb359ecbd73a1f4a2520ac8a65b753449be55bd Signed-off-by: Noam Slomianko <nslom...@redhat.com> --- A plugins/examples/ksm_same_os_score.py 1 file changed, 62 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-scheduler-proxy refs/changes/33/20033/1 diff --git a/plugins/examples/ksm_same_os_score.py b/plugins/examples/ksm_same_os_score.py new file mode 100644 index 0000000..f46657f --- /dev/null +++ b/plugins/examples/ksm_same_os_score.py @@ -0,0 +1,62 @@ +from ovirtsdk.xml import params +from ovirtsdk.api import API +import sys + + +class ksm_same_os_score(): + '''rank hosts higher the more vms they have with similar os to the scored vm''' + + properties_validation = '' + + def _get_connection(self): + #open a connection to the rest api + connection = None + try: + connection = API(url='http://localhost:8080', + username='admin@internal', password='1') + except BaseException as ex: + #letting the external proxy know there was an error + print >> sys.stderr, ex + return None + + return connection + + def _get_hosts(self, host_ids, connection): + #get all the hosts with the given ids + engine_hosts = connection.hosts.list( + query=" or ".join(["id=%s" % u for u in host_ids])) + + return engine_hosts + + def _get_vms(self, host_name, connection): + #get all the vms with the given host + host_vms = connection.vms.list('host='+host_name) + + return host_vms + + def score_host(self, vm, host, connection): + score = 0 + host_vms = self._get_vms(host.name, connection) + if not host_vms: + return (host.id, 0) + for host_vm in host_vms: + if(vm.get_os().get_type() == host_vm.get_os().get_type()): + if(vm.get_os().get_version() == host_vm.get_os().get_version()): + score += 100 + else: + score += 20 + return (host.id, score / len(host_vms)) + + def do_score(self, hosts_ids, vm_id, args_map): + conn = self._get_connection() + if conn is None: + return + + engine_hosts = self._get_hosts(hosts_ids, conn) + vm = conn.vms.get(id=vm_id) + + host_scores = [] + for host in engine_hosts: + host_scores.append(self.score_host(vm, host, conn)) + + print host_scores \ No newline at end of file -- To view, visit http://gerrit.ovirt.org/20033 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idfb359ecbd73a1f4a2520ac8a65b753449be55bd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-scheduler-proxy Gerrit-Branch: master Gerrit-Owner: Noam Slomianko <nslom...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches