mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-29 18:50:08 +03:00
Feature #862: Merge RequestManagerPoolInfo into RequestManagerPoolInfoFilter
This commit is contained in:
parent
a5005f5533
commit
2f080668d8
@ -1,102 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_POOL_INFO_H_
|
||||
#define REQUEST_MANAGER_POOL_INFO_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerPoolInfo: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerPoolInfo(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:s",help)
|
||||
{};
|
||||
|
||||
~RequestManagerPoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostPoolInfo : public RequestManagerPoolInfo
|
||||
{
|
||||
public:
|
||||
HostPoolInfo():
|
||||
RequestManagerPoolInfo("HostPoolInfo",
|
||||
"Returns the host pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
};
|
||||
|
||||
~HostPoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupPoolInfo: public RequestManagerPoolInfo
|
||||
{
|
||||
public:
|
||||
GroupPoolInfo():
|
||||
RequestManagerPoolInfo("GroupPoolInfo",
|
||||
"Returns the group pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
};
|
||||
|
||||
~GroupPoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserPoolInfo: public RequestManagerPoolInfo
|
||||
{
|
||||
public:
|
||||
UserPoolInfo():
|
||||
RequestManagerPoolInfo("UserPoolInfo",
|
||||
"Returns the user pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
};
|
||||
|
||||
~UserPoolInfo(){};
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -48,8 +48,14 @@ protected:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
virtual void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void dump(RequestAttributes& att, int filter_flag,
|
||||
int start_id, int end_id,
|
||||
string and_clause, string or_clause);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -76,6 +82,12 @@ public:
|
||||
};
|
||||
|
||||
~VirtualMachinePoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -135,6 +147,78 @@ public:
|
||||
~ImagePoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostPoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
HostPoolInfo():
|
||||
RequestManagerPoolInfoFilter("HostPoolInfo",
|
||||
"Returns the host pool",
|
||||
"A:s")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = PoolObjectSQL::HOST;
|
||||
};
|
||||
|
||||
~HostPoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupPoolInfo: public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
GroupPoolInfo():
|
||||
RequestManagerPoolInfoFilter("GroupPoolInfo",
|
||||
"Returns the group pool",
|
||||
"A:s")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
auth_object = PoolObjectSQL::GROUP;
|
||||
};
|
||||
|
||||
~GroupPoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserPoolInfo: public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
UserPoolInfo():
|
||||
RequestManagerPoolInfoFilter("UserPoolInfo",
|
||||
"Returns the user pool",
|
||||
"A:s")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = PoolObjectSQL::USER;
|
||||
};
|
||||
|
||||
~UserPoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <cerrno>
|
||||
|
||||
#include "RequestManagerPoolInfoFilter.h"
|
||||
#include "RequestManagerPoolInfo.h"
|
||||
#include "RequestManagerInfo.h"
|
||||
#include "RequestManagerDelete.h"
|
||||
#include "RequestManagerAllocate.h"
|
||||
|
@ -1,52 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, 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 "RequestManagerPoolInfo.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
// TODO: Authorization is not required, but results must be filtered to
|
||||
// return only the objects this user has USE rights
|
||||
/*
|
||||
if ( basic_authorization(-1, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
*/
|
||||
// Call the template pool dump
|
||||
rc = pool->dump(oss,"");
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,request_error("Internal Error",""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oss.str(), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -42,6 +42,91 @@ void RequestManagerPoolInfoFilter::request_execute(
|
||||
int start_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int end_id = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
|
||||
dump(att, filter_flag, start_id, end_id, "", "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachinePoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int start_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int end_id = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
int state = xmlrpc_c::value_int(paramList.getInt(4));
|
||||
|
||||
ostringstream state_filter;
|
||||
|
||||
if (( state < VirtualMachinePoolInfo::ALL_VM ) ||
|
||||
( state > VirtualMachine::FAILED ))
|
||||
{
|
||||
failure_response(XML_RPC_API,
|
||||
request_error("Incorrect filter_flag, state",""),
|
||||
att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case VirtualMachinePoolInfo::ALL_VM:
|
||||
break;
|
||||
|
||||
case VirtualMachinePoolInfo::NOT_DONE:
|
||||
state_filter << "state <> " << VirtualMachine::DONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
state_filter << "state = " << state;
|
||||
break;
|
||||
}
|
||||
|
||||
dump(att, filter_flag, start_id, end_id, state_filter.str(), "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void HostPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void GroupPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void UserPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerPoolInfoFilter::dump(
|
||||
RequestAttributes& att,
|
||||
int filter_flag,
|
||||
int start_id,
|
||||
int end_id,
|
||||
string and_clause,
|
||||
string or_clause)
|
||||
{
|
||||
set<int>::iterator it;
|
||||
|
||||
ostringstream oss;
|
||||
@ -49,11 +134,9 @@ void RequestManagerPoolInfoFilter::request_execute(
|
||||
ostringstream where_string;
|
||||
|
||||
ostringstream uid_filter;
|
||||
ostringstream state_filter;
|
||||
ostringstream id_filter;
|
||||
|
||||
string uid_str;
|
||||
string state_str;
|
||||
string id_str;
|
||||
|
||||
int rc;
|
||||
@ -77,7 +160,6 @@ void RequestManagerPoolInfoFilter::request_execute(
|
||||
vector<int> gids;
|
||||
|
||||
|
||||
|
||||
if ( att.uid == 0 || att.gid == 0 )
|
||||
{
|
||||
all = true;
|
||||
@ -135,7 +217,6 @@ void RequestManagerPoolInfoFilter::request_execute(
|
||||
|
||||
uid_str = uid_filter.str();
|
||||
|
||||
|
||||
// ------------------------------------------
|
||||
// Resource ID filter
|
||||
// ------------------------------------------
|
||||
@ -152,71 +233,51 @@ void RequestManagerPoolInfoFilter::request_execute(
|
||||
|
||||
id_str = id_filter.str();
|
||||
|
||||
// ------------ State filter for VM --------------
|
||||
if ( auth_object == PoolObjectSQL::VM )
|
||||
{
|
||||
int state = xmlrpc_c::value_int(paramList.getInt(4));
|
||||
|
||||
if (( state < VirtualMachinePoolInfo::ALL_VM ) ||
|
||||
( state > VirtualMachine::FAILED ))
|
||||
{
|
||||
failure_response(XML_RPC_API,
|
||||
request_error("Incorrect filter_flag, state",""),
|
||||
att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case VirtualMachinePoolInfo::ALL_VM:
|
||||
break;
|
||||
|
||||
case VirtualMachinePoolInfo::NOT_DONE:
|
||||
state_filter << "state <> " << VirtualMachine::DONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
state_filter << "state = " << state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
state_str = state_filter.str();
|
||||
|
||||
// ------------------------------------------
|
||||
// Compound WHERE clause
|
||||
// ------------------------------------------
|
||||
|
||||
// WHERE ( id_str ) AND ( uid_str ) AND ( and_clause ) OR ( or_clause )
|
||||
|
||||
if (!id_str.empty())
|
||||
{
|
||||
where_string << "(" << id_str << ")" ;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
if (!uid_str.empty())
|
||||
{
|
||||
where_string << "(" << uid_str << ")" ;
|
||||
if (!empty)
|
||||
{
|
||||
where_string << " AND ";
|
||||
}
|
||||
|
||||
where_string << "(" << uid_str << ")";
|
||||
empty = false;
|
||||
}
|
||||
|
||||
if (!id_str.empty())
|
||||
if (!and_clause.empty())
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
where_string << " AND ";
|
||||
}
|
||||
|
||||
where_string << "(" << id_str << ")";
|
||||
empty = false;
|
||||
where_string << "(" << and_clause << ")";
|
||||
}
|
||||
|
||||
if (!state_str.empty())
|
||||
if (!or_clause.empty())
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
where_string << " AND ";
|
||||
where_string << " OR ";
|
||||
}
|
||||
|
||||
where_string << "(" << state_str << ")";
|
||||
where_string << "(" << or_clause << ")";
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// Authorize & get the pool
|
||||
// Get the pool
|
||||
// ------------------------------------------
|
||||
|
||||
rc = pool->dump(oss,where_string.str());
|
||||
|
@ -25,7 +25,6 @@ source_files=[
|
||||
'Request.cc',
|
||||
'RequestManager.cc',
|
||||
'RequestManagerInfo.cc',
|
||||
'RequestManagerPoolInfo.cc',
|
||||
'RequestManagerPoolInfoFilter.cc',
|
||||
'RequestManagerDelete.cc',
|
||||
'RequestManagerAllocate.cc',
|
||||
|
Loading…
x
Reference in New Issue
Block a user