Revision 6329d8b3

View differences:

include/ClusterPool.h
42 42
     */
43 43
    int set_default_cluster(Host * host)
44 44
    {
45
        return host->set_cluster(ClusterPool::DEFAULT_CLUSTER_NAME);
45
        return host->set_cluster(ClusterPool::DEFAULT_CLUSTER_ID);
46 46
    };
47 47

  
48 48
    /**
......
50 50
     */
51 51
    static const string DEFAULT_CLUSTER_NAME;
52 52

  
53
    /**
54
     *  Cluster id for the default cluster
55
     */
56
    static const int DEFAULT_CLUSTER_ID;
57

  
53 58
    /* ---------------------------------------------------------------------- */
54 59
    /* Methods for DB management                                              */
55 60
    /* ---------------------------------------------------------------------- */
include/Host.h
173 173

  
174 174
    /**
175 175
     *  Sets the cluster for this host
176
     *    @return time_t last monitored time
176
     *    @param cluster_id Cluster's oid
177
     *    @return 0 on success
177 178
     */
178
    int set_cluster(const string& cluster_name)
179
    int set_cluster(int cluster_id)
179 180
    {
180
        cluster = cluster_name;
181
        gid = cluster_id;
181 182
        return 0;
182 183
    };
183 184

  
......
329 330
     */
330 331
    time_t      last_monitored;
331 332

  
332
    /**
333
     *  Name of the cluster this host belongs to.
334
     */
335
    string      cluster;
336

  
337 333
    // -------------------------------------------------------------------------
338 334
    //  Host Attributes
339 335
    // -------------------------------------------------------------------------
......
347 343
    // *************************************************************************
348 344

  
349 345
    Host(int           id=-1,
346
         int           cluster_id=-1,
350 347
         const string& hostname="",
351 348
         const string& im_mad_name="",
352 349
         const string& vmm_mad_name="",
353
         const string& tm_mad_name="",
354
         const string& cluster="");
350
         const string& tm_mad_name="");
355 351

  
356 352
    virtual ~Host();
357 353

  
src/cli/onehost
46 46
        :left => true,
47 47
        :proc => lambda {|d,e| d.name }
48 48
    },
49
    :cid => {
50
        :name => "CID",
51
        :desc => "Cluster ID",
52
        :size => 4,
53
        :proc => lambda {|d,e| d.cluster_id }
54
    },
49 55
    :cluster => {
50 56
        :name => "CLUSTER",
51 57
        :desc => "Clustername",
52 58
        :size => 8,
53 59
        :left => true,
54
        :proc => lambda {|d,e| d.cluster }
60
        :proc => lambda { "TODO" }
55 61
    },
56 62
    :rvm => {
57 63
        :name => "RVM",
src/cli/oneimage
44 44
        :desc => "Name of the owner",
45 45
        :size => 8,
46 46
        :proc => lambda {|d,e| 
47
            d["USERNAME"]
47
            "TODO"
48 48
        }
49 49
    },
50 50
    :uid=> {
......
60 60
        :desc => "Id of the group",
61 61
        :size => 4,
62 62
        :proc => lambda {|d,e|
63
            d["GID"]
63
            d.gid
64 64
        }
65 65
    },
66 66
    :name => {
src/cli/onetemplate
44 44
        :desc => "Name of the owner",
45 45
        :size => 8,
46 46
        :proc => lambda {|d,e|
47
            d["USERNAME"]
47
            "TODO"
48 48
        }
49 49
    },
50 50
    :uid=> {
......
60 60
        :desc => "Id of the group",
61 61
        :size => 4,
62 62
        :proc => lambda {|d,e|
63
            d["GID"]
63
            d.gid
64 64
        }
65 65
    },
66 66
    :name => {
src/cli/oneuser
44 44
        :desc => "Id of the group",
45 45
        :size => 4,
46 46
        :proc => lambda {|d,e|
47
            d["GID"]
47
            d.gid
48 48
        }
49 49
    },
50 50
    :user => {
src/cli/onevm
52 52
        :desc => "Id of the group",
53 53
        :size => 4,
54 54
        :proc => lambda {|d,e|
55
            d["GID"]
55
            d.gid
56 56
        }
57 57
    },
58 58
    :name => {
......
68 68
        :desc => "Name of the owner",
69 69
        :size => 8,
70 70
        :proc => lambda {|d,e|
71
            d["USERNAME"]
71
            "TODO"
72 72
        }
73 73
    },
74 74
    :stat => {
src/cli/onevnet
51 51
        :desc => "Username of the virtual network owner",
52 52
        :size => 8,
53 53
        :left => true,
54
        :proc => lambda {|d,e| d["USERNAME"] }
54
        :proc => lambda {|d,e| "TODO" }
55 55
    },
56 56
    :uid=> {
57 57
        :name => "UID",
......
66 66
        :desc => "Id of the group",
67 67
        :size => 4,
68 68
        :proc => lambda {|d,e|
69
            d["GID"]
69
            d.gid
70 70
        }
71 71
    },
72 72
    :type => {
src/cluster/ClusterPool.cc
21 21
#include <stdexcept>
22 22

  
23 23
const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
24
const int    ClusterPool::DEFAULT_CLUSTER_ID   = 0;
24 25

  
25 26
/* -------------------------------------------------------------------------- */
26 27
/* -------------------------------------------------------------------------- */
......
35 36
        string      error_str;
36 37

  
37 38
        // Build a new Cluster object
38
        cluster = new Cluster(0, ClusterPool::DEFAULT_CLUSTER_NAME);
39
        cluster = new Cluster(DEFAULT_CLUSTER_ID, DEFAULT_CLUSTER_NAME);
39 40

  
40 41
        // Insert the Object in the pool
41 42
        rc = PoolSQL::allocate(cluster, error_str);
......
110 111
    Nebula&     nd = Nebula::instance();
111 112
    HostPool *  hpool = nd.get_hpool();
112 113

  
113
    string      cluster_name = cluster->get_name();
114
    string      where = "cluster = '" + cluster_name + "'";
114
    int         cluster_id = cluster->get_oid();
115

  
116
    ostringstream where;
117
    where << "cid = " << cluster_id;
115 118

  
116 119
    // Return error if cluster is 'default'
117
    if( cluster->get_oid() == 0 )
120
    if( cluster->get_oid() == DEFAULT_CLUSTER_ID )
118 121
    {
119 122
        NebulaLog::log("CLUSTER",Log::WARNING,
120 123
                       "Default cluster cannot be deleted.");
......
127 130
    // Move the hosts assigned to the deleted cluster to the default one
128 131
    if( rc == 0 )
129 132
    {
130
        hpool->search(hids, where);
133
        hpool->search(hids, where.str());
131 134

  
132 135
        for ( hid_it=hids.begin() ; hid_it < hids.end(); hid_it++ )
133 136
        {
src/cluster/test/ClusterPoolTest.cc
38 38
    "<CLUSTER_POOL><CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER><CLUSTER><ID>1</ID><NAME>cluster_a</NAME></CLUSTER><CLUSTER><ID>3</ID><NAME>cluster_c</NAME></CLUSTER><CLUSTER><ID>4</ID><NAME>cluster_d</NAME></CLUSTER></CLUSTER_POOL>";
39 39

  
40 40
const string host_0_cluster =
41
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>cluster_a</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
41
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>1</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
42 42

  
43 43
const string host_0_default =
44 44
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
45 45
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
46
    "<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
46
    "<LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
47 47
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
48 48
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
49 49
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
......
271 271
        host = hpool->get(0, false);
272 272
        CPPUNIT_ASSERT(host != 0);
273 273

  
274
        rc = host->set_cluster("cluster_a");
274
        rc = host->set_cluster(1);
275 275
        CPPUNIT_ASSERT( rc == 0 );
276 276

  
277 277
        hpool->update(host);
......
295 295
        CPPUNIT_ASSERT(host != 0);
296 296

  
297 297
        // Set cluster
298
        rc = host->set_cluster("cluster_a");
298
        rc = host->set_cluster(1);
299 299
        CPPUNIT_ASSERT( rc == 0 );
300 300

  
301 301
        hpool->update(host);
......
339 339
        cluster = cpool->get(1, false);
340 340

  
341 341
        // Set cluster
342
        rc = host->set_cluster(cluster->get_name());
342
        rc = host->set_cluster(cluster->get_oid());
343 343
        CPPUNIT_ASSERT( rc == 0 );
344 344

  
345 345
        hpool->update(host);
src/host/Host.cc
29 29

  
30 30
Host::Host(
31 31
    int     id,
32
    int     cluster_id,
32 33
    const string& _hostname,
33 34
    const string& _im_mad_name,
34 35
    const string& _vmm_mad_name,
35
    const string& _tm_mad_name,
36
    const string& _cluster):
37
        PoolObjectSQL(id,_hostname,-1,-1,table),
36
    const string& _tm_mad_name):
37
        PoolObjectSQL(id,_hostname,-1,cluster_id,table),
38 38
        state(INIT),
39 39
        im_mad_name(_im_mad_name),
40 40
        vmm_mad_name(_vmm_mad_name),
41 41
        tm_mad_name(_tm_mad_name),
42
        last_monitored(0),
43
        cluster(_cluster)
42
        last_monitored(0)
44 43
{
45 44
    obj_template = new HostTemplate;        
46 45
}
......
59 58

  
60 59
const char * Host::table = "host_pool";
61 60

  
62
const char * Host::db_names = "oid, name, body, state, last_mon_time, cluster";
61
const char * Host::db_names = "oid, name, body, state, last_mon_time, cid";
63 62

  
64 63
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
65 64
    "oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, "
66
    "last_mon_time INTEGER, cluster VARCHAR(128), UNIQUE(name))";
65
    "last_mon_time INTEGER, cid INTEGER, UNIQUE(name))";
67 66

  
68 67
/* ------------------------------------------------------------------------ */
69 68
/* ------------------------------------------------------------------------ */
......
105 104
    string xml_body;
106 105

  
107 106
    char * sql_hostname;
108
    char * sql_cluster;
109 107
    char * sql_xml;
110 108

  
111 109
   // Update the Host
......
117 115
        goto error_hostname;
118 116
    }
119 117

  
120
    sql_cluster = db->escape_str(cluster.c_str());
121

  
122
    if ( sql_cluster == 0 )
123
    {
124
        goto error_cluster;
125
    }
126

  
127 118
    sql_xml = db->escape_str(to_xml(xml_body).c_str());
128 119

  
129 120
    if ( sql_xml == 0 )
......
148 139
        << "'" <<   sql_xml             << "',"
149 140
        <<          state               << ","
150 141
        <<          last_monitored      << ","
151
        << "'" <<   sql_cluster         << "')";
142
        <<          gid                 << ")";
152 143

  
153 144
    rc = db->exec(oss);
154 145

  
155 146
    db->free_str(sql_hostname);
156
    db->free_str(sql_cluster);
157 147
    db->free_str(sql_xml);
158 148

  
159 149
    return rc;
160 150

  
161 151
error_body:
162
    db->free_str(sql_cluster);
163
error_cluster:
164 152
    db->free_str(sql_hostname);
165 153
error_hostname:
166 154
    return -1;
......
227 215
       "<VM_MAD>"        << vmm_mad_name   << "</VM_MAD>"        <<
228 216
       "<TM_MAD>"        << tm_mad_name    << "</TM_MAD>"        <<
229 217
       "<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
230
       "<CLUSTER>"       << cluster        << "</CLUSTER>"       <<
218
       "<CID>"           << gid            << "</CID>"       <<
231 219
       host_share.to_xml(share_xml)  <<
232 220
       obj_template->to_xml(template_xml) <<
233 221
    "</HOST>";
......
260 248
    rc += xpath(tm_mad_name, "/HOST/TM_MAD", "not_found");
261 249

  
262 250
    rc += xpath(last_monitored, "/HOST/LAST_MON_TIME", 0);
263
    rc += xpath(cluster, "/HOST/CLUSTER", "not_found");
251
    rc += xpath(gid, "/HOST/CID", 0);
264 252

  
265 253
    state = static_cast<HostState>( int_state );
266 254

  
src/host/HostPool.cc
175 175
    // Build a new Host object
176 176

  
177 177
    host = new Host(-1,
178
        ClusterPool::DEFAULT_CLUSTER_ID,
178 179
        hostname,
179 180
        im_mad_name,
180 181
        vmm_mad_name,
181
        tm_mad_name,
182
        ClusterPool::DEFAULT_CLUSTER_NAME);
182
        tm_mad_name);
183 183

  
184 184
    // Insert the Object in the pool
185 185

  
src/host/test/HostPoolTest.cc
33 33
{
34 34
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
35 35
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
36
    "<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
36
    "<LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
37 37
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
38 38
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
39 39
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
......
42 42

  
43 43
    "<HOST><ID>1</ID><NAME>Second host</NAME><STATE>0</STATE>"
44 44
    "<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
45
    "<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
45
    "<LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
46 46
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
47 47
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
48 48
    "<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
......
54 54
const string xml_dump =
55 55
    "<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
56 56
    "M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
57
    "</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
57
    "</LAST_MON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
58 58
    "_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
59 59
    ">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
60 60
    "MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
61 61
    "SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST>"
62 62
    "<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
63 63
    "D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
64
    "ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
64
    "ON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
65 65
    "M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
66 66
    "<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
67 67
    "U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
68 68
    "SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>2</ID><N"
69 69
    "AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
70
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
70
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOS"
71 71
    "T_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
72 72
    "_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
73 73
    "MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
74 74
    "U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
75 75
    "NING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>3</ID><NAME>another "
76 76
    "name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
77
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
77
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHAR"
78 78
    "E><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
79 79
    ">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
80 80
    "U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
81 81
    "D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
82 82
    "MS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
83 83
    "ATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad"
84
    "</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
84
    "</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE>"
85 85
    "<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
86 86
    "<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
87 87
    "</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
......
91 91
const string xml_dump_like_a =
92 92
    "<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
93 93
    "M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
94
    "</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
94
    "</LAST_MON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
95 95
    "_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
96 96
    ">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
97 97
    "MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
98 98
    "SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST>"
99 99
    "<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
100 100
    "D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
101
    "ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
101
    "ON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
102 102
    "M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
103 103
    "<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
104 104
    "U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
105 105
    "SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>2</ID><N"
106 106
    "AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
107
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
107
    "M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOS"
108 108
    "T_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
109 109
    "_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
110 110
    "MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
111 111
    "U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
112 112
    "NING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>3</ID><NAME>another "
113 113
    "name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
114
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
114
    "<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHAR"
115 115
    "E><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
116 116
    ">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
117 117
    "U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
......
119 119
    "MS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST></HOST_POOL>";
120 120

  
121 121
const string host0_updated =
122
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE><ATT_A><![CDATA[VALUE_A]]></ATT_A><ATT_B><![CDATA[VALUE_B]]></ATT_B></TEMPLATE></HOST>";
122
    "<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CID>0</CID><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE><ATT_A><![CDATA[VALUE_A]]></ATT_A><ATT_B><![CDATA[VALUE_B]]></ATT_B></TEMPLATE></HOST>";
123 123

  
124 124
const string cluster_default =
125 125
    "<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
src/oca/ruby/OpenNebula/Host.rb
121 121
            SHORT_HOST_STATES[state_str]
122 122
        end
123 123

  
124
        # Returns the cluster of the Host
125
        def cluster
126
            self['CLUSTER']
124
        # Returns the cluster ID of the Host
125
        def cluster_id
126
            self['CID']
127 127
        end
128 128

  
129 129

  
src/oca/ruby/OpenNebula/Image.rb
178 178
            SHORT_IMAGE_TYPES[type_str]
179 179
        end
180 180

  
181
        # Returns the group identifier
182
        # [return] _Integer_ the element's group ID
183
        def gid
184
            self['GID'].to_i
185
        end
186

  
181 187
    private
182 188

  
183 189
        def set_enabled(enabled)
src/oca/ruby/OpenNebula/Template.rb
103 103
            set_publish(false)
104 104
        end
105 105

  
106
        # ---------------------------------------------------------------------
107
        # Helpers to get Template information
108
        # ---------------------------------------------------------------------
109

  
110
        # Returns the group identifier
111
        # [return] _Integer_ the element's group ID
112
        def gid
113
            self['GID'].to_i
114
        end
115

  
106 116
    private
107 117

  
108 118
        def set_publish(published)
src/oca/ruby/OpenNebula/User.rb
89 89
            return rc
90 90
        end
91 91

  
92
        # ---------------------------------------------------------------------
93
        # Helpers to get User information
94
        # ---------------------------------------------------------------------
95

  
96
        # Returns the group identifier
97
        # [return] _Integer_ the element's group ID
98
        def gid
99
            self['GID'].to_i
100
        end
101

  
92 102
    end
93 103
end
src/oca/ruby/OpenNebula/VirtualMachine.rb
259 259
            short_state_str
260 260
        end
261 261

  
262
        # Returns the group identifier
263
        # [return] _Integer_ the element's group ID
264
        def gid
265
            self['GID'].to_i
266
        end
267

  
262 268
    private
263 269
        def action(name)
264 270
            return Error.new('ID not defined') if !@pe_id
src/oca/ruby/OpenNebula/VirtualNetwork.rb
111 111
            return rc
112 112
        end
113 113

  
114
        # ---------------------------------------------------------------------
115
        # Helpers to get VirtualNetwork information
116
        # ---------------------------------------------------------------------
117

  
118
        # Returns the group identifier
119
        # [return] _Integer_ the element's group ID
120
        def gid
121
            self['GID'].to_i
122
        end
123

  
114 124
    private
115 125
        def set_publish(published)
116 126
            return Error.new('ID not defined') if !@pe_id
src/onedb/1.rb
88 88
        @db.run "ALTER TABLE host_pool RENAME TO old_host_pool;"
89 89

  
90 90
        # Create new table
91
        @db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, cluster VARCHAR(128), UNIQUE(name));"
91
        @db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, cid INTEGER, UNIQUE(name));"
92 92

  
93 93
        # Read each entry in the old table, and insert into new table
94 94
        @db.fetch("SELECT * FROM old_host_pool") do |row|
......
98 98
            last_mon_time   = row[:last_mon_time]
99 99
            cluster         = row[:cluster]
100 100

  
101
            # OpenNebula 2.X stored the cluster name, we need the cluster ID
102
            cluster_id = 0
103
            @db.fetch("SELECT oid FROM cluster_pool WHERE name='#{cluster}'") do |cluster_row|
104
                cluster_id = cluster_row[:oid]
105
            end
106

  
101 107
            # There is one host share for each host
102 108
            host_share = ""
103 109
            @db.fetch("SELECT * FROM host_shares WHERE hid=#{oid}") do |share|
104 110
                host_share = "<HOST_SHARE><DISK_USAGE>#{share[:disk_usage]}</DISK_USAGE><MEM_USAGE>#{share[:mem_usage]}</MEM_USAGE><CPU_USAGE>#{share[:cpu_usage]}</CPU_USAGE><MAX_DISK>#{share[:max_disk]}</MAX_DISK><MAX_MEM>#{share[:max_mem]}</MAX_MEM><MAX_CPU>#{share[:max_cpu]}</MAX_CPU><FREE_DISK>#{share[:free_disk]}</FREE_DISK><FREE_MEM>#{share[:free_mem]}</FREE_MEM><FREE_CPU>#{share[:free_cpu]}</FREE_CPU><USED_DISK>#{share[:used_disk]}</USED_DISK><USED_MEM>#{share[:used_mem]}</USED_MEM><USED_CPU>#{share[:used_cpu]}</USED_CPU><RUNNING_VMS>#{share[:running_vms]}</RUNNING_VMS></HOST_SHARE>"
105 111
            end
106 112

  
107
            body = "<HOST><ID>#{oid}</ID><NAME>#{name}</NAME><STATE>#{state}</STATE><IM_MAD>#{row[:im_mad]}</IM_MAD><VM_MAD>#{row[:vm_mad]}</VM_MAD><TM_MAD>#{row[:tm_mad]}</TM_MAD><LAST_MON_TIME>#{last_mon_time}</LAST_MON_TIME><CLUSTER>#{cluster}</CLUSTER>#{host_share}#{row[:template]}</HOST>"
113
            body = "<HOST><ID>#{oid}</ID><NAME>#{name}</NAME><STATE>#{state}</STATE><IM_MAD>#{row[:im_mad]}</IM_MAD><VM_MAD>#{row[:vm_mad]}</VM_MAD><TM_MAD>#{row[:tm_mad]}</TM_MAD><LAST_MON_TIME>#{last_mon_time}</LAST_MON_TIME><CID>#{cluster_id}</CID>#{host_share}#{row[:template]}</HOST>"
108 114

  
109 115
            @db.run "INSERT INTO host_pool VALUES(#{oid},'#{name}','#{body}', #{state}, #{last_mon_time}, '#{cluster}');"
110 116
        end
src/rm/RequestManagerClusterAdd.cc
89 89
    }
90 90

  
91 91
    // Set cluster
92
    rc = host->set_cluster(cluster->get_name());
92
    rc = host->set_cluster(cluster->get_oid());
93 93

  
94 94
    if ( rc != 0 )
95 95
    {

Also available in: Unified diff