mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 11:22:55 +09:00
Merge branch 'master' into feature-1664-template
This commit is contained in:
commit
1a593b7ac7
65 files changed
+2747
-559
No files matched your search
@@ -44,6 +44,37 @@ required gems. You have more information at:
|
||||
|
||||
http://opennebula.org/documentation:documentation:compile
|
||||
|
||||
If you want to install them manually here are the list of required rubygems:
|
||||
|
||||
* OpenNebula and clients (plus cloud interfaces)
|
||||
* sqlite3
|
||||
* json
|
||||
* sequel
|
||||
* mysql
|
||||
* net-ldap
|
||||
* amazon-ec2
|
||||
* rack
|
||||
* sinatra
|
||||
* thin
|
||||
* uuidtools
|
||||
* curb
|
||||
* nokogiri
|
||||
|
||||
* OpenNebula zones (client and server)
|
||||
* json
|
||||
* sequel
|
||||
* sqlite3
|
||||
* mysql
|
||||
* nokogiri
|
||||
|
||||
* Sunstone server
|
||||
* json
|
||||
* rack
|
||||
* sinatra
|
||||
* thin
|
||||
* sequel
|
||||
* nokogiri
|
||||
|
||||
### OPTIONAL PACKAGES
|
||||
|
||||
These packages are not needed to run or build OpenNebula. They improve the
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the string representation of an DatastoreType
|
||||
* Return the string representation of a DatastoreType
|
||||
* @param ob the type
|
||||
* @return the string
|
||||
*/
|
||||
@@ -56,9 +56,9 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the string representation of an DatastoreType
|
||||
* Return the string representation of a DatastoreType
|
||||
* @param str_type string representing the DatastoreTypr
|
||||
* @return the ImageType (defaults to IMAGE_DS)
|
||||
* @return the DatastoreType (defaults to IMAGE_DS)
|
||||
*/
|
||||
static DatastoreType str_to_type(string& str_type);
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef DEFAULT_QUOTAS_H_
|
||||
#define DEFAULT_QUOTAS_H_
|
||||
|
||||
#include "Quotas.h"
|
||||
#include "SqlDB.h"
|
||||
#include "ObjectSQL.h"
|
||||
|
||||
class DefaultQuotas : public Quotas
|
||||
{
|
||||
public:
|
||||
DefaultQuotas(
|
||||
const char * _root_elem,
|
||||
const char * _ds_xpath,
|
||||
const char * _net_xpath,
|
||||
const char * _img_xpath,
|
||||
const char * _vm_xpath):
|
||||
Quotas(_ds_xpath, _net_xpath, _img_xpath, _vm_xpath, true),
|
||||
root_elem(_root_elem)
|
||||
{};
|
||||
|
||||
~DefaultQuotas(){};
|
||||
|
||||
/**
|
||||
* Generates a string representation of the quotas in XML format
|
||||
* @param xml the string to store the XML
|
||||
* @return the same xml string to use it in << compounds
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Writes the quotas in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert();
|
||||
|
||||
/**
|
||||
* Writes/updates the quotas data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update();
|
||||
|
||||
/**
|
||||
* Reads the Quotas from the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Name for the default quota attribute
|
||||
*/
|
||||
const char * root_elem;
|
||||
|
||||
/**
|
||||
* Builds quota object from an ObjectXML
|
||||
* @param xml The xml-formatted string
|
||||
* @return 0 on success
|
||||
*/
|
||||
int from_xml(const string& xml);
|
||||
};
|
||||
|
||||
#endif /*DEFAULT_QUOTAS_H_*/
|
||||
+6
-2
@@ -38,7 +38,9 @@ public:
|
||||
OS = 0, /** < Base OS image */
|
||||
CDROM = 1, /** < An ISO9660 image */
|
||||
DATABLOCK = 2, /** < User persistent data device */
|
||||
DATAFILE = 3 /** < Context, kernels and initrd files */
|
||||
KERNEL = 3, /** < Kernel files */
|
||||
RAMDISK = 4, /** < Initrd files */
|
||||
CONTEXT = 5 /** < Context files */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -53,7 +55,9 @@ public:
|
||||
case OS: return "OS" ; break;
|
||||
case CDROM: return "CDROM" ; break;
|
||||
case DATABLOCK: return "DATABLOCK" ; break;
|
||||
case DATAFILE: return "FILE" ; break;
|
||||
case KERNEL: return "KERNEL" ; break;
|
||||
case RAMDISK: return "RAMDISK" ; break;
|
||||
case CONTEXT: return "CONTEXT" ; break;
|
||||
default: return "";
|
||||
}
|
||||
};
|
||||
|
||||
+120
-35
@@ -18,6 +18,7 @@
|
||||
#define NEBULA_H_
|
||||
|
||||
#include "SqlDB.h"
|
||||
#include "SystemDB.h"
|
||||
|
||||
#include "NebulaTemplate.h"
|
||||
|
||||
@@ -42,9 +43,17 @@
|
||||
#include "AclManager.h"
|
||||
#include "ImageManager.h"
|
||||
|
||||
#include "DefaultQuotas.h"
|
||||
|
||||
#include "Callbackable.h"
|
||||
|
||||
class Nebula : public Callbackable
|
||||
|
||||
/**
|
||||
* This is the main class for the OpenNebula daemon oned. It stores references
|
||||
* to the main modules and data pools. It also includes functions to bootstrap
|
||||
* the system and start all its components.
|
||||
*/
|
||||
class Nebula
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -311,15 +320,103 @@ public:
|
||||
return nebula_configuration->to_xml(xml);
|
||||
};
|
||||
|
||||
const DefaultQuotas& get_default_user_quota()
|
||||
{
|
||||
return default_user_quota;
|
||||
};
|
||||
|
||||
int set_default_user_quota(Template *tmpl, string& error)
|
||||
{
|
||||
int rc;
|
||||
rc = default_user_quota.set(tmpl, error);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
rc = default_user_quota.update();
|
||||
}
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
const DefaultQuotas& get_default_group_quota()
|
||||
{
|
||||
return default_group_quota;
|
||||
};
|
||||
|
||||
int set_default_group_quota(Template *tmpl, string& error)
|
||||
{
|
||||
int rc;
|
||||
rc = default_group_quota.set(tmpl, error);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
rc = default_group_quota.update();
|
||||
}
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// System attributes
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* Reads a System attribute from the DB
|
||||
* @param attr_name name of the attribute
|
||||
* @param cb Callback that will receive the attribute in XML
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select_sys_attribute(const string& attr_name, string& attr_xml)
|
||||
{
|
||||
return system_db->select_sys_attribute(attr_name, attr_xml);
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a system attribute in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert_sys_attribute(
|
||||
const string& attr_name,
|
||||
const string& xml_attr,
|
||||
string& error_str)
|
||||
{
|
||||
return system_db->insert_sys_attribute(attr_name, xml_attr, error_str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the system attribute in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_sys_attribute(
|
||||
const string& attr_name,
|
||||
const string& xml_attr,
|
||||
string& error_str)
|
||||
{
|
||||
return system_db->update_sys_attribute(attr_name, xml_attr, error_str);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
//Constructors and = are private to only access the class through instance
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),
|
||||
upool(0),ipool(0),gpool(0),tpool(0),dspool(0),clpool(0),docpool(0),
|
||||
lcm(0),vmm(0),im(0),tm(0),dm(0),rm(0),hm(0),authm(0),aclm(0),imagem(0)
|
||||
Nebula():nebula_configuration(0),
|
||||
default_user_quota( "DEFAULT_USER_QUOTAS",
|
||||
"/DEFAULT_USER_QUOTAS/DATASTORE_QUOTA",
|
||||
"/DEFAULT_USER_QUOTAS/NETWORK_QUOTA",
|
||||
"/DEFAULT_USER_QUOTAS/IMAGE_QUOTA",
|
||||
"/DEFAULT_USER_QUOTAS/VM_QUOTA"),
|
||||
default_group_quota("DEFAULT_GROUP_QUOTAS",
|
||||
"/DEFAULT_GROUP_QUOTAS/DATASTORE_QUOTA",
|
||||
"/DEFAULT_GROUP_QUOTAS/NETWORK_QUOTA",
|
||||
"/DEFAULT_GROUP_QUOTAS/IMAGE_QUOTA",
|
||||
"/DEFAULT_GROUP_QUOTAS/VM_QUOTA"),
|
||||
system_db(0), db(0), vmpool(0), hpool(0), vnpool(0),
|
||||
upool(0), ipool(0), gpool(0), tpool(0), dspool(0), clpool(0),
|
||||
docpool(0), lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), authm(0),
|
||||
aclm(0), imagem(0)
|
||||
{
|
||||
const char * nl = getenv("ONE_LOCATION");
|
||||
|
||||
@@ -465,9 +562,12 @@ private:
|
||||
{
|
||||
delete db;
|
||||
}
|
||||
};
|
||||
|
||||
Nebula(Nebula const&){};
|
||||
if ( system_db != 0 )
|
||||
{
|
||||
delete system_db;
|
||||
}
|
||||
};
|
||||
|
||||
Nebula& operator=(Nebula const&){return *this;};
|
||||
|
||||
@@ -492,7 +592,20 @@ private:
|
||||
// Configuration
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
OpenNebulaTemplate * nebula_configuration;
|
||||
OpenNebulaTemplate * nebula_configuration;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Default quotas
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
DefaultQuotas default_user_quota;
|
||||
DefaultQuotas default_group_quota;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// The system database
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
SystemDB * system_db;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Nebula Pools
|
||||
@@ -530,34 +643,6 @@ private:
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
friend void nebula_signal_handler (int sig);
|
||||
|
||||
/**
|
||||
* Bootstraps the database control tables
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int bootstrap();
|
||||
|
||||
/**
|
||||
* Callback function for the check_db_version method. Stores the read
|
||||
* version in loaded_db_version
|
||||
* @param _loaded_db_version returned columns
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select_cb(void *_loaded_db_version, int num, char **values,
|
||||
char **names);
|
||||
|
||||
/**
|
||||
* Reads the current DB version.
|
||||
*
|
||||
* @return 0 on success,
|
||||
* -1 if there is a version mismatch,
|
||||
* -2 if the DB needs a bootstrap
|
||||
*/
|
||||
int check_db_version();
|
||||
};
|
||||
|
||||
#endif /*NEBULA_H_*/
|
||||
@@ -94,6 +94,30 @@ public:
|
||||
int xpath(unsigned int& value, const char * xpath_expr,
|
||||
const unsigned int& def);
|
||||
|
||||
/**
|
||||
* Gets and sets a xpath attribute, if the attribute is not found a default
|
||||
* is used
|
||||
* @param value to set
|
||||
* @param xpath_expr of the xml element
|
||||
* @param def default value if the element is not found
|
||||
*
|
||||
* @return -1 if default was set
|
||||
*/
|
||||
int xpath(long long& value, const char * xpath_expr,
|
||||
const long long& def);
|
||||
|
||||
/**
|
||||
* Gets and sets a xpath attribute, if the attribute is not found a default
|
||||
* is used
|
||||
* @param value to set
|
||||
* @param xpath_expr of the xml element
|
||||
* @param def default value if the element is not found
|
||||
*
|
||||
* @return -1 if default was set
|
||||
*/
|
||||
int xpath(unsigned long long& value, const char * xpath_expr,
|
||||
const unsigned long long& def);
|
||||
|
||||
/**
|
||||
* Gets and sets a xpath attribute, if the attribute is not found a default
|
||||
* is used
|
||||
|
||||
+53
-22
@@ -19,32 +19,37 @@
|
||||
|
||||
#include "Template.h"
|
||||
|
||||
// Forward declaration to avoid include cycle
|
||||
class Quotas;
|
||||
|
||||
/**
|
||||
* Base class for resource quotas, it provides basic storage and management of
|
||||
* the quotas. Each resource MUST inherit from it to implement check and
|
||||
* the quotas. Each resource MUST inherit from it to implement check and
|
||||
* update methods. Quotas are stored in a template form, each class store the
|
||||
* limits and usage in a resource specific format.
|
||||
*/
|
||||
class Quota: public Template
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Set the quotas. If the quota previously exists its limit is updated.
|
||||
* @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(vector<Attribute*> * quotas, string& error);
|
||||
|
||||
/**
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @param tmpl template for the resource
|
||||
* @param error string
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string
|
||||
* @return true if the operation can be performed
|
||||
*/
|
||||
virtual bool check(Template* tmpl, string& error) = 0;
|
||||
virtual bool check(Template* tmpl, Quotas& default_quotas, string& error) = 0;
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@@ -61,22 +66,35 @@ public:
|
||||
return template_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a quota identified by its ID.
|
||||
* @param id of the quota
|
||||
* @param va The quota, if it is found
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
virtual int get_quota(const string& id, VectorAttribute **va)
|
||||
{
|
||||
map<string, Attribute *>::iterator it;
|
||||
return get_quota(id, va, it);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Quota(const char * quota_name,
|
||||
const char * _template_name,
|
||||
const char ** _metrics,
|
||||
int _num_metrics)
|
||||
int _num_metrics,
|
||||
bool _is_default)
|
||||
: Template(false, '=', quota_name),
|
||||
template_name(_template_name),
|
||||
metrics(_metrics),
|
||||
num_metrics(_num_metrics){};
|
||||
|
||||
num_metrics(_num_metrics),
|
||||
is_default(_is_default){};
|
||||
|
||||
virtual ~Quota(){};
|
||||
|
||||
/**
|
||||
* Generic Quota Names
|
||||
* Generic Quota Names
|
||||
*
|
||||
* template_name = [
|
||||
* ID = "ID to identify the resource",
|
||||
@@ -102,15 +120,24 @@ protected:
|
||||
*/
|
||||
int num_metrics;
|
||||
|
||||
/**
|
||||
* Check a given quota for an usage request and update counters if the
|
||||
/**
|
||||
* Whether or not this is a default quota. Default quotas do not have usage,
|
||||
* and can't have a limit of -1
|
||||
*/
|
||||
bool is_default;
|
||||
|
||||
/**
|
||||
* Check a given quota for an usage request and update counters if the
|
||||
* request does not exceed quota limits
|
||||
* @param qid id that identifies the quota, to be used by get_quota
|
||||
* @param usage_req usage for each metric
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string describing the error
|
||||
* @return true if the request does not exceed current limits
|
||||
*/
|
||||
bool check_quota(const string& qid,
|
||||
bool check_quota(const string& qid,
|
||||
map<string, float>& usage_req,
|
||||
Quotas& default_quotas,
|
||||
string& error);
|
||||
|
||||
/**
|
||||
@@ -118,20 +145,21 @@ protected:
|
||||
* @param qid id that identifies the quota, to be used by get_quota
|
||||
* @param usage_req usage for each metric
|
||||
*/
|
||||
void del_quota(const string& qid,
|
||||
void del_quota(const string& qid,
|
||||
map<string, float>& usage_req);
|
||||
|
||||
/**
|
||||
* Gets a quota identified by its ID.
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
virtual int get_quota(const string& id, VectorAttribute **va)
|
||||
{
|
||||
map<string, Attribute *>::iterator it;
|
||||
return get_quota(id, va, it);
|
||||
}
|
||||
virtual int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va) = 0;
|
||||
|
||||
/**
|
||||
* Gets a quota identified by its ID.
|
||||
@@ -159,7 +187,8 @@ private:
|
||||
* Creates an empty quota based on the given attribute. The attribute va
|
||||
* contains the limits for the quota.
|
||||
* @param va limits for the new quota if 0 limits will be 0
|
||||
* @return a new attribute representing the quota
|
||||
*
|
||||
* @return a new attribute representing the quota, 0 on error
|
||||
*/
|
||||
VectorAttribute * new_quota(VectorAttribute* va);
|
||||
|
||||
@@ -181,13 +210,15 @@ private:
|
||||
*/
|
||||
void add_to_quota(VectorAttribute * attr, const string& va_name, float num);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets new limit values for the quota
|
||||
* @param quota to be updated
|
||||
* @param va attribute with the new limits
|
||||
*
|
||||
* @return 0 on success or -1 if wrong limits
|
||||
*/
|
||||
int update_limits(VectorAttribute* quota, const VectorAttribute* va);
|
||||
int update_limits(VectorAttribute* quota,
|
||||
const VectorAttribute* va);
|
||||
|
||||
/**
|
||||
* Extract the limits for the defined quota metrics from a given attribute
|
||||
|
||||
@@ -35,23 +35,26 @@
|
||||
class QuotaDatastore : public Quota
|
||||
{
|
||||
public:
|
||||
|
||||
QuotaDatastore():Quota("DATASTORE_QUOTA",
|
||||
"DATASTORE",
|
||||
DS_METRICS,
|
||||
NUM_DS_METRICS)
|
||||
|
||||
QuotaDatastore(bool is_default):
|
||||
Quota("DATASTORE_QUOTA",
|
||||
"DATASTORE",
|
||||
DS_METRICS,
|
||||
NUM_DS_METRICS,
|
||||
is_default)
|
||||
{};
|
||||
|
||||
~QuotaDatastore(){};
|
||||
|
||||
/**
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @param tmpl template for the resource
|
||||
* @param error string
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string
|
||||
* @return true if the operation can be performed
|
||||
*/
|
||||
bool check(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@@ -60,9 +63,23 @@ public:
|
||||
void del(Template* tmpl);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * DS_METRICS[];
|
||||
|
||||
static const int NUM_DS_METRICS;
|
||||
};
|
||||
|
||||
#endif /*QUOTA_DATASTORE_H_*/
|
||||
#endif /*QUOTA_DATASTORE_H_*/
|
||||
+25
-8
@@ -33,23 +33,26 @@
|
||||
class QuotaImage : public Quota
|
||||
{
|
||||
public:
|
||||
|
||||
QuotaImage():Quota("IMAGE_QUOTA",
|
||||
"IMAGE",
|
||||
IMAGE_METRICS,
|
||||
NUM_IMAGE_METRICS)
|
||||
|
||||
QuotaImage(bool is_default):
|
||||
Quota("IMAGE_QUOTA",
|
||||
"IMAGE",
|
||||
IMAGE_METRICS,
|
||||
NUM_IMAGE_METRICS,
|
||||
is_default)
|
||||
{};
|
||||
|
||||
~QuotaImage(){};
|
||||
|
||||
/**
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @param tmpl template for the resource
|
||||
* @param error string
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string
|
||||
* @return true if the operation can be performed
|
||||
*/
|
||||
bool check(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@@ -58,6 +61,20 @@ public:
|
||||
void del(Template* tmpl);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * IMAGE_METRICS[];
|
||||
|
||||
static const int NUM_IMAGE_METRICS;
|
||||
|
||||
+25
-8
@@ -33,23 +33,26 @@
|
||||
class QuotaNetwork : public Quota
|
||||
{
|
||||
public:
|
||||
|
||||
QuotaNetwork():Quota("NETWORK_QUOTA",
|
||||
"NETWORK",
|
||||
NET_METRICS,
|
||||
NUM_NET_METRICS)
|
||||
|
||||
QuotaNetwork(bool is_default):
|
||||
Quota("NETWORK_QUOTA",
|
||||
"NETWORK",
|
||||
NET_METRICS,
|
||||
NUM_NET_METRICS,
|
||||
is_default)
|
||||
{};
|
||||
|
||||
~QuotaNetwork(){};
|
||||
|
||||
/**
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @param tmpl template for the resource
|
||||
* @param error string
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string
|
||||
* @return true if the operation can be performed
|
||||
*/
|
||||
bool check(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@@ -58,6 +61,20 @@ public:
|
||||
void del(Template* tmpl);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * NET_METRICS[];
|
||||
|
||||
static const int NUM_NET_METRICS;
|
||||
|
||||
@@ -36,23 +36,26 @@
|
||||
class QuotaVirtualMachine : public Quota
|
||||
{
|
||||
public:
|
||||
|
||||
QuotaVirtualMachine():Quota("VM_QUOTA",
|
||||
"VM",
|
||||
VM_METRICS,
|
||||
NUM_VM_METRICS)
|
||||
|
||||
QuotaVirtualMachine(bool is_default):
|
||||
Quota("VM_QUOTA",
|
||||
"VM",
|
||||
VM_METRICS,
|
||||
NUM_VM_METRICS,
|
||||
is_default)
|
||||
{};
|
||||
|
||||
~QuotaVirtualMachine(){};
|
||||
|
||||
/**
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* Check if the resource allocation will exceed the quota limits. If not
|
||||
* the usage counters are updated
|
||||
* @param tmpl template for the resource
|
||||
* @param error string
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error string
|
||||
* @return true if the operation can be performed
|
||||
*/
|
||||
bool check(Template* tmpl, string& error);
|
||||
bool check(Template* tmpl, Quotas& default_quotas, string& error);
|
||||
|
||||
/**
|
||||
* Decrement usage counters when deallocating image
|
||||
@@ -60,7 +63,6 @@ public:
|
||||
*/
|
||||
void del(Template* tmpl);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Gets a quota, overrides base to not to use ID.
|
||||
* @param id of the quota, ignored
|
||||
@@ -70,6 +72,8 @@ protected:
|
||||
*/
|
||||
int get_quota(const string& id, VectorAttribute **va);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Gets a quota, overrides base to not to use ID.
|
||||
*
|
||||
@@ -88,6 +92,20 @@ protected:
|
||||
return get_quota(id, va);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va);
|
||||
|
||||
static const char * VM_METRICS[];
|
||||
|
||||
static const int NUM_VM_METRICS;
|
||||
|
||||
+88
-32
@@ -30,7 +30,11 @@ public:
|
||||
Quotas(const char * _ds_xpath,
|
||||
const char * _net_xpath,
|
||||
const char * _img_xpath,
|
||||
const char * _vm_xpath):
|
||||
const char * _vm_xpath):
|
||||
datastore_quota(false),
|
||||
network_quota(false),
|
||||
image_quota(false),
|
||||
vm_quota(false),
|
||||
ds_xpath(_ds_xpath),
|
||||
net_xpath(_net_xpath),
|
||||
img_xpath(_img_xpath),
|
||||
@@ -59,18 +63,6 @@ public:
|
||||
*/
|
||||
int set(Template *tmpl, string& error);
|
||||
|
||||
/**
|
||||
* Check Datastore quotas, it updates usage counters if quotas are not
|
||||
* exceeded.
|
||||
* @param tmpl template for the image
|
||||
* @param reason string describing the error
|
||||
* @return true if image can be allocated, false otherwise
|
||||
*/
|
||||
bool ds_check(Template * tmpl, string& reason)
|
||||
{
|
||||
return datastore_quota.check(tmpl, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete usage from quota counters.
|
||||
* @param tmpl template for the image, with usage
|
||||
@@ -80,16 +72,17 @@ public:
|
||||
datastore_quota.del(tmpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Virtual Machine quotas (network, image and compute), it updates
|
||||
* usage counters if quotas are not exceeded.
|
||||
* @param tmpl template for the VirtualMachine
|
||||
* @param error_str string describing the error
|
||||
* @return true if VM can be allocated, false otherwise
|
||||
*/
|
||||
bool vm_check(Template * tmpl, string& error_str)
|
||||
/**
|
||||
* Gets a Datastore quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int ds_get(const string& id, VectorAttribute **va)
|
||||
{
|
||||
return quota_check(VIRTUALMACHINE, tmpl, error_str);
|
||||
return datastore_quota.get_quota(id, va);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,14 +96,57 @@ public:
|
||||
image_quota.del(tmpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a VM quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int vm_get(const string& id, VectorAttribute **va)
|
||||
{
|
||||
return vm_quota.get_quota(id, va);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Network quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int network_get(const string& id, VectorAttribute **va)
|
||||
{
|
||||
return network_quota.get_quota(id, va);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an Image quota identified by its ID.
|
||||
*
|
||||
* @param id of the quota
|
||||
* @param va The quota, if it is found
|
||||
*
|
||||
* @return 0 on success, -1 if not found
|
||||
*/
|
||||
int image_get(const string& id, VectorAttribute **va)
|
||||
{
|
||||
return image_quota.get_quota(id, va);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check quota, it updates usage counters if quotas are not exceeded.
|
||||
* @param type the quota to work with
|
||||
* @param tmpl template for the VirtualMachine
|
||||
* @param default_quotas Quotas that contain the default limits
|
||||
* @param error_str string describing the error
|
||||
* @return true if VM can be allocated, false otherwise
|
||||
*/
|
||||
bool quota_check(QuotaType type, Template *tmpl, string& error_str);
|
||||
bool quota_check(QuotaType type,
|
||||
Template *tmpl,
|
||||
Quotas& default_quotas,
|
||||
string& error_str);
|
||||
|
||||
/**
|
||||
* Delete usage from the given quota counters.
|
||||
@@ -128,7 +164,7 @@ public:
|
||||
|
||||
/**
|
||||
* Builds quota object from an ObjectXML
|
||||
* @param object_xml pointer to the ObjectXML
|
||||
* @param object_xml pointer to the ObjectXML
|
||||
* @return 0 if success
|
||||
*/
|
||||
int from_xml(ObjectXML * object_xml);
|
||||
@@ -167,29 +203,49 @@ public:
|
||||
*/
|
||||
static void quota_del(QuotaType type, int uid, int gid, Template * tmpl);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This is an specialized constructor only for derived Quotas classes.
|
||||
* It allows to set the defaultness attribute
|
||||
*/
|
||||
Quotas(const char * _ds_xpath,
|
||||
const char * _net_xpath,
|
||||
const char * _img_xpath,
|
||||
const char * _vm_xpath,
|
||||
bool is_deafult):
|
||||
datastore_quota(is_deafult),
|
||||
network_quota(is_deafult),
|
||||
image_quota(is_deafult),
|
||||
vm_quota(is_deafult),
|
||||
ds_xpath(_ds_xpath),
|
||||
net_xpath(_net_xpath),
|
||||
img_xpath(_img_xpath),
|
||||
vm_xpath(_vm_xpath)
|
||||
{};
|
||||
|
||||
private:
|
||||
//--------------------------------------------------------------------------
|
||||
// Usage Counters and Quotas
|
||||
// Usage Counters and Quotas
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Datastore Quotas
|
||||
*/
|
||||
* Datastore Quotas
|
||||
*/
|
||||
QuotaDatastore datastore_quota;
|
||||
|
||||
/**
|
||||
* Network Quotas
|
||||
* Network Quotas
|
||||
*/
|
||||
QuotaNetwork network_quota;
|
||||
|
||||
/**
|
||||
* Image Quotas
|
||||
*/
|
||||
* Image Quotas
|
||||
*/
|
||||
QuotaImage image_quota;
|
||||
|
||||
/**
|
||||
* Virtual Machine Quotas
|
||||
*/
|
||||
* Virtual Machine Quotas
|
||||
*/
|
||||
QuotaVirtualMachine vm_quota;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#define REQUEST_MANAGER_SYSTEM_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "DefaultQuotas.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -78,6 +79,107 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserQuotaInfo : public RequestManagerSystem
|
||||
{
|
||||
public:
|
||||
UserQuotaInfo():
|
||||
RequestManagerSystem("UserQuotaInfo",
|
||||
"Returns the default user quota limits",
|
||||
"A:s")
|
||||
{
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
~UserQuotaInfo(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupQuotaInfo : public RequestManagerSystem
|
||||
{
|
||||
public:
|
||||
GroupQuotaInfo():
|
||||
RequestManagerSystem("GroupQuotaInfo",
|
||||
"Returns the default group quota limits",
|
||||
"A:s")
|
||||
{
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
~GroupQuotaInfo(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class QuotaUpdate : public RequestManagerSystem
|
||||
{
|
||||
public:
|
||||
QuotaUpdate(const string& method_name,
|
||||
const string& help):
|
||||
RequestManagerSystem(method_name,
|
||||
help,
|
||||
"A:ss")
|
||||
{
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
~QuotaUpdate(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
virtual int set_default_quota(Template *tmpl, string& error) = 0;
|
||||
|
||||
const virtual DefaultQuotas* get_default_quota() = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserQuotaUpdate : public QuotaUpdate
|
||||
{
|
||||
public:
|
||||
UserQuotaUpdate():
|
||||
QuotaUpdate("UserQuotaUpdate",
|
||||
"Updates the default user quota limits")
|
||||
{
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
int set_default_quota(Template *tmpl, string& error);
|
||||
|
||||
const DefaultQuotas* get_default_quota();
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupQuotaUpdate : public QuotaUpdate
|
||||
{
|
||||
public:
|
||||
GroupQuotaUpdate():
|
||||
QuotaUpdate("GroupQuotaUpdate",
|
||||
"Updates the default group quota limits")
|
||||
{
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
int set_default_quota(Template *tmpl, string& error);
|
||||
|
||||
const DefaultQuotas* get_default_quota();
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef SYSTEM_DB_H_
|
||||
#define SYSTEM_DB_H_
|
||||
|
||||
#include "SqlDB.h"
|
||||
#include "Callbackable.h"
|
||||
|
||||
class Nebula;
|
||||
|
||||
/**
|
||||
* This class represents the OpenNebula core system data tables:
|
||||
* - pool_control
|
||||
* - db_versioning
|
||||
* - system attributes
|
||||
*/
|
||||
class SystemDB: public Callbackable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Reads a System attribute from the DB
|
||||
* @param attr_name name of the attribute
|
||||
* @param attr_xml the attribute in a XML document
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select_sys_attribute(const string& attr_name, string& attr_zml);
|
||||
|
||||
/**
|
||||
* Writes a system attribute in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert_sys_attribute(
|
||||
const string& attr_name,
|
||||
const string& xml_attr,
|
||||
string& error_str)
|
||||
{
|
||||
return insert_replace(attr_name, xml_attr, false, error_str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the system attribute in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_sys_attribute(
|
||||
const string& attr_name,
|
||||
const string& xml_attr,
|
||||
string& error_str)
|
||||
{
|
||||
return insert_replace(attr_name, xml_attr, true, error_str);
|
||||
};
|
||||
|
||||
private:
|
||||
friend class Nebula; //Only for Nebula class
|
||||
|
||||
SystemDB(SqlDB *_db):db(_db){};
|
||||
|
||||
~SystemDB(){};
|
||||
|
||||
// Pool control table
|
||||
static const char * pc_names;
|
||||
|
||||
static const char * pc_bootstrap;
|
||||
|
||||
static const char * pc_table;
|
||||
|
||||
// DB versioning table
|
||||
static const char * ver_names;
|
||||
|
||||
static const char * ver_bootstrap;
|
||||
|
||||
static const char * ver_table;
|
||||
|
||||
// System attributes table
|
||||
static const char * sys_names;
|
||||
|
||||
static const char * sys_bootstrap;
|
||||
|
||||
static const char * sys_table;
|
||||
|
||||
// Pointer to the db database
|
||||
SqlDB *db;
|
||||
|
||||
/**
|
||||
* Execute an INSERT or REPLACE Sql query for a system attribute.
|
||||
* @param db The SQL DB
|
||||
* @param replace Execute an INSERT or a REPLACE
|
||||
* @param error_str Returns the error reason, if any
|
||||
* @return 0 one success
|
||||
*/
|
||||
int insert_replace(const string& attr_name,
|
||||
const string& xml_attr,
|
||||
bool replace,
|
||||
string& error_str);
|
||||
/**
|
||||
* Bootstraps the database control tables
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int bootstrap();
|
||||
|
||||
/**
|
||||
* Callback function for the check_db_version method. Stores the read
|
||||
* version in loaded_db_version
|
||||
* @param _loaded_db_version returned columns
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select_cb(void *_loaded_db_version,
|
||||
int num,
|
||||
char **values,
|
||||
char **names);
|
||||
/**
|
||||
* Callback function for selecting system attributes
|
||||
*/
|
||||
int select_attr_cb(void *_attr_xml,
|
||||
int num,
|
||||
char **values,
|
||||
char **names);
|
||||
/**
|
||||
* Reads the current DB version.
|
||||
*
|
||||
* @return 0 on success,
|
||||
* -1 if there is a version mismatch,
|
||||
* -2 if the DB needs a bootstrap
|
||||
*/
|
||||
int check_db_version();
|
||||
};
|
||||
|
||||
#endif //SYSTEM_DB_H
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "VirtualMachineTemplate.h"
|
||||
#include "PoolSQL.h"
|
||||
#include "History.h"
|
||||
#include "Image.h"
|
||||
#include "Log.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
@@ -173,13 +174,13 @@ public:
|
||||
* @param _memory Kilobytes used by the VM (total)
|
||||
* @param _cpu used by the VM (rate)
|
||||
* @param _net_tx transmitted bytes (total)
|
||||
* @param _net_tx received bytes (total)
|
||||
* @param _net_rx received bytes (total)
|
||||
*/
|
||||
void update_info(
|
||||
const int _memory,
|
||||
const int _cpu,
|
||||
const int _net_tx,
|
||||
const int _net_rx)
|
||||
const long long _net_tx,
|
||||
const long long _net_rx)
|
||||
{
|
||||
if (_memory != -1)
|
||||
{
|
||||
@@ -1009,12 +1010,12 @@ private:
|
||||
/**
|
||||
* Network usage, transmitted bytes
|
||||
*/
|
||||
int net_tx;
|
||||
long long net_tx;
|
||||
|
||||
/**
|
||||
* Network usage, received bytes
|
||||
*/
|
||||
int net_rx;
|
||||
long long net_rx;
|
||||
|
||||
/**
|
||||
* History record, for the current host
|
||||
@@ -1137,11 +1138,13 @@ private:
|
||||
* INITRD files.
|
||||
* @param os attribute of the VM template
|
||||
* @param base_name of the attribute "KERNEL", or "INITRD"
|
||||
* @param base_type of the image attribute KERNEL, RAMDISK
|
||||
* @param error_str Returns the error reason, if any
|
||||
* @return 0 on success
|
||||
*/
|
||||
int set_os_file(VectorAttribute * os,
|
||||
const string& base_name,
|
||||
Image::ImageType base_type,
|
||||
string& error_str);
|
||||
/**
|
||||
* Parse the "OS" attribute of the template by substituting
|
||||
|
||||
+2
-1
@@ -1108,7 +1108,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
|
||||
src/oca/ruby/OpenNebula/DatastorePool.rb \
|
||||
src/oca/ruby/OpenNebula/Cluster.rb \
|
||||
src/oca/ruby/OpenNebula/ClusterPool.rb \
|
||||
src/oca/ruby/OpenNebula/XMLUtils.rb"
|
||||
src/oca/ruby/OpenNebula/XMLUtils.rb \
|
||||
src/oca/ruby/OpenNebula/System.rb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Common Cloud Files
|
||||
|
||||
@@ -41,8 +41,8 @@ end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
#require 'OpenNebula'
|
||||
#include OpenNebula
|
||||
require 'OpenNebula'
|
||||
include OpenNebula
|
||||
|
||||
require 'getoptlong'
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ class AcctHelper < OpenNebulaHelper::OneHelper
|
||||
:format => String # TODO Time
|
||||
}
|
||||
|
||||
USER = {
|
||||
:name => "user",
|
||||
USERFILTER = {
|
||||
:name => "userfilter",
|
||||
:short => "-u user",
|
||||
:large => "--user user" ,
|
||||
:large => "--userfilter user" ,
|
||||
:description => "User name or id to filter the results",
|
||||
:format => String,
|
||||
:proc => lambda { |o, options|
|
||||
@@ -95,7 +95,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
|
||||
:description => "Split the output in a table for each VM"
|
||||
}
|
||||
|
||||
ACCT_OPTIONS = [START_TIME, END_TIME, USER, GROUP, HOST, XPATH, XML, JSON, SPLIT]
|
||||
ACCT_OPTIONS = [START_TIME, END_TIME, USERFILTER, GROUP, HOST, XPATH, XML, JSON, SPLIT]
|
||||
|
||||
|
||||
ACCT_TABLE = CLIHelper::ShowTable.new("oneacct.yaml", nil) do
|
||||
|
||||
@@ -48,6 +48,13 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
system = System.new(@client)
|
||||
default_quotas = system.get_group_quotas()
|
||||
|
||||
if OpenNebula::is_error?(default_quotas)
|
||||
raise "Error retrieving the default group quotas: #{default_quotas.message}"
|
||||
end
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Group", :size=>4 do |d|
|
||||
d["ID"]
|
||||
@@ -67,7 +74,14 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :VMS , "Number of VMS", :size=>9 do |d|
|
||||
if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
|
||||
"%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]]
|
||||
limit = d['VM_QUOTA']['VM']["VMS"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_quotas['VM_QUOTA/VM/VMS']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
"%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], limit]
|
||||
else
|
||||
"-"
|
||||
end
|
||||
@@ -75,8 +89,16 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d|
|
||||
if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
|
||||
limit = d['VM_QUOTA']['VM']["MEMORY"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_quotas['VM_QUOTA/VM/MEMORY']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
d['VM_QUOTA']['VM']['MEMORY_USED']
|
||||
"%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
|
||||
OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")]
|
||||
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
|
||||
else
|
||||
"-"
|
||||
end
|
||||
@@ -84,7 +106,14 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d|
|
||||
if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
|
||||
"%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]]
|
||||
limit = d['VM_QUOTA']['VM']["CPU"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_quotas['VM_QUOTA/VM/CPU']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
"%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit]
|
||||
else
|
||||
"-"
|
||||
end
|
||||
@@ -113,6 +142,13 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
def format_resource(group)
|
||||
system = System.new(@client)
|
||||
default_quotas = system.get_group_quotas()
|
||||
|
||||
if OpenNebula::is_error?(default_quotas)
|
||||
raise "Error retrieving the default group quotas: #{default_quotas.message}"
|
||||
end
|
||||
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
@@ -129,6 +165,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
group_hash = group.to_hash
|
||||
|
||||
OneQuotaHelper.format_quota(group_hash['GROUP'])
|
||||
helper = OneQuotaHelper.new
|
||||
helper.format_quota(group_hash['GROUP'], default_quotas)
|
||||
end
|
||||
end
|
||||
@@ -20,60 +20,6 @@ class OneQuotaHelper
|
||||
|
||||
EDITOR_PATH='/usr/bin/vi'
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Tables to format user quotas
|
||||
#---------------------------------------------------------------------------
|
||||
TABLE_DS = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"DATASTORE ID", "", :size=>12 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"IMAGES", "", :right, :size=>20 do |d|
|
||||
"%8d / %8d" % [d["IMAGES_USED"], d["IMAGES"]] if !d.nil?
|
||||
end
|
||||
|
||||
column :"SIZE", "", :right, :size=>19 do |d|
|
||||
"%8s / %8s" % [OpenNebulaHelper.unit_to_str(d["SIZE_USED"].to_i,{},"M"),
|
||||
OpenNebulaHelper.unit_to_str(d["SIZE"].to_i,{},"M")] if !d.nil?
|
||||
end
|
||||
end
|
||||
|
||||
TABLE_NET = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"NETWORK ID", "", :size=>12 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"LEASES", "", :right, :size=>20 do |d|
|
||||
"%8d / %8d" % [d["LEASES_USED"], d["LEASES"]] if !d.nil?
|
||||
end
|
||||
end
|
||||
|
||||
TABLE_VM = CLIHelper::ShowTable.new(nil, self) do
|
||||
|
||||
column :"NUMBER OF VMS", "", :right, :size=>20 do |d|
|
||||
"%8d / %8d" % [d["VMS_USED"], d["VMS"]] if !d.nil?
|
||||
end
|
||||
|
||||
column :"MEMORY", "", :right, :size=>20 do |d|
|
||||
"%8s / %8s" % [OpenNebulaHelper.unit_to_str(d["MEMORY_USED"].to_i,{},"M"),
|
||||
OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i,{},"M")] if !d.nil?
|
||||
end
|
||||
|
||||
column :"CPU", "", :right, :size=>20 do |d|
|
||||
"%8.2f / %8.2f" % [d["CPU_USED"], d["CPU"]] if !d.nil?
|
||||
end
|
||||
end
|
||||
|
||||
TABLE_IMG = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"IMAGE ID", "", :size=>12 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"RUNNING VMS", "", :right, :size=>20 do |d|
|
||||
"%8d / %8d" % [d["RVMS_USED"], d["RVMS"]] if !d.nil?
|
||||
end
|
||||
end
|
||||
|
||||
HELP_QUOTA = <<-EOT.unindent
|
||||
#-----------------------------------------------------------------------
|
||||
# Supported quota limits:
|
||||
@@ -96,18 +42,22 @@ class OneQuotaHelper
|
||||
# ]
|
||||
#
|
||||
# IMAGE = [
|
||||
# ID = <ID of the image>
|
||||
# RVMS = <Max. number of VMs using the image>
|
||||
# ID = <ID of the image>
|
||||
# RVMS = <Max. number of VMs using the image>
|
||||
# ]
|
||||
#
|
||||
# In any quota 0 means unlimited. The usage counters "*_USED" are
|
||||
# shown for information purposes and will NOT be modified.
|
||||
# In any quota:
|
||||
# -1 means use the default limit ('defaultquota' command)
|
||||
# 0 means unlimited.
|
||||
#
|
||||
# The usage counters "*_USED" are shown for information
|
||||
# purposes and will NOT be modified.
|
||||
#-----------------------------------------------------------------------
|
||||
EOT
|
||||
|
||||
# Edits the quota template of a resource
|
||||
# @param resource [PoolElement] to get the current info from
|
||||
# @param path [String] path to the new contents. If nil a editor will be
|
||||
# @param [XMLElement] resource to get the current info from
|
||||
# @param [String] path to the new contents. If nil a editor will be
|
||||
# used
|
||||
# @return [String] contents of the new quotas
|
||||
def self.set_quota(resource, path)
|
||||
@@ -119,13 +69,6 @@ class OneQuotaHelper
|
||||
tmp = Tempfile.new('one-cli')
|
||||
path = tmp.path
|
||||
|
||||
rc = resource.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
tmp << HELP_QUOTA
|
||||
tmp << resource.template_like_str("DATASTORE_QUOTA") << "\n"
|
||||
tmp << resource.template_like_str("VM_QUOTA") << "\n"
|
||||
@@ -220,8 +163,9 @@ class OneQuotaHelper
|
||||
|
||||
# Outputs formated quota information to stdout
|
||||
# @param qh [Hash] with the quotas for a given resource
|
||||
# @param default_quotas_hash [XMLElement] with the default quota limits
|
||||
#
|
||||
def self.format_quota(qh)
|
||||
def format_quota(qh, default_quotas)
|
||||
str_h1="%-80s"
|
||||
|
||||
puts
|
||||
@@ -230,27 +174,145 @@ class OneQuotaHelper
|
||||
|
||||
puts
|
||||
|
||||
@default_quotas = default_quotas
|
||||
|
||||
vm_quotas = [qh['VM_QUOTA']['VM']].flatten
|
||||
|
||||
if !vm_quotas[0].nil?
|
||||
TABLE_VM.show(vm_quotas, {})
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"NUMBER OF VMS", "", :right, :size=>20 do |d|
|
||||
if !d.nil?
|
||||
elem = 'VMS'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "VM_QUOTA/VM/#{elem}")
|
||||
|
||||
"%8d / %8d" % [d["VMS_USED"], limit]
|
||||
end
|
||||
end
|
||||
|
||||
column :"MEMORY", "", :right, :size=>20 do |d|
|
||||
if !d.nil?
|
||||
elem = 'MEMORY'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "VM_QUOTA/VM/#{elem}")
|
||||
|
||||
"%8s / %8s" % [
|
||||
OpenNebulaHelper.unit_to_str(d["MEMORY_USED"].to_i,{},"M"),
|
||||
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
column :"CPU", "", :right, :size=>20 do |d|
|
||||
if !d.nil?
|
||||
elem = 'CPU'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "VM_QUOTA/VM/#{elem}")
|
||||
|
||||
"%8.2f / %8.2f" % [d["CPU_USED"], limit]
|
||||
end
|
||||
end
|
||||
end.show(vm_quotas, {})
|
||||
|
||||
puts
|
||||
end
|
||||
|
||||
ds_quotas = [qh['DATASTORE_QUOTA']['DATASTORE']].flatten
|
||||
|
||||
if !ds_quotas[0].nil?
|
||||
TABLE_DS.show(ds_quotas, {})
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"DATASTORE ID", "", :size=>12 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"IMAGES", "", :right, :size=>20 do |d|
|
||||
if !d.nil?
|
||||
elem = 'IMAGES'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "DATASTORE_QUOTA/DATASTORE[ID=#{d['ID']}]/#{elem}")
|
||||
|
||||
"%8d / %8d" % [d["IMAGES_USED"], limit]
|
||||
end
|
||||
end
|
||||
|
||||
column :"SIZE", "", :right, :size=>19 do |d|
|
||||
if !d.nil?
|
||||
elem = 'SIZE'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "DATASTORE_QUOTA/DATASTORE[ID=#{d['ID']}]/#{elem}")
|
||||
|
||||
"%8s / %8s" % [
|
||||
OpenNebulaHelper.unit_to_str(d["SIZE_USED"].to_i,{},"M"),
|
||||
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")
|
||||
]
|
||||
end
|
||||
end
|
||||
end.show(ds_quotas, {})
|
||||
|
||||
puts
|
||||
end
|
||||
|
||||
net_quotas = [qh['NETWORK_QUOTA']['NETWORK']].flatten
|
||||
|
||||
if !net_quotas[0].nil?
|
||||
TABLE_NET.show(net_quotas, {})
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"NETWORK ID", "", :size=>12 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"LEASES", "", :right, :size=>20 do |d|
|
||||
if !d.nil?
|
||||
elem = 'LEASES'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "NETWORK_QUOTA/NETWORK[ID=#{d['ID']}]/#{elem}")
|
||||
|
||||
"%8d / %8d" % [d["LEASES_USED"], limit]
|
||||
end
|
||||
end
|
||||
end.show(net_quotas, {})
|
||||
|
||||
puts
|
||||
end
|
||||
|
||||
image_quotas = [qh['IMAGE_QUOTA']['IMAGE']].flatten
|
||||
|
||||
if !image_quotas[0].nil?
|
||||
TABLE_IMG.show(image_quotas, {})
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
column :"IMAGE ID", "", :size=>12 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"RUNNING VMS", "", :right, :size=>20 do |d|
|
||||
if !d.nil?
|
||||
elem = 'RVMS'
|
||||
limit = d[elem]
|
||||
limit = helper.get_default_limit(
|
||||
limit, "IMAGE_QUOTA/IMAGE[ID=#{d['ID']}]/RVMS")
|
||||
|
||||
"%8d / %8d" % [d["RVMS_USED"], limit]
|
||||
end
|
||||
end
|
||||
end.show(image_quotas, {})
|
||||
end
|
||||
end
|
||||
|
||||
def get_default_limit(limit, xpath)
|
||||
if limit == "-1"
|
||||
if !@default_quotas.nil?
|
||||
limit = @default_quotas[xpath]
|
||||
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
else
|
||||
limit = "0"
|
||||
end
|
||||
end
|
||||
|
||||
return limit
|
||||
end
|
||||
end
|
||||
@@ -147,6 +147,13 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
system = System.new(@client)
|
||||
default_quotas = system.get_user_quotas()
|
||||
|
||||
if OpenNebula::is_error?(default_quotas)
|
||||
raise "Error retrieving the default user quotas: #{default_quotas.message}"
|
||||
end
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the User", :size=>4 do |d|
|
||||
d["ID"]
|
||||
@@ -166,7 +173,14 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :VMS , "Number of VMS", :size=>9 do |d|
|
||||
if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
|
||||
"%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]]
|
||||
limit = d['VM_QUOTA']['VM']["VMS"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_quotas['VM_QUOTA/VM/VMS']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
"%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], limit]
|
||||
else
|
||||
"-"
|
||||
end
|
||||
@@ -174,9 +188,16 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d|
|
||||
if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
|
||||
limit = d['VM_QUOTA']['VM']["MEMORY"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_quotas['VM_QUOTA/VM/MEMORY']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
d['VM_QUOTA']['VM']['MEMORY_USED']
|
||||
"%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
|
||||
OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")]
|
||||
OpenNebulaHelper.unit_to_str(limit.to_i,{},"M")]
|
||||
else
|
||||
"-"
|
||||
end
|
||||
@@ -184,7 +205,14 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d|
|
||||
if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
|
||||
"%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]]
|
||||
limit = d['VM_QUOTA']['VM']["CPU"]
|
||||
|
||||
if limit == "-1"
|
||||
limit = default_quotas['VM_QUOTA/VM/CPU']
|
||||
limit = "0" if limit.nil? || limit == ""
|
||||
end
|
||||
|
||||
"%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], limit]
|
||||
else
|
||||
"-"
|
||||
end
|
||||
@@ -217,6 +245,13 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
def format_resource(user)
|
||||
system = System.new(@client)
|
||||
default_quotas = system.get_user_quotas()
|
||||
|
||||
if OpenNebula::is_error?(default_quotas)
|
||||
raise "Error retrieving the default user quotas: #{default_quotas.message}"
|
||||
end
|
||||
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
@@ -237,6 +272,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
user_hash = user.to_hash
|
||||
|
||||
OneQuotaHelper.format_quota(user_hash['USER'])
|
||||
helper = OneQuotaHelper.new
|
||||
helper.format_quota(user_hash['USER'], default_quotas)
|
||||
end
|
||||
end
|
||||
+9
-4
@@ -37,12 +37,17 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
description ""
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
client = OpenNebulaHelper::OneHelper.get_client({})
|
||||
helper=OpenNebulaHelper::OneHelper.new
|
||||
|
||||
option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
main do
|
||||
filter_flag = (options[:user] || VirtualMachinePool::INFO_ALL)
|
||||
filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
|
||||
start_time = options[:start] ? options[:start].to_i : -1
|
||||
end_time = options[:end] ? options[:end].to_i : -1
|
||||
|
||||
@@ -54,7 +59,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
:xpath => options[:xpath]
|
||||
}
|
||||
|
||||
pool = OpenNebula::VirtualMachinePool.new(client)
|
||||
pool = OpenNebula::VirtualMachinePool.new(helper.client)
|
||||
|
||||
if options[:json] || options[:xml]
|
||||
xml_str = pool.accounting_xml(filter_flag, common_opts)
|
||||
|
||||
@@ -109,6 +109,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :quota, quota_desc, :groupid, [:file, nil] do
|
||||
helper.perform_action(args[0], options, "modified") do |group|
|
||||
rc = group.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
str = OneQuotaHelper.set_quota(group, args[1])
|
||||
rc = group.set_quota(str)
|
||||
|
||||
@@ -138,4 +145,32 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
defaultquota_desc = <<-EOT.unindent
|
||||
Sets the default quota limits for the groups. If a path is not provided
|
||||
the editor will be launched to modify the current default quotas.
|
||||
EOT
|
||||
|
||||
command :defaultquota, defaultquota_desc, [:file, nil] do
|
||||
system = System.new(OneGroupHelper.get_client(options))
|
||||
|
||||
default_quotas = system.get_group_quotas()
|
||||
|
||||
if OpenNebula.is_error?(default_quotas)
|
||||
puts default_quotas.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
str = OneQuotaHelper.set_quota(default_quotas, args[0])
|
||||
|
||||
rc = system.set_group_quotas(str)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
exit 0
|
||||
end
|
||||
end
|
||||
+3
-3
@@ -76,12 +76,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
format(:type, 'Image type: OS, DATABLOCK or CDROM') do |arg|
|
||||
format(:type, "Image type: #{Image::IMAGE_TYPES.join(", ")}") do |arg|
|
||||
type=arg.strip.upcase
|
||||
if %w{OS DATABLOCK CDROM}.include? type
|
||||
if Image::IMAGE_TYPES.include? type
|
||||
[0, type]
|
||||
else
|
||||
[1, "Image type not supported. Must be OS, DATABLOCK or CDROM."]
|
||||
[1, "Image type not supported. Must be #{Image::IMAGE_TYPES.join(", ")}."]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+34
-1
@@ -206,6 +206,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :quota, quota_desc, :userid, [:file, nil] do
|
||||
helper.perform_action(args[0], options, "modified") do |user|
|
||||
rc = user.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
str = OneQuotaHelper.set_quota(user, args[1])
|
||||
rc = user.set_quota(str)
|
||||
|
||||
@@ -213,7 +220,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -237,6 +243,33 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
defaultquota_desc = <<-EOT.unindent
|
||||
Sets the default quota limits for the users. If a path is not provided
|
||||
the editor will be launched to modify the current default quotas.
|
||||
EOT
|
||||
|
||||
command :defaultquota, defaultquota_desc, [:file, nil] do
|
||||
system = System.new(OneUserHelper.get_client(options))
|
||||
|
||||
default_quotas = system.get_user_quotas()
|
||||
|
||||
if OpenNebula.is_error?(default_quotas)
|
||||
puts default_quotas.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
str = OneQuotaHelper.set_quota(default_quotas, args[0])
|
||||
|
||||
rc = system.set_user_quotas(str)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
exit 0
|
||||
end
|
||||
|
||||
login_desc = <<-EOT.unindent
|
||||
Creates the Login token for authentication
|
||||
Examples:
|
||||
|
||||
+44
-28
@@ -128,37 +128,34 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
goto error_type;
|
||||
}
|
||||
|
||||
// ------------ PERSISTENT --------------------
|
||||
// ------------ PERSISTENT & PREFIX --------------------
|
||||
|
||||
erase_template_attribute("PERSISTENT", persistent_attr);
|
||||
|
||||
if ( type != DATAFILE )
|
||||
switch (type)
|
||||
{
|
||||
TO_UPPER(persistent_attr);
|
||||
case OS:
|
||||
case DATABLOCK:
|
||||
case CDROM:
|
||||
TO_UPPER(persistent_attr);
|
||||
persistent_img = (persistent_attr == "YES");
|
||||
|
||||
persistent_img = (persistent_attr == "YES");
|
||||
}
|
||||
else // Files are always non-persistent
|
||||
{
|
||||
persistent_img = false;
|
||||
}
|
||||
get_template_attribute("DEV_PREFIX", dev_prefix);
|
||||
|
||||
// ------------ PREFIX --------------------
|
||||
|
||||
if ( type != DATAFILE )
|
||||
{
|
||||
get_template_attribute("DEV_PREFIX", dev_prefix);
|
||||
|
||||
if( dev_prefix.empty() )
|
||||
{
|
||||
SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
|
||||
if( dev_prefix.empty() )
|
||||
{
|
||||
SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
|
||||
ImagePool::default_dev_prefix());
|
||||
obj_template->set(dev_att);
|
||||
}
|
||||
}
|
||||
else // Do not set dev_prefix for files
|
||||
{
|
||||
erase_template_attribute("DEV_PREFIX", dev_prefix);
|
||||
obj_template->set(dev_att);
|
||||
}
|
||||
break;
|
||||
|
||||
case KERNEL: // Files are always non-persistent with no dev_prefix
|
||||
case RAMDISK:
|
||||
case CONTEXT:
|
||||
persistent_img = false;
|
||||
erase_template_attribute("DEV_PREFIX", dev_prefix);
|
||||
break;
|
||||
}
|
||||
|
||||
// ------------ SIZE --------------------
|
||||
@@ -545,6 +542,9 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
disk_attr_type = "CDROM";
|
||||
disk->replace("READONLY","YES");
|
||||
break;
|
||||
|
||||
default: //Other file types should not be never a DISK
|
||||
break;
|
||||
}
|
||||
|
||||
disk->replace("TYPE",disk_attr_type);
|
||||
@@ -583,9 +583,17 @@ int Image::set_type(string& _type)
|
||||
{
|
||||
type = DATABLOCK;
|
||||
}
|
||||
else if ( _type == "FILE" )
|
||||
else if ( _type == "KERNEL" )
|
||||
{
|
||||
type = DATAFILE;
|
||||
type = KERNEL;
|
||||
}
|
||||
else if ( _type == "RAMDISK" )
|
||||
{
|
||||
type = RAMDISK;
|
||||
}
|
||||
else if ( _type == "CONTEXT" )
|
||||
{
|
||||
type = CONTEXT;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -648,9 +656,17 @@ Image::ImageType Image::str_to_type(string& str_type)
|
||||
{
|
||||
it = DATABLOCK;
|
||||
}
|
||||
else if ( str_type == "FILE" )
|
||||
else if ( str_type == "KERNEL" )
|
||||
{
|
||||
it = DATAFILE;
|
||||
it = KERNEL;
|
||||
}
|
||||
else if ( str_type == "RAMDISK" )
|
||||
{
|
||||
it = RAMDISK;
|
||||
}
|
||||
else if ( str_type == "CONTEXT" )
|
||||
{
|
||||
it = CONTEXT;
|
||||
}
|
||||
|
||||
return it;
|
||||
|
||||
@@ -88,15 +88,24 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ( img->get_type() == Image::DATAFILE )
|
||||
switch(img->get_type())
|
||||
{
|
||||
ostringstream oss;
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
break;
|
||||
|
||||
oss << "Image " << img->get_oid() << " (" << img->get_name() << ") "
|
||||
<< "of type FILE cannot be used as DISK.";
|
||||
error = oss.str();
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
ostringstream oss;
|
||||
|
||||
return -1;
|
||||
oss << "Image " << img->get_oid() << " (" << img->get_name() << ") "
|
||||
<< "of type " << Image::type_to_str(img->get_type())
|
||||
<< " cannot be used as DISK.";
|
||||
|
||||
error = oss.str();
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (img->get_state())
|
||||
@@ -160,12 +169,20 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
return;
|
||||
}
|
||||
|
||||
if ( img->get_type() == Image::DATAFILE )
|
||||
switch(img->get_type())
|
||||
{
|
||||
NebulaLog::log("ImM", Log::ERROR, "Trying to release a FILE image");
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
break;
|
||||
|
||||
img->unlock();
|
||||
return;
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
NebulaLog::log("ImM", Log::ERROR, "Trying to release a KERNEL, "
|
||||
"RAMDISK or CONTEXT image");
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (img->get_state())
|
||||
@@ -257,12 +274,20 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id)
|
||||
return;
|
||||
}
|
||||
|
||||
if ( img->get_type() == Image::DATAFILE )
|
||||
switch(img->get_type())
|
||||
{
|
||||
NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning FILE image");
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
break;
|
||||
|
||||
img->unlock();
|
||||
return;
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning "
|
||||
"KERNEL, RAMDISK or CONTEXT image");
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (img->get_state())
|
||||
@@ -709,7 +734,9 @@ int ImageManager::stat_image(Template* img_tmpl,
|
||||
{
|
||||
case Image::OS:
|
||||
case Image::CDROM:
|
||||
case Image::DATAFILE:
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
img_tmpl->get("SOURCE", res);
|
||||
|
||||
if (!res.empty())
|
||||
|
||||
+21
-10
@@ -105,16 +105,25 @@ int ImagePool::allocate (
|
||||
|
||||
img->get_template_attribute("TYPE", type);
|
||||
|
||||
if ( ds_type == Datastore::FILE_DS &&
|
||||
img->str_to_type(type) != Image::DATAFILE )
|
||||
switch (img->str_to_type(type))
|
||||
{
|
||||
goto error_types_missmatch_file;
|
||||
}
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
if ( ds_type != Datastore::IMAGE_DS )
|
||||
{
|
||||
goto error_types_missmatch_file;
|
||||
}
|
||||
break;
|
||||
|
||||
if ( ds_type == Datastore::IMAGE_DS &&
|
||||
img->str_to_type(type) == Image::DATAFILE )
|
||||
{
|
||||
goto error_types_missmatch_image;
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
if ( ds_type != Datastore::FILE_DS )
|
||||
{
|
||||
goto error_types_missmatch_image;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
img_aux = get(name,uid,false);
|
||||
@@ -197,11 +206,13 @@ error_name_length:
|
||||
goto error_common;
|
||||
|
||||
error_types_missmatch_file:
|
||||
oss << "Only IMAGES of type FILE can be registered in a FILE_DS datastore";
|
||||
oss << "Only IMAGES of type KERNEL, RAMDISK and CONTEXT can be registered"
|
||||
" in a FILE_DS datastore";
|
||||
goto error_common;
|
||||
|
||||
error_types_missmatch_image:
|
||||
oss << "IMAGES of type FILE cannot be registered in a IMAGE_DS datastore";
|
||||
oss << "IMAGES of type KERNEL, RAMDISK and CONTEXT cannot be registered"
|
||||
" in an IMAGE_DS datastore";
|
||||
goto error_common;
|
||||
|
||||
error_duplicated:
|
||||
|
||||
+249
-99
@@ -33,6 +33,238 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// Pool control table
|
||||
const char * SystemDB::pc_table = "pool_control";
|
||||
const char * SystemDB::pc_names = "tablename, last_oid";
|
||||
|
||||
const char * SystemDB::pc_bootstrap = "CREATE TABLE pool_control "
|
||||
"(tablename VARCHAR(32) PRIMARY KEY, last_oid BIGINT UNSIGNED)";
|
||||
|
||||
|
||||
// DB versioning table
|
||||
const char * SystemDB::ver_table = "db_versioning";
|
||||
const char * SystemDB::ver_names = "oid, version, timestamp, comment";
|
||||
|
||||
const char * SystemDB::ver_bootstrap = "CREATE TABLE db_versioning "
|
||||
"(oid INTEGER PRIMARY KEY, version VARCHAR(256), timestamp INTEGER, "
|
||||
"comment VARCHAR(256))";
|
||||
|
||||
// System attributes table
|
||||
const char * SystemDB::sys_table = "system_attributes";
|
||||
const char * SystemDB::sys_names = "name, body";
|
||||
|
||||
const char * SystemDB::sys_bootstrap = "CREATE TABLE IF NOT EXISTS"
|
||||
" system_attributes (name VARCHAR(128) PRIMARY KEY, body TEXT)";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::bootstrap()
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// pool control, tracks the last ID's assigned to objects
|
||||
// ------------------------------------------------------------------------
|
||||
oss.str(pc_bootstrap);
|
||||
rc = db->exec(oss);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// db versioning, version of OpenNebula. Insert this version number
|
||||
// ------------------------------------------------------------------------
|
||||
oss.str(ver_bootstrap);
|
||||
rc += db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO " << ver_table << " (" << ver_names << ") "
|
||||
<< "VALUES (0, '" << Nebula::db_version() << "', " << time(0)
|
||||
<< ", '" << Nebula::version() << " daemon bootstrap')";
|
||||
|
||||
rc += db->exec(oss);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// system , version of OpenNebula. Insert this version number
|
||||
// ------------------------------------------------------------------------
|
||||
oss.str(sys_bootstrap);
|
||||
rc += db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::select_cb(void *_loaded_db_version, int num, char **values,
|
||||
char **names)
|
||||
{
|
||||
istringstream iss;
|
||||
string * loaded_db_version;
|
||||
|
||||
loaded_db_version = static_cast<string *>(_loaded_db_version);
|
||||
|
||||
if ( (values[0]) && (num == 1) )
|
||||
{
|
||||
*loaded_db_version = values[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::check_db_version()
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
string loaded_db_version = "";
|
||||
|
||||
// Try to read latest version
|
||||
set_callback( static_cast<Callbackable::Callback>(&SystemDB::select_cb),
|
||||
static_cast<void *>(&loaded_db_version) );
|
||||
|
||||
oss << "SELECT version FROM " << ver_table
|
||||
<< " WHERE oid=(SELECT MAX(oid) FROM " << ver_table << ")";
|
||||
|
||||
db->exec(oss, this);
|
||||
|
||||
oss.str("");
|
||||
unset_callback();
|
||||
|
||||
if( loaded_db_version == "" )
|
||||
{
|
||||
// Table user_pool is present for all OpenNebula versions, and it
|
||||
// always contains at least the oneadmin user.
|
||||
oss << "SELECT MAX(oid) FROM user_pool";
|
||||
rc = db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
|
||||
if( rc != 0 ) // Database needs bootstrap
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if( Nebula::db_version() != loaded_db_version )
|
||||
{
|
||||
oss << "Database version mismatch. "
|
||||
<< "Installed " << Nebula::version() << " uses DB version '"
|
||||
<< Nebula::db_version() << "', and existing DB version is '"
|
||||
<< loaded_db_version << "'.";
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::insert_replace(
|
||||
const string& attr_name,
|
||||
const string& xml_attr,
|
||||
bool replace,
|
||||
string& err)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
char * sql_xml;
|
||||
|
||||
sql_xml = db->escape_str(xml_attr.c_str());
|
||||
|
||||
if ( sql_xml == 0 )
|
||||
{
|
||||
goto error_body;
|
||||
}
|
||||
|
||||
if ( ObjectXML::validate_xml(sql_xml) != 0 )
|
||||
{
|
||||
goto error_xml;
|
||||
}
|
||||
|
||||
if ( replace )
|
||||
{
|
||||
oss << "REPLACE";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "INSERT";
|
||||
}
|
||||
|
||||
// Construct the SQL statement to Insert or Replace
|
||||
|
||||
oss <<" INTO "<< sys_table <<
|
||||
" ("<< sys_names <<") VALUES ("
|
||||
<< "'" << attr_name << "',"
|
||||
<< "'" << sql_xml << "')";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
db->free_str(sql_xml);
|
||||
|
||||
return rc;
|
||||
|
||||
error_xml:
|
||||
db->free_str(sql_xml);
|
||||
|
||||
error_body:
|
||||
err = "Error inserting system attribute in DB.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::select_attr_cb(void * _xml_attr,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
istringstream iss;
|
||||
string * xml_attr;
|
||||
|
||||
xml_attr = static_cast<string *>(_xml_attr);
|
||||
|
||||
if ( (values[0]) && (num == 1) )
|
||||
{
|
||||
*xml_attr = values[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::select_sys_attribute(const string& attr_name, string& attr_xml)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&SystemDB::select_attr_cb),
|
||||
static_cast<void *>(&attr_xml) );
|
||||
|
||||
oss << "SELECT body FROM " << sys_table << " WHERE name = '"
|
||||
<< attr_name << "'";
|
||||
|
||||
rc = db->exec(oss, this);
|
||||
|
||||
unset_callback();
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -219,8 +451,15 @@ void Nebula::start()
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Prepare the SystemDB and check versions
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
NebulaLog::log("ONE",Log::INFO,"Checking database version.");
|
||||
rc = check_db_version();
|
||||
|
||||
system_db = new SystemDB(db);
|
||||
|
||||
rc = system_db->check_db_version();
|
||||
|
||||
if( rc == -1 )
|
||||
{
|
||||
@@ -245,12 +484,16 @@ void Nebula::start()
|
||||
rc += ClusterPool::bootstrap(db);
|
||||
rc += DocumentPool::bootstrap(db);
|
||||
|
||||
// Create the versioning table only if bootstrap went well
|
||||
// Create the system tables only if bootstrap went well
|
||||
if ( rc == 0 )
|
||||
{
|
||||
rc += bootstrap();
|
||||
rc += system_db->bootstrap();
|
||||
}
|
||||
|
||||
// Insert default system attributes
|
||||
rc += default_user_quota.insert();
|
||||
rc += default_group_quota.insert();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Error bootstrapping database.");
|
||||
@@ -340,6 +583,9 @@ void Nebula::start()
|
||||
tpool = new VMTemplatePool(db);
|
||||
|
||||
dspool = new DatastorePool(db);
|
||||
|
||||
default_user_quota.select();
|
||||
default_group_quota.select();
|
||||
}
|
||||
catch (exception&)
|
||||
{
|
||||
@@ -674,99 +920,3 @@ void Nebula::start()
|
||||
NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Nebula::bootstrap()
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, "
|
||||
"last_oid BIGINT UNSIGNED)";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, "
|
||||
"version VARCHAR(256), timestamp INTEGER, comment VARCHAR(256))";
|
||||
|
||||
rc += db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO db_versioning (oid, version, timestamp, comment) "
|
||||
<< "VALUES (0, '" << db_version() << "', " << time(0)
|
||||
<< ", '" << version() << " daemon bootstrap')";
|
||||
|
||||
rc += db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Nebula::check_db_version()
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
string loaded_db_version = "";
|
||||
|
||||
// Try to read latest version
|
||||
set_callback( static_cast<Callbackable::Callback>(&Nebula::select_cb),
|
||||
static_cast<void *>(&loaded_db_version) );
|
||||
|
||||
oss << "SELECT version FROM db_versioning "
|
||||
<< "WHERE oid=(SELECT MAX(oid) FROM db_versioning)";
|
||||
|
||||
db->exec(oss, this);
|
||||
|
||||
oss.str("");
|
||||
unset_callback();
|
||||
|
||||
if( loaded_db_version == "" )
|
||||
{
|
||||
// Table user_pool is present for all OpenNebula versions, and it
|
||||
// always contains at least the oneadmin user.
|
||||
oss << "SELECT MAX(oid) FROM user_pool";
|
||||
rc = db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
|
||||
if( rc != 0 ) // Database needs bootstrap
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if( db_version() != loaded_db_version )
|
||||
{
|
||||
oss << "Database version mismatch. "
|
||||
<< "Installed " << version() << " uses DB version '" << db_version()
|
||||
<< "', and existing DB version is '"
|
||||
<< loaded_db_version << "'.";
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Nebula::select_cb(void *_loaded_db_version, int num, char **values,
|
||||
char **names)
|
||||
{
|
||||
istringstream iss;
|
||||
string * loaded_db_version;
|
||||
|
||||
loaded_db_version = static_cast<string *>(_loaded_db_version);
|
||||
|
||||
if ( (values[0]) && (num == 1) )
|
||||
{
|
||||
*loaded_db_version = values[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -23,6 +23,7 @@ lib_name='nebula_core'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'SystemDB.cc',
|
||||
'Nebula.cc',
|
||||
'NebulaTemplate.cc',
|
||||
]
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "Nebula.h"
|
||||
#include "SystemDB.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// Pool control table
|
||||
const char * SystemDB::pc_table = "pool_control";
|
||||
const char * SystemDB::pc_names = "tablename, last_oid";
|
||||
|
||||
const char * SystemDB::pc_bootstrap = "CREATE TABLE pool_control "
|
||||
"(tablename VARCHAR(32) PRIMARY KEY, last_oid BIGINT UNSIGNED)";
|
||||
|
||||
|
||||
// DB versioning table
|
||||
const char * SystemDB::ver_table = "db_versioning";
|
||||
const char * SystemDB::ver_names = "oid, version, timestamp, comment";
|
||||
|
||||
const char * SystemDB::ver_bootstrap = "CREATE TABLE db_versioning "
|
||||
"(oid INTEGER PRIMARY KEY, version VARCHAR(256), timestamp INTEGER, "
|
||||
"comment VARCHAR(256))";
|
||||
|
||||
// System attributes table
|
||||
const char * SystemDB::sys_table = "system_attributes";
|
||||
const char * SystemDB::sys_names = "name, body";
|
||||
|
||||
const char * SystemDB::sys_bootstrap = "CREATE TABLE IF NOT EXISTS"
|
||||
" system_attributes (name VARCHAR(128) PRIMARY KEY, body TEXT)";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::bootstrap()
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// pool control, tracks the last ID's assigned to objects
|
||||
// ------------------------------------------------------------------------
|
||||
oss.str(pc_bootstrap);
|
||||
rc = db->exec(oss);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// db versioning, version of OpenNebula. Insert this version number
|
||||
// ------------------------------------------------------------------------
|
||||
oss.str(ver_bootstrap);
|
||||
rc += db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO " << ver_table << " (" << ver_names << ") "
|
||||
<< "VALUES (0, '" << Nebula::db_version() << "', " << time(0)
|
||||
<< ", '" << Nebula::version() << " daemon bootstrap')";
|
||||
|
||||
rc += db->exec(oss);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// system , version of OpenNebula. Insert this version number
|
||||
// ------------------------------------------------------------------------
|
||||
oss.str(sys_bootstrap);
|
||||
rc += db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::select_cb(void *_loaded_db_version, int num, char **values,
|
||||
char **names)
|
||||
{
|
||||
istringstream iss;
|
||||
string * loaded_db_version;
|
||||
|
||||
loaded_db_version = static_cast<string *>(_loaded_db_version);
|
||||
|
||||
if ( (values[0]) && (num == 1) )
|
||||
{
|
||||
*loaded_db_version = values[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::check_db_version()
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
string loaded_db_version = "";
|
||||
|
||||
// Try to read latest version
|
||||
set_callback( static_cast<Callbackable::Callback>(&SystemDB::select_cb),
|
||||
static_cast<void *>(&loaded_db_version) );
|
||||
|
||||
oss << "SELECT version FROM " << ver_table
|
||||
<< " WHERE oid=(SELECT MAX(oid) FROM " << ver_table << ")";
|
||||
|
||||
db->exec(oss, this);
|
||||
|
||||
oss.str("");
|
||||
unset_callback();
|
||||
|
||||
if( loaded_db_version == "" )
|
||||
{
|
||||
// Table user_pool is present for all OpenNebula versions, and it
|
||||
// always contains at least the oneadmin user.
|
||||
oss << "SELECT MAX(oid) FROM user_pool";
|
||||
rc = db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
|
||||
if( rc != 0 ) // Database needs bootstrap
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if( Nebula::db_version() != loaded_db_version )
|
||||
{
|
||||
oss << "Database version mismatch. "
|
||||
<< "Installed " << Nebula::version() << " uses DB version '"
|
||||
<< Nebula::db_version() << "', and existing DB version is '"
|
||||
<< loaded_db_version << "'.";
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::insert_replace(
|
||||
const string& attr_name,
|
||||
const string& xml_attr,
|
||||
bool replace,
|
||||
string& err)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
char * sql_xml;
|
||||
|
||||
sql_xml = db->escape_str(xml_attr.c_str());
|
||||
|
||||
if ( sql_xml == 0 )
|
||||
{
|
||||
goto error_body;
|
||||
}
|
||||
|
||||
if ( ObjectXML::validate_xml(sql_xml) != 0 )
|
||||
{
|
||||
goto error_xml;
|
||||
}
|
||||
|
||||
if ( replace )
|
||||
{
|
||||
oss << "REPLACE";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "INSERT";
|
||||
}
|
||||
|
||||
// Construct the SQL statement to Insert or Replace
|
||||
|
||||
oss <<" INTO "<< sys_table << " ("<< sys_names <<") VALUES ("
|
||||
<< "'" << attr_name << "'," << "'" << sql_xml << "')";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
db->free_str(sql_xml);
|
||||
|
||||
return rc;
|
||||
|
||||
error_xml:
|
||||
db->free_str(sql_xml);
|
||||
|
||||
error_body:
|
||||
err = "Error inserting system attribute in DB.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::select_attr_cb(void * _xml_attr,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
istringstream iss;
|
||||
string * xml_attr;
|
||||
|
||||
xml_attr = static_cast<string *>(_xml_attr);
|
||||
|
||||
if ( (values[0]) && (num == 1) )
|
||||
{
|
||||
*xml_attr = values[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SystemDB::select_sys_attribute(const string& attr_name, string& attr_xml)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&SystemDB::select_attr_cb),
|
||||
static_cast<void *>(&attr_xml) );
|
||||
|
||||
oss << "SELECT body FROM " << sys_table << " WHERE name = '"
|
||||
<< attr_name << "'";
|
||||
|
||||
rc = db->exec(oss, this);
|
||||
|
||||
unset_callback();
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
package org.opennebula.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class OneSystem
|
||||
{
|
||||
protected Client client;
|
||||
|
||||
private static final String USER_QUOTA_INFO = "userquota.info";
|
||||
private static final String USER_QUOTA_UPDATE = "userquota.update";
|
||||
private static final String GROUP_QUOTA_INFO = "groupquota.info";
|
||||
private static final String GROUP_QUOTA_UPDATE = "groupquota.update";
|
||||
|
||||
|
||||
public OneSystem(Client client)
|
||||
{
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default user quota limits
|
||||
*
|
||||
* @return the default user quota in case of success, Error otherwise
|
||||
*/
|
||||
public OneResponse getUserQuotas()
|
||||
{
|
||||
return client.call(USER_QUOTA_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default user quota limits
|
||||
*
|
||||
* @return The xml root node in case of success, null otherwise
|
||||
*/
|
||||
public Node getUserQuotasXML()
|
||||
{
|
||||
OneResponse r = getUserQuotas();
|
||||
Node xml = null;
|
||||
|
||||
if (r.isError())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DocumentBuilder builder =
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = builder.parse(
|
||||
new ByteArrayInputStream(r.getMessage().getBytes()));
|
||||
|
||||
xml = doc.getDocumentElement();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default user quota limits
|
||||
*
|
||||
* @param quota a template (XML or txt) with the new quota limits
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse setUserQuotas(String quota)
|
||||
{
|
||||
return client.call(USER_QUOTA_UPDATE, quota);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default group quota limits
|
||||
*
|
||||
* @return the default group quota in case of success, Error otherwise
|
||||
*/
|
||||
public OneResponse getGroupQuotas()
|
||||
{
|
||||
return client.call(GROUP_QUOTA_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default group quota limits
|
||||
*
|
||||
* @return The xml root node in case of success, null otherwise
|
||||
*/
|
||||
public Node getGroupQuotasXML()
|
||||
{
|
||||
OneResponse r = getGroupQuotas();
|
||||
Node xml = null;
|
||||
|
||||
if (r.isError())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DocumentBuilder builder =
|
||||
DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document doc = builder.parse(
|
||||
new ByteArrayInputStream(r.getMessage().getBytes()));
|
||||
|
||||
xml = doc.getDocumentElement();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default group quota limits
|
||||
*
|
||||
* @param quota a template (XML or txt) with the new quota limits
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse setGroupQuotas(String quota)
|
||||
{
|
||||
return client.call(GROUP_QUOTA_UPDATE, quota);
|
||||
}
|
||||
}
|
||||
@@ -47,10 +47,10 @@ public class Image extends PoolElement
|
||||
{"init", "rdy", "used", "disa", "lock", "err", "clon", "dele", "used"};
|
||||
|
||||
private static final String[] IMAGE_TYPES =
|
||||
{"OS", "CDROM", "DATABLOCK", "FILE"};
|
||||
{"OS", "CDROM", "DATABLOCK", "KERNEL", "RAMDISK", "CONTEXT"};
|
||||
|
||||
private static final String[] SHORT_IMAGE_TYPES =
|
||||
{"OS", "CD", "DB", "FL"};
|
||||
{"OS", "CD", "DB", "KL", "RD", "CX"};
|
||||
|
||||
/**
|
||||
* Creates a new Image representation.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -15,6 +15,10 @@
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
@@ -22,8 +26,10 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.OneSystem;
|
||||
import org.opennebula.client.group.Group;
|
||||
import org.opennebula.client.group.GroupPool;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class GroupTest
|
||||
{
|
||||
@@ -63,7 +69,7 @@ public class GroupTest
|
||||
{
|
||||
res = Group.allocate(client, group_name);
|
||||
|
||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
group = new Group(group_id, client);
|
||||
}
|
||||
|
||||
@@ -84,7 +90,7 @@ public class GroupTest
|
||||
res = Group.allocate(client, group_name);
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
group = new Group(group_id, client);
|
||||
|
||||
|
||||
@@ -130,6 +136,30 @@ public class GroupTest
|
||||
assertTrue( !found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultqutoas()
|
||||
{
|
||||
OneSystem system = new OneSystem(client);
|
||||
|
||||
res = system.getGroupQuotas();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = system.setGroupQuotas("VM = [ VMS = 7, MEMORY = 0, CPU = 3]");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
Node node = system.getGroupQuotasXML();
|
||||
XPathFactory factory = XPathFactory.newInstance();
|
||||
XPath xpath = factory.newXPath();
|
||||
|
||||
try
|
||||
{
|
||||
assertTrue( xpath.evaluate("VM_QUOTA/VM/VMS", node).equals("7") );
|
||||
} catch (XPathExpressionException e)
|
||||
{
|
||||
assertTrue(e.getMessage(), false);
|
||||
}
|
||||
}
|
||||
|
||||
// Commented out, secondary groups do not exist any more
|
||||
/*
|
||||
@Test
|
||||
@@ -185,17 +215,17 @@ public class GroupTest
|
||||
assertTrue( users.get("a").isPartOf( groups.get("b").id() ) );
|
||||
assertFalse( users.get("a").isPartOf( groups.get("c").id() ) );
|
||||
assertFalse( users.get("a").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
|
||||
assertFalse( users.get("b").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("b").isPartOf( groups.get("b").id() ) );
|
||||
assertFalse( users.get("b").isPartOf( groups.get("c").id() ) );
|
||||
assertFalse( users.get("b").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
|
||||
assertFalse( users.get("c").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("c").isPartOf( groups.get("b").id() ) );
|
||||
assertTrue( users.get("c").isPartOf( groups.get("c").id() ) );
|
||||
assertTrue( users.get("c").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
|
||||
assertFalse( users.get("d").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("d").isPartOf( groups.get("b").id() ) );
|
||||
assertTrue( users.get("d").isPartOf( groups.get("c").id() ) );
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -15,6 +15,10 @@
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
@@ -22,8 +26,10 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.OneSystem;
|
||||
import org.opennebula.client.user.User;
|
||||
import org.opennebula.client.user.UserPool;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class UserTest
|
||||
{
|
||||
@@ -98,7 +104,7 @@ public class UserTest
|
||||
{
|
||||
res = user.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
|
||||
assertTrue( user.id() >= 0 );
|
||||
assertTrue( user.getName().equals(name) );
|
||||
}
|
||||
@@ -158,4 +164,28 @@ public class UserTest
|
||||
res = user.info();
|
||||
assertTrue( res.getErrorMessage(), res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultqutoas()
|
||||
{
|
||||
OneSystem system = new OneSystem(client);
|
||||
|
||||
res = system.getUserQuotas();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = system.setUserQuotas("VM = [ VMS = 7, MEMORY = 0, CPU = 3]");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
Node node = system.getUserQuotasXML();
|
||||
XPathFactory factory = XPathFactory.newInstance();
|
||||
XPath xpath = factory.newXPath();
|
||||
|
||||
try
|
||||
{
|
||||
assertTrue( xpath.evaluate("VM_QUOTA/VM/VMS", node).equals("7") );
|
||||
} catch (XPathExpressionException e)
|
||||
{
|
||||
assertTrue(e.getMessage(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ require 'OpenNebula/Cluster'
|
||||
require 'OpenNebula/ClusterPool'
|
||||
require 'OpenNebula/Document'
|
||||
require 'OpenNebula/DocumentPool'
|
||||
require 'OpenNebula/System'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
||||
@@ -52,13 +52,15 @@ module OpenNebula
|
||||
"USED_PERS" => "used"
|
||||
}
|
||||
|
||||
IMAGE_TYPES=%w{OS CDROM DATABLOCK FILE}
|
||||
IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT}
|
||||
|
||||
SHORT_IMAGE_TYPES={
|
||||
"OS" => "OS",
|
||||
"CDROM" => "CD",
|
||||
"DATABLOCK" => "DB",
|
||||
"FILE" => "FL"
|
||||
"KERNEL" => "KL",
|
||||
"RAMDISK" => "RD",
|
||||
"CONTEXT" => "CX"
|
||||
}
|
||||
|
||||
# Creates an Image description with just its identifier
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'OpenNebula/Pool'
|
||||
|
||||
module OpenNebula
|
||||
class System
|
||||
#######################################################################
|
||||
# Constants and Class attribute accessors
|
||||
#######################################################################
|
||||
|
||||
SYSTEM_METHODS = {
|
||||
:userquotainfo => "userquota.info",
|
||||
:userquotaupdate => "userquota.update",
|
||||
:groupquotainfo => "groupquota.info",
|
||||
:groupquotaupdate => "groupquota.update"
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# Class constructor
|
||||
#######################################################################
|
||||
|
||||
# Constructor
|
||||
# @param [Client] client that represents a XML-RPC connection
|
||||
def initialize(client)
|
||||
@client = client
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods
|
||||
#######################################################################
|
||||
|
||||
# Gets the default user quota limits
|
||||
#
|
||||
# @return [XMLElement, OpenNebula::Error] the default user quota in case
|
||||
# of success, Error otherwise
|
||||
def get_user_quotas()
|
||||
rc = @client.call(SYSTEM_METHODS[:userquotainfo])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
default_quotas = XMLElement.new
|
||||
default_quotas.initialize_xml(rc, 'DEFAULT_USER_QUOTAS')
|
||||
|
||||
return default_quotas
|
||||
end
|
||||
|
||||
# Sets the default user quota limits
|
||||
# @param quota [String] a template (XML or txt) with the new quota limits
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def set_user_quotas(quota)
|
||||
return @client.call(SYSTEM_METHODS[:userquotaupdate], quota)
|
||||
end
|
||||
|
||||
# Gets the default group quota limits
|
||||
#
|
||||
# @return [XMLElement, OpenNebula::Error] the default group quota in case
|
||||
# of success, Error otherwise
|
||||
def get_group_quotas()
|
||||
rc = @client.call(SYSTEM_METHODS[:groupquotainfo])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
default_quotas = XMLElement.new
|
||||
default_quotas.initialize_xml(rc, 'DEFAULT_GROUP_QUOTAS')
|
||||
|
||||
return default_quotas
|
||||
end
|
||||
|
||||
# Sets the default group quota limits
|
||||
# @param quota [String] a template (XML or txt) with the new quota limits
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def set_group_quotas(quota)
|
||||
return @client.call(SYSTEM_METHODS[:groupquotaupdate], quota)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -79,12 +79,18 @@ module OpenNebula
|
||||
|
||||
return doc
|
||||
end
|
||||
# Extract an element from the XML description of the PoolElement.
|
||||
# key::_String_ The name of the element
|
||||
# [return] _String_ the value of the element
|
||||
# Examples:
|
||||
# ['VID'] # gets VM id
|
||||
# ['HISTORY/HOSTNAME'] # get the hostname from the history
|
||||
|
||||
# Extract a text element from the XML description of the PoolElement.
|
||||
#
|
||||
# @param [String] key Xpath expression
|
||||
#
|
||||
# @return [String, nil] If a text element is found, the element's
|
||||
# text value. Otherwise, an empty string or nil, depending
|
||||
# on the backend
|
||||
#
|
||||
# @example
|
||||
# vm['VID'] # gets VM id
|
||||
# vm['HISTORY/HOSTNAME'] # get the hostname from the history
|
||||
def [](key)
|
||||
if NOKOGIRI
|
||||
element=@xml.xpath(key.to_s)
|
||||
|
||||
@@ -112,6 +112,153 @@ module Migrator
|
||||
@db.run("DROP TABLE image_pool")
|
||||
@db.run("ALTER TABLE image_pool_new RENAME TO image_pool")
|
||||
|
||||
########################################################################
|
||||
# Feature #1617
|
||||
# New datastore, 2 "files"
|
||||
# DATASTORE/SYSTEM is now DATASTORE/TYPE
|
||||
########################################################################
|
||||
|
||||
@db.run "ALTER TABLE datastore_pool RENAME TO old_datastore_pool;"
|
||||
@db.run "CREATE TABLE datastore_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
|
||||
|
||||
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
|
||||
doc = Document.new(row[:body])
|
||||
|
||||
type = "0" # IMAGE_DS
|
||||
|
||||
system_elem = doc.root.delete_element("SYSTEM")
|
||||
|
||||
if ( !system_elem.nil? && system_elem.text == "1" )
|
||||
type = "1" # SYSTEM_DS
|
||||
end
|
||||
|
||||
doc.root.add_element("TYPE").text = type
|
||||
|
||||
doc.root.each_element("TEMPLATE") do |e|
|
||||
e.delete_element("SYSTEM")
|
||||
e.add_element("TYPE").text = type == "0" ? "IMAGE_DS" : "SYSTEM_DS"
|
||||
end
|
||||
|
||||
@db[:datastore_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => doc.root.to_s,
|
||||
:uid => row[:uid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.run "DROP TABLE old_datastore_pool;"
|
||||
|
||||
|
||||
user_0_name = "oneadmin"
|
||||
|
||||
@db.fetch("SELECT name FROM user_pool WHERE oid=0") do |row|
|
||||
user_0_name = row[:name]
|
||||
end
|
||||
|
||||
group_0_name = "oneadmin"
|
||||
|
||||
@db.fetch("SELECT name FROM group_pool WHERE oid=0") do |row|
|
||||
group_0_name = row[:name]
|
||||
end
|
||||
|
||||
base_path = "/var/lib/one/datastores/2"
|
||||
|
||||
@db.fetch("SELECT body FROM datastore_pool WHERE oid=0") do |row|
|
||||
doc = Document.new(row[:body])
|
||||
|
||||
doc.root.each_element("BASE_PATH") do |e|
|
||||
base_path = e.text
|
||||
base_path[-1] = "2"
|
||||
end
|
||||
end
|
||||
|
||||
@db.run "INSERT INTO datastore_pool VALUES(2,'files','<DATASTORE><ID>2</ID><UID>0</UID><GID>0</GID><UNAME>#{user_0_name}</UNAME><GNAME>#{group_0_name}</GNAME><NAME>files</NAME><PERMISSIONS><OWNER_U>1</OWNER_U><OWNER_M>1</OWNER_M><OWNER_A>0</OWNER_A><GROUP_U>1</GROUP_U><GROUP_M>0</GROUP_M><GROUP_A>0</GROUP_A><OTHER_U>1</OTHER_U><OTHER_M>0</OTHER_M><OTHER_A>0</OTHER_A></PERMISSIONS><DS_MAD>fs</DS_MAD><TM_MAD>ssh</TM_MAD><BASE_PATH>#{base_path}</BASE_PATH><TYPE>2</TYPE><DISK_TYPE>0</DISK_TYPE><CLUSTER_ID>-1</CLUSTER_ID><CLUSTER></CLUSTER><IMAGES></IMAGES><TEMPLATE><DS_MAD><![CDATA[fs]]></DS_MAD><TM_MAD><![CDATA[ssh]]></TM_MAD><TYPE><![CDATA[FILE_DS]]></TYPE></TEMPLATE></DATASTORE>',0,0,1,1,1);"
|
||||
|
||||
|
||||
########################################################################
|
||||
# Feature #1611: Default quotas
|
||||
########################################################################
|
||||
|
||||
@db.run("CREATE TABLE IF NOT EXISTS system_attributes (name VARCHAR(128) PRIMARY KEY, body TEXT)")
|
||||
@db.run("INSERT INTO system_attributes VALUES('DEFAULT_GROUP_QUOTAS','<DEFAULT_GROUP_QUOTAS><DATASTORE_QUOTA></DATASTORE_QUOTA><NETWORK_QUOTA></NETWORK_QUOTA><VM_QUOTA></VM_QUOTA><IMAGE_QUOTA></IMAGE_QUOTA></DEFAULT_GROUP_QUOTAS>');")
|
||||
@db.run("INSERT INTO system_attributes VALUES('DEFAULT_USER_QUOTAS','<DEFAULT_USER_QUOTAS><DATASTORE_QUOTA></DATASTORE_QUOTA><NETWORK_QUOTA></NETWORK_QUOTA><VM_QUOTA></VM_QUOTA><IMAGE_QUOTA></IMAGE_QUOTA></DEFAULT_USER_QUOTAS>');")
|
||||
|
||||
|
||||
@db.run "ALTER TABLE user_pool RENAME TO old_user_pool;"
|
||||
@db.run "CREATE TABLE user_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
|
||||
|
||||
# oneadmin does not have quotas
|
||||
@db.fetch("SELECT * FROM old_user_pool WHERE oid=0") do |row|
|
||||
@db[:user_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => row[:body],
|
||||
:uid => row[:oid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.fetch("SELECT * FROM old_user_pool WHERE oid>0") do |row|
|
||||
doc = Document.new(row[:body])
|
||||
|
||||
set_default_quotas(doc)
|
||||
|
||||
@db[:user_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => doc.root.to_s,
|
||||
:uid => row[:oid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.run "DROP TABLE old_user_pool;"
|
||||
|
||||
|
||||
@db.run "ALTER TABLE group_pool RENAME TO old_group_pool;"
|
||||
@db.run "CREATE TABLE group_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
|
||||
|
||||
|
||||
# oneadmin group does not have quotas
|
||||
@db.fetch("SELECT * FROM old_group_pool WHERE oid=0") do |row|
|
||||
@db[:group_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => row[:body],
|
||||
:uid => row[:oid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.fetch("SELECT * FROM old_group_pool WHERE oid>0") do |row|
|
||||
doc = Document.new(row[:body])
|
||||
|
||||
set_default_quotas(doc)
|
||||
|
||||
@db[:group_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => doc.root.to_s,
|
||||
:uid => row[:oid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.run "DROP TABLE old_group_pool;"
|
||||
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Banner for the new /var/lib/one/vms directory
|
||||
@@ -130,4 +277,44 @@ module Migrator
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
def set_default_quotas(doc)
|
||||
|
||||
# VM quotas
|
||||
|
||||
doc.root.each_element("VM_QUOTA/VM/CPU") do |e|
|
||||
e.text = "-1" if e.text.to_f == 0
|
||||
end
|
||||
|
||||
doc.root.each_element("VM_QUOTA/VM/MEMORY") do |e|
|
||||
e.text = "-1" if e.text.to_i == 0
|
||||
end
|
||||
|
||||
doc.root.each_element("VM_QUOTA/VM/VMS") do |e|
|
||||
e.text = "-1" if e.text.to_i == 0
|
||||
end
|
||||
|
||||
# VNet quotas
|
||||
|
||||
doc.root.each_element("NETWORK_QUOTA/NETWORK/LEASES") do |e|
|
||||
e.text = "-1" if e.text.to_i == 0
|
||||
end
|
||||
|
||||
# Image quotas
|
||||
|
||||
doc.root.each_element("IMAGE_QUOTA/IMAGE/RVMS") do |e|
|
||||
e.text = "-1" if e.text.to_i == 0
|
||||
end
|
||||
|
||||
# Datastore quotas
|
||||
|
||||
doc.root.each_element("DATASTORE_QUOTA/DATASTORE/IMAGES") do |e|
|
||||
e.text = "-1" if e.text.to_i == 0
|
||||
end
|
||||
|
||||
doc.root.each_element("DATASTORE_QUOTA/DATASTORE/SIZE") do |e|
|
||||
e.text = "-1" if e.text.to_i == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
+6
-2
@@ -278,7 +278,9 @@ bool Request::user_quota_authorization (Template * tmpl,
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = user->quota.quota_check(qtype, tmpl, error_str);
|
||||
Quotas default_user_quotas = nd.get_default_user_quota();
|
||||
|
||||
rc = user->quota.quota_check(qtype, tmpl, default_user_quotas, error_str);
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
@@ -320,7 +322,9 @@ bool Request::group_quota_authorization (Template * tmpl,
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = group->quota.quota_check(qtype, tmpl, error_str);
|
||||
Quotas default_group_quotas = nd.get_default_group_quota();
|
||||
|
||||
rc = group->quota.quota_check(qtype, tmpl, default_group_quotas, error_str);
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
|
||||
@@ -368,6 +368,12 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr system_version(new SystemVersion());
|
||||
xmlrpc_c::methodPtr system_config(new SystemConfig());
|
||||
|
||||
xmlrpc_c::methodPtr user_get_default_quota(new UserQuotaInfo());
|
||||
xmlrpc_c::methodPtr user_set_default_quota(new UserQuotaUpdate());
|
||||
|
||||
xmlrpc_c::methodPtr group_get_default_quota(new GroupQuotaInfo());
|
||||
xmlrpc_c::methodPtr group_set_default_quota(new GroupQuotaUpdate());
|
||||
|
||||
/* VM related methods */
|
||||
RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy);
|
||||
RequestManagerRegistry.addMethod("one.vm.action", vm_action);
|
||||
@@ -416,6 +422,9 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.groupquota.info", group_get_default_quota);
|
||||
RequestManagerRegistry.addMethod("one.groupquota.update", group_set_default_quota);
|
||||
|
||||
/* Network related methods*/
|
||||
RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases);
|
||||
RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases);
|
||||
@@ -441,6 +450,9 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.user.quota", user_set_quota);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.userquota.info", user_get_default_quota);
|
||||
RequestManagerRegistry.addMethod("one.userquota.update", user_set_default_quota);
|
||||
|
||||
/* Image related methods*/
|
||||
RequestManagerRegistry.addMethod("one.image.persistent", image_persistent);
|
||||
@@ -500,8 +512,6 @@ void RequestManager::register_xml_methods()
|
||||
/* System related methods */
|
||||
RequestManagerRegistry.addMethod("one.system.version", system_version);
|
||||
RequestManagerRegistry.addMethod("one.system.config", system_config);
|
||||
|
||||
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -87,12 +87,20 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( image->get_type() == Image::DATAFILE )
|
||||
switch (image->get_type())
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("FILE images must be non-persistent",""), att);
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
break;
|
||||
|
||||
image->unlock();
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
failure_response(ACTION,
|
||||
request_error("KERNEL, RAMDISK and CONTEXT files must be "
|
||||
"non-persistent",""), att);
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -132,6 +140,8 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
string type = xmlrpc_c::value_string(paramList.getString(2));
|
||||
int rc;
|
||||
|
||||
Image::ImageType itype;
|
||||
|
||||
Image * image;
|
||||
string err_msg;
|
||||
|
||||
@@ -151,15 +161,43 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( image->get_type() == Image::DATAFILE )
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("Only FILE images can be stored in a FILE_DS"
|
||||
" datastore.",""),
|
||||
att);
|
||||
itype = Image::str_to_type(type);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
switch (image->get_type())
|
||||
{
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
if ((itype != Image::OS) &&
|
||||
(itype != Image::DATABLOCK)&&
|
||||
(itype != Image::CDROM) )
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("Cannot change image type to an incompatible"
|
||||
" type for the current datastore.",""),
|
||||
att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
if ((itype != Image::KERNEL) &&
|
||||
(itype != Image::RAMDISK)&&
|
||||
(itype != Image::CONTEXT) )
|
||||
{
|
||||
failure_response(ACTION,
|
||||
request_error("Cannot change image type to an incompatible"
|
||||
" type for the current datastore.",""),
|
||||
att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rc = image->set_type(type);
|
||||
@@ -220,14 +258,20 @@ void ImageClone::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
if ( img->get_type() == Image::DATAFILE )
|
||||
switch (img->get_type())
|
||||
{
|
||||
failure_response(ACTION,
|
||||
allocate_error("Image of type FILE cannot be clonned"),
|
||||
att);
|
||||
|
||||
img->unlock();
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
break;
|
||||
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
failure_response(ACTION,
|
||||
allocate_error("KERNEL, RAMDISK and CONTEXT files cannot be "
|
||||
"cloned."), att);
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,3 +56,102 @@ void SystemConfig::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void UserQuotaInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
string xml;
|
||||
|
||||
success_response(Nebula::instance().get_default_user_quota().to_xml(xml), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void GroupQuotaInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
string xml;
|
||||
|
||||
success_response(Nebula::instance().get_default_group_quota().to_xml(xml), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void QuotaUpdate::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
string quota_str = xmlrpc_c::value_string(paramList.getString(1));
|
||||
string error_str, xml;
|
||||
Template quota_tmpl;
|
||||
|
||||
int rc;
|
||||
|
||||
if ( att.gid != GroupPool::ONEADMIN_ID )
|
||||
{
|
||||
failure_response(AUTHORIZATION,
|
||||
"The default quotas can only be updated by users in the oneadmin group",
|
||||
att);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = quota_tmpl.parse_str_or_xml(quota_str, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(ACTION, request_error(error_str,""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = set_default_quota("a_tmpl, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(ACTION, request_error(error_str,""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(get_default_quota()->to_xml(xml), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int UserQuotaUpdate::set_default_quota(Template *tmpl, string& error)
|
||||
{
|
||||
return Nebula::instance().set_default_user_quota(tmpl, error);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const DefaultQuotas * UserQuotaUpdate::get_default_quota()
|
||||
{
|
||||
return &Nebula::instance().get_default_user_quota();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int GroupQuotaUpdate::set_default_quota(Template *tmpl, string& error)
|
||||
{
|
||||
return Nebula::instance().set_default_group_quota(tmpl, error);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const DefaultQuotas * GroupQuotaUpdate::get_default_quota()
|
||||
{
|
||||
return &Nebula::instance().get_default_group_quota();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -641,11 +641,19 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
return;
|
||||
}
|
||||
|
||||
if ( type == Image::DATAFILE )
|
||||
switch (type)
|
||||
{
|
||||
failure_response(INTERNAL,
|
||||
request_error("Cannot save_as image of type FILE", ""),
|
||||
att);
|
||||
case Image::OS:
|
||||
case Image::DATABLOCK:
|
||||
case Image::CDROM:
|
||||
break;
|
||||
|
||||
case Image::KERNEL:
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
failure_response(INTERNAL,
|
||||
request_error("Cannot save_as image of type " + Image::type_to_str(type), ""),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
policy(vm);
|
||||
|
||||
if(priority.empty()!=true)
|
||||
if(!priority.empty())
|
||||
{
|
||||
sw.max = fabs(*max_element(
|
||||
priority.begin(),
|
||||
|
||||
@@ -538,7 +538,7 @@ Attribute * Template::single_xml_att(const xmlNode * node)
|
||||
Attribute * attr = 0;
|
||||
xmlNode * child = node->children;
|
||||
|
||||
if( child->next == 0 && child != 0 &&
|
||||
if( child != 0 && child->next == 0 &&
|
||||
(child->type == XML_TEXT_NODE ||
|
||||
child->type == XML_CDATA_SECTION_NODE))
|
||||
{
|
||||
|
||||
@@ -1553,8 +1553,8 @@ void TransferManager::migrate_transfer_command(
|
||||
|
||||
xfr << "MIGRATE " //TM action PRE or POST to be completed by VMM driver
|
||||
<< vm->get_tm_mad() << " "
|
||||
<< vm->get_hostname() << " "
|
||||
<< vm->get_previous_hostname() << " "
|
||||
<< vm->get_hostname() << " "
|
||||
<< vm->get_remote_system_dir() << " "
|
||||
<< vm->get_oid() << " "
|
||||
<< vm->get_ds_id()
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "DefaultQuotas.h"
|
||||
#include "ObjectXML.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& DefaultQuotas::to_xml(string& xml) const
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
string aux_xml;
|
||||
|
||||
oss << "<" << root_elem << ">"
|
||||
<< Quotas::to_xml(aux_xml)
|
||||
<< "</" << root_elem << ">";
|
||||
|
||||
xml = oss.str();
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DefaultQuotas::from_xml(const string& xml)
|
||||
{
|
||||
ObjectXML *object_xml = new ObjectXML(xml);
|
||||
|
||||
int rc = Quotas::from_xml(object_xml);
|
||||
|
||||
delete object_xml;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DefaultQuotas::select()
|
||||
{
|
||||
string xml_body;
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
if ( nd.select_sys_attribute(root_elem, xml_body) != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return from_xml(xml_body);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DefaultQuotas::insert()
|
||||
{
|
||||
string xml_body;
|
||||
string error;
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
return nd.insert_sys_attribute(root_elem, to_xml(xml_body), error);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DefaultQuotas::update()
|
||||
{
|
||||
string xml_body;
|
||||
string error;
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
return nd.update_sys_attribute(root_elem, to_xml(xml_body), error);
|
||||
}
|
||||
+68
-50
@@ -120,12 +120,12 @@ int Quota::set(vector<Attribute*> * new_quotas, string& error)
|
||||
if (update_limits(tq, iq) != 0)
|
||||
{
|
||||
goto error_limits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup_quota(id);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
error_limits:
|
||||
@@ -141,20 +141,22 @@ error_limits:
|
||||
|
||||
delete quota_str;
|
||||
}
|
||||
|
||||
|
||||
error = oss.str();
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool Quota::check_quota(const string& qid,
|
||||
bool Quota::check_quota(const string& qid,
|
||||
map<string, float>& usage_req,
|
||||
Quotas& default_quotas,
|
||||
string& error)
|
||||
{
|
||||
VectorAttribute * q;
|
||||
VectorAttribute * default_q;
|
||||
map<string, float>::iterator it;
|
||||
|
||||
bool check;
|
||||
@@ -171,43 +173,36 @@ bool Quota::check_quota(const string& qid,
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( get_default_quota(qid, default_quotas, &default_q) == -1 )
|
||||
{
|
||||
default_q = 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Quota does not exist, create a new one
|
||||
// -------------------------------------------------------------------------
|
||||
if ( q == 0 )
|
||||
{
|
||||
map<string, string> values;
|
||||
|
||||
|
||||
for (int i=0; i < num_metrics; i++)
|
||||
{
|
||||
ostringstream usage_req_str;
|
||||
string metrics_used = metrics[i];
|
||||
string metrics_used = metrics[i];
|
||||
|
||||
metrics_used += "_USED";
|
||||
|
||||
it = usage_req.find(metrics[i]);
|
||||
|
||||
if (it == usage_req.end())
|
||||
{
|
||||
usage_req_str << "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
usage_req_str << it->second;
|
||||
}
|
||||
|
||||
values.insert(make_pair(metrics[i], "0"));
|
||||
values.insert(make_pair(metrics_used, usage_req_str.str()));
|
||||
values.insert(make_pair(metrics[i], "-1"));
|
||||
values.insert(make_pair(metrics_used, "0"));
|
||||
}
|
||||
|
||||
|
||||
if (!qid.empty())
|
||||
{
|
||||
values.insert(make_pair("ID", qid));
|
||||
}
|
||||
|
||||
add(new VectorAttribute(template_name, values));
|
||||
q = new VectorAttribute(template_name, values);
|
||||
|
||||
return true;
|
||||
add(q);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -216,7 +211,7 @@ bool Quota::check_quota(const string& qid,
|
||||
for (int i=0; i < num_metrics; i++)
|
||||
{
|
||||
string metrics_used = metrics[i];
|
||||
|
||||
|
||||
metrics_used += "_USED";
|
||||
|
||||
it = usage_req.find(metrics[i]);
|
||||
@@ -229,6 +224,18 @@ bool Quota::check_quota(const string& qid,
|
||||
q->vector_value(metrics[i], limit);
|
||||
q->vector_value(metrics_used.c_str(), usage);
|
||||
|
||||
if ( limit == -1 )
|
||||
{
|
||||
if ( default_q != 0 )
|
||||
{
|
||||
default_q->vector_value(metrics[i], limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
}
|
||||
|
||||
check = ( limit == 0 ) || ( ( usage + it->second ) <= limit );
|
||||
|
||||
if ( !check )
|
||||
@@ -238,7 +245,7 @@ bool Quota::check_quota(const string& qid,
|
||||
oss << "limit of " << limit << " reached for " << metrics[i]
|
||||
<< " quota in " << template_name;
|
||||
|
||||
if ( !qid.empty() )
|
||||
if ( !qid.empty() )
|
||||
{
|
||||
oss << " with ID: " << qid;
|
||||
}
|
||||
@@ -255,7 +262,7 @@ bool Quota::check_quota(const string& qid,
|
||||
for (int i=0; i < num_metrics; i++)
|
||||
{
|
||||
string metrics_used = metrics[i];
|
||||
|
||||
|
||||
metrics_used += "_USED";
|
||||
|
||||
it = usage_req.find(metrics[i]);
|
||||
@@ -287,12 +294,12 @@ void Quota::del_quota(const string& qid, map<string, float>& usage_req)
|
||||
if ( q == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i < num_metrics; i++)
|
||||
{
|
||||
string metrics_used = metrics[i];
|
||||
|
||||
|
||||
metrics_used += "_USED";
|
||||
|
||||
it = usage_req.find(metrics[i]);
|
||||
@@ -316,8 +323,7 @@ void Quota::cleanup_quota(const string& qid)
|
||||
VectorAttribute * q;
|
||||
map<string, Attribute *>::iterator q_it;
|
||||
|
||||
float limit, limit_tmp;
|
||||
float usage, usage_tmp;
|
||||
float usage, limit, implicit_limit;
|
||||
|
||||
if ( get_quota(qid, &q, q_it) == -1)
|
||||
{
|
||||
@@ -329,8 +335,14 @@ void Quota::cleanup_quota(const string& qid)
|
||||
return;
|
||||
}
|
||||
|
||||
limit = 0;
|
||||
usage = 0;
|
||||
if ( is_default )
|
||||
{
|
||||
implicit_limit = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
implicit_limit = -1;
|
||||
}
|
||||
|
||||
for (int i=0; i < num_metrics; i++)
|
||||
{
|
||||
@@ -338,26 +350,27 @@ void Quota::cleanup_quota(const string& qid)
|
||||
|
||||
metrics_used += "_USED";
|
||||
|
||||
q->vector_value(metrics[i], limit_tmp);
|
||||
q->vector_value(metrics_used.c_str(), usage_tmp);
|
||||
q->vector_value(metrics[i], limit);
|
||||
q->vector_value(metrics_used.c_str(), usage);
|
||||
|
||||
limit += limit_tmp;
|
||||
usage += usage_tmp;
|
||||
if ( usage != 0 || limit != implicit_limit )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( limit == 0 && usage == 0 )
|
||||
{
|
||||
delete static_cast<Attribute *>(q_it->second);
|
||||
delete static_cast<Attribute *>(q_it->second);
|
||||
|
||||
attributes.erase(q_it);
|
||||
}
|
||||
attributes.erase(q_it);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Quota::update_limits(VectorAttribute * quota, const VectorAttribute * va)
|
||||
{
|
||||
int Quota::update_limits(
|
||||
VectorAttribute * quota,
|
||||
const VectorAttribute * va)
|
||||
{
|
||||
string limit;
|
||||
float limit_i;
|
||||
|
||||
@@ -365,7 +378,10 @@ int Quota::update_limits(VectorAttribute * quota, const VectorAttribute * va)
|
||||
{
|
||||
limit = va->vector_value_str(metrics[i], limit_i);
|
||||
|
||||
if ( limit_i < 0 ) //No quota, NaN or negative
|
||||
//No quota, NaN or negative
|
||||
if ((!is_default &&
|
||||
( limit_i < -1 || ( limit_i == -1 && limit == "" ))) ||
|
||||
(is_default && limit_i < 0) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -374,7 +390,7 @@ int Quota::update_limits(VectorAttribute * quota, const VectorAttribute * va)
|
||||
quota->replace(metrics[i], limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -391,14 +407,16 @@ VectorAttribute * Quota::new_quota(VectorAttribute * va)
|
||||
for (int i=0; i < num_metrics; i++)
|
||||
{
|
||||
string metrics_used = metrics[i];
|
||||
|
||||
|
||||
metrics_used += "_USED";
|
||||
|
||||
limit = va->vector_value_str(metrics[i], limit_i);
|
||||
|
||||
if ( limit_i < 0 ) //No quota, NaN or negative
|
||||
|
||||
//No quota, NaN or negative
|
||||
if ( (!is_default && limit_i < -1) ||
|
||||
(is_default && limit_i < 0) )
|
||||
{
|
||||
limit = "0";
|
||||
return 0;
|
||||
}
|
||||
|
||||
limits.insert(make_pair(metrics[i], limit));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "QuotaDatastore.h"
|
||||
#include "Quotas.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -26,7 +27,7 @@ const int QuotaDatastore::NUM_DS_METRICS = 2;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaDatastore::check(Template * tmpl, string& error)
|
||||
bool QuotaDatastore::check(Template * tmpl, Quotas& default_quotas, string& error)
|
||||
{
|
||||
map<string, float> ds_request;
|
||||
|
||||
@@ -49,8 +50,8 @@ bool QuotaDatastore::check(Template * tmpl, string& error)
|
||||
|
||||
ds_request.insert(make_pair("IMAGES",1));
|
||||
ds_request.insert(make_pair("SIZE", size));
|
||||
|
||||
return check_quota(ds_id, ds_request, error);
|
||||
|
||||
return check_quota(ds_id, ds_request, default_quotas, error);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -83,3 +84,14 @@ void QuotaDatastore::del(Template * tmpl)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaDatastore::get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va)
|
||||
{
|
||||
return default_quotas.ds_get(id, va);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
+16
-4
@@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "QuotaImage.h"
|
||||
#include "Quotas.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -26,7 +27,7 @@ const int QuotaImage::NUM_IMAGE_METRICS = 1;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaImage::check(Template * tmpl, string& error)
|
||||
bool QuotaImage::check(Template * tmpl, Quotas& default_quotas, string& error)
|
||||
{
|
||||
vector<Attribute*> disks;
|
||||
VectorAttribute * disk;
|
||||
@@ -50,10 +51,10 @@ bool QuotaImage::check(Template * tmpl, string& error)
|
||||
}
|
||||
|
||||
image_id = disk->vector_value("IMAGE_ID");
|
||||
|
||||
|
||||
if ( !image_id.empty() )
|
||||
{
|
||||
if ( !check_quota(image_id, image_request, error) )
|
||||
if ( !check_quota(image_id, image_request, default_quotas, error) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -91,10 +92,21 @@ void QuotaImage::del(Template * tmpl)
|
||||
}
|
||||
|
||||
image_id = disk->vector_value("IMAGE_ID");
|
||||
|
||||
|
||||
del_quota(image_id, image_request);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaImage::get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va)
|
||||
{
|
||||
return default_quotas.image_get(id, va);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
+15
-3
@@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "QuotaNetwork.h"
|
||||
#include "Quotas.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -26,7 +27,7 @@ const int QuotaNetwork::NUM_NET_METRICS = 1;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaNetwork::check(Template * tmpl, string& error)
|
||||
bool QuotaNetwork::check(Template * tmpl, Quotas& default_quotas, string& error)
|
||||
{
|
||||
vector<Attribute*> nics;
|
||||
VectorAttribute * nic;
|
||||
@@ -53,7 +54,7 @@ bool QuotaNetwork::check(Template * tmpl, string& error)
|
||||
|
||||
if ( !net_id.empty() )
|
||||
{
|
||||
if ( !check_quota(net_id, net_request, error) )
|
||||
if ( !check_quota(net_id, net_request, default_quotas, error) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -91,10 +92,21 @@ void QuotaNetwork::del(Template * tmpl)
|
||||
}
|
||||
|
||||
net_id = nic->vector_value("NETWORK_ID");
|
||||
|
||||
|
||||
del_quota(net_id, net_request);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaNetwork::get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va)
|
||||
{
|
||||
return default_quotas.network_get(id, va);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "QuotaVirtualMachine.h"
|
||||
#include "Quotas.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -48,7 +49,9 @@ int QuotaVirtualMachine::get_quota(const string& id, VectorAttribute **va)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool QuotaVirtualMachine::check(Template * tmpl, string& error)
|
||||
bool QuotaVirtualMachine::check(Template * tmpl,
|
||||
Quotas& default_quotas,
|
||||
string& error)
|
||||
{
|
||||
map<string, float> vm_request;
|
||||
|
||||
@@ -70,8 +73,8 @@ bool QuotaVirtualMachine::check(Template * tmpl, string& error)
|
||||
vm_request.insert(make_pair("VMS",1));
|
||||
vm_request.insert(make_pair("MEMORY", memory));
|
||||
vm_request.insert(make_pair("CPU", cpu));
|
||||
|
||||
return check_quota("", vm_request, error);
|
||||
|
||||
return check_quota("", vm_request, default_quotas, error);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -97,9 +100,20 @@ void QuotaVirtualMachine::del(Template * tmpl)
|
||||
vm_request.insert(make_pair("VMS",1));
|
||||
vm_request.insert(make_pair("MEMORY", memory));
|
||||
vm_request.insert(make_pair("CPU", cpu));
|
||||
|
||||
|
||||
del_quota("", vm_request);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int QuotaVirtualMachine::get_default_quota(
|
||||
const string& id,
|
||||
Quotas& default_quotas,
|
||||
VectorAttribute **va)
|
||||
{
|
||||
return default_quotas.vm_get(id, va);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
+11
-9
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "ObjectXML.h"
|
||||
|
||||
|
||||
int Quotas::set(Template *tmpl, string& error)
|
||||
{
|
||||
vector<Attribute *> vquotas;
|
||||
@@ -173,35 +172,38 @@ void Quotas::quota_del(QuotaType type, Template *tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool Quotas::quota_check(QuotaType type, Template *tmpl, string& error_str)
|
||||
bool Quotas::quota_check(QuotaType type,
|
||||
Template *tmpl,
|
||||
Quotas &default_quotas,
|
||||
string &error_str)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DATASTORE:
|
||||
return datastore_quota.check(tmpl, error_str);
|
||||
return datastore_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case NETWORK:
|
||||
return network_quota.check(tmpl, error_str);
|
||||
return network_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case IMAGE:
|
||||
return image_quota.check(tmpl, error_str);
|
||||
return image_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case VM:
|
||||
return vm_quota.check(tmpl, error_str);
|
||||
return vm_quota.check(tmpl, default_quotas, error_str);
|
||||
|
||||
case VIRTUALMACHINE:
|
||||
if ( network_quota.check(tmpl, error_str) == false )
|
||||
if ( network_quota.check(tmpl, default_quotas, error_str) == false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( vm_quota.check(tmpl, error_str) == false )
|
||||
if ( vm_quota.check(tmpl, default_quotas, error_str) == false )
|
||||
{
|
||||
network_quota.del(tmpl);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( image_quota.check(tmpl, error_str) == false )
|
||||
if ( image_quota.check(tmpl, default_quotas, error_str) == false )
|
||||
{
|
||||
network_quota.del(tmpl);
|
||||
vm_quota.del(tmpl);
|
||||
|
||||
+2
-1
@@ -29,7 +29,8 @@ source_files=[
|
||||
'QuotaNetwork.cc',
|
||||
'QuotaVirtualMachine.cc',
|
||||
'QuotaImage.cc',
|
||||
'Quotas.cc'
|
||||
'Quotas.cc',
|
||||
'DefaultQuotas.cc'
|
||||
]
|
||||
|
||||
# Build library
|
||||
|
||||
@@ -390,6 +390,7 @@ error_common:
|
||||
|
||||
int VirtualMachine::set_os_file(VectorAttribute * os,
|
||||
const string& base_name,
|
||||
Image::ImageType base_type,
|
||||
string& error_str)
|
||||
{
|
||||
vector<int> img_ids;
|
||||
@@ -398,6 +399,8 @@ int VirtualMachine::set_os_file(VectorAttribute * os,
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
Image * img = 0;
|
||||
|
||||
Image::ImageType type;
|
||||
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
Datastore * ds;
|
||||
int ds_id;
|
||||
@@ -437,6 +440,7 @@ int VirtualMachine::set_os_file(VectorAttribute * os,
|
||||
}
|
||||
|
||||
ds_id = img->get_ds_id();
|
||||
type = img->get_type();
|
||||
|
||||
os->remove(base_name);
|
||||
|
||||
@@ -446,6 +450,18 @@ int VirtualMachine::set_os_file(VectorAttribute * os,
|
||||
|
||||
img->unlock();
|
||||
|
||||
if ( type != base_type )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << base_name << " needs an image of type "
|
||||
<< Image::type_to_str(base_type) << " and not "
|
||||
<< Image::type_to_str(type);
|
||||
|
||||
error_str = oss.str();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds = ds_pool->get(ds_id, true);
|
||||
|
||||
if ( ds == 0 )
|
||||
@@ -496,14 +512,14 @@ int VirtualMachine::parse_os(string& error_str)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = set_os_file(os, "KERNEL", error_str);
|
||||
rc = set_os_file(os, "KERNEL", Image::KERNEL, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = set_os_file(os, "INITRD", error_str);
|
||||
rc = set_os_file(os, "INITRD", Image::RAMDISK, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -608,6 +624,8 @@ int VirtualMachine::parse_context(string& error_str)
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
Image * img = 0;
|
||||
|
||||
Image::ImageType type;
|
||||
|
||||
for ( it=img_ids.begin() ; it < img_ids.end(); it++ )
|
||||
{
|
||||
img = ipool->get(*it, true);
|
||||
@@ -615,8 +633,16 @@ int VirtualMachine::parse_context(string& error_str)
|
||||
if ( img != 0 )
|
||||
{
|
||||
oss_parsed << img->get_source() << " ";
|
||||
type = img->get_type();
|
||||
|
||||
img->unlock();
|
||||
|
||||
if (type != Image::CONTEXT)
|
||||
{
|
||||
error_str = "Only images of type CONTEXT can be used in"
|
||||
" FILE_DS attribute.";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,14 +196,6 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
img->get_permissions(perm);
|
||||
|
||||
if ( img->get_type() != Image::DATAFILE )
|
||||
{
|
||||
error_str = "FILE variables must use images of type FILE.";
|
||||
img->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
|
||||
AuthRequest ar(vm->get_uid(), vm->get_gid());
|
||||
@@ -226,7 +218,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
|
||||
/* Line 360 of yacc.c */
|
||||
#line 230 "vm_file_var_syntax.cc"
|
||||
#line 222 "vm_file_var_syntax.cc"
|
||||
|
||||
# ifndef YY_NULL
|
||||
# if defined __cplusplus && 201103L <= __cplusplus
|
||||
@@ -279,7 +271,7 @@ extern int vm_file_var__debug;
|
||||
typedef union YYSTYPE
|
||||
{
|
||||
/* Line 376 of yacc.c */
|
||||
#line 178 "vm_file_var_syntax.y"
|
||||
#line 170 "vm_file_var_syntax.y"
|
||||
|
||||
char * val_str;
|
||||
int val_int;
|
||||
@@ -287,7 +279,7 @@ typedef union YYSTYPE
|
||||
|
||||
|
||||
/* Line 376 of yacc.c */
|
||||
#line 291 "vm_file_var_syntax.cc"
|
||||
#line 283 "vm_file_var_syntax.cc"
|
||||
} YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
@@ -327,7 +319,7 @@ int vm_file_var__parse ();
|
||||
/* Copy the second part of user declarations. */
|
||||
|
||||
/* Line 379 of yacc.c */
|
||||
#line 331 "vm_file_var_syntax.cc"
|
||||
#line 323 "vm_file_var_syntax.cc"
|
||||
|
||||
#ifdef short
|
||||
# undef short
|
||||
@@ -618,7 +610,7 @@ static const yytype_int8 yyrhs[] =
|
||||
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
|
||||
static const yytype_uint8 yyrline[] =
|
||||
{
|
||||
0, 202, 202, 203, 207, 225
|
||||
0, 194, 194, 195, 199, 217
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1626,7 +1618,7 @@ yyreduce:
|
||||
{
|
||||
case 4:
|
||||
/* Line 1778 of yacc.c */
|
||||
#line 208 "vm_file_var_syntax.y"
|
||||
#line 200 "vm_file_var_syntax.y"
|
||||
{
|
||||
string file((yyvsp[(1) - (7)].val_str));
|
||||
string var1((yyvsp[(3) - (7)].val_str));
|
||||
@@ -1648,7 +1640,7 @@ yyreduce:
|
||||
|
||||
case 5:
|
||||
/* Line 1778 of yacc.c */
|
||||
#line 226 "vm_file_var_syntax.y"
|
||||
#line 218 "vm_file_var_syntax.y"
|
||||
{
|
||||
string file((yyvsp[(1) - (11)].val_str));
|
||||
string var1((yyvsp[(3) - (11)].val_str));
|
||||
@@ -1673,7 +1665,7 @@ yyreduce:
|
||||
|
||||
|
||||
/* Line 1778 of yacc.c */
|
||||
#line 1677 "vm_file_var_syntax.cc"
|
||||
#line 1669 "vm_file_var_syntax.cc"
|
||||
default: break;
|
||||
}
|
||||
/* User semantic actions sometimes alter yychar, and that requires
|
||||
@@ -1912,7 +1904,7 @@ yyreturn:
|
||||
|
||||
|
||||
/* Line 2041 of yacc.c */
|
||||
#line 247 "vm_file_var_syntax.y"
|
||||
#line 239 "vm_file_var_syntax.y"
|
||||
|
||||
|
||||
extern "C" void vm_file_var__error(
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* A Bison parser, made by GNU Bison 2.6.5. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
|
||||
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
@@ -63,7 +63,7 @@ extern int vm_file_var__debug;
|
||||
typedef union YYSTYPE
|
||||
{
|
||||
/* Line 2042 of yacc.c */
|
||||
#line 178 "vm_file_var_syntax.y"
|
||||
#line 170 "vm_file_var_syntax.y"
|
||||
|
||||
char * val_str;
|
||||
int val_int;
|
||||
|
||||
@@ -138,14 +138,6 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
img->get_permissions(perm);
|
||||
|
||||
if ( img->get_type() != Image::DATAFILE )
|
||||
{
|
||||
error_str = "FILE variables must use images of type FILE.";
|
||||
img->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
|
||||
AuthRequest ar(vm->get_uid(), vm->get_gid());
|
||||
|
||||
@@ -334,10 +334,7 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
|
||||
// ---- Disk type and source for the image ----
|
||||
|
||||
if (type.empty() == false)
|
||||
{
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
}
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
|
||||
if ( type == "BLOCK" )
|
||||
{
|
||||
@@ -548,13 +545,10 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
passwd = graphics->vector_value("PASSWD");
|
||||
keymap = graphics->vector_value("KEYMAP");
|
||||
|
||||
if (type.empty() != false)
|
||||
{
|
||||
transform(type.begin(),
|
||||
type.end(),
|
||||
type.begin(),
|
||||
(int(*)(int))tolower);
|
||||
}
|
||||
transform(type.begin(),
|
||||
type.end(),
|
||||
type.begin(),
|
||||
(int(*)(int))tolower);
|
||||
|
||||
if ( type == "vnc" || type == "spice" )
|
||||
{
|
||||
|
||||
@@ -214,10 +214,7 @@ int LibVirtDriver::deployment_description_vmware(
|
||||
}
|
||||
}
|
||||
|
||||
if (type.empty() == false)
|
||||
{
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
}
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
|
||||
// ---- Disk type and source for the image ----
|
||||
|
||||
|
||||
@@ -386,8 +386,8 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
int cpu = -1;
|
||||
int memory = -1;
|
||||
int net_tx = -1;
|
||||
int net_rx = -1;
|
||||
long long net_tx = -1;
|
||||
long long net_rx = -1;
|
||||
char state = '-';
|
||||
|
||||
string monitor_str = is.str();
|
||||
|
||||
@@ -248,10 +248,7 @@ int XenDriver::deployment_description(
|
||||
goto error_disk;
|
||||
}
|
||||
|
||||
if (type.empty() == false)
|
||||
{
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
}
|
||||
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
|
||||
|
||||
mode = "w";
|
||||
|
||||
|
||||
@@ -222,6 +222,74 @@ int ObjectXML::xpath(unsigned int& value, const char * xpath_expr,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ObjectXML::xpath(long long& value, const char * xpath_expr,
|
||||
const long long& def)
|
||||
{
|
||||
vector<string> values;
|
||||
int rc = 0;
|
||||
|
||||
values = (*this)[xpath_expr];
|
||||
|
||||
if (values.empty() == true)
|
||||
{
|
||||
value = def;
|
||||
rc = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
istringstream iss;
|
||||
|
||||
iss.str(values[0]);
|
||||
|
||||
iss >> dec >> value;
|
||||
|
||||
if (iss.fail() == true)
|
||||
{
|
||||
value = def;
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ObjectXML::xpath(unsigned long long& value, const char * xpath_expr,
|
||||
const unsigned long long& def)
|
||||
{
|
||||
vector<string> values;
|
||||
int rc = 0;
|
||||
|
||||
values = (*this)[xpath_expr];
|
||||
|
||||
if (values.empty() == true)
|
||||
{
|
||||
value = def;
|
||||
rc = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
istringstream iss;
|
||||
|
||||
iss.str(values[0]);
|
||||
|
||||
iss >> dec >> value;
|
||||
|
||||
if (iss.fail() == true)
|
||||
{
|
||||
value = def;
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ObjectXML::xpath(time_t& value, const char * xpath_expr, const time_t& def)
|
||||
{
|
||||
int int_val;
|
||||
|
||||
Reference in new issue
Block a user