Revision 007f5f6b

View differences:

include/RequestManager.h
438 438
        UserPool           * upool;
439 439
    };
440 440

  
441
    /* ---------------------------------------------------------------------- */
442

  
443
    class VirtualMachineSaveDisk: public xmlrpc_c::method
444
    {
445
    public:
446
        VirtualMachineSaveDisk(
447
            VirtualMachinePool * _vmpool,
448
            UserPool           * _upool,
449
            ImagePool          * _ipool):
450
                vmpool(_vmpool),
451
                upool(_upool),
452
                ipool(_ipool)
453
        {
454
            _signature="A:siii";
455
            _help="Sets the disk to be saved in the given image.";
456
        };
457

  
458
        ~VirtualMachineSaveDisk(){};
459

  
460
        void execute(
461
            xmlrpc_c::paramList const& paramList,
462
            xmlrpc_c::value *   const  retval);
463

  
464
    private:
465
        VirtualMachinePool * vmpool;
466
        UserPool           * upool;
467
        ImagePool          * ipool;
468
    };
441 469

  
442 470
    /* ---------------------------------------------------------------------- */
443 471

  
include/VirtualMachine.h
731 731
     */
732 732
    int  generate_context(string &files);
733 733

  
734

  
735
    // ------------------------------------------------------------------------
736
    // Image repository related functions
737
    // ------------------------------------------------------------------------
738
    /**
739
     *  Set the SAVE_AS attribute for the "disk_id"th disk.
740
     *    @param  disk_id Index of the disk to save
741
     *    @param  img_id ID of the image this disk will be saved to.
742
     *    @return 0 if success
743
     */
744
    int  save_disk(int disk_id, int img_id);
745

  
734 746
private:
735 747

  
736 748
    // -------------------------------------------------------------------------
src/rm/RequestManager.cc
224 224
        
225 225
    xmlrpc_c::methodPtr vm_action(new 
226 226
        RequestManager::VirtualMachineAction(vmpool,upool));
227
        
227

  
228
    xmlrpc_c::methodPtr vm_savedisk(new
229
        RequestManager::VirtualMachineSaveDisk(vmpool,upool,ipool));
230

  
228 231
    xmlrpc_c::methodPtr vm_info(new 
229 232
        RequestManager::VirtualMachineInfo(vmpool,upool));
230 233

  
......
322 325
    RequestManagerRegistry.addMethod("one.vm.action",  vm_action);
323 326
    RequestManagerRegistry.addMethod("one.vm.migrate", vm_migrate);
324 327
    RequestManagerRegistry.addMethod("one.vm.info",    vm_info);
328
    RequestManagerRegistry.addMethod("one.vm.savedisk",vm_savedisk);
325 329

  
326 330
    RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
327 331
     
src/rm/SConstruct
27 27
    'RequestManagerAllocate.cc',
28 28
    'RequestManagerDeploy.cc',
29 29
    'RequestManagerMigrate.cc',
30
    'RequestManagerSaveDisk.cc',
30 31
    'RequestManagerInfo.cc',
31 32
    'RequestManagerPoolInfo.cc',
32 33
    'RequestManagerHostAllocate.cc',
src/vm/VirtualMachine.cc
1098 1098
/* -------------------------------------------------------------------------- */
1099 1099
/* -------------------------------------------------------------------------- */
1100 1100

  
1101
int VirtualMachine::save_disk(int disk_id, int img_id)
1102
{
1103
    int                   num_disks;
1104
    vector<Attribute  * > disks;
1105
    VectorAttribute *     disk;
1106

  
1107
    string                disk_id_str;
1108
    int                   tmp_disk_id;
1109

  
1110
    ostringstream oss;
1111
    istringstream iss;
1112

  
1113

  
1114
    num_disks  = vm_template->get("DISK",disks);
1115

  
1116
    for(int i=0; i<num_disks; i++)
1117
    {
1118
        disk = dynamic_cast<VectorAttribute * >(disks[i]);
1119

  
1120
        if ( disk == 0 )
1121
        {
1122
            continue;
1123
        }
1124

  
1125
        disk_id_str = disk->vector_value("DISK_ID");
1126

  
1127
        iss.str(disk_id_str);
1128
        iss >> tmp_disk_id;
1129

  
1130
        if( tmp_disk_id == disk_id )
1131
        {
1132
            disk->replace("SAVE", "YES");
1133

  
1134
            oss << (img_id);
1135
            disk->replace("SAVE_AS", oss.str());
1136

  
1137
            return 0;
1138
        }
1139
    }
1140

  
1141
    return -1;
1142
}
1143

  
1144
/* -------------------------------------------------------------------------- */
1145
/* -------------------------------------------------------------------------- */
1146

  
1101 1147
pthread_mutex_t VirtualMachine::lex_mutex = PTHREAD_MUTEX_INITIALIZER;
1102 1148

  
1103 1149
extern "C"

Also available in: Unified diff