Revision 9b8862eb

View differences:

include/Image.h
286 286
     *  Type of the Image
287 287
     */
288 288
    ImageType    type;
289
    
289

  
290
    /**
291
     *  Public scope of the Image
292
     */
293
    string       public_img;
294

  
290 295
    /**
291 296
     *  Registration time
292 297
     */
......
370 375
        UID              = 1,    /* Image owner id              */
371 376
        NAME             = 2,    /* Image name                  */
372 377
        TYPE             = 3,    /* 0) OS 1) CDROM 2) DATABLOCK */
373
        REGTIME          = 4,    /* Time of registration        */
374
        SOURCE           = 5,    /* Path to the image           */
375
        STATE            = 6,    /* 0) INIT   1) ALLOCATED      */
378
        PUBLIC           = 4,    /* Public scope (YES OR NO)    */
379
        REGTIME          = 5,    /* Time of registration        */
380
        SOURCE           = 6,    /* Path to the image           */
381
        STATE            = 7,    /* 0) INIT   1) ALLOCATED      */
376 382
                                 /* 2) READY  3) USED           */
377
        RUNNING_VMS      = 7,    /* Number of VMs using the img */
378
        LIMIT            = 8
383
        RUNNING_VMS      = 8,    /* Number of VMs using the img */
384
        LIMIT            = 9
379 385
    };
380 386
    
381 387
    static const char * db_names;
include/ImagePool.h
155 155
     * Default image type
156 156
     **/
157 157
    string              default_type;
158
    
158

  
159
    /**
160
     * Default public scope
161
     **/
162
    string              default_public;
163

  
159 164
    /**
160 165
     * Default device prefix
161 166
     **/
src/image/Image.cc
44 44

  
45 45
const char * Image::table = "image_pool";
46 46

  
47
const char * Image::db_names = "(oid, uid, name, type, regtime, " 
47
const char * Image::db_names = "(oid, uid, name, type, public, regtime, " 
48 48
                               "source, state, running_vms)";
49 49

  
50 50
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
51 51
    "oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(128), "
52
    "type INTEGER, regtime INTEGER, source TEXT, state INTEGER, "
52
    "type INTEGER, public TEXT, regtime INTEGER, source TEXT, state INTEGER, "
53 53
    "running_vms INTEGER, UNIQUE(name) )";
54 54

  
55 55
/* ------------------------------------------------------------------------ */
......
61 61
        (!values[UID]) ||
62 62
        (!values[NAME]) ||
63 63
        (!values[TYPE]) ||
64
        (!values[PUBLIC]) ||
64 65
        (!values[REGTIME]) ||
65 66
        (!values[SOURCE]) ||
66 67
        (!values[STATE]) ||
......
76 77
    name        = values[NAME];
77 78
    
78 79
    type        = static_cast<ImageType>(atoi(values[TYPE]));
80
    public_img  = values[PUBLIC];
79 81
    regtime     = static_cast<time_t>(atoi(values[REGTIME]));
80 82

  
81 83
    source      = values[SOURCE];
......
194 196
    int    rc;
195 197

  
196 198
    char * sql_name;
199
    char * sql_public;
197 200
    char * sql_source;
198 201

  
199 202
   // Update the Image
......
205 208
        goto error_name;
206 209
    }
207 210

  
211
    sql_public = db->escape_str(public_img.c_str());
212

  
213
    if ( sql_public == 0 )
214
    {
215
        goto error_public;
216
    }
208 217

  
209 218
    sql_source = db->escape_str(source.c_str());
210 219

  
......
228 237
        <<          oid             << ","
229 238
        <<          uid             << ","
230 239
        << "'" <<   sql_name        << "',"
231
        <<          type            << ","       
240
        <<          type            << ","
241
        << "'" <<   sql_public      << "',"
232 242
        <<          regtime         << ","
233 243
        << "'" <<   sql_source      << "',"
234 244
        <<          state           << ","
235
        <<          running_vms     << ")";     
245
        <<          running_vms     << ")";
236 246

  
237 247
    rc = db->exec(oss);
238 248

  
239 249
    db->free_str(sql_name);
250
    db->free_str(sql_public);
240 251
    db->free_str(sql_source);
241 252

  
242 253
    return rc;
243 254

  
244 255
error_source:
256
    db->free_str(sql_public);
257
error_public:
245 258
    db->free_str(sql_name);
246 259
error_name:
247 260
    return -1;
......
256 269
        (!values[UID]) ||
257 270
        (!values[NAME]) ||
258 271
        (!values[TYPE]) ||
272
        (!values[PUBLIC]) ||
259 273
        (!values[REGTIME]) ||
260 274
        (!values[SOURCE]) ||
261 275
        (!values[STATE]) ||
......
271 285
            "<UID>"            << values[UID]         << "</UID>"         <<
272 286
            "<NAME>"           << values[NAME]        << "</NAME>"        <<
273 287
            "<TYPE>"           << values[TYPE]        << "</TYPE>"        <<
288
            "<PUBLIC>"         << values[PUBLIC]      << "</PUBLIC>"      <<
274 289
            "<REGTIME>"        << values[REGTIME]     << "</REGTIME>"     <<
275 290
            "<SOURCE>"         << values[SOURCE]      << "</SOURCE>"      <<
276 291
            "<STATE>"          << values[STATE]       << "</STATE>"       <<
......
333 348
            "<UID>"            << uid         << "</UID>"         <<
334 349
            "<NAME>"           << name        << "</NAME>"        <<
335 350
            "<TYPE>"           << type        << "</TYPE>"        <<
351
            "<PUBLIC>"         << public_img  << "</PUBLIC>"      <<
336 352
            "<REGTIME>"        << regtime     << "</REGTIME>"     <<
337 353
            "<SOURCE>"         << source      << "</SOURCE>"      <<
338 354
            "<STATE>"          << state       << "</STATE>"       <<
......
359 375
        "UID         = "    << uid         << endl <<
360 376
        "NAME        = "    << name        << endl <<
361 377
        "TYPE        = "    << type        << endl <<
378
        "PUBLIC      = "    << public_img  << endl <<
362 379
        "REGTIME     = "    << regtime     << endl <<
363 380
        "SOURCE      = "    << source      << endl <<
364 381
        "STATE       = "    << state       << endl <<
src/image/ImagePool.cc
67 67
        default_type = _default_type;
68 68
    }
69 69

  
70
    default_public = "NO";
71

  
70 72
    // Read from the DB the existing images, and build the ID:Name map
71 73
    set_callback(static_cast<Callbackable::Callback>(&ImagePool::init_cb));
72 74

  
......
93 95
        string  name           = "";
94 96
        string  source         = "";
95 97
        string  type           = "";
98
        string  public_attr    = "";
96 99
        string  original_path  = "";
97 100
        string  dev_prefix     = "";
98 101

  
......
142 145
            img->image_template.erase("TYPE");
143 146
        }
144 147

  
148
        img->get_template_attribute("PUBLIC", public_attr);
149

  
150
        if ( public_attr.empty() == true )
151
        {
152
            public_attr = default_public;
153
        }
154
        else
155
        {
156
            img->image_template.erase("PUBLIC");
157
        }
158

  
145 159
        img->get_template_attribute("ORIGINAL_PATH", original_path);
146 160
        
147 161
        if  ( (type == "OS" || type == "CDROM") &&
......
175 189

  
176 190
        img->name        = name;
177 191
        img->source      = tmp_sourcestream.str();
192
        img->public_img  = public_attr;
178 193

  
179 194
        if (img->set_type(type) != 0)
180 195
        {

Also available in: Unified diff