Пример #1
0
bool
VMUniverseMgr::canCreateVM(ClassAd *jobAd)
{
	if( !m_starter_has_vmcode || ( m_vm_type.Length() == 0 )) {
		return false;
	}

	if( ( m_vm_max_num > 0 ) && 
		( numOfRunningVM() >= m_vm_max_num) ) {
		dprintf(D_ALWAYS, "Current number(%d) of running VM reaches to "
				"maximum number(%d)\n", numOfRunningVM(), m_vm_max_num);
		return false;
	}

	if( !jobAd ) {
		return true;
	}

	// check free memory for VM
	int int_value = 0;
	if( (jobAd->LookupInteger(ATTR_JOB_VM_MEMORY, int_value) != 1) &&
		(jobAd->LookupInteger(ATTR_REQUEST_MEMORY, int_value) != 1) ) {
		dprintf(D_ALWAYS, "Can't find VM memory in Job ClassAd\n");
		return false;
	}
	if( !int_value || ( int_value > getFreeVMMemSize() )) {
		dprintf(D_ALWAYS, "Not enough memory for VM: Requested mem=%d(MB),"
			   " Freemem=%d(MB)\n", int_value, getFreeVMMemSize()); 
		return false;
	}

	// check if the MAC address for checkpointed VM
	// is conflict with running VMs.
	MyString string_value;
	if( jobAd->LookupString(ATTR_VM_CKPT_MAC, string_value) == 1 ) {
		if( findVMStarterInfoWithMac(string_value.Value()) ) {
			dprintf(D_ALWAYS, "MAC address[%s] for VM is already being used "
					"by other VM\n", string_value.Value());
			return false;
		}
	}

	return true;
}
Пример #2
0
void 
VMUniverseMgr::checkVMUniverse(void)
{
	dprintf( D_ALWAYS, "VM-gahp server reported an internal error\n");

	if( numOfRunningVM() == 0 ) {
		// There is no running VM job.
		// So test vm universe right now.
		docheckVMUniverse();
		return;
	}
	
	// There are running VM jobs.
	// We need to wait for all jobs to be finished
	// When all jobs are finished, we will call docheckVMUniverse function
	m_needCheck = true;
}
Пример #3
0
void
VMUniverseMgr::checkVMUniverse( bool warn )
{
	// This might be better as detect, where detect never sets m_needCheck
	// because it should be an error for there to be running VMs on startup.
	if( warn ) {
		dprintf( D_ALWAYS, "VM-gahp server reported an internal error\n");
	}

	if( numOfRunningVM() == 0 ) {
		// There is no running VM job.
		// So test vm universe right now.
		docheckVMUniverse();
		return;
	}

	// There are running VM jobs.
	// We need to wait for all jobs to be finished
	// When all jobs are finished, we will call docheckVMUniverse function
	m_needCheck = true;
}
Пример #4
0
void
VMUniverseMgr::publish( ClassAd* ad, amask_t  /*mask*/ )
{
	if( !ad ) {
		return;
	}
	if( !m_starter_has_vmcode || ( m_vm_type.Length() == 0 )) {
		ad->Assign(ATTR_HAS_VM, false);
		return;
	}

	ad->Assign(ATTR_HAS_VM, true);

	// publish the number of still executable Virtual machines
	if( m_vm_max_num > 0 ) {
		int avail_vm_num = m_vm_max_num - numOfRunningVM();
		ad->Assign(ATTR_VM_AVAIL_NUM, avail_vm_num);
	}else {
		// no limit of the number of executable VM
		ad->Assign(ATTR_VM_AVAIL_NUM, VM_AVAIL_UNLIMITED_NUM);
	}

	// we will publish all information provided by vmgahp server
	m_vmgahp_info.ResetExpr();

	ExprTree* expr = NULL;
	const char *attr_name = NULL;
	while(m_vmgahp_info.NextExpr(attr_name, expr)) {
		// we need to adjust available vm memory
		if( strcasecmp(attr_name, ATTR_VM_MEMORY) == MATCH ) {
			int freemem = getFreeVMMemSize();
			ad->Assign(ATTR_VM_MEMORY, freemem);
		}else if( strcasecmp(attr_name, ATTR_VM_NETWORKING) == MATCH ) {
			ad->Assign(ATTR_VM_NETWORKING, m_vm_networking); 
		}else {
			ExprTree * pTree =  expr->Copy();
			ad->Insert(attr_name, pTree, false);
		}
	}

	// Now, we will publish mac and ip addresses of all guest VMs.
	MyString all_macs;
	MyString all_ips;
	VMStarterInfo *info = NULL;
	const char* guest_ip = NULL;
	const char* guest_mac = NULL;

	m_vm_starter_list.Rewind();
	while( m_vm_starter_list.Next(info) ) {
		guest_ip = info->getIPForVM();
		if( guest_ip ) {
			if( all_ips.IsEmpty() == false ) {
				all_ips += ",";
			}
			all_ips += guest_ip;
		}

		guest_mac = info->getMACForVM();
		if( guest_mac ) {
			if( all_macs.IsEmpty() == false ) {
				all_macs += ",";
			}
			all_macs += guest_mac;
		}
	}
	if( all_ips.IsEmpty() == false ) {
		ad->Assign(ATTR_VM_ALL_GUEST_IPS, all_ips);
	}
	if( all_macs.IsEmpty() == false ) {
		ad->Assign(ATTR_VM_ALL_GUEST_MACS, all_macs);
	}
}