1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Hector Sanjuan 2012-01-26 09:05:06 +01:00
commit 936650bc07
28 changed files with 554 additions and 391 deletions

View File

@ -93,9 +93,23 @@ public:
*/
Group * get(const string& name, bool lock)
{
// The owner is set to -1, because it is not used in the key() method
return static_cast<Group *>(PoolSQL::get(name,-1,lock));
};
/**
* Generate an index key for the object
* @param name of the object
* @param uid owner of the object, only used if needed
*
* @return the key, a string
*/
string key(const string& name, int uid)
{
// Name is enough key because Groups can't repeat names.
return name;
};
/** Update a particular Group
* @param user pointer to Group
* @return 0 on success

View File

@ -79,9 +79,23 @@ public:
*/
Host * get(string name, bool lock)
{
// The owner is set to -1, because it is not used in the key() method
return static_cast<Host *>(PoolSQL::get(name,-1,lock));
};
/**
* Generate an index key for the object
* @param name of the object
* @param uid owner of the object, only used if needed
*
* @return the key, a string
*/
string key(const string& name, int uid)
{
// Name is enough key because Hosts can't repeat names.
return name;
};
/**
* Bootstraps the database table(s) associated to the Host pool
* @return 0 on success

View File

@ -46,7 +46,15 @@ private:
static vector<string> restricted_attributes;
static void set_restricted_attributes(vector<const Attribute *>& rattrs);
/**
* Stores the attributes as restricted, these attributes will be used in
* ImageTemplate::check
* @param rattrs Attributes to restrict
*/
static void set_restricted_attributes(vector<const Attribute *>& rattrs)
{
Template::set_restricted_attributes(rattrs, restricted_attributes);
};
};
/* -------------------------------------------------------------------------- */

View File

@ -82,6 +82,20 @@ public:
*/
PoolObjectSQL * get(const string& name, int uid, bool lock);
/**
* Updates the cache name index. Must be called when the owner of an object
* is changed
*
* @param old_name Object's name before the change
* @param old_uid Object's owner ID before the change
* @param new_name Object's name after the change
* @param new_uid Object's owner ID after the change
*/
void update_cache_index(string& old_name,
int old_uid,
string& new_name,
int new_uid);
/**
* Finds a set objects that satisfies a given condition
* @param oids a vector with the oids of the objects.
@ -273,7 +287,7 @@ private:
*
* @return the key, a string
*/
string key(const string& name, int uid)
virtual string key(const string& name, int uid)
{
ostringstream key;

View File

@ -221,6 +221,16 @@ protected:
*/
Attribute* vector_xml_att(const xmlNode * node);
/**
* Stores the attributes as restricted, these attributes will be used in
* Template::check
* @param rattrs Attributes to restrict
* @param restricted_attributes The attributes will be stored here
*/
static void set_restricted_attributes(
vector<const Attribute *>& rattrs,
vector<string>& restricted_attributes);
/**
* Checks the template for RESTRICTED ATTRIBUTES
* @param rs_attr the first restricted attribute found if any

View File

@ -80,9 +80,23 @@ public:
*/
User * get(string name, bool lock)
{
// The owner is set to -1, because it is not used in the key() method
return static_cast<User *>(PoolSQL::get(name,-1,lock));
};
/**
* Generate an index key for the object
* @param name of the object
* @param uid owner of the object, only used if needed
*
* @return the key, a string
*/
string key(const string& name, int uid)
{
// Name is enough key because Users can't repeat names.
return name;
};
/** Update a particular User
* @param user pointer to User
* @return 0 on success

View File

@ -52,7 +52,15 @@ private:
static vector<string> restricted_attributes;
static void set_restricted_attributes(vector<const Attribute *>& rattrs);
/**
* Stores the attributes as restricted, these attributes will be used in
* VirtualMachineTemplate::check
* @param rattrs Attributes to restrict
*/
static void set_restricted_attributes(vector<const Attribute *>& rattrs)
{
Template::set_restricted_attributes(rattrs, restricted_attributes);
};
};
/* -------------------------------------------------------------------------- */

View File

@ -112,7 +112,7 @@ EOT
`gem install rubygems-update --version '= 1.3.6'`
if $?.ecxitstatus!=0
if $?.exitstatus!=0
puts "Error updating rubygems"
exit(-1)
end

View File

@ -287,7 +287,12 @@ EOT
end
def pool_to_array(pool)
phash = pool.to_hash
if !pool.instance_of?(Hash)
phash = pool.to_hash
else
phash = pool
end
rname = self.class.rname
if phash["#{rname}_POOL"] &&

View File

@ -44,6 +44,24 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
exit_code
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Group", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Group", :left, :size=>15 do |d|
d["NAME"]
end
default :ID, :NAME
end
table
end
private
def factory(id=nil)
@ -75,22 +93,4 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
puts "%-15s" % [uid]
end
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Group", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Group", :left, :size=>15 do |d|
d["NAME"]
end
default :ID, :NAME
end
table
end
end

View File

@ -31,58 +31,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
return Host::SHORT_HOST_STATES[state_str]
end
private
def factory(id=nil)
if id
OpenNebula::Host.new_with_id(id, @client)
else
xml=OpenNebula::Host.build_xml
OpenNebula::Host.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
#TBD OpenNebula::HostPool.new(@client, user_flag)
OpenNebula::HostPool.new(@client)
end
def format_resource(host)
str = "%-22s: %-20s"
str_h1 = "%-80s"
CLIHelper.print_header(
str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
puts str % ["ID", host.id.to_s]
puts str % ["NAME", host.name]
puts str % ["STATE", host.state_str]
puts str % ["IM_MAD", host['IM_MAD']]
puts str % ["VM_MAD", host['VM_MAD']]
puts str % ["VN_MAD", host['VN_MAD']]
puts str % ["TM_MAD", host['TM_MAD']]
puts str % ["LAST MONITORING TIME", host['LAST_MON_TIME']]
puts
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
puts str % ["MAX MEM", host['HOST_SHARE/MAX_MEM']]
puts str % ["USED MEM (REAL)", host['HOST_SHARE/USED_MEM']]
puts str % ["USED MEM (ALLOCATED)", host['HOST_SHARE/MEM_USAGE']]
puts str % ["MAX CPU", host['HOST_SHARE/MAX_CPU']]
puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
puts str % ["MAX DISK", host['HOST_SHARE/MAX_DISK']]
puts str % ["USED DISK (REAL)", host['HOST_SHARE/USED_DISK']]
puts str % ["USED DISK (ALLOCATED)", host['HOST_SHARE/DISK_USAGE']]
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
puts
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
puts host.template_str
end
def format_pool(options)
config_file = self.class.table_conf
@ -144,4 +92,56 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
table
end
private
def factory(id=nil)
if id
OpenNebula::Host.new_with_id(id, @client)
else
xml=OpenNebula::Host.build_xml
OpenNebula::Host.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
#TBD OpenNebula::HostPool.new(@client, user_flag)
OpenNebula::HostPool.new(@client)
end
def format_resource(host)
str = "%-22s: %-20s"
str_h1 = "%-80s"
CLIHelper.print_header(
str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
puts str % ["ID", host.id.to_s]
puts str % ["NAME", host.name]
puts str % ["STATE", host.state_str]
puts str % ["IM_MAD", host['IM_MAD']]
puts str % ["VM_MAD", host['VM_MAD']]
puts str % ["VN_MAD", host['VN_MAD']]
puts str % ["TM_MAD", host['TM_MAD']]
puts str % ["LAST MONITORING TIME", host['LAST_MON_TIME']]
puts
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
puts str % ["MAX MEM", host['HOST_SHARE/MAX_MEM']]
puts str % ["USED MEM (REAL)", host['HOST_SHARE/USED_MEM']]
puts str % ["USED MEM (ALLOCATED)", host['HOST_SHARE/MEM_USAGE']]
puts str % ["MAX CPU", host['HOST_SHARE/MAX_CPU']]
puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
puts str % ["MAX DISK", host['HOST_SHARE/MAX_DISK']]
puts str % ["USED DISK (REAL)", host['HOST_SHARE/USED_DISK']]
puts str % ["USED DISK (ALLOCATED)", host['HOST_SHARE/DISK_USAGE']]
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
puts
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
puts host.template_str
end
end

View File

@ -36,60 +36,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
type_str = Image::IMAGE_TYPES[id]
return Image::SHORT_IMAGE_TYPES[type_str]
end
private
def factory(id=nil)
if id
OpenNebula::Image.new_with_id(id, @client)
else
xml=OpenNebula::Image.build_xml
OpenNebula::Image.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
OpenNebula::ImagePool.new(@client, user_flag)
end
def format_resource(image)
str="%-15s: %-20s"
str_h1="%-80s"
CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
puts str % ["ID", image.id.to_s]
puts str % ["NAME", image.name]
puts str % ["USER", image['UNAME']]
puts str % ["GROUP",image['GNAME']]
puts str % ["TYPE", image.type_str]
puts str % ["REGISTER TIME",
OpenNebulaHelper.time_to_str(image['REGTIME'])]
puts str % ["PERSISTENT",
OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
puts str % ["SOURCE",image['SOURCE']]
puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty?
puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty?
puts str % ["SIZE", image['SIZE']]
puts str % ["STATE", image.short_state_str]
puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
puts
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
["OWNER", "GROUP", "OTHER"].each { |e|
mask = "---"
mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1"
mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1"
mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1"
puts str % [e, mask]
}
puts
CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
puts image.template_str
end
def format_pool(options)
config_file = self.class.table_conf
@ -146,4 +93,57 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
table
end
private
def factory(id=nil)
if id
OpenNebula::Image.new_with_id(id, @client)
else
xml=OpenNebula::Image.build_xml
OpenNebula::Image.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
OpenNebula::ImagePool.new(@client, user_flag)
end
def format_resource(image)
str="%-15s: %-20s"
str_h1="%-80s"
CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
puts str % ["ID", image.id.to_s]
puts str % ["NAME", image.name]
puts str % ["USER", image['UNAME']]
puts str % ["GROUP",image['GNAME']]
puts str % ["TYPE", image.type_str]
puts str % ["REGISTER TIME",
OpenNebulaHelper.time_to_str(image['REGTIME'])]
puts str % ["PERSISTENT",
OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
puts str % ["SOURCE",image['SOURCE']]
puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty?
puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty?
puts str % ["SIZE", image['SIZE']]
puts str % ["STATE", image.short_state_str]
puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
puts
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
["OWNER", "GROUP", "OTHER"].each { |e|
mask = "---"
mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1"
mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1"
mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1"
puts str % [e, mask]
}
puts
CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
puts image.template_str
end
end

View File

@ -41,6 +41,38 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
"onetemplate.yaml"
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Template", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Template", :left, :size=>15 do |d|
d["NAME"]
end
column :USER, "Username of the Template owner", :left,
:size=>8 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the Template", :left, :size=>8 do |d|
helper.group_name(d, options)
end
column :REGTIME, "Registration time of the Template",
:size=>20 do |d|
OpenNebulaHelper.time_to_str(d["REGTIME"])
end
default :ID, :USER, :GROUP, :NAME, :REGTIME
end
table
end
private
def factory(id=nil)
@ -85,36 +117,4 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
puts template.template_str
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Template", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Template", :left, :size=>15 do |d|
d["NAME"]
end
column :USER, "Username of the Template owner", :left,
:size=>8 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the Template", :left, :size=>8 do |d|
helper.group_name(d, options)
end
column :REGTIME, "Registration time of the Template",
:size=>20 do |d|
OpenNebulaHelper.time_to_str(d["REGTIME"])
end
default :ID, :USER, :GROUP, :NAME, :REGTIME
end
table
end
end

View File

@ -143,6 +143,36 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
return 0, 'export ONE_AUTH=' << auth.class::LOGIN_PATH
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the User", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the User", :left, :size=>15 do |d|
d["NAME"]
end
column :GROUP, "Group of the User", :left, :size=>8 do |d|
helper.group_name(d, options)
end
column :AUTH, "Auth driver of the User", :left, :size=>8 do |d|
d["AUTH_DRIVER"]
end
column :PASSWORD, "Password of the User", :size=>50 do |d|
d['PASSWORD']
end
default :ID, :GROUP, :NAME, :AUTH, :PASSWORD
end
table
end
private
def factory(id=nil)
@ -178,34 +208,4 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "USER TEMPLATE",false)
puts user.template_str
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the User", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the User", :left, :size=>15 do |d|
d["NAME"]
end
column :GROUP, "Group of the User", :left, :size=>8 do |d|
helper.group_name(d, options)
end
column :AUTH, "Auth driver of the User", :left, :size=>8 do |d|
d["AUTH_DRIVER"]
end
column :PASSWORD, "Password of the User", :size=>50 do |d|
d['PASSWORD']
end
default :ID, :GROUP, :NAME, :AUTH, :PASSWORD
end
table
end
end

View File

@ -47,6 +47,68 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
return short_state_str
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
d["ID"]
end
column :NAME, "Name of the Virtual Machine", :left,
:size=>15 do |d|
d["NAME"]
end
column :USER, "Username of the Virtual Machine owner", :left,
:size=>8 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the Virtual Machine", :left,
:size=>8 do |d|
helper.group_name(d, options)
end
column :STAT, "Actual status", :size=>4 do |d,e|
OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"])
end
column :CPU, "CPU percentage used by the VM", :size=>3 do |d|
d["CPU"]
end
column :MEM, "Memory used by the VM", :size=>7 do |d|
OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i, options)
end
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d|
if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY']
state_str = VirtualMachine::VM_STATE[d['STATE'].to_i]
if %w{ACTIVE SUSPENDED}.include? state_str
d['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
end
end
end
column :TIME, "Time since the VM was submitted", :size=>11 do |d|
stime = Time.at(d["STIME"].to_i)
etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i)
dtime = Time.at(etime-stime).getgm
"%02d %02d:%02d:%02d" % [
dtime.yday-1,
dtime.hour,
dtime.min,
dtime.sec]
end
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME,
:TIME
end
table
end
private
def factory(id=nil)
@ -120,68 +182,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
d["ID"]
end
column :NAME, "Name of the Virtual Machine", :left,
:size=>15 do |d|
d["NAME"]
end
column :USER, "Username of the Virtual Machine owner", :left,
:size=>8 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the Virtual Machine", :left,
:size=>8 do |d|
helper.group_name(d, options)
end
column :STAT, "Actual status", :size=>4 do |d,e|
OneVMHelper.state_to_str(d["STATE"], d["LCM_STATE"])
end
column :CPU, "CPU percentage used by the VM", :size=>3 do |d|
d["CPU"]
end
column :MEM, "Memory used by the VM", :size=>7 do |d|
OpenNebulaHelper.unit_to_str(d["MEMORY"].to_i, options)
end
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d|
if d['HISTORY_RECORDS'] && d['HISTORY_RECORDS']['HISTORY']
state_str = VirtualMachine::VM_STATE[d['STATE'].to_i]
if %w{ACTIVE SUSPENDED}.include? state_str
d['HISTORY_RECORDS']['HISTORY']['HOSTNAME']
end
end
end
column :TIME, "Time since the VM was submitted", :size=>11 do |d|
stime = Time.at(d["STIME"].to_i)
etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i)
dtime = Time.at(etime-stime).getgm
"%02d %02d:%02d:%02d" % [
dtime.yday-1,
dtime.hour,
dtime.min,
dtime.sec]
end
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME,
:TIME
end
table
end
def format_history(vm)
table=CLIHelper::ShowTable.new(nil, self) do
column :SEQ, "Sequence number", :size=>4 do |d|

View File

@ -31,6 +31,53 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
return VirtualNetwork::SHORT_VN_TYPES[type_str]
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for Virtual Network", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Virtual Network", :left,
:size=>15 do |d|
d["NAME"]
end
column :USER, "Username of the Virtual Network owner", :left,
:size=>8 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the Virtual Network", :left,
:size=>8 do |d|
helper.group_name(d, options)
end
column :TYPE, "Type of Virtual Network", :size=>6 do |d|
OneVNetHelper.type_to_str(d["TYPE"])
end
column :SIZE, "Size of the Virtual Network", :size=>6 do |d|
d["SIZE"]
end
column :BRIDGE, "Bridge associated to the Virtual Network",
:size=>6 do |d|
d["BRIDGE"]
end
column :LEASES, "Number of this Virtual Network's given leases",
:size=>7 do |d|
d["TOTAL_LEASES"]
end
default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :LEASES
end
table
end
private
def factory(id=nil)
@ -101,51 +148,4 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
end
}
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for Virtual Network", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the Virtual Network", :left,
:size=>15 do |d|
d["NAME"]
end
column :USER, "Username of the Virtual Network owner", :left,
:size=>8 do |d|
helper.user_name(d, options)
end
column :GROUP, "Group of the Virtual Network", :left,
:size=>8 do |d|
helper.group_name(d, options)
end
column :TYPE, "Type of Virtual Network", :size=>6 do |d|
OneVNetHelper.type_to_str(d["TYPE"])
end
column :SIZE, "Size of the Virtual Network", :size=>6 do |d|
d["SIZE"]
end
column :BRIDGE, "Bridge associated to the Virtual Network",
:size=>6 do |d|
d["BRIDGE"]
end
column :LEASES, "Number of this Virtual Network's given leases",
:size=>7 do |d|
d["TOTAL_LEASES"]
end
default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :LEASES
end
table
end
end

View File

@ -22,7 +22,7 @@ class ImageOCCI < Image
OCCI_IMAGE = %q{
<STORAGE href="<%= base_url %>/storage/<%= self.id.to_s %>">
<ID><%= self.id.to_s %></ID>
<NAME><%= self.name %></NAME
<NAME><%= self.name %></NAME>
<STATE><%= self.state_str %></STATE>
<% if self['TYPE'] != nil %>
<TYPE><%= self.type_str %></TYPE>

View File

@ -1,5 +1,5 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2012, OpenNebula Project Leads (OCCI.org) */
/* 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 */

View File

@ -228,13 +228,12 @@ void ImageManagerDriver::protocol(
if ( rc < 0 )
{
image->unlock();
NebulaLog::log("ImM",Log::ERROR,"Image could not be removed from DB");
}
if ( result == "SUCCESS" )
{
NebulaLog::log("ImM",Log::ERROR,"Image successfully removed.");
NebulaLog::log("ImM",Log::INFO,"Image successfully removed.");
}
else
{
@ -267,10 +266,23 @@ error_mkfs:
goto error_common;
error_rm:
image->unlock();
os.str("");
os << "Error removing image from repository. Remove file " << source
<< " to completely delete image.";
getline(is,info);
if (!info.empty() && (info[0] != '-'))
{
os << ": " << info;
}
NebulaLog::log("ImM", Log::ERROR, os);
return;
error_common:
getline(is,info);

View File

@ -23,22 +23,3 @@ vector<string> ImageTemplate::restricted_attributes;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ImageTemplate::set_restricted_attributes(vector<const Attribute *>& rattrs)
{
const SingleAttribute * sattr;
string attr;
for (unsigned int i = 0 ; i < rattrs.size() ; i++ )
{
sattr = static_cast<const SingleAttribute *>(rattrs[i]);
attr = sattr->value();
transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper);
restricted_attributes.push_back(attr);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -79,6 +79,30 @@ module OpenNebula
value.class==OpenNebula::Error
end
if OpenNebula::NOKOGIRI
class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser
def initialize
@parser_class = NokogiriParser
end
class NokogiriParser < Nokogiri::XML::SAX::Document
include XMLRPC::XMLParser::StreamParserMixin
alias :cdata_block :character
alias :characters :character
alias :end_element :endElement
alias :start_element :startElement
def parse(str)
parser = Nokogiri::XML::SAX::Parser.new(self)
parser.parse(str)
end
end
end
end
# The client class, represents the connection with the core and handles the
# xml-rpc calls.
class Client
@ -113,14 +137,15 @@ module OpenNebula
end
@server = XMLRPC::Client.new2(@one_endpoint)
if OpenNebula::NOKOGIRI
@server.set_parser(NokogiriStreamParser.new)
elsif XMLPARSER
@server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
end
end
def call(action, *args)
if XMLPARSER
@server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
end
begin
response = @server.call_async("one."+action, @one_auth, *args)

View File

@ -30,6 +30,15 @@ $: << RUBY_LIB_LOCATION+"/cli"
require 'command_parser'
require 'ozones_helper/zones_helper.rb'
class Hash
def self.transform_keys_to_strings(value)
return value if not value.is_a?(Hash)
hash = value.inject({}){|memo,(k,v)| memo[k.to_s] = Hash.transform_keys_to_strings(v); memo}
return hash
end
end
cmd=CommandParser::CmdParser.new(ARGV) do
usage "`onezone` <command> [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
@ -56,7 +65,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
show_desc = <<-EOT.unindent
Show information of a particular Zone
Available resources: host, vm, image, vn, template, user
Available resources: host, vm, image, vnet, vmtemplate, user
Examples:
onezone show 4
onezone show 4 host
@ -67,50 +76,42 @@ cmd=CommandParser::CmdParser.new(ARGV) do
case args[1]
when "host"
aux_helper = OneHostHelper.new(
zone[:ONENAME] + ":" + zone[:ONEPASS],
zone[:ENDPOINT],
false)
aux_helper.list_pool(options)
aux_helper = OneHostHelper.new
when "vm"
aux_helper = OneVMHelper.new(
zone[:ONENAME] + ":" + zone[:ONEPASS],
zone[:ENDPOINT],
false)
aux_helper.list_pool(options)
aux_helper = OneVMHelper.new
when "image"
aux_helper = OneImageHelper.new(
zone[:ONENAME] + ":" + zone[:ONEPASS],
zone[:ENDPOINT],
false)
aux_helper.list_pool(options)
when "vn"
aux_helper = OneVNetHelper.new(
zone[:ONENAME] + ":" + zone[:ONEPASS],
zone[:ENDPOINT],
false)
aux_helper.list_pool(options)
when "template"
aux_helper = OneTemplateHelper.new(
zone[:ONENAME] + ":" + zone[:ONEPASS],
zone[:ENDPOINT],
false)
aux_helper.list_pool(options)
aux_helper = OneImageHelper.new
when "vnet"
aux_helper = OneVNetHelper.new
when "vmtemplate"
aux_helper = OneTemplateHelper.new
when "user"
aux_helper = OneUserHelper.new(
zone[:ONENAME] + ":" + zone[:ONEPASS],
zone[:ENDPOINT],
false)
aux_helper.list_pool(options)
aux_helper = OneUserHelper.new
else
puts "\n:!: Pool #{args[1]} doesn't exist or is not supported\n\n"
next 0
end
pool_hash_data = helper.get_resource_pool("zone", zone[:ID], args[1])
if pool_hash_data[0] != 0
puts "\nError retrieving information for pool #{args[1]}. Reason: " + pool_hash_data[1] + "\n\n"
next 0
end
if !pool_hash_data[1]
next 0
end
if pool_hash_data[1].is_a?(Hash)
pool_hash_data[1]=[Hash.transform_keys_to_strings(pool_hash_data[1])]
else
pool_hash_data[1].each{|hash| hash.replace(Hash.transform_keys_to_strings(hash))}
end
table = aux_helper.format_pool(options)
table.show(pool_hash_data[1])
0
end

View File

@ -61,6 +61,16 @@ module OZonesHelper
end
end
def get_resource_pool(kind, id, pool)
rc = @client.get_resource_pool(kind, id, pool)
if Zona::is_error?(rc)
[-1, rc.message]
else
[0 , Zona::OZonesJSON.parse_json(rc.body, pool.upcase+"_POOL")[pool.upcase.to_sym]]
end
end
def delete_resource(kind, id, options)
rc = @client.delete_resource(kind, id)

View File

@ -190,6 +190,23 @@ EOT
return Client.parse_error(res, kind)
end
# Retrieves a pool belonging to a specific resource
# @param [String] Kind resource kind: vdc, zone...
# @param [#to_i] id resource id
# @param [String] Kind of pool: image, vm, host, etc
# @return [String, Zona::Error] Response string or Error
def get_resource_pool(kind, id, pool)
url = URI.parse("#{@endpoint}/#{kind}/#{id}/#{pool}")
req = Net::HTTP::Get.new(url.path)
req.basic_auth @ozonesauth[0], @ozonesauth[1]
res = Client.http_start(url, @timeout) {|http|
http.request(req)
}
return Client.parse_error(res, kind)
end
# Deletes a resource
# @param [String] kind resource kind: vdc, zone...
# @param [#to_i] id resource id

View File

@ -339,6 +339,32 @@ PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void PoolSQL::update_cache_index(string& old_name,
int old_uid,
string& new_name,
int new_uid)
{
map<string,PoolObjectSQL *>::iterator index;
lock();
string old_key = key(old_name, old_uid);
string new_key = key(new_name, new_uid);
index = name_pool.find(old_key);
if ( index != name_pool.end() )
{
name_pool.erase(old_key);
name_pool.insert(make_pair(new_key, index->second));
}
unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void PoolSQL::replace()
{
bool removed = false;

View File

@ -134,11 +134,16 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
{
failure_response(NO_EXISTS,get_error(object_name(auth_object),oid),att);
return;
}
}
if ( noid != -1 )
{
string obj_name = object->get_name();
int old_uid = object->get_uid();
object->set_user(noid,nuname);
pool->update_cache_index(obj_name, old_uid, obj_name, noid);
}
if ( ngid != -1 )
@ -273,4 +278,3 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
return;
}

View File

@ -533,6 +533,26 @@ void Template::rebuild_attributes(const xmlNode * root_element)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Template::set_restricted_attributes( vector<const Attribute *>& rattrs,
vector<string>& restricted_attributes)
{
const SingleAttribute * sattr;
string attr;
for (unsigned int i = 0 ; i < rattrs.size() ; i++ )
{
sattr = static_cast<const SingleAttribute *>(rattrs[i]);
attr = sattr->value();
transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper);
restricted_attributes.push_back(attr);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Template::check(string& rs_attr, const vector<string> &restricted_attributes)
{
size_t pos;

View File

@ -23,23 +23,3 @@ vector<string> VirtualMachineTemplate::restricted_attributes;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineTemplate::set_restricted_attributes(
vector<const Attribute *>& rattrs)
{
const SingleAttribute * sattr;
string attr;
for (unsigned int i = 0 ; i < rattrs.size() ; i++ )
{
sattr = static_cast<const SingleAttribute *>(rattrs[i]);
attr = sattr->value();
transform (attr.begin(),attr.end(),attr.begin(),(int(*)(int))toupper);
restricted_attributes.push_back(attr);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */