Skip to content

Commit

Permalink
F #6342: Support for cluster quotas
Browse files Browse the repository at this point in the history
This feature adds support for VM quotas at cluster level. CLUSTER_IDS
can be set for a VM quota so the admin can limit the number of resources (e.g. VMs) a
user/group can create in a given cluster.

This commit also fixes:

- B #2226
- B #6823

Co-authored-by: Pavel Czerny <[email protected]>
  • Loading branch information
rsmontero and paczerny committed Jan 20, 2025
1 parent 49fc105 commit d2c0104
Show file tree
Hide file tree
Showing 35 changed files with 1,044 additions and 908 deletions.
11 changes: 0 additions & 11 deletions include/DatastorePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,6 @@ class DatastorePool : public PoolSQL
where, sid, eid, desc);
};

/**
* Lists the Datastore ids
* @param oids a vector with the oids of the objects.
*
* @return 0 on success
*/
int list(std::vector<int>& oids)
{
return PoolSQL::list(oids, one_db::ds_table);
}

/**
* Adds to the disk the datastore inherit attributes and conf values
* @param ds_id of the datastore to use
Expand Down
2 changes: 1 addition & 1 deletion include/LifeCycleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LifeCycleManager : public Listener
// -------------------------------------------------------------------------
void start_prolog_migrate(VirtualMachine* vm);

void revert_migrate_after_failure(VirtualMachine* vm);
void revert_migrate_after_failure(VirtualMachine* vm, bool live);

void trigger_save_success(int vid);
void trigger_save_failure(int vid);
Expand Down
11 changes: 0 additions & 11 deletions include/MarketPlacePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ class MarketPlacePool : public PoolSQL
where, sid, eid, desc);
};

/**
* Lists the MarketPlace ids
* @param oids a vector with the oids of the objects.
*
* @return 0 on success
*/
int list(std::vector<int>& oids)
{
return PoolSQL::list(oids, one_db::mp_table);
}

/**
* Factory method to produce objects
* @return a pointer to the new object
Expand Down
5 changes: 2 additions & 3 deletions include/PoolSQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ class PoolSQL
* @return 0 on success
*/
int list(
std::vector<int>& oids,
const char * table)
std::vector<int>& oids)
{
return search(oids, table, "");
return search(oids, table.c_str(), "");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/Quota.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class Quota: public Template, public QuotaInterface
*/
void cleanup_quota(const std::string& qid);

private:
/**
* Creates an empty quota based on the given attribute. The attribute va
* contains the limits for the quota.
Expand Down Expand Up @@ -335,6 +334,7 @@ class Quota: public Template, public QuotaInterface
int update_limits(VectorAttribute* quota,
const VectorAttribute* va);

private:
/**
* Extract the limits for the defined quota metrics from a given attribute
* @param va the attribute with the limits
Expand Down
60 changes: 43 additions & 17 deletions include/QuotaVirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
* VM Quotas, defined as:
* VM = [
* CLUSTER_IDS = Comma separated list of clusters or empty for global quotas
* VMS = <Max. number of VMs>
* RUNNING_VMS = <Max. number of RUNNING VMS>
* MEMORY = <Max. number of MB requested by VMs>
Expand Down Expand Up @@ -54,6 +55,22 @@ class QuotaVirtualMachine : public Quota

~QuotaVirtualMachine() {};

int get_quota(const std::string& id, VectorAttribute **va) override
{
std::map<std::string, Attribute *>::iterator it;
return get_quota(id, va, it);
}

/**
* Set the quotas. If the quota previously exists its limit is updated.
* The quotas are indexed by CLUSTER_IDS
* @param quota_str the quota template in ASCII or XML formats
* @param error describe the error in case of error
*
* @return 0 on success -1 otherwise
*/
int set(std::vector<VectorAttribute*> * quotas, std::string& error) override;

/**
* Check if the resource allocation will exceed the quota limits. If not
* the usage counters are updated
Expand Down Expand Up @@ -86,15 +103,6 @@ class QuotaVirtualMachine : public Quota
*/
void del(Template* tmpl) override;

/**
* Gets a quota, overrides base to not to use ID.
* @param id of the quota, ignored
* @param va The quota
*
* @return a pointer to the quota or 0 if not found
*/
int get_quota(const std::string& id, VectorAttribute **va) override;

/**
* Add generic quota to metrics. It adds also RUNNING_ quota attribute
* @param metric Name of the quota metri
Expand All @@ -119,22 +127,32 @@ class QuotaVirtualMachine : public Quota
protected:

/**
* Gets a quota, overrides base to not to use ID.
* Gets a quota, overrides base to use CLUSTER_IDS as id
*
* @param id of the quota, ignored
* @param cluster_ids Comma separated list of cluster ids
* @param va The quota
* @param it The quota iterator, if it is found
*
* @return 0 on success, -1 if not found
*/
int get_quota(
const std::string& id,
const std::string& cluster_ids,
VectorAttribute **va,
std::map<std::string, Attribute *>::iterator& it) override
{
it = attributes.begin();
return get_quota(id, va);
}
std::map<std::string, Attribute *>::iterator& it) override;

/**
* Gets a quota for cluster ID (the id is included in cluster_ids)
*
* @param cluster_id Cluster ID
* @param va The quota
*
* @return 0 on success, -1 if not found
*/
int get_quota(
int cluster_id,
VectorAttribute **va);

int get_quota_id(const Template& tmpl, std::string& cluster_ids);

/**
* Gets the default quota identified by its ID.
Expand All @@ -150,6 +168,14 @@ class QuotaVirtualMachine : public Quota
Quotas& default_quotas,
VectorAttribute **va) override;

/**
* Recomputes VM cluster quota usage for specific user or group.
* @param user_id user ID or -1 if not specified
* @param group_id group ID or -1 if not specified
* @param vm_quota New VM cluster quota to recompute
*/
void recompute_clusters(int user_id, int group_id, VectorAttribute* vm_quota);

static std::vector<std::string> VM_METRICS;
static std::vector<std::string> VM_GENERIC;
};
Expand Down
11 changes: 0 additions & 11 deletions include/VdcPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ class VdcPool : public PoolSQL
where, sid, eid, desc);
};

/**
* Lists the VDC ids
* @param oids a vector with the oids of the objects.
*
* @return 0 on success
*/
int list(std::vector<int>& oids)
{
return PoolSQL::list(oids, one_db::vdc_table);
}

/**
* Default name for the default VDC
*/
Expand Down
15 changes: 15 additions & 0 deletions include/VirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,16 @@ class VirtualMachine : public PoolObjectSQL
return history->cid;
}

/**
* Set new cluster id. The hasHistory()
* function MUST be called before this one.
*/
void set_cid(int cid)
{
history->cid = cid;
}


/**
* Get cluster id where the VM was executing. The hasPreviousHistory()
* function MUST be called before this one.
Expand Down Expand Up @@ -1580,6 +1590,11 @@ class VirtualMachine : public PoolObjectSQL
void delete_non_persistent_disk_snapshots(Template& vm_quotas,
std::vector<Template *>& ds_quotas)
{
if (hasHistory())
{
vm_quotas.replace("CLUSTER_ID", get_cid());
}

disks.delete_non_persistent_snapshots(vm_quotas, ds_quotas);
}

Expand Down
11 changes: 11 additions & 0 deletions include/VirtualMachinePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ class VirtualMachinePool : public PoolSQL
*/
int get_backup(std::vector<int>& oids);

/**
* Function to get the IDs of VMs deployd on specific cluster
* @param user_id user ID or -1
* @param group_id group ID or -1
* @param cid a cluster ID
* @param oids a vector that contains the IDs
* @return 0 on success
*/
int get_cluster_vms(int user_id, int group_id, int cid,
std::vector<int>& oids);

/**
* Gets the IDs of VMs matching the given SQL where string.
* @param oids a vector that contains the IDs
Expand Down
10 changes: 0 additions & 10 deletions include/ZonePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ class ZonePool : public PoolSQL
*/
unsigned int get_zone_servers(int zone_id, std::map<int, std::string>& srv);

/**
* Return the list of zones defined
* @param zone_ids of the zones
* @return 0 on success
*/
int list_zones(std::vector<int>& zone_ids)
{
return list( zone_ids, one_db::zone_table);
}

/**
* ID for the special local zone in stand-alone mode
*/
Expand Down
Loading

0 comments on commit d2c0104

Please sign in to comment.