mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
Merge branch 'feature-1739'
Conflicts: src/common/NebulaUtil.cc src/common/SConstruct
This commit is contained in:
commit
b84a0350a7
@ -21,8 +21,8 @@
|
||||
|
||||
#include "ActionManager.h"
|
||||
#include "PoolObjectAuth.h"
|
||||
#include "SSLTools.h"
|
||||
#include "AuthManager.h"
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
#include "SyncRequest.h"
|
||||
|
||||
@ -75,22 +75,22 @@ public:
|
||||
username = _username;
|
||||
password = _password;
|
||||
session = _session;
|
||||
|
||||
|
||||
driver = _driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a CREATE authorization request.
|
||||
*
|
||||
*
|
||||
* OBJECT:<-1|OBJECT_TMPL_XML64>:CREATE:UID:AUTH
|
||||
*
|
||||
*
|
||||
* @param type of the object to be created
|
||||
* @param template (base64 encoded) of the new object
|
||||
*/
|
||||
void add_create_auth(PoolObjectSQL::ObjectType type, const string& txml_64)
|
||||
{
|
||||
PoolObjectAuth perms; //oid & gid set to -1
|
||||
|
||||
|
||||
perms.uid = uid;
|
||||
perms.obj_type = type;
|
||||
|
||||
@ -143,20 +143,20 @@ public:
|
||||
|
||||
bool core_authenticate()
|
||||
{
|
||||
string sha1_session = SSLTools::sha1_digest(session);
|
||||
string sha1_session = one_util::sha1_digest(session);
|
||||
|
||||
return (password == sha1_session);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
friend class AuthManager;
|
||||
|
||||
|
||||
/**
|
||||
* The user id for this request
|
||||
*/
|
||||
int uid;
|
||||
|
||||
|
||||
/**
|
||||
* The user group ID
|
||||
*/
|
||||
|
@ -80,27 +80,6 @@ public:
|
||||
return ((state == MONITORING_ERROR) || (state==MONITORING_MONITORED));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Host's last_monitored time stamp.
|
||||
* @param success if the monitored action was successfully performed
|
||||
*/
|
||||
void touch(bool success)
|
||||
{
|
||||
last_monitored = time(0);
|
||||
|
||||
if ( state != DISABLED) //Don't change the state is host is disabled
|
||||
{
|
||||
if (success == true)
|
||||
{
|
||||
state = MONITORED;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = ERROR;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Disables the current host, it will not be monitored nor used by the
|
||||
* scheduler
|
||||
@ -119,11 +98,27 @@ public:
|
||||
state = INIT;
|
||||
};
|
||||
|
||||
/** Update host counters and update the whole host on the DB
|
||||
/**
|
||||
* Update host after a successful monitor. It modifies counters, state
|
||||
* and template attributes
|
||||
* @param parse_str string with values to be parsed
|
||||
* @param with_vm_info if monitoring contains VM information
|
||||
* @param lost set of VMs that should be in the host and were not found
|
||||
* @param found VMs running in the host (as expected) and info.
|
||||
* @return 0 on success
|
||||
**/
|
||||
int update_info(string &parse_str);
|
||||
int update_info(string &parse_str,
|
||||
bool &with_vm_info,
|
||||
set<int> &lost,
|
||||
map<int,string> &found);
|
||||
|
||||
/**
|
||||
* Update host after a failed monitor. It state
|
||||
* and template attributes
|
||||
* @param message from the driver
|
||||
* @param vm_ids running on the host
|
||||
*/
|
||||
void error_info(const string& message, set<int> &vm_ids);
|
||||
|
||||
/**
|
||||
* Inserts the last monitoring, and deletes old monitoring entries.
|
||||
@ -134,7 +129,7 @@ public:
|
||||
int update_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Retrives host state
|
||||
* Retrieves host state
|
||||
* @return HostState code number
|
||||
*/
|
||||
HostState get_state() const
|
||||
@ -143,7 +138,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrives VMM mad name
|
||||
* Retrieves VMM mad name
|
||||
* @return string vmm mad name
|
||||
*/
|
||||
const string& get_vmm_mad() const
|
||||
@ -152,7 +147,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrives VNM mad name
|
||||
* Retrieves VNM mad name
|
||||
* @return string vnm mad name
|
||||
*/
|
||||
const string& get_vnm_mad() const
|
||||
@ -161,7 +156,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrives IM mad name
|
||||
* Retrieves IM mad name
|
||||
* @return string im mad name
|
||||
*/
|
||||
const string& get_im_mad() const
|
||||
@ -194,7 +189,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrives last time the host was monitored
|
||||
* Retrieves last time the host was monitored
|
||||
* @return time_t last monitored time
|
||||
*/
|
||||
time_t get_last_monitored() const
|
||||
@ -273,7 +268,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new VM to the given share by icrementing the cpu, mem and disk
|
||||
* Adds a new VM to the given share by incrementing the cpu, mem and disk
|
||||
* counters
|
||||
* @param vm_id id of the vm to add to the host
|
||||
* @param cpu needed by the VM (percentage)
|
||||
@ -302,7 +297,7 @@ public:
|
||||
* disk counters
|
||||
* @param vm_id id of the vm to delete from the host
|
||||
* @param cpu used by the VM (percentage)
|
||||
* @param mem used by the VM (in Kb)
|
||||
* @param mem used by the VM (in KB)
|
||||
* @param disk used by the VM
|
||||
* @return 0 on success
|
||||
*/
|
||||
@ -409,6 +404,31 @@ private:
|
||||
|
||||
virtual ~Host();
|
||||
|
||||
// *************************************************************************
|
||||
// Host Management
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Updates the Host's last_monitored time stamp.
|
||||
* @param success if the monitored action was successfully performed
|
||||
*/
|
||||
void touch(bool success)
|
||||
{
|
||||
last_monitored = time(0);
|
||||
|
||||
if ( state != DISABLED) //Don't change the state is host is disabled
|
||||
{
|
||||
if (success == true)
|
||||
{
|
||||
state = MONITORED;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = ERROR;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
@ -109,12 +109,12 @@ public:
|
||||
|
||||
/**
|
||||
* Get the least monitored hosts
|
||||
* @param discovered hosts, map to store the retrieved hosts hids and
|
||||
* hostnames
|
||||
* @param discovered hosts
|
||||
* @param host_limit max. number of hosts to monitor at a time
|
||||
* @param target_time Filters hosts with last_mon_time <= target_time
|
||||
* @return int 0 if success
|
||||
*/
|
||||
int discover(map<int, string> * discovered_hosts, int host_limit);
|
||||
int discover(set<int> * discovered_hosts, int host_limit, time_t target_time);
|
||||
|
||||
/**
|
||||
* Allocates a given capacity to the host
|
||||
@ -267,12 +267,15 @@ private:
|
||||
/**
|
||||
* Callback function to get the IDs of the hosts to be monitored
|
||||
* (Host::discover)
|
||||
*
|
||||
* @param _set the set<int>* of host ids
|
||||
* @param num the number of columns read from the DB
|
||||
* @param values the column values
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int discover_cb(void * _map, int num, char **values, char **names);
|
||||
int discover_cb(void * _set, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for all hosts
|
||||
|
@ -122,7 +122,7 @@ private:
|
||||
friend void * im_action_loop(void *arg);
|
||||
|
||||
/**
|
||||
* Time in seconds to expire a monitoring action (10 minutes)
|
||||
* Time in seconds to expire a monitoring action (5 minutes)
|
||||
*/
|
||||
static const time_t monitor_expire;
|
||||
|
||||
|
@ -28,6 +28,30 @@ namespace one_util
|
||||
std::string log_time(time_t the_time);
|
||||
|
||||
std::string log_time();
|
||||
|
||||
/**
|
||||
* sha1 digest
|
||||
* @param in the string to be hashed
|
||||
* @return sha1 hash of str
|
||||
*/
|
||||
std::string sha1_digest(const std::string& in);
|
||||
|
||||
/**
|
||||
* Base 64 encoding
|
||||
* @param in the string to encoded
|
||||
* @return a pointer to the encoded string (must be freed) or 0 in case of
|
||||
* error
|
||||
*/
|
||||
std::string * base64_encode(const std::string& in);
|
||||
|
||||
/**
|
||||
* Base 64 deencoding
|
||||
* @param in the string to decode
|
||||
* @return a pointer to the decoded string (must be freed) or 0 in case of
|
||||
* error
|
||||
*/
|
||||
std::string * base64_decode(const std::string& in);
|
||||
|
||||
};
|
||||
|
||||
#endif /* _NEBULA_UTIL_H_ */
|
||||
|
@ -397,12 +397,36 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an error message for the VM in the template
|
||||
* @param message
|
||||
* @return 0 on success
|
||||
* Sets an error message with timestamp in the template
|
||||
* @param message Message string
|
||||
*/
|
||||
void set_template_error_message(const string& message);
|
||||
|
||||
/**
|
||||
* Deletes the error message from the template
|
||||
*/
|
||||
void clear_template_error_message();
|
||||
|
||||
/**
|
||||
* Adds a string attribute
|
||||
* @param att_name Name for the attribute
|
||||
* @param att_val Message string
|
||||
*/
|
||||
void add_template_attribute(const string& name, const string& value)
|
||||
{
|
||||
obj_template->add(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an int attribute
|
||||
* @param att_name Name for the attribute
|
||||
* @param att_val integer
|
||||
*/
|
||||
void add_template_attribute(const string& name, int value)
|
||||
{
|
||||
obj_template->add(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for templates, it should be implemented
|
||||
* by classes that uses templates
|
||||
|
@ -1,51 +0,0 @@
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
|
||||
/* */
|
||||
/* 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 SSL_TOOLS_H_
|
||||
#define SSL_TOOLS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The SSLTools class provides a simple interface to common SSL utils used
|
||||
* in OpenNebula
|
||||
*/
|
||||
class SSLTools
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* sha1 digest
|
||||
* @param in the string to be hashed
|
||||
* @return sha1 hash of str
|
||||
*/
|
||||
static string sha1_digest(const string& in);
|
||||
|
||||
/**
|
||||
* Base 64 encoding
|
||||
* @param in the string to encoded
|
||||
* @return a pointer to the encoded string (must be freed) or 0 in case of
|
||||
* error
|
||||
*/
|
||||
static string * base64_encode(const string& in);
|
||||
|
||||
private:
|
||||
SSLTools(){};
|
||||
~SSLTools(){};
|
||||
};
|
||||
|
||||
#endif /*SSL_TOOLS_H_*/
|
@ -171,7 +171,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates VM dynamic information (usage counters).
|
||||
* Updates VM dynamic information (usage counters), and updates last_poll
|
||||
* @param _memory Kilobytes used by the VM (total)
|
||||
* @param _cpu used by the VM (rate)
|
||||
* @param _net_tx transmitted bytes (total)
|
||||
@ -181,28 +181,8 @@ public:
|
||||
const int _memory,
|
||||
const int _cpu,
|
||||
const long long _net_tx,
|
||||
const long long _net_rx)
|
||||
{
|
||||
if (_memory != -1)
|
||||
{
|
||||
memory = _memory;
|
||||
}
|
||||
|
||||
if (_cpu != -1)
|
||||
{
|
||||
cpu = _cpu;
|
||||
}
|
||||
|
||||
if (_net_tx != -1)
|
||||
{
|
||||
net_tx = _net_tx;
|
||||
}
|
||||
|
||||
if (_net_rx != -1)
|
||||
{
|
||||
net_rx = _net_rx;
|
||||
}
|
||||
};
|
||||
const long long _net_rx,
|
||||
const map<string, string> &custom);
|
||||
|
||||
/**
|
||||
* Returns the deployment ID
|
||||
@ -778,15 +758,6 @@ public:
|
||||
return last_poll;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets time of last information polling.
|
||||
* @param poll time in epoch, normally time(0)
|
||||
*/
|
||||
void set_last_poll(time_t poll)
|
||||
{
|
||||
last_poll = poll;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the VM physical requirements for the host.
|
||||
* @param cpu
|
||||
|
@ -68,6 +68,22 @@ public:
|
||||
const VirtualMachine * vm,
|
||||
const string& file_name) const = 0;
|
||||
|
||||
/**
|
||||
* Updates the VM with the information gathered by the drivers
|
||||
*
|
||||
* @param id VM id
|
||||
* @param monitor_str String returned by the poll driver call
|
||||
*/
|
||||
static void process_poll(int id, const string &monitor_str);
|
||||
|
||||
/**
|
||||
* Updates the VM with the information gathered by the drivers
|
||||
*
|
||||
* @param vm VM to update, must be locked
|
||||
* @param monitor_str String returned by the poll driver call
|
||||
*/
|
||||
static void process_poll(VirtualMachine* vm, const string &monitor_str);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Gets a configuration attr from driver configuration file (single
|
||||
@ -268,8 +284,6 @@ private:
|
||||
write_drv("DETACHDISK", oid, drv_msg);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void write_drv(const char * aname, const int oid, const string& msg) const
|
||||
{
|
||||
ostringstream os;
|
||||
@ -278,6 +292,25 @@ private:
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets VM information from the driver answer
|
||||
* @param monitor_str from the driver
|
||||
* @param memory Kilobytes used by the VM (total)
|
||||
* @param cpu used by the VM (rate)
|
||||
* @param net_tx transmitted bytes (total)
|
||||
* @param net_rx received bytes (total)
|
||||
* @param state of the vm
|
||||
* @param custom monitor information
|
||||
*/
|
||||
static int parse_vm_info(
|
||||
const string& monitor_str,
|
||||
int &cpu,
|
||||
int &memory,
|
||||
long long &net_tx,
|
||||
long long &net_rx,
|
||||
char &state,
|
||||
map<string,string> &custom);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -813,11 +813,13 @@ IM_PROBES_FILES="src/im_mad/remotes/run_probes"
|
||||
IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/kvm.rb \
|
||||
src/im_mad/remotes/kvm.d/architecture.sh \
|
||||
src/im_mad/remotes/kvm.d/cpu.sh \
|
||||
src/im_mad/remotes/kvm.d/poll.sh \
|
||||
src/im_mad/remotes/kvm.d/name.sh"
|
||||
|
||||
IM_PROBES_XEN_FILES="src/im_mad/remotes/xen.d/xen.rb \
|
||||
src/im_mad/remotes/xen.d/architecture.sh \
|
||||
src/im_mad/remotes/xen.d/cpu.sh \
|
||||
src/im_mad/remotes/xen.d/poll.sh \
|
||||
src/im_mad/remotes/xen.d/name.sh"
|
||||
|
||||
IM_PROBES_VMWARE_FILES="src/im_mad/remotes/vmware.d/vmware.rb"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,16 +6,14 @@
|
||||
# Daemon configuration attributes
|
||||
#-------------------------------------------------------------------------------
|
||||
# MANAGER_TIMER: Time in seconds the core uses to evaluate periodical functions.
|
||||
# HOST_MONITORING_INTERVAL and VM_POLLING_INTERVAL can not have smaller values
|
||||
# than MANAGER_TIMER.
|
||||
# MONITORING_INTERVAL cannot have a smaller value than MANAGER_TIMER.
|
||||
#
|
||||
# MONITORING_INTERVAL: Time in seconds between host and VM monitorization.
|
||||
#
|
||||
# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization.
|
||||
# HOST_PER_INTERVAL: Number of hosts monitored in each interval.
|
||||
# HOST_MONITORING_EXPIRATION_TIME: Time, in seconds, to expire monitoring
|
||||
# information. Use 0 to disable HOST monitoring recording.
|
||||
#
|
||||
# VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization.
|
||||
# Use 0 to disable VM monitoring.
|
||||
# VM_PER_INTERVAL: Number of VMs monitored in each interval.
|
||||
# VM_MONITORING_EXPIRATION_TIME: Time, in seconds, to expire monitoring
|
||||
# information. Use 0 to disable VM monitoring recording.
|
||||
@ -46,7 +44,6 @@
|
||||
# VM_SUBMIT_ON_HOLD: Forces VMs to be created on hold state instead of pending.
|
||||
# Values: YES or NO.
|
||||
#*******************************************************************************
|
||||
#
|
||||
|
||||
LOG = [
|
||||
system = "file",
|
||||
@ -55,11 +52,11 @@ LOG = [
|
||||
|
||||
#MANAGER_TIMER = 30
|
||||
|
||||
HOST_MONITORING_INTERVAL = 600
|
||||
MONITORING_INTERVAL = 300
|
||||
|
||||
#HOST_PER_INTERVAL = 15
|
||||
#HOST_MONITORING_EXPIRATION_TIME = 86400
|
||||
|
||||
VM_POLLING_INTERVAL = 600
|
||||
#VM_PER_INTERVAL = 5
|
||||
#VM_MONITORING_EXPIRATION_TIME = 86400
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "AuthManager.h"
|
||||
#include "AuthRequest.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "SSLTools.h"
|
||||
#include "NebulaUtil.h"
|
||||
#include "PoolObjectAuth.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
@ -40,7 +40,7 @@ void AuthRequest::add_auth(Operation op,
|
||||
|
||||
if ( !ob_template.empty() )
|
||||
{
|
||||
string * encoded_id = SSLTools::base64_encode(ob_template);
|
||||
string * encoded_id = one_util::base64_encode(ob_template);
|
||||
|
||||
if (encoded_id != 0)
|
||||
{
|
||||
|
@ -270,6 +270,11 @@ int VectorAttribute::vector_value(const char *name, int & value) const
|
||||
istringstream iss(it->second);
|
||||
iss >> value;
|
||||
|
||||
if (iss.fail() || !iss.eof())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -295,6 +300,11 @@ int VectorAttribute::vector_value(const char *name, float & value) const
|
||||
istringstream iss(it->second);
|
||||
iss >> value;
|
||||
|
||||
if (iss.fail() || !iss.eof())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,16 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/buffer.h>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
@ -25,12 +35,18 @@ string& one_util::toupper(string& st)
|
||||
return st;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& one_util::tolower(string& st)
|
||||
{
|
||||
transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::tolower);
|
||||
return st;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string one_util::log_time(time_t the_time)
|
||||
{
|
||||
char time_str[26];
|
||||
@ -46,8 +62,115 @@ string one_util::log_time(time_t the_time)
|
||||
return string(time_str);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string one_util::log_time()
|
||||
{
|
||||
return log_time( time(0) );
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string * one_util::base64_encode(const string& in)
|
||||
{
|
||||
BIO * bio_mem;
|
||||
BIO * bio_64;
|
||||
|
||||
char * encoded_c;
|
||||
long int size;
|
||||
|
||||
bio_64 = BIO_new(BIO_f_base64());
|
||||
bio_mem = BIO_new(BIO_s_mem());
|
||||
|
||||
BIO_push(bio_64, bio_mem);
|
||||
|
||||
BIO_set_flags(bio_64, BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
BIO_write(bio_64, in.c_str(), in.length());
|
||||
|
||||
if (BIO_flush(bio_64) != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = BIO_get_mem_data(bio_mem,&encoded_c);
|
||||
|
||||
string * encoded = new string(encoded_c,size);
|
||||
|
||||
BIO_free_all(bio_64);
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string * one_util::base64_decode(const string& in)
|
||||
{
|
||||
BIO * bio_mem_in;
|
||||
BIO * bio_mem_out;
|
||||
BIO * bio_64;
|
||||
|
||||
char inbuf[512];
|
||||
int inlen;
|
||||
|
||||
char * decoded_c;
|
||||
long int size;
|
||||
|
||||
bio_64 = BIO_new(BIO_f_base64());
|
||||
|
||||
bio_mem_in = BIO_new(BIO_s_mem());
|
||||
bio_mem_out = BIO_new(BIO_s_mem());
|
||||
|
||||
bio_64 = BIO_push(bio_64, bio_mem_in);
|
||||
|
||||
BIO_set_flags(bio_64, BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
BIO_write(bio_mem_in, in.c_str(), in.length());
|
||||
|
||||
while((inlen = BIO_read(bio_64, inbuf, 512)) > 0)
|
||||
{
|
||||
BIO_write(bio_mem_out, inbuf, inlen);
|
||||
}
|
||||
|
||||
size = BIO_get_mem_data(bio_mem_out, &decoded_c);
|
||||
|
||||
string * decoded = new string(decoded_c, size);
|
||||
|
||||
BIO_free_all(bio_64);
|
||||
BIO_free_all(bio_mem_out);
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string one_util::sha1_digest(const string& in)
|
||||
{
|
||||
EVP_MD_CTX mdctx;
|
||||
unsigned char md_value[EVP_MAX_MD_SIZE];
|
||||
unsigned int md_len;
|
||||
ostringstream oss;
|
||||
|
||||
EVP_MD_CTX_init(&mdctx);
|
||||
EVP_DigestInit_ex(&mdctx, EVP_sha1(), NULL);
|
||||
|
||||
EVP_DigestUpdate(&mdctx, in.c_str(), in.length());
|
||||
|
||||
EVP_DigestFinal_ex(&mdctx,md_value,&md_len);
|
||||
EVP_MD_CTX_cleanup(&mdctx);
|
||||
|
||||
for(unsigned int i = 0; i<md_len; i++)
|
||||
{
|
||||
oss << setfill('0') << setw(2) << hex << nouppercase
|
||||
<< (unsigned short) md_value[i];
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -25,7 +25,6 @@ source_files=[
|
||||
'ActionManager.cc',
|
||||
'Attribute.cc',
|
||||
'mem_collector.c',
|
||||
'SSLTools.cc',
|
||||
'NebulaUtil.cc'
|
||||
]
|
||||
|
||||
|
@ -1,98 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
|
||||
/* */
|
||||
/* 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 <openssl/sha.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/buffer.h>
|
||||
|
||||
#include "SSLTools.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
//#include <iostream>
|
||||
|
||||
|
||||
//#include <sys/types.h>
|
||||
//#include <pwd.h>
|
||||
//#include <stdlib.h>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string * SSLTools::base64_encode(const string& in)
|
||||
{
|
||||
BIO * bio_mem;
|
||||
BIO * bio_64;
|
||||
|
||||
char * encoded_c;
|
||||
long int size;
|
||||
|
||||
bio_64 = BIO_new(BIO_f_base64());
|
||||
bio_mem = BIO_new(BIO_s_mem());
|
||||
|
||||
BIO_push(bio_64, bio_mem);
|
||||
|
||||
BIO_set_flags(bio_64,BIO_FLAGS_BASE64_NO_NL);
|
||||
|
||||
BIO_write(bio_64, in.c_str(), in.length());
|
||||
|
||||
if (BIO_flush(bio_64) != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = BIO_get_mem_data(bio_mem,&encoded_c);
|
||||
|
||||
string * encoded = new string(encoded_c,size);
|
||||
|
||||
BIO_free_all(bio_64);
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string SSLTools::sha1_digest(const string& in)
|
||||
{
|
||||
EVP_MD_CTX mdctx;
|
||||
unsigned char md_value[EVP_MAX_MD_SIZE];
|
||||
unsigned int md_len;
|
||||
ostringstream oss;
|
||||
|
||||
EVP_MD_CTX_init(&mdctx);
|
||||
EVP_DigestInit_ex(&mdctx, EVP_sha1(), NULL);
|
||||
|
||||
EVP_DigestUpdate(&mdctx, in.c_str(), in.length());
|
||||
|
||||
EVP_DigestFinal_ex(&mdctx,md_value,&md_len);
|
||||
EVP_MD_CTX_cleanup(&mdctx);
|
||||
|
||||
for(unsigned int i = 0; i<md_len; i++)
|
||||
{
|
||||
oss << setfill('0') << setw(2) << hex << nouppercase
|
||||
<< (unsigned short) md_value[i];
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
149
src/host/Host.cc
149
src/host/Host.cc
@ -170,22 +170,60 @@ error_common:
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::update_info(string &parse_str)
|
||||
int Host::update_info(string &parse_str,
|
||||
bool &with_vm_info,
|
||||
set<int> &lost,
|
||||
map<int,string> &found)
|
||||
{
|
||||
char * error_msg;
|
||||
int rc;
|
||||
float fv;
|
||||
char * error_msg;
|
||||
Template* tmpl;
|
||||
|
||||
VectorAttribute* vatt;
|
||||
vector<Attribute*>::iterator it;
|
||||
vector<Attribute*> vm_att;
|
||||
|
||||
int rc;
|
||||
int vmid;
|
||||
float fv;
|
||||
|
||||
ostringstream zombie;
|
||||
ostringstream wild;
|
||||
|
||||
int num_zombies = 0;
|
||||
int num_wilds = 0;
|
||||
|
||||
//
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Parse Template (twice because of repeated VM values) //
|
||||
// ---------------------------------------------------------------------- //
|
||||
rc = obj_template->parse(parse_str, &error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
NebulaLog::log("ONE", Log::ERROR, error_msg);
|
||||
ostringstream ess;
|
||||
|
||||
ess << "Error parsing host information: " << error_msg
|
||||
<< "Monitoring information: " << parse_str;
|
||||
|
||||
NebulaLog::log("ONE", Log::ERROR, ess);
|
||||
|
||||
touch(false);
|
||||
|
||||
set_template_error_message("Error parsing monitor information."
|
||||
" Check oned.log for more details.");
|
||||
|
||||
free(error_msg);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmpl = new Template();
|
||||
|
||||
tmpl->parse(parse_str, &error_msg);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Extract share information //
|
||||
// ---------------------------------------------------------------------- //
|
||||
get_template_attribute("TOTALCPU", fv);
|
||||
host_share.max_cpu = static_cast<int>(fv);
|
||||
get_template_attribute("TOTALMEMORY", fv);
|
||||
@ -201,12 +239,113 @@ int Host::update_info(string &parse_str)
|
||||
get_template_attribute("USEDMEMORY", fv);
|
||||
host_share.used_mem = static_cast<int>(fv);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Remove expired information //
|
||||
// ---------------------------------------------------------------------- //
|
||||
clear_template_error_message();
|
||||
|
||||
remove_template_attribute("ZOMBIES");
|
||||
remove_template_attribute("TOTAL_ZOMBIES");
|
||||
|
||||
remove_template_attribute("WILDS");
|
||||
remove_template_attribute("TOTAL_WILDS");
|
||||
|
||||
remove_template_attribute("VM");
|
||||
|
||||
get_template_attribute("VM_POLL", with_vm_info);
|
||||
remove_template_attribute("VM_POLL");
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Correlate VM information with the list of running VMs //
|
||||
// ---------------------------------------------------------------------- //
|
||||
tmpl->remove("VM", vm_att);
|
||||
|
||||
lost = vm_collection.get_collection_copy();
|
||||
|
||||
for (it = vm_att.begin(); it != vm_att.end(); it++)
|
||||
{
|
||||
vatt = dynamic_cast<VectorAttribute*>(*it);
|
||||
|
||||
if (vatt == 0)
|
||||
{
|
||||
delete *it;
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = vatt->vector_value("ID", vmid);
|
||||
|
||||
if (rc == 0 && vmid != -1)
|
||||
{
|
||||
if (lost.erase(vmid) == 1) //Good, known
|
||||
{
|
||||
found.insert(make_pair(vmid, vatt->vector_value("POLL")));
|
||||
}
|
||||
else //Bad, known but should not be here
|
||||
{
|
||||
if (num_zombies++ > 0)
|
||||
{
|
||||
zombie << ", ";
|
||||
}
|
||||
|
||||
zombie << vatt->vector_value("DEPLOY_ID");
|
||||
}
|
||||
}
|
||||
else if (rc == 0) //not ours
|
||||
{
|
||||
if (num_wilds++ > 0)
|
||||
{
|
||||
wild << ", ";
|
||||
}
|
||||
|
||||
wild << vatt->vector_value("DEPLOY_ID");
|
||||
}
|
||||
|
||||
delete *it;
|
||||
}
|
||||
|
||||
if (num_wilds > 0)
|
||||
{
|
||||
add_template_attribute("TOTAL_WILDS", num_wilds);
|
||||
add_template_attribute("WILDS", wild.str());
|
||||
}
|
||||
|
||||
if (num_zombies > 0)
|
||||
{
|
||||
add_template_attribute("TOTAL_ZOMBIES", num_zombies);
|
||||
add_template_attribute("ZOMBIES", zombie.str());
|
||||
}
|
||||
|
||||
delete tmpl;
|
||||
|
||||
// Touch the host to update its last_monitored timestamp and state
|
||||
|
||||
touch(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Host::error_info(const string& message, set<int> &vm_ids)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
vm_ids = vm_collection.get_collection_copy();
|
||||
|
||||
oss << "Error monitoring Host " << get_name() << " (" << get_oid() << ")"
|
||||
<< ": " << message;
|
||||
|
||||
NebulaLog::log("ONE", Log::ERROR, oss);
|
||||
|
||||
touch(false);
|
||||
|
||||
set_template_error_message(oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::update_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
@ -243,36 +243,32 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::discover_cb(void * _map, int num, char **values, char **names)
|
||||
int HostPool::discover_cb(void * _set, int num, char **values, char **names)
|
||||
{
|
||||
map<int, string> * discovered_hosts;
|
||||
string im_mad;
|
||||
int hid;
|
||||
int rc;
|
||||
set<int> * discovered_hosts;
|
||||
string im_mad;
|
||||
int hid;
|
||||
|
||||
discovered_hosts = static_cast<map<int, string> *>(_map);
|
||||
discovered_hosts = static_cast<set<int> *>(_set);
|
||||
|
||||
if ( (num<2) || (values[0] == 0) || (values[1] == 0) )
|
||||
if ( (num<1) || (values[0] == 0) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
hid = atoi(values[0]);
|
||||
rc = ObjectXML::xpath_value(im_mad,values[1],"/HOST/IM_MAD");
|
||||
|
||||
if( rc != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
discovered_hosts->insert(make_pair(hid,im_mad));
|
||||
discovered_hosts->insert(hid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::discover(map<int, string> * discovered_hosts, int host_limit)
|
||||
int HostPool::discover(
|
||||
set<int> * discovered_hosts,
|
||||
int host_limit,
|
||||
time_t target_time)
|
||||
{
|
||||
ostringstream sql;
|
||||
int rc;
|
||||
@ -280,9 +276,9 @@ int HostPool::discover(map<int, string> * discovered_hosts, int host_limit)
|
||||
set_callback(static_cast<Callbackable::Callback>(&HostPool::discover_cb),
|
||||
static_cast<void *>(discovered_hosts));
|
||||
|
||||
sql << "SELECT oid, body FROM "
|
||||
<< Host::table << " WHERE state != "
|
||||
<< Host::DISABLED << " ORDER BY last_mon_time ASC LIMIT " << host_limit;
|
||||
sql << "SELECT oid FROM " << Host::table
|
||||
<< " WHERE last_mon_time <= " << target_time
|
||||
<< " ORDER BY last_mon_time ASC LIMIT " << host_limit;
|
||||
|
||||
rc = db->exec(sql,this);
|
||||
|
||||
|
@ -19,9 +19,10 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
|
||||
|
||||
const time_t InformationManager::monitor_expire = 600;
|
||||
const time_t InformationManager::monitor_expire = 300;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -97,6 +98,8 @@ int InformationManager::start()
|
||||
return -1;
|
||||
}
|
||||
|
||||
utime(remotes_location.c_str(), 0);
|
||||
|
||||
NebulaLog::log("InM",Log::INFO,"Starting Information Manager...");
|
||||
|
||||
pthread_attr_init (&pattr);
|
||||
@ -144,8 +147,8 @@ void InformationManager::timer_action()
|
||||
|
||||
struct stat sb;
|
||||
|
||||
map<int, string> discovered_hosts;
|
||||
map<int, string>::iterator it;
|
||||
set<int> discovered_hosts;
|
||||
set<int>::iterator it;
|
||||
|
||||
const InformationManagerDriver * imd;
|
||||
|
||||
@ -153,6 +156,7 @@ void InformationManager::timer_action()
|
||||
istringstream iss;
|
||||
|
||||
time_t monitor_length;
|
||||
time_t target_time;
|
||||
|
||||
mark = mark + timer_period;
|
||||
|
||||
@ -165,15 +169,17 @@ void InformationManager::timer_action()
|
||||
// Clear the expired monitoring records
|
||||
hpool->clean_expired_monitoring();
|
||||
|
||||
rc = hpool->discover(&discovered_hosts, host_limit);
|
||||
now = time(0);
|
||||
|
||||
target_time = now - monitor_period;
|
||||
|
||||
rc = hpool->discover(&discovered_hosts, host_limit, target_time);
|
||||
|
||||
if ((rc != 0) || (discovered_hosts.empty() == true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
now = time(0);
|
||||
|
||||
if (stat(remotes_location.c_str(), &sb) == -1)
|
||||
{
|
||||
sb.st_mtime = 0;
|
||||
@ -184,7 +190,7 @@ void InformationManager::timer_action()
|
||||
|
||||
for(it=discovered_hosts.begin();it!=discovered_hosts.end();it++)
|
||||
{
|
||||
host = hpool->get(it->first,true);
|
||||
host = hpool->get(*it,true);
|
||||
|
||||
if (host == 0)
|
||||
{
|
||||
@ -200,21 +206,21 @@ void InformationManager::timer_action()
|
||||
hpool->update(host);
|
||||
}
|
||||
|
||||
if ( host->isEnabled() && !(host->isMonitoring()) &&
|
||||
(monitor_length >= monitor_period))
|
||||
if ( !(host->isMonitoring()) &&
|
||||
(host->isEnabled() || host->get_share_running_vms() != 0) )
|
||||
{
|
||||
oss.str("");
|
||||
oss << "Monitoring host " << host->get_name()
|
||||
<< " (" << it->first << ")";
|
||||
<< " (" << host->get_oid() << ")";
|
||||
|
||||
NebulaLog::log("InM",Log::INFO,oss);
|
||||
|
||||
imd = get(it->second);
|
||||
imd = get(host->get_im_mad());
|
||||
|
||||
if (imd == 0)
|
||||
{
|
||||
oss.str("");
|
||||
oss << "Could not find information driver " << it->second;
|
||||
oss << "Could not find information driver " << host->get_im_mad();
|
||||
NebulaLog::log("InM",Log::ERROR,oss);
|
||||
|
||||
host->set_state(Host::ERROR);
|
||||
@ -229,7 +235,7 @@ void InformationManager::timer_action()
|
||||
update_remotes = true;
|
||||
}
|
||||
|
||||
imd->monitor(it->first,host->get_name(),update_remotes);
|
||||
imd->monitor(host->get_oid(),host->get_name(),update_remotes);
|
||||
|
||||
host->set_monitoring_state();
|
||||
}
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
#include "InformationManagerDriver.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaUtil.h"
|
||||
#include "VirtualMachineManagerDriver.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@ -45,13 +48,18 @@ void InformationManagerDriver::protocol(
|
||||
string action;
|
||||
//stores the action result
|
||||
string result;
|
||||
//stores the action id of the asociated HOSR
|
||||
//stores the action id of the associated HOST
|
||||
int id;
|
||||
|
||||
ostringstream ess;
|
||||
string hinfo;
|
||||
|
||||
Host * host;
|
||||
|
||||
set<int> vm_ids;
|
||||
|
||||
string hinfo64;
|
||||
string* hinfo;
|
||||
|
||||
// Parse the driver message
|
||||
|
||||
if ( is.good() )
|
||||
@ -87,6 +95,13 @@ void InformationManagerDriver::protocol(
|
||||
|
||||
if ( action == "MONITOR" )
|
||||
{
|
||||
bool vm_poll;
|
||||
|
||||
set<int> lost;
|
||||
map<int,string> found;
|
||||
|
||||
int rc;
|
||||
|
||||
host = hpool->get(id,true);
|
||||
|
||||
if ( host == 0 )
|
||||
@ -94,43 +109,74 @@ void InformationManagerDriver::protocol(
|
||||
goto error_host;
|
||||
}
|
||||
|
||||
if (result == "SUCCESS")
|
||||
getline (is, hinfo64);
|
||||
|
||||
hinfo = one_util::base64_decode(hinfo64);
|
||||
|
||||
if (result != "SUCCESS")
|
||||
{
|
||||
size_t pos;
|
||||
int rc;
|
||||
set<int> vm_ids;
|
||||
|
||||
ostringstream oss;
|
||||
host->error_info(*hinfo, vm_ids);
|
||||
|
||||
getline (is,hinfo);
|
||||
|
||||
for (pos=hinfo.find(',');pos!=string::npos;pos=hinfo.find(','))
|
||||
for (set<int>::iterator it = vm_ids.begin(); it != vm_ids.end(); it++)
|
||||
{
|
||||
hinfo.replace(pos,1,"\n");
|
||||
Nebula &ne = Nebula::instance();
|
||||
LifeCycleManager *lcm = ne.get_lcm();
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_DONE, *it);
|
||||
}
|
||||
|
||||
hinfo += "\n";
|
||||
delete hinfo;
|
||||
|
||||
oss << "Host " << id << " successfully monitored.";
|
||||
NebulaLog::log("InM",Log::DEBUG,oss);
|
||||
hpool->update(host);
|
||||
host->unlock();
|
||||
|
||||
rc = host->update_info(hinfo);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
goto error_parse_info;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
rc = host->update_info(*hinfo, vm_poll, lost, found);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
goto error_driver_info;
|
||||
delete hinfo;
|
||||
|
||||
hpool->update(host);
|
||||
host->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
host->touch(true);
|
||||
delete hinfo;
|
||||
|
||||
hpool->update(host);
|
||||
hpool->update_monitoring(host);
|
||||
|
||||
ess << "Host " << host->get_name() << " (" << host->get_oid() << ")"
|
||||
<< " successfully monitored.";
|
||||
|
||||
NebulaLog::log("InM", Log::DEBUG, ess);
|
||||
|
||||
host->unlock();
|
||||
|
||||
if (vm_poll)
|
||||
{
|
||||
set<int>::iterator its;
|
||||
map<int,string>::iterator itm;
|
||||
|
||||
for (its = lost.begin(); its != lost.end(); its++)
|
||||
{
|
||||
Nebula &ne = Nebula::instance();
|
||||
LifeCycleManager *lcm = ne.get_lcm();
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_DONE, *its);
|
||||
}
|
||||
|
||||
for (itm = found.begin(); itm != found.end(); itm++)
|
||||
{
|
||||
VirtualMachineManagerDriver::process_poll(itm->first, itm->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action == "LOG")
|
||||
{
|
||||
@ -142,27 +188,6 @@ void InformationManagerDriver::protocol(
|
||||
|
||||
return;
|
||||
|
||||
error_driver_info:
|
||||
ess << "Error monitoring host " << id << " : " << is.str();
|
||||
goto error_common_info;
|
||||
|
||||
error_parse_info:
|
||||
ess << "Error parsing host information: " << hinfo;
|
||||
goto error_common_info;
|
||||
|
||||
error_common_info:
|
||||
NebulaLog::log("InM",Log::ERROR,ess);
|
||||
|
||||
host->set_template_error_message(ess.str());
|
||||
|
||||
host->touch(false);
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
return;
|
||||
|
||||
error_host:
|
||||
ess << "Could not get host " << id;
|
||||
NebulaLog::log("InM",Log::ERROR,ess);
|
||||
@ -170,7 +195,6 @@ error_host:
|
||||
return;
|
||||
|
||||
error_parse:
|
||||
|
||||
ess << "Error while parsing driver message: " << message;
|
||||
NebulaLog::log("InM",Log::ERROR,ess);
|
||||
|
||||
|
@ -30,6 +30,7 @@ $: << RUBY_LIB_LOCATION
|
||||
|
||||
require 'OpenNebulaDriver'
|
||||
require 'CommandManager'
|
||||
require 'base64'
|
||||
|
||||
|
||||
# The SSH Information Manager Driver
|
||||
@ -48,20 +49,22 @@ class DummyInformationManager < OpenNebulaDriver
|
||||
|
||||
# Execute the sensor array in the remote host
|
||||
def action_monitor(number, host, not_used)
|
||||
results = "HYPERVISOR=dummy,"
|
||||
results << "HOSTNAME=#{host},"
|
||||
results = "HYPERVISOR=dummy\n"
|
||||
results << "HOSTNAME=#{host}\n"
|
||||
|
||||
results << "CPUSPEED=2.2GHz,"
|
||||
results << "CPUSPEED=2.2GHz\n"
|
||||
|
||||
used_memory = rand(16777216)
|
||||
results << "TOTALMEMORY=16777216,"
|
||||
results << "USEDMEMORY=#{used_memory},"
|
||||
results << "FREEMEMORY=#{16777216-used_memory},"
|
||||
results << "TOTALMEMORY=16777216\n"
|
||||
results << "USEDMEMORY=#{used_memory}\n"
|
||||
results << "FREEMEMORY=#{16777216-used_memory}\n"
|
||||
|
||||
used_cpu = rand(800)
|
||||
results << "TOTALCPU=800,"
|
||||
results << "USEDCPU=#{used_cpu},"
|
||||
results << "FREECPU=#{800-used_cpu}"
|
||||
results << "TOTALCPU=800\n"
|
||||
results << "USEDCPU=#{used_cpu}\n"
|
||||
results << "FREECPU=#{800-used_cpu}\n"
|
||||
|
||||
results = Base64::encode64(results).strip.delete("\n")
|
||||
|
||||
send_message("MONITOR", RESULT[:success], number, results)
|
||||
end
|
||||
|
@ -28,6 +28,7 @@ $: << RUBY_LIB_LOCATION
|
||||
|
||||
require 'pp'
|
||||
require 'OpenNebulaDriver'
|
||||
require 'base64'
|
||||
|
||||
# The EC2 Information Manager Driver
|
||||
class EC2InformationManagerDriver < OpenNebulaDriver
|
||||
@ -57,15 +58,16 @@ class EC2InformationManagerDriver < OpenNebulaDriver
|
||||
totalmemory = smem + lmem + xlmem
|
||||
totalcpu = scpu + lcpu + xlcpu
|
||||
|
||||
@info="HYPERVISOR=ec2,TOTALMEMORY=#{totalmemory},"<<
|
||||
"TOTALCPU=#{totalcpu},CPUSPEED=1000,FREEMEMORY=#{totalmemory},"<<
|
||||
"FREECPU=#{totalcpu}"
|
||||
@info="HYPERVISOR=ec2\nTOTALMEMORY=#{totalmemory}\n"<<
|
||||
"TOTALCPU=#{totalcpu}\nCPUSPEED=1000\nFREEMEMORY=#{totalmemory}"<<
|
||||
"\nFREECPU=#{totalcpu}\n"
|
||||
end
|
||||
|
||||
# The monitor action, just print the capacity info and hostname
|
||||
def action_monitor(num, host, not_used)
|
||||
send_message("MONITOR", RESULT[:success], num,
|
||||
"HOSTNAME=#{host},#{@info}")
|
||||
info = "HOSTNAME=\"#{host}\"\n#{@info}"
|
||||
info64 = Base64::encode64(info).strip.delete("\n")
|
||||
send_message("MONITOR", RESULT[:success], num, info64)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,8 +71,9 @@ class InformationManagerDriver < OpenNebulaDriver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do_action("#{@hypervisor}", number, host, :MONITOR,
|
||||
:script_name => 'run_probes')
|
||||
:script_name => 'run_probes', :base64 => true)
|
||||
end
|
||||
end
|
||||
|
||||
@ -102,7 +103,7 @@ begin
|
||||
when '--local'
|
||||
local_actions={ 'MONITOR' => nil }
|
||||
when '--force-copy'
|
||||
force_copy=true
|
||||
force_copy=true
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
|
@ -87,5 +87,5 @@ info.each do |key, value|
|
||||
GangliaHost.print_info(key, value)
|
||||
end
|
||||
|
||||
|
||||
system("../../vmm/kvm/poll_ganglia #{host}")
|
||||
|
||||
|
20
src/im_mad/remotes/kvm.d/poll.sh
Executable file
20
src/im_mad/remotes/kvm.d/poll.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
../../vmm/kvm/poll --kvm -t
|
||||
|
@ -50,7 +50,7 @@ data=$(
|
||||
|
||||
EXIT_CODE=$?
|
||||
|
||||
echo $data | tr '\n' ' '
|
||||
echo "$data"
|
||||
|
||||
if [ "x$EXIT_CODE" != "x0" ]; then
|
||||
exit $EXIT_CODE
|
||||
|
@ -77,13 +77,46 @@ end
|
||||
|
||||
def add_info(name, value)
|
||||
value = "0" if value.nil? or value.to_s.empty?
|
||||
@result_str << "#{name}=#{value} "
|
||||
@result_str << "#{name}=#{value}\n"
|
||||
end
|
||||
|
||||
def print_info
|
||||
puts @result_str
|
||||
end
|
||||
|
||||
def get_vm_names
|
||||
rc, data = do_action("virsh -c #{@uri} --readonly list")
|
||||
return [] if !rc
|
||||
|
||||
data.gsub!(/^.*----$/m, '').strip!
|
||||
lines=data.split(/\n/)
|
||||
|
||||
lines.map do |line|
|
||||
line.split(/\s+/).delete_if {|d| d.empty? }[1]
|
||||
end.compact
|
||||
end
|
||||
|
||||
def get_vm_info(host, vm)
|
||||
`../../vmm/vmware/poll #{vm} #{host}`.strip
|
||||
end
|
||||
|
||||
def get_all_vm_info(host, vms)
|
||||
puts "VM_POLL=YES"
|
||||
vms.each do |vm|
|
||||
info=get_vm_info(host, vm)
|
||||
|
||||
number = -1
|
||||
if (vm =~ /^one-\d*$/)
|
||||
number = vm.split('-').last
|
||||
end
|
||||
|
||||
puts "VM=["
|
||||
puts " ID=#{number},"
|
||||
puts " DEPLOY_ID=#{vm},"
|
||||
puts " POLL=\"#{info}\" ]"
|
||||
end
|
||||
end
|
||||
|
||||
# ######################################################################## #
|
||||
# Main Procedure #
|
||||
# ######################################################################## #
|
||||
@ -165,3 +198,5 @@ add_info("TOTALMEMORY",$total_memory)
|
||||
add_info("FREEMEMORY",free_memory.to_i)
|
||||
|
||||
print_info
|
||||
|
||||
get_all_vm_info(host, get_vm_names)
|
||||
|
20
src/im_mad/remotes/xen.d/poll.sh
Executable file
20
src/im_mad/remotes/xen.d/poll.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
../../vmm/xen/poll --xen -t
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "ImageManager.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "ImagePool.h"
|
||||
#include "SSLTools.h"
|
||||
#include "SyncRequest.h"
|
||||
#include "Template.h"
|
||||
#include "Nebula.h"
|
||||
@ -812,7 +811,7 @@ string * ImageManager::format_message(
|
||||
<< ds_data
|
||||
<< "</DS_DRIVER_ACTION_DATA>";
|
||||
|
||||
return SSLTools::base64_encode(oss.str());
|
||||
return one_util::base64_encode(oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -18,6 +18,7 @@ require "ActionManager"
|
||||
require "CommandManager"
|
||||
|
||||
require "DriverExecHelper"
|
||||
require 'base64'
|
||||
|
||||
# This class provides basic messaging and logging functionality
|
||||
# to implement OpenNebula Drivers. A driver is a program that
|
||||
@ -29,7 +30,7 @@ require "DriverExecHelper"
|
||||
# with the action name through the register_action function
|
||||
class OpenNebulaDriver < ActionManager
|
||||
include DriverExecHelper
|
||||
|
||||
|
||||
# @return [String] Base path for scripts
|
||||
attr_reader :local_scripts_base_path, :remote_scripts_base_path
|
||||
# @return [String] Path for scripts
|
||||
@ -57,10 +58,10 @@ class OpenNebulaDriver < ActionManager
|
||||
|
||||
super(@options[:concurrency], @options[:threaded])
|
||||
|
||||
@retries = @options[:retries]
|
||||
@retries = @options[:retries]
|
||||
|
||||
#Set default values
|
||||
initialize_helper(directory, @options)
|
||||
initialize_helper(directory, @options)
|
||||
|
||||
register_action(:INIT, method("init"))
|
||||
end
|
||||
@ -78,13 +79,15 @@ class OpenNebulaDriver < ActionManager
|
||||
# @option ops [String] :stdin text to be writen to stdin
|
||||
# @option ops [String] :script_name default script name for the action,
|
||||
# action name is used by defaults
|
||||
# @option ops [String] :respond if defined will send result to ONE core
|
||||
# @option ops [Bool] :respond if defined will send result to ONE core
|
||||
# @option ops [Bool] :base64 encode the information sent to ONE core
|
||||
def do_action(parameters, id, host, aname, ops={})
|
||||
options={
|
||||
:stdin => nil,
|
||||
:script_name => nil,
|
||||
:respond => true,
|
||||
:ssh_stream => nil
|
||||
:ssh_stream => nil,
|
||||
:base64 => false
|
||||
}.merge(ops)
|
||||
|
||||
params = parameters + " #{id} #{host}"
|
||||
@ -115,7 +118,8 @@ class OpenNebulaDriver < ActionManager
|
||||
result, info = get_info_from_execution(execution)
|
||||
|
||||
if options[:respond]
|
||||
send_message(aname,result,id,info)
|
||||
info = Base64::encode64(info).strip.delete("\n") if options[:base64]
|
||||
send_message(aname, result, id, info)
|
||||
end
|
||||
|
||||
[result, info]
|
||||
|
@ -638,17 +638,19 @@ void Nebula::start()
|
||||
MadManager::mad_manager_system_init();
|
||||
|
||||
time_t timer_period;
|
||||
time_t monitor_period;
|
||||
|
||||
nebula_configuration->get("MANAGER_TIMER", timer_period);
|
||||
nebula_configuration->get("MONITORING_INTERVAL", monitor_period);
|
||||
|
||||
// ---- Virtual Machine Manager ----
|
||||
try
|
||||
{
|
||||
time_t poll_period;
|
||||
vector<const Attribute *> vmm_mads;
|
||||
int vm_limit;
|
||||
time_t poll_period;
|
||||
|
||||
nebula_configuration->get("VM_POLLING_INTERVAL", poll_period);
|
||||
poll_period = monitor_period * 2.5;
|
||||
|
||||
nebula_configuration->get("VM_PER_INTERVAL", vm_limit);
|
||||
|
||||
@ -695,11 +697,8 @@ void Nebula::start()
|
||||
try
|
||||
{
|
||||
vector<const Attribute *> im_mads;
|
||||
time_t monitor_period;
|
||||
int host_limit;
|
||||
|
||||
nebula_configuration->get("HOST_MONITORING_INTERVAL", monitor_period);
|
||||
|
||||
nebula_configuration->get("HOST_PER_INTERVAL", host_limit);
|
||||
|
||||
nebula_configuration->get("IM_MAD", im_mads);
|
||||
|
@ -89,10 +89,9 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
#*******************************************************************************
|
||||
# Daemon configuration attributes
|
||||
#-------------------------------------------------------------------------------
|
||||
# HOST_MONITORING_INTERVAL
|
||||
# MONITORING_INTERVAL
|
||||
# HOST_PER_INTERVAL
|
||||
# HOST_MONITORING_EXPIRATION_TIME
|
||||
# VM_POLLING_INTERVAL
|
||||
# VM_PER_INTERVAL
|
||||
# VM_MONITORING_EXPIRATION_TIME
|
||||
# PORT
|
||||
@ -102,10 +101,10 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
# VM_SUBMIT_ON_HOLD
|
||||
#*******************************************************************************
|
||||
*/
|
||||
// MONITOR_INTERVAL
|
||||
value = "600";
|
||||
// MONITORING_INTERVAL
|
||||
value = "300";
|
||||
|
||||
attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value);
|
||||
attribute = new SingleAttribute("MONITORING_INTERVAL",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// HOST_PER_INTERVAL
|
||||
@ -120,12 +119,6 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
attribute = new SingleAttribute("HOST_MONITORING_EXPIRATION_TIME",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// POLL_INTERVAL
|
||||
value = "600";
|
||||
|
||||
attribute = new SingleAttribute("VM_POLLING_INTERVAL",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// VM_PER_INTERVAL
|
||||
value = "5";
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "PoolObjectSQL.h"
|
||||
#include "PoolObjectAuth.h"
|
||||
#include "SSLTools.h"
|
||||
#include "NebulaUtil.h"
|
||||
#include "Nebula.h"
|
||||
#include "Clusterable.h"
|
||||
|
||||
@ -29,7 +29,7 @@ string& PoolObjectSQL::to_xml64(string &xml64)
|
||||
|
||||
to_xml(xml64);
|
||||
|
||||
str64 = SSLTools::base64_encode(xml64);
|
||||
str64 = one_util::base64_encode(xml64);
|
||||
|
||||
xml64 = *str64;
|
||||
|
||||
@ -141,20 +141,7 @@ void PoolObjectSQL::set_template_error_message(const string& message)
|
||||
SingleAttribute * attr;
|
||||
ostringstream error_value;
|
||||
|
||||
char str[26];
|
||||
time_t the_time;
|
||||
|
||||
the_time = time(NULL);
|
||||
|
||||
#ifdef SOLARIS
|
||||
ctime_r(&(the_time),str,sizeof(char)*26);
|
||||
#else
|
||||
ctime_r(&(the_time),str);
|
||||
#endif
|
||||
|
||||
str[24] = '\0'; // Get rid of final enter character
|
||||
|
||||
error_value << str << " : " << message;
|
||||
error_value << one_util::log_time() << " : " << message;
|
||||
|
||||
//Replace previous error message and insert the new one
|
||||
|
||||
@ -167,6 +154,14 @@ void PoolObjectSQL::set_template_error_message(const string& message)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void PoolObjectSQL::clear_template_error_message()
|
||||
{
|
||||
remove_template_attribute(error_attribute_name);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int PoolObjectSQL::replace_template(const string& tmpl_str, string& error)
|
||||
{
|
||||
Template * new_tmpl = get_new_template();
|
||||
|
@ -15,6 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManagerUser.h"
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -47,14 +48,14 @@ void RequestManagerUser::
|
||||
failure_response(ACTION, request_error(error_str,""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int UserChangePassword::user_action(int user_id,
|
||||
int UserChangePassword::user_action(int user_id,
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
string& error_str)
|
||||
{
|
||||
@ -71,7 +72,7 @@ int UserChangePassword::user_action(int user_id,
|
||||
|
||||
if (user->get_auth_driver() == UserPool::CORE_AUTH)
|
||||
{
|
||||
new_pass = SSLTools::sha1_digest(new_pass);
|
||||
new_pass = one_util::sha1_digest(new_pass);
|
||||
}
|
||||
|
||||
int rc = user->set_password(new_pass, error_str);
|
||||
@ -128,7 +129,7 @@ int UserChangeAuth::user_action(int user_id,
|
||||
{
|
||||
if ( new_auth == UserPool::CORE_AUTH)
|
||||
{
|
||||
new_pass = SSLTools::sha1_digest(new_pass);
|
||||
new_pass = one_util::sha1_digest(new_pass);
|
||||
}
|
||||
|
||||
// The password may be invalid, try to change it first
|
||||
@ -170,7 +171,7 @@ void UserChangeAuth::log_xmlrpc_param(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int UserSetQuota::user_action(int user_id,
|
||||
int UserSetQuota::user_action(int user_id,
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
string& error_str)
|
||||
{
|
||||
|
@ -15,7 +15,6 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "Client.h"
|
||||
#include "SSLTools.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <pwd.h>
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "NebulaLog.h"
|
||||
#include "Nebula.h"
|
||||
#include "AuthManager.h"
|
||||
#include "SSLTools.h"
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
@ -145,7 +145,7 @@ UserPool::UserPool(SqlDB * db,
|
||||
srand(time(0));
|
||||
sstr << rand();
|
||||
|
||||
random = SSLTools::sha1_digest( sstr.str() );
|
||||
random = one_util::sha1_digest(sstr.str());
|
||||
|
||||
filenames[0] = nd.get_var_location() + "/.one/sunstone_auth";
|
||||
filenames[1] = nd.get_var_location() + "/.one/occi_auth";
|
||||
@ -188,7 +188,7 @@ UserPool::UserPool(SqlDB * db,
|
||||
GroupPool::ONEADMIN_ID,
|
||||
SERVER_NAME,
|
||||
GroupPool::ONEADMIN_NAME,
|
||||
SSLTools::sha1_digest(random),
|
||||
one_util::sha1_digest(random),
|
||||
"server_cipher",
|
||||
true,
|
||||
error_str);
|
||||
@ -289,7 +289,7 @@ int UserPool::allocate (
|
||||
|
||||
if (auth_driver == UserPool::CORE_AUTH)
|
||||
{
|
||||
upass = SSLTools::sha1_digest(password);
|
||||
upass = one_util::sha1_digest(password);
|
||||
}
|
||||
|
||||
// Build a new User object
|
||||
|
@ -2465,6 +2465,47 @@ string VirtualMachine::get_system_dir() const
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::update_info(
|
||||
const int _memory,
|
||||
const int _cpu,
|
||||
const long long _net_tx,
|
||||
const long long _net_rx,
|
||||
const map<string, string> &custom)
|
||||
{
|
||||
map<string, string>::const_iterator it;
|
||||
|
||||
last_poll = time(0);
|
||||
|
||||
if (_memory != -1)
|
||||
{
|
||||
memory = _memory;
|
||||
}
|
||||
|
||||
if (_cpu != -1)
|
||||
{
|
||||
cpu = _cpu;
|
||||
}
|
||||
|
||||
if (_net_tx != -1)
|
||||
{
|
||||
net_tx = _net_tx;
|
||||
}
|
||||
|
||||
if (_net_rx != -1)
|
||||
{
|
||||
net_rx = _net_rx;
|
||||
}
|
||||
|
||||
for (it = custom.begin(); it != custom.end(); it++)
|
||||
{
|
||||
replace_template_attribute(it->first, it->second);
|
||||
}
|
||||
|
||||
set_vm_info();
|
||||
|
||||
clear_template_error_message();
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "XenDriver.h"
|
||||
#include "XMLDriver.h"
|
||||
#include "LibVirtDriver.h"
|
||||
#include "NebulaUtil.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
@ -380,7 +381,7 @@ string * VirtualMachineManager::format_message(
|
||||
oss << tmpl
|
||||
<< "</VMM_DRIVER_ACTION_DATA>";
|
||||
|
||||
return SSLTools::base64_encode(oss.str());
|
||||
return one_util::base64_encode(oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -1337,8 +1338,6 @@ void VirtualMachineManager::poll_action(
|
||||
"",
|
||||
vm->to_xml(vm_tmpl));
|
||||
|
||||
vm->set_last_poll(time(0));
|
||||
|
||||
vmd->poll(vid, *drv_msg);
|
||||
|
||||
delete drv_msg;
|
||||
@ -1420,7 +1419,8 @@ error_common:
|
||||
|
||||
void VirtualMachineManager::timer_action()
|
||||
{
|
||||
static int mark = 0;
|
||||
static int mark = 0;
|
||||
static int timer_start = time(0);
|
||||
|
||||
VirtualMachine * vm;
|
||||
vector<int> oids;
|
||||
@ -1446,6 +1446,13 @@ void VirtualMachineManager::timer_action()
|
||||
// Clear the expired monitoring records
|
||||
vmpool->clean_expired_monitoring();
|
||||
|
||||
// Skip monitoring the first poll_period to allow the Host monitoring to
|
||||
// gather the VM info
|
||||
if ( timer_start + poll_period > thetime )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Monitor only VMs that hasn't been monitored for 'poll_period' seconds.
|
||||
rc = vmpool->get_running(oids, vm_limit, thetime - poll_period);
|
||||
|
||||
@ -1478,8 +1485,6 @@ void VirtualMachineManager::timer_action()
|
||||
os << "Monitoring VM " << *it << ".";
|
||||
NebulaLog::log("VMM", Log::INFO, os);
|
||||
|
||||
vm->set_last_poll(thetime);
|
||||
|
||||
vmd = get(vm->get_vmm_mad());
|
||||
|
||||
if ( vmd == 0 )
|
||||
@ -1505,8 +1510,6 @@ void VirtualMachineManager::timer_action()
|
||||
|
||||
delete drv_msg;
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
}
|
||||
|
@ -206,12 +206,10 @@ void VirtualMachineManagerDriver::protocol(
|
||||
if (result == "SUCCESS")
|
||||
{
|
||||
string deploy_id;
|
||||
time_t thetime = time(0);
|
||||
|
||||
is >> deploy_id;
|
||||
|
||||
vm->update_info(deploy_id);
|
||||
vm->set_last_poll(thetime);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
@ -236,7 +234,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error(vm,os,is,"Error shuting down VM");
|
||||
log_error(vm,os,is,"Error shutting down VM");
|
||||
vmpool->update(vm);
|
||||
|
||||
lcm->trigger(LifeCycleManager::SHUTDOWN_FAILURE, id);
|
||||
@ -314,7 +312,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
{
|
||||
if (result == "SUCCESS")
|
||||
{
|
||||
vm->log("VMM",Log::ERROR,"VM Successfully rebooted.");
|
||||
vm->log("VMM",Log::INFO,"VM successfully rebooted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -326,7 +324,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
{
|
||||
if (result == "SUCCESS")
|
||||
{
|
||||
vm->log("VMM",Log::ERROR,"VM Successfully reseted.");
|
||||
vm->log("VMM",Log::INFO,"VM successfully reset.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -340,8 +338,8 @@ void VirtualMachineManagerDriver::protocol(
|
||||
LifeCycleManager *lcm = ne.get_lcm();
|
||||
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
vm->log("VMM", Log::ERROR, "VM Disk Successfully attached.");
|
||||
{
|
||||
vm->log("VMM", Log::INFO, "VM Disk successfully attached.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::ATTACH_SUCCESS, id);
|
||||
}
|
||||
@ -360,7 +358,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
vm->log("VMM",Log::ERROR,"VM Disk Successfully detached.");
|
||||
vm->log("VMM",Log::INFO,"VM Disk successfully detached.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::DETACH_SUCCESS, id);
|
||||
}
|
||||
@ -379,7 +377,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
if ( result == "SUCCESS" )
|
||||
{
|
||||
vm->log("VMM", Log::ERROR, "Host Successfully cleaned.");
|
||||
vm->log("VMM", Log::INFO, "Host successfully cleaned.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::CLEANUP_SUCCESS, id);
|
||||
}
|
||||
@ -395,161 +393,19 @@ void VirtualMachineManagerDriver::protocol(
|
||||
{
|
||||
if (result == "SUCCESS")
|
||||
{
|
||||
size_t pos;
|
||||
string monitor_str;
|
||||
getline(is, monitor_str);
|
||||
|
||||
string tmp;
|
||||
string var;
|
||||
ostringstream os;
|
||||
istringstream tiss;
|
||||
|
||||
int cpu = -1;
|
||||
int memory = -1;
|
||||
long long net_tx = -1;
|
||||
long long net_rx = -1;
|
||||
char state = '-';
|
||||
|
||||
string monitor_str = is.str();
|
||||
bool parse_error = false;
|
||||
|
||||
while(is.good())
|
||||
{
|
||||
is >> tmp >> ws;
|
||||
|
||||
pos = tmp.find('=');
|
||||
|
||||
if ( pos == string::npos )
|
||||
{
|
||||
parse_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp.replace(pos,1," ");
|
||||
|
||||
tiss.clear();
|
||||
|
||||
tiss.str(tmp);
|
||||
|
||||
tiss >> var >> ws;
|
||||
|
||||
if (!tiss.good())
|
||||
{
|
||||
parse_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (var == "USEDMEMORY")
|
||||
{
|
||||
tiss >> memory;
|
||||
}
|
||||
else if (var == "USEDCPU")
|
||||
{
|
||||
tiss >> cpu;
|
||||
}
|
||||
else if (var == "NETRX")
|
||||
{
|
||||
tiss >> net_rx;
|
||||
}
|
||||
else if (var == "NETTX")
|
||||
{
|
||||
tiss >> net_tx;
|
||||
}
|
||||
else if (var == "STATE")
|
||||
{
|
||||
tiss >> state;
|
||||
}
|
||||
else if (!var.empty())
|
||||
{
|
||||
string val;
|
||||
|
||||
os.str("");
|
||||
os << "Adding custom monitoring attribute: " << tmp;
|
||||
|
||||
vm->log("VMM",Log::WARNING,os);
|
||||
|
||||
tiss >> val;
|
||||
|
||||
vm->replace_template_attribute(var,val);
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_error)
|
||||
{
|
||||
os.str("");
|
||||
os << "Error parsing monitoring str:\"" << monitor_str <<"\"";
|
||||
|
||||
vm->log("VMM",Log::ERROR,os);
|
||||
|
||||
vm->set_template_error_message(os.str());
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
vm->update_info(memory,cpu,net_tx,net_rx);
|
||||
vm->set_vm_info();
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_monitoring(vm);
|
||||
|
||||
if (state != '-' &&
|
||||
(vm->get_lcm_state() == VirtualMachine::RUNNING ||
|
||||
vm->get_lcm_state() == VirtualMachine::UNKNOWN))
|
||||
{
|
||||
Nebula &ne = Nebula::instance();
|
||||
LifeCycleManager * lcm = ne.get_lcm();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case 'a': // Still active, good!
|
||||
os.str("");
|
||||
os << "Monitor Information:\n"
|
||||
<< "\tCPU : "<< cpu << "\n"
|
||||
<< "\tMemory: "<< memory << "\n"
|
||||
<< "\tNet_TX: "<< net_tx << "\n"
|
||||
<< "\tNet_RX: "<< net_rx;
|
||||
vm->log("VMM",Log::DEBUG,os);
|
||||
|
||||
if ( vm->get_lcm_state() == VirtualMachine::UNKNOWN)
|
||||
{
|
||||
vm->log("VMM",Log::INFO,"VM was now found, new state is"
|
||||
" RUNNING");
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
vmpool->update(vm);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p': // It's paused
|
||||
vm->log("VMM",Log::INFO,"VM running but new state "
|
||||
"from monitor is PAUSED.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_SUSPEND, id);
|
||||
break;
|
||||
|
||||
case 'e': //Failed
|
||||
vm->log("VMM",Log::INFO,"VM running but new state "
|
||||
"from monitor is ERROR.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_FAILURE, id);
|
||||
break;
|
||||
|
||||
case 'd': //The VM was not found
|
||||
vm->log("VMM",Log::INFO,"VM running but it was not found."
|
||||
" Restart and delete actions available or try to"
|
||||
" recover it manually");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_DONE, id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
process_poll(vm, monitor_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error(vm,os,is,"Error monitoring VM");
|
||||
vmpool->update(vm);
|
||||
Nebula &ne = Nebula::instance();
|
||||
LifeCycleManager* lcm = ne.get_lcm();
|
||||
|
||||
vm->log("VMM",Log::ERROR,os);
|
||||
log_error(vm, os, is, "Error monitoring VM");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_DONE, vm->get_oid());
|
||||
}
|
||||
}
|
||||
else if (action == "LOG")
|
||||
@ -566,6 +422,211 @@ void VirtualMachineManagerDriver::protocol(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineManagerDriver::process_poll(
|
||||
int id,
|
||||
const string &monitor_str)
|
||||
{
|
||||
// Get the VM from the pool
|
||||
VirtualMachine* vm = Nebula::instance().get_vmpool()->get(id,true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
process_poll(vm, monitor_str);
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineManagerDriver::process_poll(
|
||||
VirtualMachine* vm,
|
||||
const string& monitor_str)
|
||||
{
|
||||
int rc;
|
||||
|
||||
int cpu;
|
||||
int memory;
|
||||
long long net_tx;
|
||||
long long net_rx;
|
||||
char state;
|
||||
|
||||
map<string, string> custom;
|
||||
ostringstream oss;
|
||||
|
||||
Nebula &ne = Nebula::instance();
|
||||
|
||||
LifeCycleManager* lcm = ne.get_lcm();
|
||||
VirtualMachinePool* vmpool = ne.get_vmpool();
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Parse VM info and update VM */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
rc = parse_vm_info(monitor_str, cpu, memory, net_tx, net_rx, state, custom);
|
||||
|
||||
if (rc == -1)
|
||||
{
|
||||
vm->set_template_error_message("Error parsing monitoring information.");
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
oss << "VM " << vm->get_oid() << " successfully monitored: " << monitor_str;
|
||||
NebulaLog::log("VMM", Log::INFO, oss);
|
||||
|
||||
vm->update_info(memory, cpu, net_tx, net_rx, custom);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
|
||||
vmpool->update_monitoring(vm);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Process the VM state from the monitoring info */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
if (state == '-' || ( vm->get_lcm_state() != VirtualMachine::RUNNING &&
|
||||
vm->get_lcm_state() != VirtualMachine::UNKNOWN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case 'a': // Still active, good!
|
||||
if ( vm->get_lcm_state() == VirtualMachine::UNKNOWN)
|
||||
{
|
||||
vm->log("VMM", Log::INFO, "VM found again, state is RUNNING");
|
||||
|
||||
vm->set_state(VirtualMachine::RUNNING);
|
||||
vmpool->update(vm);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'p': // It's paused
|
||||
vm->log("VMM",Log::INFO, "VM running but monitor state is PAUSED.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_SUSPEND, vm->get_oid());
|
||||
break;
|
||||
|
||||
case 'e': //Failed
|
||||
vm->log("VMM", Log::INFO, "VM running but monitor state is ERROR.");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_FAILURE, vm->get_oid());
|
||||
break;
|
||||
|
||||
case 'd': //The VM was not found
|
||||
vm->log("VMM", Log::INFO, "VM running but it was not found."
|
||||
" Restart and delete actions available or try to"
|
||||
" recover it manually");
|
||||
|
||||
lcm->trigger(LifeCycleManager::MONITOR_DONE, vm->get_oid());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachineManagerDriver::parse_vm_info(
|
||||
const string& monitor_str,
|
||||
int &cpu,
|
||||
int &memory,
|
||||
long long &net_tx,
|
||||
long long &net_rx,
|
||||
char &state,
|
||||
map<string,string> &custom)
|
||||
{
|
||||
istringstream is;
|
||||
|
||||
int parse_error = 0;
|
||||
size_t pos;
|
||||
|
||||
string tmp;
|
||||
string var;
|
||||
|
||||
ostringstream os;
|
||||
istringstream tiss;
|
||||
|
||||
cpu = -1;
|
||||
memory = -1;
|
||||
net_tx = -1;
|
||||
net_rx = -1;
|
||||
state = '-';
|
||||
|
||||
custom.clear();
|
||||
|
||||
is.str(monitor_str);
|
||||
|
||||
while(is.good())
|
||||
{
|
||||
is >> tmp >> ws;
|
||||
|
||||
pos = tmp.find('=');
|
||||
|
||||
if ( pos == string::npos )
|
||||
{
|
||||
parse_error = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp.replace(pos,1," ");
|
||||
|
||||
tiss.clear();
|
||||
|
||||
tiss.str(tmp);
|
||||
|
||||
tiss >> var >> ws;
|
||||
|
||||
if (!tiss.good())
|
||||
{
|
||||
parse_error = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (var == "USEDMEMORY")
|
||||
{
|
||||
tiss >> memory;
|
||||
}
|
||||
else if (var == "USEDCPU")
|
||||
{
|
||||
tiss >> cpu;
|
||||
}
|
||||
else if (var == "NETRX")
|
||||
{
|
||||
tiss >> net_rx;
|
||||
}
|
||||
else if (var == "NETTX")
|
||||
{
|
||||
tiss >> net_tx;
|
||||
}
|
||||
else if (var == "STATE")
|
||||
{
|
||||
tiss >> state;
|
||||
}
|
||||
else if (!var.empty())
|
||||
{
|
||||
string val;
|
||||
|
||||
tiss >> val;
|
||||
|
||||
custom.insert(make_pair(var, val));
|
||||
}
|
||||
}
|
||||
|
||||
return parse_error;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineManagerDriver::recover()
|
||||
{
|
||||
NebulaLog::log("VMM",Log::INFO,"Recovering VMM drivers");
|
||||
|
@ -49,9 +49,40 @@ GANGLIA_PORT=8649
|
||||
#GANGLIA_FILE='data.xml'
|
||||
|
||||
|
||||
domain=ARGV[0]
|
||||
dom_id=ARGV[2]
|
||||
host=ARGV[1]
|
||||
def info_string(dom_info)
|
||||
if dom_info
|
||||
info=dom_info.map do |key, value|
|
||||
"#{key.to_s.upcase}=#{value}"
|
||||
end.join(' ')
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def vm_info(name, dom_info)
|
||||
number = -1
|
||||
|
||||
if (name =~ /^one-\d*$/)
|
||||
number = name.split('-').last
|
||||
end
|
||||
|
||||
string="VM=[\n"
|
||||
string<<" ID=\"#{number}\",\n"
|
||||
string<<" DEPLOY_ID=#{name},\n"
|
||||
string<<" POLL=\"#{info_string(dom_info)}\" ]"
|
||||
string
|
||||
end
|
||||
|
||||
|
||||
if ARGV.length==1
|
||||
host=ARGV[0]
|
||||
ALL=true
|
||||
else
|
||||
domain=ARGV[0]
|
||||
dom_id=ARGV[2]
|
||||
host=ARGV[1]
|
||||
ALL=false
|
||||
end
|
||||
|
||||
# Gets monitoring data from ganglia or file
|
||||
begin
|
||||
@ -66,24 +97,26 @@ rescue
|
||||
end
|
||||
|
||||
doms_info=ganglia.get_vms_information
|
||||
dom_id=domain.split('-').last
|
||||
|
||||
# Unknown state when the VM is not found
|
||||
if !doms_info || !(doms_info[domain] || doms_info[dom_id])
|
||||
puts "STATE=d"
|
||||
exit(0)
|
||||
if !ALL
|
||||
dom_id=domain.split('-').last
|
||||
|
||||
# Unknown state when the VM is not found
|
||||
if !doms_info || !(doms_info[domain] || doms_info[dom_id])
|
||||
puts "STATE=d"
|
||||
exit(0)
|
||||
end
|
||||
|
||||
# Get key one-<vmid> or <vmid> key from the hash
|
||||
dom_info=doms_info[domain]
|
||||
dom_info=doms_info[dom_id] if !dom_info
|
||||
|
||||
puts info_string(dom_info)
|
||||
else
|
||||
puts "VM_POLL=YES"
|
||||
|
||||
doms_info.each do |name, data|
|
||||
puts vm_info(name, data)
|
||||
end
|
||||
end
|
||||
|
||||
# Get key one-<vmid> or <vmid> key from the hash
|
||||
dom_info=doms_info[domain]
|
||||
dom_info=doms_info[dom_id] if !dom_info
|
||||
|
||||
if dom_info
|
||||
info=dom_info.map do |key, value|
|
||||
"#{key.to_s.upcase}=#{value}"
|
||||
end.join(' ')
|
||||
|
||||
puts info
|
||||
end
|
||||
|
||||
|
||||
|
@ -343,6 +343,34 @@ def print_all_vm_info(hypervisor)
|
||||
puts Base64.encode64(compressed).delete("\n")
|
||||
end
|
||||
|
||||
def print_all_vm_template(hypervisor)
|
||||
vms=hypervisor.get_all_vm_info
|
||||
|
||||
puts "VM_POLL=YES"
|
||||
|
||||
vms.each do |name, data|
|
||||
number = -1
|
||||
|
||||
if (name =~ /^one-\d*$/)
|
||||
number = name.split('-').last
|
||||
end
|
||||
|
||||
string="VM=[\n"
|
||||
string<<" ID=#{number},\n"
|
||||
string<<" DEPLOY_ID=#{name},\n"
|
||||
|
||||
values=data.map do |key, value|
|
||||
print_data(key, value)
|
||||
end
|
||||
|
||||
monitor=values.zip.join(' ')
|
||||
|
||||
string<<" POLL=\"#{monitor}\" ]"
|
||||
|
||||
puts string
|
||||
end
|
||||
end
|
||||
|
||||
hypervisor=select_hypervisor
|
||||
|
||||
if !hypervisor
|
||||
@ -354,7 +382,9 @@ load_vars(hypervisor)
|
||||
|
||||
vm_id=ARGV[0]
|
||||
|
||||
if vm_id
|
||||
if vm_id=='-t'
|
||||
print_all_vm_template(hypervisor)
|
||||
elsif vm_id
|
||||
print_one_vm_info(hypervisor, vm_id)
|
||||
else
|
||||
print_all_vm_info(hypervisor)
|
||||
|
Loading…
x
Reference in New Issue
Block a user