diff --git a/src/scheduler/include/UserPoolXML.h b/src/scheduler/include/UserPoolXML.h new file mode 100644 index 0000000000..44d151c71c --- /dev/null +++ b/src/scheduler/include/UserPoolXML.h @@ -0,0 +1,57 @@ +/* -------------------------------------------------------------------------- */ +/* 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 USER_POOL_XML_H_ +#define USER_POOL_XML_H_ + +#include "PoolXML.h" +#include "UserXML.h" + +using namespace std; + +class UserPoolXML : public PoolXML +{ +public: + + UserPoolXML(Client* client):PoolXML(client){}; + + int set_up(); + + /** + * Gets an object from the pool + * @param oid the object unique identifier + * + * @return a pointer to the object, 0 in case of failure + */ + UserXML * get(int oid) const + { + return static_cast(PoolXML::get(oid)); + }; + +protected: + + int get_suitable_nodes(vector& content) + { + return get_nodes("/USER_POOL/USER[ENABLED=1]", content); + }; + + void add_object(xmlNodePtr node); + + int load_info(xmlrpc_c::value &result); +}; + +#endif /* HOST_POOL_XML_H_ */ diff --git a/src/scheduler/include/UserXML.h b/src/scheduler/include/UserXML.h new file mode 100644 index 0000000000..56e01040da --- /dev/null +++ b/src/scheduler/include/UserXML.h @@ -0,0 +1,53 @@ +/* -------------------------------------------------------------------------- */ +/* 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 USER_XML_H_ +#define USER_XML_H_ + +#include "ObjectXML.h" +#include + +using namespace std; + +class UserXML : public ObjectXML +{ +public: + UserXML(const string &xml_doc):ObjectXML(xml_doc) + { + init_attributes(); + }; + + UserXML(const xmlNodePtr node):ObjectXML(node) + { + init_attributes(); + }; + + int get_uid() + { + return oid; + }; + +private: + int oid; + int gid; + + set group_ids; + + void init_attributes(); +}; + +#endif /* USER_XML_H_ */ diff --git a/src/scheduler/src/pool/UserPoolXML.cc b/src/scheduler/src/pool/UserPoolXML.cc new file mode 100644 index 0000000000..04252e45cf --- /dev/null +++ b/src/scheduler/src/pool/UserPoolXML.cc @@ -0,0 +1,90 @@ +/* -------------------------------------------------------------------------- */ +/* 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 "UserPoolXML.h" + + +int UserPoolXML::set_up() +{ + ostringstream oss; + int rc; + + rc = PoolXML::set_up(); + + if ( rc == 0 ) + { + oss.str(""); + oss << "Users (enabled):"; + + map::iterator it; + + for (it=objects.begin();it!=objects.end();it++) + { + oss << " " << it->first; + } + + NebulaLog::log("HOST",Log::DEBUG,oss); + } + + return rc; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void UserPoolXML::add_object(xmlNodePtr node) +{ + if ( node == 0 || node->children == 0 ) + { + NebulaLog::log("USER",Log::ERROR, + "XML Node does not represent a valid User"); + + return; + } + + UserXML* user = new UserXML(node); + + objects.insert(pair(user->get_uid(), user)); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int UserPoolXML::load_info(xmlrpc_c::value &result) +{ + try + { + client->call(client->get_endpoint(), // serverUrl + "one.userpool.info", // methodName + "s", // arguments format + &result, // resultP + client->get_oneauth().c_str()); // argument + return 0; + } + catch (exception const& e) + { + ostringstream oss; + oss << "Exception raised: " << e.what(); + + NebulaLog::log("USER", Log::ERROR, oss); + + return -1; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/scheduler/src/pool/UserXML.cc b/src/scheduler/src/pool/UserXML.cc new file mode 100644 index 0000000000..95cfb108d0 --- /dev/null +++ b/src/scheduler/src/pool/UserXML.cc @@ -0,0 +1,74 @@ +/* -------------------------------------------------------------------------- */ +/* 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 "UserXML.h" +#include + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void UserXML::init_attributes() +{ + vector content; + + oid = atoi(((*this)["/USER/ID"] )[0].c_str() ); + gid = atoi(((*this)["/USER/GID"] )[0].c_str() ); + + get_nodes("/USER/GROUPS",content); + + if (!content.empty()) + { + xmlNodePtr cur_node = 0; + istringstream iss; + int id; + + for (cur_node = content[0]->children; + cur_node != 0; + cur_node = cur_node->next) + { + if ((cur_node->type == XML_ELEMENT_NODE) && + (cur_node->children != 0) && + ((cur_node->children->type == XML_TEXT_NODE ) || + (cur_node->children->type == XML_CDATA_SECTION_NODE))) + { + iss.clear(); + iss.str(reinterpret_cast(cur_node->children->content)); + iss >> dec >> id; + + if ( iss.fail() ) + { + //TODO Print a warning message + break; + } + else + { + group_ids.insert(id); + } + } + else + { + //TODO Print a warning message + break; + } + } + } + + free_nodes(content); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +