Revision d797d04a

View differences:

include/Attribute.h
348 348
    }
349 349

  
350 350
    /**
351
     *  Replace the value of the given vector attribute
352
     */
353
    void replace(const string& name, const char* value)
354
    {
355
        string svalue(value);
356

  
357
        replace(name, svalue);
358
    }
359

  
360
    /**
361
     *  Replace the value of the given vector attribute
362
     */
363
    void replace(const string& name, bool value)
364
    {
365
        string b_value;
366

  
367
        if (value == true)
368
        {
369
            b_value = "YES";
370
        }
371
        else
372
        {
373
            b_value = "NO";
374
        }
375

  
376
        replace(name, b_value);
377
    }
378

  
379
    /**
351 380
     * Removes given the vector attribute
352 381
     * @param name of the vector attribute
353 382
     */
include/PoolObjectSQL.h
110 110
             other_u(0),
111 111
             other_m(0),
112 112
             other_a(0),
113
             obj_template(0), 
113
             obj_template(0),
114 114
             table(_table)
115 115
    {
116 116
        pthread_mutex_init(&mutex,0);
......
164 164
    {
165 165
        return gname;
166 166
    };
167
    
167

  
168 168
    /**
169 169
     * Changes the object's owner
170 170
     * @param _uid New User ID
......
350 350
    }
351 351

  
352 352
    /**
353
     *  Gets a boolean attribute (single) (YES = true)
354
     *    @param name of the attribute
355
     *    @param value of the attribute (True if "YES", false otherwise)
356
     *
357
     *    @return True if the Single attribute was found and is a valid boolean
358
     *    value
359
     */
360
    bool get_template_attribute(
361
        const char *    name,
362
        bool&           value) const
363
    {
364
        return obj_template->get(name,value);
365
    }
366

  
367
    /**
353 368
     *  Adds a new attribute to the template (replacing it if
354 369
     *  already defined), the object's mutex SHOULD be locked
355 370
     *    @param name of the new attribute
src/common/Attribute.cc
219 219
/* -------------------------------------------------------------------------- */
220 220
/* -------------------------------------------------------------------------- */
221 221

  
222
int VectorAttribute::vector_value(const char *name, bool & value) const
222
int VectorAttribute::vector_value(const char *name, bool& value) const
223 223
{
224 224
    map<string,string>::const_iterator it;
225 225

  
src/image/Image.cc
474 474
    string driver;
475 475
    string disk_attr_type;
476 476

  
477
    bool ro;
478

  
477 479
    ostringstream iid;
478 480

  
479 481
    img_type   = type;
......
484 486

  
485 487
    string template_target;
486 488
    string template_driver;
489
    string template_ptype;
487 490

  
488 491
    get_template_attribute("TARGET", template_target);
489 492
    get_template_attribute("DRIVER", template_driver);
493
    get_template_attribute("PERSISTENT_TYPE", template_ptype);
494

  
495
    TO_UPPER(template_ptype);
490 496

  
491
   //---------------------------------------------------------------------------
492
   //                       DEV_PREFIX ATTRIBUTE
493
   //---------------------------------------------------------------------------
497
    //---------------------------------------------------------------------------
498
    //                       DEV_PREFIX ATTRIBUTE
499
    //---------------------------------------------------------------------------
494 500
    if ( dev_prefix.empty() ) //DEV_PEFIX not in DISK, check for it in IMAGE
495 501
    {
496 502
        get_template_attribute("DEV_PREFIX", dev_prefix);
......
503 509
        disk->replace("DEV_PREFIX", dev_prefix);
504 510
    }
505 511

  
506
   //---------------------------------------------------------------------------
507
   //                       BASE DISK ATTRIBUTES
508
   //---------------------------------------------------------------------------
512
    //--------------------------------------------------------------------------
513
    //                       BASE DISK ATTRIBUTES
514
    //--------------------------------------------------------------------------
509 515
    disk->replace("IMAGE",    name);
510 516
    disk->replace("IMAGE_ID", iid.str());
511 517
    disk->replace("SOURCE",   source);
......
515 521
        disk->replace("DRIVER",template_driver);
516 522
    }
517 523

  
518
   //---------------------------------------------------------------------------
519
   //   TYPE, READONLY, CLONE, and SAVE attributes
520
   //---------------------------------------------------------------------------
524
    //--------------------------------------------------------------------------
525
    //   READONLY attribute
526
    //--------------------------------------------------------------------------
527
    if ( type == CDROM || template_ptype == "IMMUTABLE" )
528
    {
529
        disk->replace("READONLY", "YES");
530
    }
531
    else if ( disk->vector_value("READONLY", ro) != 0 )
532
    {
533
        if ( get_template_attribute("READONLY", ro) )
534
        {
535
            disk->replace("READONLY", ro);
536
        }
537
        else
538
        {
539
            disk->replace("READONLY", "NO");
540
        }
541
    }
542

  
543
    //--------------------------------------------------------------------------
544
    //   CLONE & SAVE attributes
545
    //--------------------------------------------------------------------------
521 546
    if ( persistent_img )
522 547
    {
523
        disk->replace("CLONE","NO");
524
        disk->replace("SAVE","YES");
525
        disk->replace("PERSISTENT","YES");
548
        disk->replace("PERSISTENT", "YES");
549
        disk->replace("CLONE", "NO");
550

  
551
        if ( template_ptype == "IMMUTABLE" )
552
        {
553
            disk->replace("SAVE", "NO");
554
        }
555
        else
556
        {
557
            disk->replace("SAVE", "YES");
558
        }
526 559
    }
527 560
    else
528 561
    {
529
        disk->replace("CLONE","YES");
530
        disk->replace("SAVE","NO");
562
        disk->replace("CLONE", "YES");
563
        disk->replace("SAVE", "NO");
531 564
    }
532 565

  
566
    //--------------------------------------------------------------------------
567
    //   TYPE attribute
568
    //--------------------------------------------------------------------------
533 569
    switch(type)
534 570
    {
535 571
        case OS:
536 572
        case DATABLOCK: //Type is FILE or BLOCK as inherited from the DS
537
          disk_attr_type = disk_type_to_str(disk_type);
538
          disk->replace("READONLY","NO");
573
            disk_attr_type = disk_type_to_str(disk_type);
539 574
        break;
540 575

  
541 576
        case CDROM: //Always use CDROM type for these ones
542
          disk_attr_type = "CDROM";
543
          disk->replace("READONLY","YES");
577
            disk_attr_type = "CDROM";
544 578
        break;
545 579

  
546 580
        default: //Other file types should not be never a DISK
547 581
        break;
548 582
    }
549 583

  
550
    disk->replace("TYPE",disk_attr_type);
584
    disk->replace("TYPE", disk_attr_type);
551 585

  
552
    //---------------------------------------------------------------------------
586
    //--------------------------------------------------------------------------
553 587
    //   TARGET attribute
554
    //---------------------------------------------------------------------------
555

  
588
    //--------------------------------------------------------------------------
556 589
    // TARGET defined in the Image template, but not in the DISK attribute
557 590
    if ( target.empty() && !template_target.empty() )
558 591
    {

Also available in: Unified diff