Statistics
| Branch: | Tag: | Revision:

one / src / vnm / AddressRangeIPAM.cc @ 1772a358

History | View | Annotate | Download (3.71 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

    
17
#include "AddressRangeIPAM.h"
18
#include "IPAMRequest.h"
19
#include "IPAMManager.h"
20

    
21
#include "Nebula.h"
22
#include "NebulaUtil.h"
23

    
24
/* ************************************************************************** */
25
/* ************************************************************************** */
26

    
27
int AddressRangeIPAM::from_vattr(VectorAttribute * attr, std::string& error_msg)
28
{
29
    IPAMManager * ipamm = Nebula::instance().get_ipamm();
30
    std::string * ar_xml= attr->to_xml();
31

    
32
    IPAMRequest ir(*ar_xml);
33

    
34
    free(ar_xml);
35

    
36
    ipamm->trigger(IPAMManager::REGISTER_ADDRESS_RANGE, &ir);
37

    
38
    ir.wait();
39

    
40
    if (ir.result != true)
41
    {
42
        error_msg = ir.message;
43
        return -1;
44
    }
45

    
46
    //attr <----> from ir.message
47
    return AddressRange::from_attr(attr, error_msg);
48
}
49

    
50
int AddressRangeIPAM::allocate_addr(unsigned int index, unsigned int rsize,
51
    std::string& error_msg)
52
{
53
    IPAMManager *      ipamm = Nebula::instance().get_ipamm();
54
    std::ostringstream oss;
55

    
56
    std::string ar_xml;
57
    std::string address_xml;
58

    
59
    to_xml(oss);
60

    
61
    ar_xml = oss.str();
62

    
63
    oss.str("");
64

    
65
    addr_to_xml(index, rsize, oss);
66

    
67
    address_xml = oss.str();
68

    
69
    IPAMRequest ir(ar_xml, address_xml);
70

    
71
    ipamm->trigger(IPAMManager::ALLOCATE_ADDRESS, &ir);
72

    
73
    ir.wait();
74

    
75
    if (ir.result != true)
76
    {
77
        error_msg = ir.message;
78
        return -1;
79
    }
80

    
81
    return 0;
82
}
83

    
84
int AddressRangeIPAM::get_addr(unsigned int& index, unsigned int rsize,
85
    std::string& error_msg)
86
{
87
    IPAMManager *      ipamm = Nebula::instance().get_ipamm();
88
    std::ostringstream oss;
89

    
90
    std::string ar_xml;
91
    std::string address_xml;
92

    
93
    to_xml(oss);
94

    
95
    ar_xml = oss.str();
96

    
97
    oss.str("");
98

    
99
    addr_to_xml(index, rsize, oss);
100

    
101
    address_xml = oss.str();
102

    
103
    IPAMRequest ir(ar_xml, address_xml);
104

    
105
    ipamm->trigger(IPAMManager::GET_ADDRESS, &ir);
106

    
107
    ir.wait();
108

    
109
    if (ir.result != true)
110
    {
111
        error_msg = ir.message;
112
        return -1;
113
    }
114

    
115
    //index <----> from ir.message
116
    return 0;
117
}
118

    
119
int AddressRangeIPAM::free_addr(unsigned int index, std::string& error_msg)
120
{
121
    IPAMManager *      ipamm = Nebula::instance().get_ipamm();
122
    std::ostringstream oss;
123

    
124
    std::string ar_xml;
125
    std::string address_xml;
126

    
127
    to_xml(oss);
128

    
129
    ar_xml = oss.str();
130

    
131
    oss.str("");
132

    
133
    addr_to_xml(index, 1, oss);
134

    
135
    address_xml = oss.str();
136

    
137
    IPAMRequest ir(ar_xml, address_xml);
138

    
139
    ipamm->trigger(IPAMManager::FREE_ADDRESS, &ir);
140

    
141
    ir.wait();
142

    
143
    if (ir.result != true)
144
    {
145
        error_msg = ir.message;
146
        return -1;
147
    }
148

    
149
    return 0;
150
}
151