2010-04-27 19:42:37 +04:00
/* ------------------------------------------------------------------------ */
2019-01-16 13:27:59 +03:00
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
2010-04-27 19:42:37 +04:00
/* */
/* 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. */
/* ------------------------------------------------------------------------ */
2008-06-17 20:27:32 +04:00
# ifndef HOST_SHARE_H_
# define HOST_SHARE_H_
2011-02-24 20:12:26 +03:00
# include "ObjectXML.h"
2013-10-22 17:42:51 +04:00
# include "Template.h"
2008-06-17 20:27:32 +04:00
# include <time.h>
2015-08-20 18:39:56 +03:00
# include <set>
2019-07-01 18:52:47 +03:00
# include <map>
2020-03-04 18:05:57 +03:00
# include "HostSharePCI.h"
# include "HostShareNUMA.h"
# include "HostShareDatastore.h"
# include "HostShareCapacity.h"
2019-07-01 18:52:47 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2016-11-05 23:14:38 +03:00
2008-06-17 20:27:32 +04:00
/**
* The HostShare class . It represents a logical partition of a host . . .
*/
2011-02-24 20:12:26 +03:00
class HostShare : public ObjectXML
2008-06-17 20:27:32 +04:00
{
public :
2019-07-01 18:52:47 +03:00
HostShare ( ) ;
2008-06-17 20:27:32 +04:00
~ HostShare ( ) { } ;
2019-07-01 18:52:47 +03:00
/**
* Pin policy for the host
*/
enum PinPolicy
{
PP_NONE = 0 , /**< No pin. Default. */
PP_CORE = 1 , /**< vCPUs are assigned to host cores exclusively */
PP_THREAD = 2 , /**< vCPUS are assigned to host threads */
PP_SHARED = 3 /**< vCPUs are assigned to a set of host threads */
} ;
static PinPolicy str_to_pin_policy ( std : : string & pp_s ) ;
2016-11-05 23:14:38 +03:00
/**
* Rebuilds the object from an xml node
* @ param node The xml node pointer
*
* @ return 0 on success , - 1 otherwise
*/
int from_xml_node ( const xmlNodePtr node ) ;
2008-06-17 20:27:32 +04:00
/**
2019-07-01 18:52:47 +03:00
* Add a VM capacity to this share
* @ param sr requested capacity by the VM
2008-06-17 20:27:32 +04:00
*/
2020-03-04 18:05:57 +03:00
void add ( HostShareCapacity & sr ) ;
2008-06-17 20:27:32 +04:00
2013-02-23 22:49:06 +04:00
/**
2019-07-01 18:52:47 +03:00
* Delete VM capacity from this share
* @ param sr requested capacity by the VM
2013-02-23 22:49:06 +04:00
*/
2020-03-04 18:05:57 +03:00
void del ( HostShareCapacity & sr ) ;
2010-04-04 03:12:52 +04:00
2008-06-17 20:27:32 +04:00
/**
2010-04-04 03:12:52 +04:00
* Check if this share can host a VM .
2008-06-17 20:27:32 +04:00
* @ param cpu requested by the VM
* @ param mem requested by the VM
* @ param disk requested by the VM
2015-08-26 13:34:27 +03:00
* @ param pci_devs requested by the VM
* @ param error Returns the error reason , if any
2010-04-04 03:12:52 +04:00
*
* @ return true if the share can host the VM or it is the only one
2008-06-17 20:27:32 +04:00
* configured
*/
2020-03-04 18:05:57 +03:00
bool test ( HostShareCapacity & sr , string & error ) const ;
2015-09-04 14:22:11 +03:00
2008-06-17 20:27:32 +04:00
/**
* Function to write a HostShare to an output stream
*/
2020-03-04 18:05:57 +03:00
friend ostream & operator < < ( ostream & os , const HostShare & hs ) ;
2008-06-17 20:27:32 +04:00
/**
2009-07-09 18:34:34 +04:00
* Function to print the HostShare object into a string in
* XML format
* @ param xml the resulting XML string
* @ return a reference to the generated string
2008-06-17 20:27:32 +04:00
*/
2009-07-09 18:34:34 +04:00
string & to_xml ( string & xml ) const ;
2010-04-04 03:12:52 +04:00
2019-07-01 18:52:47 +03:00
/**
2020-03-04 18:05:57 +03:00
* Set the capacity attributes of the share . CPU and Memory may reserve some
* capacity according to RESERVED_CPU and RESERVED_MEM . These values can be
* either absolute or a percentage .
*
* The function also set the PCI , NUMA and datastore information .
*
* Share values are read from the Host template returned by the monitoring
* probes . The values are removed from the template .
*
* @ param ht template for the host
* @ param rcpu , reserved cpu for the host
* @ param rmem , reserved mem for the host
*
* NOTE : reserved strings will be modified
2019-07-01 18:52:47 +03:00
*/
2020-03-04 18:05:57 +03:00
void set_monitorization ( Template & ht , string & rcpu , string & rmem ) ;
2019-07-01 18:52:47 +03:00
2020-03-13 12:32:53 +03:00
/**
* Set the capacity attributes of the share .
* Same as the 3 parameter method , except it does not update reserved CPU and Memory
*/
void set_monitorization ( Template & ht ) ;
2016-11-05 23:14:38 +03:00
/**
* Resets capaity values of the share
*/
void reset_capacity ( )
{
2016-11-12 23:18:25 +03:00
total_cpu = 0 ;
total_mem = 0 ;
2016-11-05 23:14:38 +03:00
max_cpu = 0 ;
max_mem = 0 ;
} ;
2016-11-12 23:18:25 +03:00
/**
* Update the capacity attributes when the RESERVED_CPU and RESERVED_MEM
2020-03-04 18:05:57 +03:00
* are updated . This function also updates VMS_THREAD and ISOLCPUS
* @ param ht , host template
* @ para rcpu , reserved cpu for the host
* @ para rmem , reserved mem for the host
*
* NOTE : reserved strings will be modified
2019-07-25 17:01:17 +03:00
*/
2020-03-04 18:05:57 +03:00
void update_capacity ( Template & ht , string & rcpu , string & rmem ) ;
2019-09-22 01:31:08 +03:00
2016-11-05 23:14:38 +03:00
/**
* Return the number of running VMs in this host
*/
long long get_running_vms ( )
{
return running_vms ;
} ;
2020-03-13 12:32:53 +03:00
long long get_total_mem ( ) const { return total_mem ; }
long long get_total_cpu ( ) const { return total_cpu ; }
long long get_max_mem ( ) const { return max_mem ; }
long long get_max_cpu ( ) const { return max_cpu ; }
2009-07-09 18:34:34 +04:00
private :
2008-06-17 20:27:32 +04:00
2013-10-02 00:34:22 +04:00
long long mem_usage ; /**< Memory allocated to VMs (in KB) */
long long cpu_usage ; /**< CPU allocated to VMs (in percentage) */
2010-04-04 03:12:52 +04:00
2016-11-12 23:18:25 +03:00
long long total_mem ; /**< Total memory capacity (in KB) */
long long total_cpu ; /**< Total cpu capacity (in percentage) */
long long max_mem ; /**< Total memory capacity (in KB) +/- reserved */
long long max_cpu ; /**< Total cpu capacity (in percentage) +/- reserved*/
2008-06-17 20:27:32 +04:00
2013-10-02 00:34:22 +04:00
long long running_vms ; /**< Number of running VMs in this Host */
2010-04-04 03:12:52 +04:00
2019-09-22 01:31:08 +03:00
unsigned int vms_thread ; /**< VMs that can be allocated to a thread */
2015-08-20 18:39:56 +03:00
HostShareDatastore ds ;
2020-03-04 18:05:57 +03:00
2015-08-20 18:39:56 +03:00
HostSharePCI pci ;
2020-03-04 18:05:57 +03:00
2019-07-01 18:52:47 +03:00
HostShareNUMA numa ;
/**
* Check if this share can host a VM , testing only the PCI devices .
* @ param pci_devs requested by the VM
* @ param error Returns the error reason , if any
*
* @ return true if the share can host the VM or it is the only one
* configured
*/
2020-03-04 18:05:57 +03:00
bool test_compute ( int cpu , long long mem , std : : string & error ) const ;
2019-07-01 18:52:47 +03:00
2020-03-04 18:05:57 +03:00
bool test_pci ( vector < VectorAttribute * > & pci_devs , string & error ) const ;
2019-07-01 18:52:47 +03:00
2020-03-04 18:05:57 +03:00
bool test_numa ( HostShareCapacity & sr , string & error ) const ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*HOST_SHARE_H_*/