Revision 0dbb3330 src/image/Image.cc

View differences:

src/image/Image.cc
32 32
/* Image :: Constructor/Destructor                                           */
33 33
/* ************************************************************************ */
34 34

  
35
Image::Image(int _uid):
35
Image::Image(int _uid, ImageTemplate * _image_template):
36 36
        PoolObjectSQL(-1),
37 37
        uid(_uid),
38 38
        name(""),
......
41 41
        source(""),
42 42
        state(INIT),
43 43
        running_vms(0)
44
        {};
44
{
45
    if (_image_template != 0)
46
    {
47
        image_template = _image_template;
48
    }
49
    else
50
    {
51
        image_template = new ImageTemplate;
52
    }
53
};
45 54

  
46
Image::~Image(){};
55
Image::~Image()
56
{
57
    if (image_template != 0)
58
    {
59
        delete image_template;
60
    }
61
};
47 62

  
48 63
/* ************************************************************************ */
49 64
/* Image :: Database Access Functions                                        */
......
93 108

  
94 109
    running_vms = atoi(values[RUNNING_VMS]);
95 110

  
96
    image_template.id  = oid;
111
    image_template->id  = oid;
97 112

  
98 113
    return 0;
99 114
}
......
123 138

  
124 139
    // Get the template
125 140

  
126
    rc = image_template.select(db);
141
    rc = image_template->select(db);
127 142

  
128 143
    if ( rc != 0 )
129 144
    {
......
182 197
    // ------------ PUBLIC --------------------
183 198

  
184 199
    get_template_attribute("PUBLIC", public_attr);
185
    image_template.erase("PUBLIC");
200
    image_template->erase("PUBLIC");
186 201

  
187 202
    transform (public_attr.begin(), public_attr.end(), public_attr.begin(),
188 203
        (int(*)(int))toupper);
......
198 213
        SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
199 214
                                          ImagePool::default_dev_prefix());
200 215

  
201
        image_template.set(dev_att);
216
        image_template->set(dev_att);
202 217
    }
203 218

  
204 219
    // ------------ SOURCE (path to store the image)--------------------
......
212 227

  
213 228
    // ------------ INSERT THE TEMPLATE --------------------
214 229

  
215
    if ( image_template.id == -1 )
230
    if ( image_template->id == -1 )
216 231
    {
217
        image_template.id = oid;
232
        image_template->id = oid;
218 233
    }
219 234

  
220 235
    state = DISABLED;
221 236

  
222
    rc = image_template.insert(db);
237
    rc = image_template->insert(db);
223 238

  
224 239
    if ( rc != 0 )
225 240
    {
......
234 249

  
235 250
    if ( rc != 0 )
236 251
    {
237
        image_template.drop(db);
252
        image_template->drop(db);
238 253

  
239 254
        return rc;
240 255
    }
......
374 389
        return -1;
375 390
    }
376 391

  
377
    image_template.drop(db);
392
    image_template->drop(db);
378 393

  
379 394
    oss << "DELETE FROM " << table << " WHERE oid=" << oid;
380 395

  
......
424 439
            "<SOURCE>"         << source      << "</SOURCE>"      <<
425 440
            "<STATE>"          << state       << "</STATE>"       <<
426 441
            "<RUNNING_VMS>"    << running_vms << "</RUNNING_VMS>" <<
427
            image_template.to_xml(template_xml)                   <<
442
            image_template->to_xml(template_xml)                   <<
428 443
        "</IMAGE>";
429 444

  
430 445
    xml = oss.str();
......
452 467
        "STATE       = "    << state       << endl <<
453 468
        "RUNNING_VMS = "    << running_vms << endl <<
454 469
        "TEMPLATE"          << endl
455
                            << image_template.to_str(template_str)
470
                            << image_template->to_str(template_str)
456 471
                            << endl;
457 472

  
458 473
    str = os.str();

Also available in: Unified diff