Revision f8615d6e src/vnm/AddressRangePool.cc

View differences:

src/vnm/AddressRangePool.cc
16 16

  
17 17
#include "AddressRangePool.h"
18 18
#include "AddressRange.h"
19
#include "AddressRangeInternal.h"
20
#include "AddressRangeIPAM.h"
19 21

  
20 22
using namespace std;
21 23

  
......
37 39

  
38 40
int AddressRangePool::from_vattr(VectorAttribute* va, string& error_msg)
39 41
{
40
    AddressRange * ar = new AddressRange(next_ar);
42
    AddressRange * ar = allocate_ar(va->vector_value("IPAM_MAD"));
41 43

  
42 44
    if (ar->from_vattr(va, error_msg) != 0)
43 45
    {
46
        next_ar = next_ar - 1;
44 47
        delete ar;
48

  
45 49
        return -1;
46 50
    }
47 51

  
48
    ar_pool.insert(make_pair(next_ar++, ar));
52
    ar_pool.insert(make_pair(ar->ar_id(), ar));
49 53

  
50 54
    ar_template.set(va);
51 55

  
......
55 59
/* -------------------------------------------------------------------------- */
56 60
/* -------------------------------------------------------------------------- */
57 61

  
58
AddressRange * AddressRangePool::allocate_ar()
62
AddressRange * AddressRangePool::allocate_ar(const string& ipam_mad)
63
{
64
    return allocate_ar(ipam_mad, next_ar++);
65
}
66

  
67
/* -------------------------------------------------------------------------- */
68

  
69
AddressRange * AddressRangePool::allocate_ar(const string& ipam_mad,
70
        unsigned int na)
59 71
{
60
    return new AddressRange(next_ar++);
72
    if ( ipam_mad.empty() || ipam_mad == "internal" )
73
    {
74
        return new AddressRangeInternal(na);
75
    }
76
    else
77
    {
78
        return new AddressRangeIPAM(na);
79
    }
61 80
}
62 81

  
63 82
/* -------------------------------------------------------------------------- */
......
134 153

  
135 154
    for (int i = 0; i < num_ar; i++)
136 155
    {
137
        AddressRange * ar = new AddressRange(0);
156
        AddressRange * ar = allocate_ar((var[i])->vector_value("IPAM_MAD"), 0);
138 157

  
139
        if (ar->from_vattr_db(var[i])!= 0)
158
        if (ar->from_vattr_db(var[i]) != 0)
140 159
        {
141 160
            return -1;
142 161
        }

Also available in: Unified diff