Revision c7625b48

View differences:

include/PoolObjectSQL.h
279 279
     *  Replace template for this object
280 280
     *    @param tmpl string representation of the template
281 281
     */
282
//    int replace_template(const string& tmpl_str, string& error)
283
//    {
284
//        Template * new_template =         
282
    int replace_template(const string& tmpl_str, string& error);
285 283

  
286
//    } 
287 284
protected:
288 285

  
289 286
    /**
src/lcm/test/SConstruct
34 34
    'nebula_group',
35 35
    'nebula_vnm',
36 36
    'nebula_image',
37
    'nebula_pool',
38 37
    'nebula_xml',
39 38
    'nebula_hm',
40 39
    'nebula_authm',
......
43 42
    'nebula_log',
44 43
    'nebula_lcm',
45 44
    'nebula_dm',
45
    'nebula_pool',
46 46
    'crypto'
47 47
])
48 48

  
src/pool/PoolObjectSQL.cc
162 162
/* -------------------------------------------------------------------------- */
163 163
/* -------------------------------------------------------------------------- */
164 164

  
165
int PoolObjectSQL::replace_template(const string& tmpl_str, string& error)
166
{
167
    Template * new_tmpl  = get_new_template();
168
    char *     error_msg = 0;
169

  
170
    if ( new_tmpl == 0 )
171
    {
172
        error = "Can not allocate a new template";
173
        return -1;
174
    }
175
    
176
    if ( new_tmpl->parse(tmpl_str, &error_msg) != 0 )
177
    {
178
        ostringstream oss;
179
        
180
        oss << "Parse error";
181
         
182
        if (error_msg != 0)
183
        {
184
            oss << ": " << error_msg;
185
        }
186
        
187
        error = oss.str();
188

  
189
        return -1;
190
    }
191

  
192
    delete obj_template;
193

  
194
    obj_template = new_tmpl;
195

  
196
    return 0;
197
} 
198

  
199
/* -------------------------------------------------------------------------- */
200
/* -------------------------------------------------------------------------- */
201

  
src/pool/test/SConstruct
23 23

  
24 24
env.Prepend(LIBS=[
25 25
    'nebula_pool',
26
    'nebula_template',
26 27
    'nebula_xml',
27 28
    'nebula_common',
28 29
    'nebula_log',
src/rm/RequestManagerVMTemplate.cc
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
#include "RequestManagerVMTemplate.h"
18
#include "Nebula.h"
19

  
20
/* -------------------------------------------------------------------------- */
21
/* -------------------------------------------------------------------------- */
22

  
23
void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList)
24
{
25
    int    id   = xmlrpc_c::value_int(paramList.getInt(1));
26
    string name = xmlrpc_c::value_string(paramList.getString(2));
27

  
28
    int    rc, ouid, vid;
29

  
30
    Nebula& nd = Nebula::instance();
31
    VirtualMachinePool* vmpool = nd.get_vmpool();
32
    VMTemplatePool * tpool     = static_cast<VMTemplatePool *>(pool);
33

  
34
    VirtualMachineTemplate * tmpl;
35
    VMTemplate *             rtmpl;
36

  
37
    string error_str;
38

  
39
    rtmpl = tpool->get(id,true);
40

  
41
    if ( rtmpl == 0 )
42
    {
43
        failure_response(NO_EXISTS, get_error(object_name(auth_object),id)); 
44
        return;
45
    }
46

  
47
    tmpl = rtmpl->clone_template();
48
    ouid = rtmpl->get_uid();
49
    
50
    rtmpl->unlock();
51

  
52
    tmpl->erase("NAME");
53
    tmpl->set(new SingleAttribute("NAME",name));
54

  
55
    if ( uid != 0 )
56
    {
57
        AuthRequest ar(uid);
58

  
59
        ar.add_auth(auth_object, id, auth_op, ouid, false);
60

  
61
        VirtualMachine::set_auth_request(uid, ar, tmpl);
62

  
63
        if (UserPool::authorize(ar) == -1)
64
        {
65
            failure_response(AUTHORIZATION, //TODO
66
                     authorization_error("INFO",object_name(auth_object),id,-1));
67
            delete tmpl;
68
            return;
69
        }
70
    }
71

  
72
    rc = vmpool->allocate(uid, gid, tmpl, &vid, error_str, false);
73

  
74
    if ( rc < 0 )
75
    {
76
        failure_response(INTERNAL, error_str); //TODO
77
        return;
78
    }
79
    
80
    success_response(vid);
81
}
82

  
83
/* -------------------------------------------------------------------------- */
84
/* -------------------------------------------------------------------------- */
85

  
src/um/test/SConstruct
20 20
    'nebula_um',
21 21
    'nebula_group',
22 22
    'nebula_pool',
23
    'nebula_template',
23 24
    'nebula_xml',
24 25
    'nebula_log',
25 26
    'nebula_authm',

Also available in: Unified diff