mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 20:02:38 +09:00
Feature #1112: Clusters are coming back into fashion this season
This commit is contained in:
1 parent
f4743b6077
commit
4e2b33fa23
26 files changed
+1312
-8
No files matched your search
@@ -0,0 +1,14 @@
|
||||
---
|
||||
:ID:
|
||||
:desc: ONE identifier for the Cluster
|
||||
:size: 4
|
||||
|
||||
:NAME:
|
||||
:desc: Name of the Cluster
|
||||
:size: 15
|
||||
:left: true
|
||||
|
||||
:default:
|
||||
- :ID
|
||||
- :NAME
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'one_helper'
|
||||
|
||||
class OneClusterHelper < OpenNebulaHelper::OneHelper
|
||||
def self.rname
|
||||
"CLUSTER"
|
||||
end
|
||||
|
||||
def self.conf_file
|
||||
"onecluster.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 Cluster", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Cluster", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
default :ID, :NAME
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::Cluster.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::Cluster.build_xml
|
||||
OpenNebula::Cluster.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
OpenNebula::ClusterPool.new(@client)
|
||||
end
|
||||
|
||||
def format_resource(cluster)
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
|
||||
puts str % ["ID", cluster.id.to_s]
|
||||
puts str % ["NAME", cluster.name]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "HOSTS", false)
|
||||
CLIHelper.print_header("%-15s" % ["ID"])
|
||||
cluster.host_ids.each do |id|
|
||||
puts "%-15s" % [id]
|
||||
end
|
||||
end
|
||||
end
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onecluster_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onecluster` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneClusterHelper.new
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
list_options << OpenNebulaHelper::NUMERIC
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
set :format, :clusterid, OneClusterHelper.to_id_desc do |arg|
|
||||
helper.to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :clusterid_list, OneClusterHelper.list_to_id_desc do |arg|
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Commands
|
||||
########################################################################
|
||||
|
||||
create_desc = <<-EOT.unindent
|
||||
Creates a new Cluster
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :name do
|
||||
helper.create_resource(options) do |cluster|
|
||||
cluster.allocate(args[0])
|
||||
end
|
||||
end
|
||||
|
||||
delete_desc = <<-EOT.unindent
|
||||
Deletes the given Cluster
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :clusterid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
|
||||
list_desc = <<-EOT.unindent
|
||||
Lists Clusters in the pool
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
show_desc = <<-EOT.unindent
|
||||
Shows information for the given Cluster
|
||||
EOT
|
||||
|
||||
command :show, show_desc,[:clusterid, nil], :options=>OpenNebulaHelper::XML do
|
||||
cluster = args[0] || OpenNebula::Cluster::SELF
|
||||
helper.show_resource(cluster,options)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,191 @@
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Cluster.h"
|
||||
#include "GroupPool.h"
|
||||
|
||||
const char * Cluster::table = "cluster_pool";
|
||||
|
||||
const char * Cluster::db_names =
|
||||
"oid, name, body, uid, gid, owner_u, group_u, other_u";
|
||||
|
||||
const char * Cluster::db_bootstrap = "CREATE TABLE IF NOT EXISTS cluster_pool ("
|
||||
"oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, "
|
||||
"gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, "
|
||||
"UNIQUE(name))";
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Cluster :: Database Access Functions */
|
||||
/* ************************************************************************ */
|
||||
|
||||
int Cluster::insert_replace(SqlDB *db, bool replace, string& error_str)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
string xml_body;
|
||||
|
||||
char * sql_name;
|
||||
char * sql_xml;
|
||||
|
||||
// Set the owner and group to oneadmin
|
||||
set_user(0, "");
|
||||
set_group(GroupPool::ONEADMIN_ID, GroupPool::ONEADMIN_NAME);
|
||||
|
||||
// Update the Cluster
|
||||
|
||||
sql_name = db->escape_str(name.c_str());
|
||||
|
||||
if ( sql_name == 0 )
|
||||
{
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
sql_xml = db->escape_str(to_xml(xml_body).c_str());
|
||||
|
||||
if ( sql_xml == 0 )
|
||||
{
|
||||
goto error_body;
|
||||
}
|
||||
|
||||
if ( validate_xml(sql_xml) != 0 )
|
||||
{
|
||||
goto error_xml;
|
||||
}
|
||||
|
||||
if ( replace )
|
||||
{
|
||||
oss << "REPLACE";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "INSERT";
|
||||
}
|
||||
|
||||
// Construct the SQL statement to Insert or Replace
|
||||
|
||||
oss <<" INTO "<<table <<" ("<< db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< "'" << sql_name << "',"
|
||||
<< "'" << sql_xml << "',"
|
||||
<< uid << ","
|
||||
<< gid << ","
|
||||
<< owner_u << ","
|
||||
<< group_u << ","
|
||||
<< other_u << ")";
|
||||
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
db->free_str(sql_name);
|
||||
db->free_str(sql_xml);
|
||||
|
||||
return rc;
|
||||
|
||||
error_xml:
|
||||
db->free_str(sql_name);
|
||||
db->free_str(sql_xml);
|
||||
|
||||
error_str = "Error transforming the Cluster to XML.";
|
||||
|
||||
goto error_common;
|
||||
|
||||
error_body:
|
||||
db->free_str(sql_name);
|
||||
goto error_generic;
|
||||
|
||||
error_name:
|
||||
goto error_generic;
|
||||
|
||||
error_generic:
|
||||
error_str = "Error inserting Cluster in DB.";
|
||||
error_common:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& Cluster::to_xml(string& xml) const
|
||||
{
|
||||
ostringstream oss;
|
||||
string collection_xml;
|
||||
|
||||
ObjectCollection::to_xml(collection_xml);
|
||||
|
||||
oss <<
|
||||
"<CLUSTER>" <<
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
collection_xml <<
|
||||
"</CLUSTER>";
|
||||
|
||||
xml = oss.str();
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Cluster::from_xml(const string& xml)
|
||||
{
|
||||
int rc = 0;
|
||||
vector<xmlNodePtr> content;
|
||||
|
||||
// Initialize the internal XML object
|
||||
update_from_str(xml);
|
||||
|
||||
// Get class base attributes
|
||||
rc += xpath(oid, "/CLUSTER/ID", -1);
|
||||
rc += xpath(name,"/CLUSTER/NAME", "not_found");
|
||||
|
||||
// Set oneadmin as the owner
|
||||
set_user(0,"");
|
||||
|
||||
// Set the Cluster ID as the cluster it belongs to
|
||||
set_group(oid, name);
|
||||
|
||||
// Get associated classes
|
||||
ObjectXML::get_nodes("/CLUSTER/HOSTS", content);
|
||||
|
||||
if (content.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set of IDs
|
||||
rc += ObjectCollection::from_xml_node(content[0]);
|
||||
|
||||
ObjectXML::free_nodes(content);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "ClusterPool.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* There is a default cluster boostrapped by the core: */
|
||||
/* The first 100 cluster IDs are reserved for system clusters. */
|
||||
/* Regular ones start from ID 100 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
|
||||
const int ClusterPool::DEFAULT_CLUSTER_ID = 0;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table)
|
||||
{
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
|
||||
if (get_lastOID() == -1) //lastOID is set in PoolSQL::init_cb
|
||||
{
|
||||
int rc;
|
||||
Cluster * cluster;
|
||||
|
||||
cluster = new Cluster(DEFAULT_CLUSTER_ID, DEFAULT_CLUSTER_NAME);
|
||||
|
||||
rc = PoolSQL::allocate(cluster, error_str);
|
||||
|
||||
if( rc < 0 )
|
||||
{
|
||||
goto error_bootstrap;
|
||||
}
|
||||
|
||||
set_update_lastOID(99);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error_bootstrap:
|
||||
oss << "Error trying to create default cluster: " << error_str;
|
||||
NebulaLog::log("CLUSTER",Log::ERROR,oss);
|
||||
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::allocate(string name, int * oid, string& error_str)
|
||||
{
|
||||
Cluster * cluster;
|
||||
ostringstream oss;
|
||||
|
||||
if ( name.empty() )
|
||||
{
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
if ( name.length() > 128 )
|
||||
{
|
||||
goto error_name_length;
|
||||
}
|
||||
|
||||
// Check for duplicates
|
||||
cluster = get(name, false);
|
||||
|
||||
if( cluster != 0 )
|
||||
{
|
||||
goto error_duplicated;
|
||||
}
|
||||
|
||||
// Build a new Cluster object
|
||||
cluster = new Cluster(-1, name);
|
||||
|
||||
// Insert the Object in the pool
|
||||
*oid = PoolSQL::allocate(cluster, error_str);
|
||||
|
||||
return *oid;
|
||||
|
||||
error_name:
|
||||
oss << "NAME cannot be empty.";
|
||||
goto error_common;
|
||||
|
||||
error_name_length:
|
||||
oss << "NAME is too long; max length is 128 chars.";
|
||||
goto error_common;
|
||||
|
||||
error_duplicated:
|
||||
oss << "NAME is already taken by CLUSTER " << cluster->get_oid() << ".";
|
||||
|
||||
error_common:
|
||||
*oid = -1;
|
||||
error_str = oss.str();
|
||||
|
||||
return *oid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
{
|
||||
Cluster * cluster = static_cast<Cluster*>(objsql);
|
||||
|
||||
int rc;
|
||||
|
||||
// Return error if the cluster is a default one.
|
||||
if( cluster->get_oid() < 100 )
|
||||
{
|
||||
error_msg = "System Clusters (ID < 100) cannot be deleted.";
|
||||
NebulaLog::log("CLUSTER", Log::ERROR, error_msg);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if( cluster->get_collection_size() > 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Cluster " << cluster->get_oid() << " is not empty.";
|
||||
error_msg = oss.str();
|
||||
NebulaLog::log("CLUSTER", Log::ERROR, error_msg);
|
||||
|
||||
return -3;
|
||||
}
|
||||
|
||||
rc = cluster->drop(db);
|
||||
|
||||
if( rc != 0 )
|
||||
{
|
||||
error_msg = "SQL DB error";
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
# SConstruct for src/group
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
Import('env')
|
||||
|
||||
lib_name='nebula_cluster'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'ClusterPool.cc',
|
||||
'Cluster.cc'
|
||||
]
|
||||
|
||||
# Build library
|
||||
env.StaticLibrary(lib_name, source_files)
|
||||
@@ -249,6 +249,7 @@ void Nebula::start()
|
||||
rc += VMTemplatePool::bootstrap(db);
|
||||
rc += AclManager::bootstrap(db);
|
||||
rc += DatastorePool::bootstrap(db);
|
||||
rc += ClusterPool::bootstrap(db);
|
||||
|
||||
// Create the versioning table only if bootstrap went well
|
||||
if ( rc == 0 )
|
||||
@@ -314,6 +315,8 @@ void Nebula::start()
|
||||
tpool = new VMTemplatePool(db);
|
||||
|
||||
dspool = new DatastorePool(db);
|
||||
|
||||
clpool = new ClusterPool(db);
|
||||
}
|
||||
catch (exception&)
|
||||
{
|
||||
|
||||
@@ -50,6 +50,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
'nebula_host',
|
||||
'nebula_cluster',
|
||||
'nebula_vnm',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
|
||||
@@ -44,6 +44,8 @@ require 'OpenNebula/Acl'
|
||||
require 'OpenNebula/AclPool'
|
||||
require 'OpenNebula/Datastore'
|
||||
require 'OpenNebula/DatastorePool'
|
||||
require 'OpenNebula/Cluster'
|
||||
require 'OpenNebula/ClusterPool'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'OpenNebula/Pool'
|
||||
|
||||
module OpenNebula
|
||||
class Cluster < PoolElement
|
||||
#######################################################################
|
||||
# Constants and Class Methods
|
||||
#######################################################################
|
||||
|
||||
CLUSTER_METHODS = {
|
||||
:info => "cluster.info",
|
||||
:allocate => "cluster.allocate",
|
||||
:delete => "cluster.delete"
|
||||
}
|
||||
|
||||
# Creates a Cluster description with just its identifier
|
||||
# this method should be used to create plain Cluster objects.
|
||||
# +id+ the id of the host
|
||||
#
|
||||
# Example:
|
||||
# cluster = Cluster.new(Cluster.build_xml(3),rpc_client)
|
||||
#
|
||||
def Cluster.build_xml(pe_id=nil)
|
||||
if pe_id
|
||||
cluster_xml = "<CLUSTER><ID>#{pe_id}</ID></CLUSTER>"
|
||||
else
|
||||
cluster_xml = "<CLUSTER></CLUSTER>"
|
||||
end
|
||||
|
||||
XMLElement.build_xml(cluster_xml,'CLUSTER')
|
||||
end
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client)
|
||||
super(xml,client)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods for the Cluster Object
|
||||
#######################################################################
|
||||
|
||||
# Retrieves the information of the given Cluster.
|
||||
def info()
|
||||
super(CLUSTER_METHODS[:info], 'CLUSTER')
|
||||
end
|
||||
|
||||
# Allocates a new Cluster in OpenNebula
|
||||
#
|
||||
# +clustername+ A string containing the name of the Cluster.
|
||||
def allocate(clustername)
|
||||
super(CLUSTER_METHODS[:allocate], clustername)
|
||||
end
|
||||
|
||||
# Deletes the Cluster
|
||||
def delete()
|
||||
super(CLUSTER_METHODS[:delete])
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Helpers to get information
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Returns whether or not the host with id 'uid' is part of this group
|
||||
def contains(uid)
|
||||
#This doesn't work in ruby 1.8.5
|
||||
#return self["HOSTS/ID[.=#{uid}]"] != nil
|
||||
|
||||
id_array = retrieve_elements('HOSTS/ID')
|
||||
return id_array != nil && id_array.include?(uid.to_s)
|
||||
end
|
||||
|
||||
# Returns an array with the numeric host ids
|
||||
def host_ids
|
||||
array = Array.new
|
||||
|
||||
self.each("HOSTS/ID") do |id|
|
||||
array << id.text.to_i
|
||||
end
|
||||
|
||||
return array
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'OpenNebula/Pool'
|
||||
|
||||
module OpenNebula
|
||||
class ClusterPool < Pool
|
||||
#######################################################################
|
||||
# Constants and Class attribute accessors
|
||||
#######################################################################
|
||||
|
||||
CLUSTER_POOL_METHODS = {
|
||||
:info => "clusterpool.info"
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# Class constructor & Pool Methods
|
||||
#######################################################################
|
||||
|
||||
# +client+ a Client object that represents a XML-RPC connection
|
||||
def initialize(client)
|
||||
super('CLUSTER_POOL','CLUSTER',client)
|
||||
end
|
||||
|
||||
# Factory method to create Cluster objects
|
||||
def factory(element_xml)
|
||||
OpenNebula::Cluster.new(element_xml,@client)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods for the Cluster Object
|
||||
#######################################################################
|
||||
|
||||
# Retrieves all the Clusters in the pool.
|
||||
def info()
|
||||
super(CLUSTER_POOL_METHODS[:info])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -179,6 +179,8 @@ string Request::object_name(PoolObjectSQL::ObjectType ob)
|
||||
return "ACL";
|
||||
case PoolObjectSQL::DATASTORE:
|
||||
return "datastore";
|
||||
case PoolObjectSQL::CLUSTER:
|
||||
return "cluster";
|
||||
default:
|
||||
return "-";
|
||||
}
|
||||
|
||||
@@ -264,6 +264,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr host_allocate(new HostAllocate());
|
||||
xmlrpc_c::methodPtr user_allocate(new UserAllocate());
|
||||
xmlrpc_c::methodPtr datastore_allocate(new DatastoreAllocate());
|
||||
xmlrpc_c::methodPtr cluster_allocate(new ClusterAllocate());
|
||||
|
||||
// Delete Methods
|
||||
xmlrpc_c::methodPtr host_delete(new HostDelete());
|
||||
@@ -273,6 +274,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr user_delete(new UserDelete());
|
||||
xmlrpc_c::methodPtr image_delete(new ImageDelete());
|
||||
xmlrpc_c::methodPtr datastore_delete(new DatastoreDelete());
|
||||
xmlrpc_c::methodPtr cluster_delete(new ClusterDelete());
|
||||
|
||||
// Info Methods
|
||||
xmlrpc_c::methodPtr vm_info(new VirtualMachineInfo());
|
||||
@@ -283,6 +285,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr user_info(new UserInfo());
|
||||
xmlrpc_c::methodPtr image_info(new ImageInfo());
|
||||
xmlrpc_c::methodPtr datastore_info(new DatastoreInfo());
|
||||
xmlrpc_c::methodPtr cluster_info(new ClusterInfo());
|
||||
|
||||
// PoolInfo Methods
|
||||
xmlrpc_c::methodPtr hostpool_info(new HostPoolInfo());
|
||||
@@ -293,6 +296,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr template_pool_info(new TemplatePoolInfo());
|
||||
xmlrpc_c::methodPtr vnpool_info(new VirtualNetworkPoolInfo());
|
||||
xmlrpc_c::methodPtr imagepool_info(new ImagePoolInfo());
|
||||
xmlrpc_c::methodPtr clusterpool_info(new ClusterPoolInfo());
|
||||
|
||||
// Host Methods
|
||||
xmlrpc_c::methodPtr host_enable(new HostEnable());
|
||||
@@ -409,6 +413,12 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.datastorepool.info",datastorepool_info);
|
||||
|
||||
/* Cluster related methods */
|
||||
RequestManagerRegistry.addMethod("one.cluster.allocate",cluster_allocate);
|
||||
RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete);
|
||||
RequestManagerRegistry.addMethod("one.cluster.info", cluster_info);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.clusterpool.info",clusterpool_info);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -386,3 +386,19 @@ int DatastoreAllocate::pool_allocate(
|
||||
|
||||
return dspool->allocate(ds_tmpl, &id, error_str);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
string name = xmlrpc_c::value_string(paramList.getString(1));
|
||||
|
||||
ClusterPool * clpool = static_cast<ClusterPool *>(pool);
|
||||
|
||||
return clpool->allocate(name, &id, error_str);
|
||||
}
|
||||
@@ -131,6 +131,16 @@ void DatastorePoolInfo::request_execute(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void ClusterPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerPoolInfoFilter::dump(
|
||||
RequestAttributes& att,
|
||||
int filter_flag,
|
||||
|
||||
Reference in new issue
Block a user