Statistics
| Branch: | Tag: | Revision:

one / src / rm / RequestManagerVMTemplate.cc @ c7625b48

History | View | Annotate | Download (2.98 KB)

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