feature #2858: First version of AddressRangePool

This commit is contained in:
Ruben S. Montero committed 2014-05-09 21:20:09 +02:00
1 parent 771b41f39f
commit c24dfec31a
5 files changed
+185 -5

No files matched your search

+8
View File
@@ -146,6 +146,14 @@ public:
*/
void free_addr(const string& mac);
/**
* Return the id for this address range
*/
unsigned int ar_id()
{
return id;
}
private:
/* ---------------------------------------------------------------------- */
/* String to binary conversion functions for different address types */
+62
View File
@@ -0,0 +1,62 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 ADDRESS_RANGE_POOL_H_
#define ADDRESS_RANGE_POOL_H_
#include <string>
#include <vector>
#include <map>
#include <libxml/parser.h>
#include "Template.h"
#include "AddressRange.h"
using namespace std;
class AddressRangePool
{
AddressRangePool();
virtual ~AddressRangePool();
/**
* Builds the address range set from an array of VectorAttributes. This
* function is used to create address ranges.
* @param ars the vector of address ranges
* @param error_msg describing the error
* @return 0 on success
*/
int from_vattr(vector<Attribute *> ars, string& error_msg);
/**
* Builds the address range set from its XML representation. This function
* is used to rebuild the address ranges from the DB.
* @param node xmlNode for the template
* @return 0 on success
*/
int from_xml_node(const xmlNodePtr node);
private:
Template ar_template;
unsigned int next_ar;
map<unsigned int, AddressRange *> ar_pool;
};
#endif
-4
View File
@@ -775,10 +775,6 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
}
}
// ------------------------------------------------------------------------
// Add a new history record and deploy the VM
// ------------------------------------------------------------------------
+113
View File
@@ -0,0 +1,113 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
/* */
/* 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 "AddressRangePool.h"
using namespace std;
AddressRangePool::AddressRangePool():ar_template(false,'=',"AR_POOL"),next_ar(0)
{};
AddressRangePool::~AddressRangePool()
{
map<unsigned int, AddressRange *>::iterator it;
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
{
delete it->second;
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AddressRangePool::from_vattr(vector<Attribute *> ars, string& error_msg)
{
vector<Attribute *>::iterator it;
/* -------------------- Init the AR pool ---------------------------- */
for (it = ars.begin(); it != ars.end(); it++)
{
VectorAttribute * va = static_cast<VectorAttribute *>(*it);
if (va == 0)
{
error_msg = "Wrong AR format";
return -1;
}
AddressRange * ar = new AddressRange(next_ar);
if (ar->from_vattr(va, error_msg) != 0)
{
delete ar;
return -1;
}
ar_pool.insert(make_pair(next_ar++, ar));
}
/* ---------------------- Template ---------------------------------- */
for (it = ars.begin(); it != ars.end(); it++)
{
ar_template.set(*it);
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AddressRangePool::from_xml_node(const xmlNodePtr node)
{
int rc = ar_template.from_xml_node(node);
if (rc != 0)
{
return -1;
}
vector<Attribute*> var;
int num_ar = ar_template.get("AR", var);
for (int i = 0; i < num_ar; i++)
{
VectorAttribute * va = static_cast<VectorAttribute *>(var[i]);
AddressRange * ar = new AddressRange(0);
if (ar->from_vattr_db(va)!= 0)
{
return -1;
}
ar_pool.insert(make_pair(ar->ar_id(), ar));
ar_template.set(va);
if (ar->ar_id() > next_ar)
{
next_ar = ar->ar_id() + 1;
}
}
return 0;
}
+2 -1
View File
@@ -27,7 +27,8 @@ source_files=[
'RangedLeases.cc',
'VirtualNetwork.cc',
'VirtualNetworkPool.cc',
'AddressRange.cc'
'AddressRange.cc',
'AddressRangePool.cc'
]
# Build library