def host_register(host, clustername): cc = libMysqlCluster.Cluster() if not cc.select_exist([(cc.col_clustername, clustername)]): print 'Cluster %s not exist' % clustername return conn = libvirt_connection(host) hs = libMysqlHost.Hosts() ninfo = conn.getInfo() nodeinfo = {} nodeinfo[hs.col_hostid] = host nodeinfo[hs.col_clustername] = clustername nodeinfo[hs.col_hashname] = hs.get_hashname(host) nodeinfo[hs.col_model] = ninfo[0] nodeinfo[hs.col_memory] = ninfo[1] nodeinfo[hs.col_cpus] = ninfo[2] nodeinfo[hs.col_mhz] = ninfo[3] nodeinfo[hs.col_numa_cell] = ninfo[4] nodeinfo[hs.col_sockets] = ninfo[5] nodeinfo[hs.col_cores] = ninfo[6] nodeinfo[hs.col_threads] = ninfo[7] nodeinfo[hs.col_update_time] = time.localtime() nodeinfo[hs.col_register_time] = time.localtime() ### clustername/node IP/disk size/ ret = hs.insert_dict(nodeinfo) if ret == 0: print 'Host %s registered. Done. ' % host return True else: print 'Something was wrong...' return False
def generate_instances_info(nodes, nums, imageid, vcpus, mem): dom_list = [] instc = libMysqlInstance.Instances() hs = libMysqlHost.Hosts() for i, pid in enumerate(nodes): dom0_hash_name = hs.get_hashname(pid) list = [] for j in range(nums[i]): domU_rand_name = str(random.randint(100000, 999999)) instancename = "cvi-%s-%s" % (dom0_hash_name, domU_rand_name) ## domU name check from db to avoid reduplication list.append(instancename) domU_rand_mac = 'd0:0d:%02x:%02x:%02x:%02x' % (random.randint( 0, 255), random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255)) domU_rand_mac = domU_rand_mac.upper() username = None tuplelist = [] tuplelist.append((instc.col_name, instancename)) tuplelist.append((instc.col_hostname, pid)) tuplelist.append((instc.col_username, username)) tuplelist.append((instc.col_imagename, imageid)) tuplelist.append((instc.col_mac, domU_rand_mac)) tuplelist.append((instc.col_status, 'Pending')) tuplelist.append((instc.col_update_time, time.localtime())) tuplelist.append((instc.col_register_time, time.localtime())) tuplelist.append((instc.col_cputime, 0)) tuplelist.append((instc.col_vcpu, vcpus)) tuplelist.append((instc.col_mem, mem)) instc.insert(tuplelist) dom_list.append(list) return dom_list
def getpms(logger): hs = libMysqlHost.Hosts() plist = hs.select(hs.col_hostid, None, None) thr = [] for pid in plist: thr.append(threading.Thread(target=getnodeinfo, args=(pid[0], logger))) for i in range(len(thr)): thr[i].start()
def getinstances(logger): hst = libMysqlHost.Hosts() columns = [hst.col_hostid, hst.col_clustername] ret = hst.select(' , '.join(columns), '', '') plist = [] for i in ret: plist.append(i[0]) thr = [] for pid in plist: thr.append(threading.Thread(target=getdomains, args=(pid, logger))) for i in range(len(thr)): thr[i].start() instc = libMysqlInstance.Instances() instc.mark_dead()
def getnodeinfo(pid,logger): try: conn = libvirt.open("xen+ssh://root@%s/" % pid) except: logger.info("Lost Contection : %s" % pid) return hs = libMysqlHost.Hosts() ninfo = conn.getInfo() wheredict = {} wheredict[hs.col_hostid] = pid nodeinfo = {} nodeinfo['model'] = ninfo[0] nodeinfo['memory'] = ninfo[1] nodeinfo['cpus'] = ninfo[2] nodeinfo['mhz'] = ninfo[3] nodeinfo['numa_cell'] = ninfo[4] nodeinfo['sockets'] = ninfo[5] nodeinfo['cores'] = ninfo[6] nodeinfo['threads'] = ninfo[7] nodeinfo['update_time'] = time.localtime() hs.update_dict(wheredict, nodeinfo)
import libMysqlHost hst = libMysqlHost.Hosts() columns = [hst.col_hostid, hst.col_clustername] ret = hst.select(' , '.join(columns), '', '') plist = [] for i in ret: plist.append(i[0]) print plist