mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #1678: Filters VMs that do not fit in the image DS
This commit is contained in:
parent
887a4191a5
commit
e68e95035e
@ -44,14 +44,41 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int get_suitable_nodes(vector<xmlNodePtr>& content)
|
||||
{
|
||||
return get_nodes("/DATASTORE_POOL/DATASTORE[TYPE=1]", content);
|
||||
};
|
||||
virtual int get_suitable_nodes(vector<xmlNodePtr>& content) = 0;
|
||||
|
||||
void add_object(xmlNodePtr node);
|
||||
|
||||
int load_info(xmlrpc_c::value &result);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class SystemDatastorePoolXML : public DatastorePoolXML
|
||||
{
|
||||
public:
|
||||
SystemDatastorePoolXML(Client* client):DatastorePoolXML(client){};
|
||||
|
||||
protected:
|
||||
int get_suitable_nodes(vector<xmlNodePtr>& content)
|
||||
{
|
||||
return get_nodes("/DATASTORE_POOL/DATASTORE[TYPE=1]", content);
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class ImageDatastorePoolXML : public DatastorePoolXML
|
||||
{
|
||||
public:
|
||||
ImageDatastorePoolXML(Client* client):DatastorePoolXML(client){};
|
||||
|
||||
protected:
|
||||
int get_suitable_nodes(vector<xmlNodePtr>& content)
|
||||
{
|
||||
return get_nodes("/DATASTORE_POOL/DATASTORE[TYPE=0]", content);
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* DATASTORE_POOL_XML_H_ */
|
||||
|
@ -42,9 +42,7 @@ public:
|
||||
*/
|
||||
bool test_capacity(unsigned int vm_disk_mb) const
|
||||
{
|
||||
return true;
|
||||
//TODO Perform test.
|
||||
//return (vm_disk_mb < free_mb);
|
||||
return (vm_disk_mb < free_mb);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -91,6 +91,11 @@ protected:
|
||||
delete dspool;
|
||||
}
|
||||
|
||||
if ( img_dspool != 0)
|
||||
{
|
||||
delete img_dspool;
|
||||
}
|
||||
|
||||
if ( acls != 0)
|
||||
{
|
||||
delete acls;
|
||||
@ -112,6 +117,7 @@ protected:
|
||||
VirtualMachinePoolXML * vmpool;
|
||||
VirtualMachineActionsPoolXML* vmapool;
|
||||
DatastorePoolXML * dspool;
|
||||
DatastorePoolXML * img_dspool;
|
||||
|
||||
AclXML * acls;
|
||||
|
||||
|
@ -257,6 +257,8 @@ protected:
|
||||
*/
|
||||
void init_attributes();
|
||||
|
||||
void init_storage_usage();
|
||||
|
||||
ResourceMatch match_hosts;
|
||||
|
||||
ResourceMatch match_datastores;
|
||||
@ -274,6 +276,9 @@ protected:
|
||||
|
||||
int memory;
|
||||
float cpu;
|
||||
float system_ds_usage;
|
||||
|
||||
map<int,float> ds_usage;
|
||||
|
||||
string rank;
|
||||
string requirements;
|
||||
|
@ -49,6 +49,8 @@ int VirtualMachinePoolXML::set_up()
|
||||
|
||||
oss << "Storage usage:" << endl;
|
||||
|
||||
int tmp, disk;
|
||||
|
||||
for (it=objects.begin();it!=objects.end();it++)
|
||||
{
|
||||
VirtualMachineXML * vm = static_cast<VirtualMachineXML *>(it->second);
|
||||
@ -58,6 +60,9 @@ int VirtualMachinePoolXML::set_up()
|
||||
|
||||
oss << "VM " << vm->get_oid() << ": ";
|
||||
|
||||
vm->get_requirements(tmp, tmp, disk);
|
||||
oss << "System " << disk << "MB; ";
|
||||
|
||||
for (ds_it = ds_usage.begin(); ds_it != ds_usage.end(); ds_it++)
|
||||
{
|
||||
oss << "DS " << ds_it->first << " " << ds_it->second << "MB; ";
|
||||
|
@ -195,6 +195,15 @@ void VirtualMachineXML::init_attributes()
|
||||
{
|
||||
user_template = 0;
|
||||
}
|
||||
|
||||
if (vm_template != 0)
|
||||
{
|
||||
init_storage_usage();
|
||||
}
|
||||
else
|
||||
{
|
||||
system_ds_usage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -254,7 +263,7 @@ void VirtualMachineXML::get_requirements (int& cpu, int& memory, int& disk)
|
||||
|
||||
cpu = (int) (this->cpu * 100);//now in 100%
|
||||
memory = this->memory * 1024; //now in Kilobytes
|
||||
disk = 0;
|
||||
disk = this->system_ds_usage; // MB
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -272,20 +281,20 @@ bool isVolatile(const VectorAttribute * disk)
|
||||
|
||||
map<int,float> VirtualMachineXML::get_storage_usage()
|
||||
{
|
||||
map<int, float> ds_usage;
|
||||
return ds_usage;
|
||||
}
|
||||
|
||||
vector<Attribute *> disks;
|
||||
vector<Attribute*>::iterator it;
|
||||
void VirtualMachineXML::init_storage_usage()
|
||||
{
|
||||
vector<Attribute *> disks;
|
||||
vector<Attribute*>::iterator it;
|
||||
|
||||
float size;
|
||||
string st;
|
||||
int ds_id;
|
||||
float size;
|
||||
string st;
|
||||
int ds_id;
|
||||
bool clone;
|
||||
|
||||
bool clone;
|
||||
|
||||
// Usage for the system DS will be stored in the index 0, although
|
||||
// it may not be DS 0
|
||||
ds_usage[0] = 0;
|
||||
system_ds_usage = 0;
|
||||
|
||||
vm_template->remove("DISK", disks);
|
||||
|
||||
@ -306,7 +315,7 @@ map<int,float> VirtualMachineXML::get_storage_usage()
|
||||
|
||||
if (isVolatile(disk))
|
||||
{
|
||||
ds_usage[0] += size;
|
||||
system_ds_usage += size;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -342,12 +351,10 @@ map<int,float> VirtualMachineXML::get_storage_usage()
|
||||
}
|
||||
else if (st == "SYSTEM")
|
||||
{
|
||||
ds_usage[0] += size;
|
||||
system_ds_usage += size;
|
||||
} // else st == NONE
|
||||
}
|
||||
}
|
||||
|
||||
return ds_usage;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -214,7 +214,8 @@ void Scheduler::start()
|
||||
machines_limit,
|
||||
(live_rescheds == 1));
|
||||
vmapool= new VirtualMachineActionsPoolXML(client, machines_limit);
|
||||
dspool = new DatastorePoolXML(client);
|
||||
dspool = new SystemDatastorePoolXML(client);
|
||||
img_dspool = new ImageDatastorePoolXML(client);
|
||||
|
||||
acls = new AclXML(client);
|
||||
|
||||
@ -317,6 +318,8 @@ int Scheduler::set_up_pools()
|
||||
//Cleans the cache and get the datastores
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// TODO: Avoid two ds pool info calls to oned
|
||||
|
||||
rc = dspool->set_up();
|
||||
|
||||
if ( rc != 0 )
|
||||
@ -324,6 +327,13 @@ int Scheduler::set_up_pools()
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = img_dspool->set_up();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//Cleans the cache and get the hosts ids
|
||||
//--------------------------------------------------------------------------
|
||||
@ -398,12 +408,15 @@ void Scheduler::match_schedule()
|
||||
|
||||
map<int, ObjectXML*>::const_iterator vm_it;
|
||||
map<int, ObjectXML*>::const_iterator h_it;
|
||||
map<int, ObjectXML*>::const_iterator ds_it;
|
||||
map<int,float>::const_iterator ds_usage_it;
|
||||
|
||||
vector<SchedulerPolicy *>::iterator it;
|
||||
|
||||
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
|
||||
const map<int, ObjectXML*> hosts = hpool->get_objects();
|
||||
const map<int, ObjectXML*> datastores = dspool->get_objects();
|
||||
const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
|
||||
const map<int, ObjectXML*> hosts = hpool->get_objects();
|
||||
const map<int, ObjectXML*> datastores = dspool->get_objects();
|
||||
const map<int, ObjectXML*> img_datastores = img_dspool->get_objects();
|
||||
|
||||
for (vm_it=pending_vms.begin(); vm_it != pending_vms.end(); vm_it++)
|
||||
{
|
||||
@ -422,6 +435,35 @@ void Scheduler::match_schedule()
|
||||
n_auth = 0;
|
||||
n_error = 0;
|
||||
|
||||
map<int,float> ds_usage = vm->get_storage_usage();
|
||||
|
||||
for (ds_usage_it = ds_usage.begin(); ds_usage_it != ds_usage.end(); ds_usage_it++)
|
||||
{
|
||||
ds_it = img_datastores.find( ds_usage_it->first );
|
||||
|
||||
if (ds_it == img_datastores.end())
|
||||
{
|
||||
// TODO log error
|
||||
continue;
|
||||
}
|
||||
|
||||
ds = static_cast<DatastoreXML *>( ds_it->second );
|
||||
|
||||
if (!ds->test_capacity((unsigned int) ds_usage_it->second))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "VM " << oid << " cannot be deployed because Datastore "
|
||||
<< ds_usage_it->first << " does not have enough free storage.";
|
||||
|
||||
NebulaLog::log("SCHED",Log::INFO,oss);
|
||||
|
||||
vm->log(oss.str());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Match hosts for this VM that:
|
||||
// 1. Fulfills ACL
|
||||
@ -663,7 +705,9 @@ void Scheduler::match_schedule()
|
||||
// Check datastore capacity
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
if (ds->test_capacity(vm_disk))
|
||||
// TODO, system DS monitorization needs to be implemented
|
||||
// if (ds->test_capacity(vm_disk))
|
||||
if (true)
|
||||
{
|
||||
vm->add_match_datastore(ds->get_oid());
|
||||
|
||||
@ -876,6 +920,8 @@ void Scheduler::dispatch()
|
||||
|
||||
host->add_capacity(cpu,mem,dsk);
|
||||
|
||||
// TODO update img & system DS free space
|
||||
|
||||
host_vms[hid]++;
|
||||
|
||||
dispatched_vms++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user