Statistics
| Branch: | Tag: | Revision:

one / src / scheduler / src / pool / HostPoolXML.cc @ 4697f1ee

History | View | Annotate | Download (3.33 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2015, 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 "HostPoolXML.h"
18

    
19
int HostPoolXML::set_up()
20
{
21
    ostringstream   oss;
22
    int             rc;
23

    
24
    rc = PoolXML::set_up();
25

    
26
    if ( rc == 0 )
27
    {
28
        if (NebulaLog::log_level() >= Log::DDDEBUG)
29
        {
30
            oss << "Discovered Hosts (enabled):" << endl;
31

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

    
34
            for (it=objects.begin();it!=objects.end();it++)
35
            {
36
                HostXML * h = dynamic_cast<HostXML *>(it->second);
37

    
38
                oss << *h << endl;
39
            }
40
        }
41
        else
42
        {
43
            oss << "Discovered " << objects.size() << " enabled hosts.";
44
        }
45

    
46
        NebulaLog::log("HOST",Log::DEBUG,oss);
47
    }
48

    
49
    return rc;
50
}
51

    
52
/* -------------------------------------------------------------------------- */
53
/* -------------------------------------------------------------------------- */
54

    
55
void HostPoolXML::add_object(xmlNodePtr node)
56
{
57
    if ( node == 0 || node->children == 0 )
58
    {
59
        NebulaLog::log("HOST",Log::ERROR,
60
                       "XML Node does not represent a valid Host");
61

    
62
        return;
63
    }
64

    
65
    HostXML* host = new HostXML( node );
66

    
67
    objects.insert( pair<int,ObjectXML*>(host->get_hid(), host) );
68
}
69

    
70
/* -------------------------------------------------------------------------- */
71
/* -------------------------------------------------------------------------- */
72

    
73
int HostPoolXML::load_info(xmlrpc_c::value &result)
74
{
75
    try
76
    {
77
        client->call( client->get_endpoint(),           // serverUrl
78
                      "one.hostpool.info",              // methodName
79
                      "s",                              // arguments format
80
                      &result,                          // resultP
81
                      client->get_oneauth().c_str()     // argument
82
                    );
83
        return 0;
84
    }
85
    catch (exception const& e)
86
    {
87
        ostringstream   oss;
88
        oss << "Exception raised: " << e.what();
89

    
90
        NebulaLog::log("HOST", Log::ERROR, oss);
91

    
92
        return -1;
93
    }
94
}
95

    
96
/* -------------------------------------------------------------------------- */
97
/* -------------------------------------------------------------------------- */