Revision a519eb13

View differences:

include/PoolObjectSQL.h
307 307
     *    @param name of the attribute
308 308
     *    @param value of the attribute (an int), will be 0 if not defined or
309 309
     *    not a single attribute
310
     *
311
     *    @return True if the Single attribute was found and is a valid integer
312
     *    value
310 313
     */
311
    void get_template_attribute(
314
    bool get_template_attribute(
312 315
        const char *    name,
313 316
        int&            value) const
314 317
    {
315
        obj_template->get(name,value);
318
        return obj_template->get(name,value);
319
    }
320

  
321
    /**
322
     *  Gets a float based attribute (single)
323
     *    @param name of the attribute
324
     *    @param value of the attribute (a float), will be 0 if not defined or
325
     *    not a single attribute
326
     *
327
     *    @return True if the Single attribute was found and is a valid float
328
     *    value
329
     */
330
    bool get_template_attribute(
331
        const char *    name,
332
        float&          value) const
333
    {
334
        return obj_template->get(name,value);
316 335
    }
317 336

  
318 337
    /**
......
330 349
    }
331 350

  
332 351
    /**
352
     *  Adds a new attribute to the template (replacing it if
353
     *  already defined), the object's mutex SHOULD be locked
354
     *    @param name of the new attribute
355
     *    @param value of the new attribute
356
     *    @return 0 on success
357
     */
358
    int replace_template_attribute(
359
        const string& name,
360
        const int&    value)
361
    {
362
        ostringstream oss;
363
        oss << value;
364

  
365
        return replace_template_attribute(name, oss.str());
366
    }
367

  
368
    /**
333 369
     *  Generates a XML string for the template of the Object
334 370
     *    @param xml the string to store the XML description.
335 371
     */
include/Template.h
245 245
     *    @param value the attribute value, an int, 0 if the attribute is not
246 246
     *    defined or not Single
247 247
     *
248
     *    @return True if the Single attribute was found
248
     *    @return True if the Single attribute was found and is a valid integer
249
     *    value
249 250
     */
250 251
    virtual bool get(
251 252
        const string& name,
......
257 258
     *    @param value the attribute value, an int, 0 if the attribute is not
258 259
     *    defined or not Single
259 260
     *
260
     *    @return True if the Single attribute was found
261
     *    @return True if the Single attribute was found and is a valid float
262
     *    value
261 263
     */
262 264
    virtual bool get(
263 265
        const string&   name,
src/template/Template.cc
430 430
    istringstream iss(sval);
431 431

  
432 432
    iss >> value;
433

  
434
    if ( iss.fail() )
435
    {
436
        value = 0;
437
        return false;
438
    }
439

  
433 440
    return true;
434 441
}
435 442

  
......
453 460
    istringstream iss(sval);
454 461

  
455 462
    iss >> value;
463

  
464
    if ( iss.fail() )
465
    {
466
        value = 0;
467
        return false;
468
    }
469

  
456 470
    return true;
457 471
}
458 472

  
src/um/QuotaDatastore.cc
41 41
        return false;
42 42
    }
43 43

  
44
    if ( tmpl->get("SIZE", size) == false )
44
    if ( tmpl->get("SIZE", size) == false || size < 0 )
45 45
    {
46
        error = "Size not defined for image";
46
        error = "Image size must be a positive integer value";
47 47
        return false;
48 48
    }
49 49

  
src/um/QuotaVirtualMachine.cc
55 55
    int memory;
56 56
    float cpu;
57 57

  
58
    if ( tmpl->get("MEMORY", memory) == false )
58
    if ( tmpl->get("MEMORY", memory) == false  || memory <= 0 )
59 59
    {
60
        memory = 0;
60
        error = "MEMORY attribute must be a positive integer value";
61
        return false;
61 62
    }
62 63

  
63
    if ( tmpl->get("CPU", cpu) == false )
64
    if ( tmpl->get("CPU", cpu) == false || cpu <= 0 )
64 65
    {
65
        cpu = 0;
66
        error = "CPU attribute must be a positive float or integer value";
67
        return false;
66 68
    }
67 69

  
68 70
    vm_request.insert(make_pair("VMS",1));
src/vm/VirtualMachine.cc
213 213
    string name;
214 214

  
215 215
    string        value;
216
    int           ivalue;
217
    float         fvalue;
216 218
    ostringstream oss;
217 219

  
218 220
    // ------------------------------------------------------------------------
......
242 244
    this->name = name;
243 245

  
244 246
    // ------------------------------------------------------------------------
245
    // Check for CPU and MEMORY attributes
247
    // Check for CPU, VCPU and MEMORY attributes
246 248
    // ------------------------------------------------------------------------
247 249

  
248
    get_template_attribute("MEMORY", value);
250
    if ( get_template_attribute("MEMORY", ivalue) == false || ivalue <= 0 )
251
    {
252
        goto error_memory;
253
    }
249 254

  
250
    if ( value.empty())
255
    replace_template_attribute("MEMORY", ivalue);
256

  
257
    if ( get_template_attribute("CPU", fvalue) == false || fvalue <= 0 )
251 258
    {
252
        goto error_no_memory;
259
        goto error_cpu;
253 260
    }
254 261

  
255
    get_template_attribute("CPU", value);
262
    get_template_attribute("VCPU", value);
256 263

  
257
    if ( value.empty())
264
    if ( value.empty() == false )
258 265
    {
259
        goto error_no_cpu;
266
        if ( get_template_attribute("VCPU", ivalue) == false || ivalue <= 0 )
267
        {
268
            goto error_vcpu;
269
        }
270

  
271
        replace_template_attribute("VCPU", ivalue);
260 272
    }
261 273

  
262 274
    // ------------------------------------------------------------------------
......
339 351
    release_network_leases();
340 352
    goto error_common;
341 353

  
342
error_no_cpu:
343
    error_str = "CPU attribute missing.";
354
error_cpu:
355
    error_str = "CPU attribute must be a positive float or integer value.";
356
    goto error_common;
357

  
358
error_vcpu:
359
    error_str = "VCPU attribute must be a positive integer value.";
344 360
    goto error_common;
345 361

  
346
error_no_memory:
347
    error_str = "MEMORY attribute missing.";
362
error_memory:
363
    error_str = "MEMORY attribute must be a positive integer value.";
348 364
    goto error_common;
349 365

  
350 366
error_name_length:

Also available in: Unified diff