Skip to content

Commit

Permalink
F #2427: Added new XML classes for scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmont committed Oct 4, 2018
1 parent bdea707 commit a4ff3b8
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/scheduler/include/VirtualNetworkPoolXML.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
/* */
/* 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 VNET_POOL_XML_H_
#define VNET_POOL_XML_H_

#include "PoolXML.h"
#include "VirtualNetworkXML.h"

using namespace std;

class VirtualNetworkPoolXML : public PoolXML
{
public:

VirtualNetworkPoolXML(Client* client):PoolXML(client) {};

~VirtualNetworkPoolXML(){};

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
*/
VirtualNetworkXML * get(int oid) const
{
return static_cast<VirtualNetworkXML *>(PoolXML::get(oid));
};

protected:

int get_suitable_nodes(vector<xmlNodePtr>& content)
{
return get_nodes("/VNET_POOL/VNET", content);
};

void add_object(xmlNodePtr node);

int load_info(xmlrpc_c::value &result);
};

#endif /* VNET_POOL_XML_H_ */
120 changes: 120 additions & 0 deletions src/scheduler/include/VirtualNetworkXML.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
/* */
/* 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 VNET_XML_H_
#define VNET_XML_H_

#include "ObjectXML.h"
#include "PoolObjectAuth.h"

using namespace std;

class VirtualNetworkXML : public ObjectXML
{
public:
VirtualNetworkXML(const string &xml_doc):ObjectXML(xml_doc)
{
init_attributes();
};

VirtualNetworkXML(const xmlNodePtr node):ObjectXML(node)
{
init_attributes();
};

/**
* Tests whether a new NIC can be attached to a vnet
* @param num_leases num leases needs by VM
* @param error error message
* @return true if the VNET can host the VM
*/
bool test_leases(int num_leases, string & error) const;

/**
* Tests whether a new NIC can be attached to a vnet
* @param num_leases num leases needs by VM
* @return true if the VNET can host the VM
*/
bool test_leases(int num_leases) const
{
string tmp_st;
return test_leases(num_leases, tmp_st);
}

/**
* Adds a new lease to the VNET
* @param num_leases leases needed by the VM
* @return 0 on success
*/
void add_leases(int ar, int num_leases)
{
free_leases -= num_leases;
};

int get_oid() const
{
return oid;
};

bool is_in_cluster(int cid) const
{
return cluster_ids.count(cid) != 0;
};

/**
* Fills a auth class to perform an authZ/authN request based on the object
* attributes
* @param auths to be filled
*/
void get_permissions(PoolObjectAuth& auth);

/**
* Prints the Virtual Network information to an output stream. This function is used
* for logging purposes.
*/
friend ostream& operator<<(ostream& o, const VirtualNetworkXML& p);

private:

int oid;
set<int> cluster_ids;

int uid;
int gid;

int owner_u;
int owner_m;
int owner_a;

int group_u;
int group_m;
int group_a;

int other_u;
int other_m;
int other_a;

int free_leases;

static const char *ds_paths[]; /**< paths for search function */

static int ds_num_paths; /**< number of paths*/

void init_attributes();
};

#endif /* VNET_XML_H_ */
97 changes: 97 additions & 0 deletions src/scheduler/src/pool/VirtualNetworkPoolXML.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
/* */
/* 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 "VirtualNetworkPoolXML.h"

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

int VirtualNetworkPoolXML::set_up()
{
ostringstream oss;
int rc;

rc = PoolXML::set_up();

if ( rc == 0 )
{
if (NebulaLog::log_level() >= Log::DDDEBUG)
{
oss << "Discovered VNETS:" << endl;

map<int, ObjectXML*>::iterator it;

for (it=objects.begin();it!=objects.end();it++)
{
VirtualNetworkXML * n = dynamic_cast<VirtualNetworkXML *>(it->second);

oss << *n << endl;
}
}
else
{
oss << "Discovered " << objects.size() << " vnets.";
}

NebulaLog::log("VNET",Log::DEBUG,oss);
}

return rc;
}


/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void VirtualNetworkPoolXML::add_object(xmlNodePtr node)
{
if ( node == 0 || node->children == 0 )
{
NebulaLog::log("VNET",Log::ERROR,
"XML Node does not represent a valid VNET");
return;
}

VirtualNetworkXML* vnet = new VirtualNetworkXML(node);

objects.insert(pair<int,ObjectXML*>(vnet->get_oid(), vnet));
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

int VirtualNetworkPoolXML::load_info(xmlrpc_c::value &result)
{
try
{
client->call("one.vnpool.info", "iii", &result, -2, -1, -1);

return 0;
}
catch (exception const& e)
{
ostringstream oss;
oss << "Exception raised: " << e.what();

NebulaLog::log("VNET", Log::ERROR, oss);

return -1;
}
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

Loading

0 comments on commit a4ff3b8

Please sign in to comment.