Revision ccced18e

View differences:

src/rm/RequestManagerClusterAllocate.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 "RequestManager.h"
18
#include "NebulaLog.h"
19

  
20
#include "AuthManager.h"
21

  
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

  
25
void RequestManager::ClusterAllocate::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string              session;
30
    string              error_str;
31

  
32
    string              clustername;
33
    int                 id;
34

  
35
    const string        method_name = "ClusterAllocate";
36

  
37
    int                 rc;
38
    ostringstream       oss;
39

  
40
    /*   -- RPC specific vars --  */
41
    vector<xmlrpc_c::value> arrayData;
42
    xmlrpc_c::value_array * arrayresult;
43

  
44
    NebulaLog::log("ReM",Log::DEBUG,"ClusterAllocate method invoked");
45

  
46
    // Get the parameters
47
    session      = xmlrpc_c::value_string(paramList.getString(0));
48
    clustername  = xmlrpc_c::value_string(paramList.getString(1));
49

  
50
    //Authenticate the user
51
    rc = ClusterAllocate::upool->authenticate(session);
52

  
53
    if ( rc == -1 )
54
    {
55
        goto error_authenticate;
56
    }
57

  
58
    //Authorize the operation
59
    if ( rc != 0 ) // rc == 0 means oneadmin
60
    {
61
        AuthRequest ar(rc);
62

  
63
        ar.add_auth(AuthRequest::CLUSTER,-1,AuthRequest::CREATE,0,false);
64

  
65
        if (UserPool::authorize(ar) == -1)
66
        {
67
            goto error_authorize;
68
        }
69
    }
70

  
71
    // Perform the allocation in the hostpool
72
    rc = ClusterAllocate::cpool->allocate(&id, clustername, error_str);
73

  
74
    if ( rc == -1 )
75
    {
76
        goto error_cluster_allocate;
77
    }
78

  
79
    // All nice, return the new id to client
80
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
81
    arrayData.push_back(xmlrpc_c::value_int(id));
82
    arrayresult = new xmlrpc_c::value_array(arrayData);
83
    // Copy arrayresult into retval mem space
84
    *retval = *arrayresult;
85
    // and get rid of the original
86
    delete arrayresult;
87

  
88
    return;
89

  
90
error_authenticate:
91
    oss.str(authenticate_error(method_name));
92
    goto error_common;
93

  
94
error_authorize:
95
    oss.str(authorization_error(method_name, "CREATE", "CLUSTER", rc, -1));
96
    goto error_common;
97

  
98
error_cluster_allocate:
99
    oss << action_error(method_name, "CREATE", "CLUSTER", -2, 0);
100
    oss << " " << error_str;
101
    goto error_common;
102

  
103
error_common:
104

  
105
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
106
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
107

  
108
    NebulaLog::log("ReM",Log::ERROR,oss);
109

  
110
    xmlrpc_c::value_array arrayresult_error(arrayData);
111

  
112
    *retval = arrayresult_error;
113

  
114
    return;
115
}
116

  
117
/* -------------------------------------------------------------------------- */
118
/* -------------------------------------------------------------------------- */
src/rm/RequestManagerGroupAllocate.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 "RequestManager.h"
18
#include "NebulaLog.h"
19

  
20
#include "AuthManager.h"
21

  
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

  
25
void RequestManager::GroupAllocate::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string              session;
30
    string              error_str;
31

  
32
    string              name;
33
    int                 id;
34

  
35
    const string        method_name = "GroupAllocate";
36

  
37
    int                 rc, uid;
38
    ostringstream       oss;
39

  
40
    /*   -- RPC specific vars --  */
41
    vector<xmlrpc_c::value> arrayData;
42
    xmlrpc_c::value_array * arrayresult;
43

  
44
    NebulaLog::log("ReM",Log::DEBUG,"GroupAllocate method invoked");
45

  
46
    // Get the parameters
47
    session      = xmlrpc_c::value_string(paramList.getString(0));
48
    name         = xmlrpc_c::value_string(paramList.getString(1));
49

  
50
    //Authenticate the user
51
    uid = GroupAllocate::upool->authenticate(session);
52

  
53
    if ( uid == -1 )
54
    {
55
        goto error_authenticate;
56
    }
57

  
58
    //Authorize the operation
59
    if ( uid != 0 ) // uid == 0 means oneadmin
60
    {
61
        AuthRequest ar(uid);
62

  
63
        ar.add_auth(AuthRequest::GROUP,
64
                    -1,
65
                    AuthRequest::CREATE,
66
                    uid,
67
                    false);
68

  
69
        if (UserPool::authorize(ar) == -1)
70
        {
71
            goto error_authorize;
72
        }
73
    }
74

  
75
    // Perform the allocation in the pool
76
    rc = GroupAllocate::gpool->allocate(uid, name, &id, error_str);
77

  
78
    if ( rc == -1 )
79
    {
80
        goto error_allocate;
81
    }
82

  
83
    // All nice, return the new id to client
84
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
85
    arrayData.push_back(xmlrpc_c::value_int(id));
86
    arrayresult = new xmlrpc_c::value_array(arrayData);
87
    // Copy arrayresult into retval mem space
88
    *retval = *arrayresult;
89
    // and get rid of the original
90
    delete arrayresult;
91

  
92
    return;
93

  
94
error_authenticate:
95
    oss.str(authenticate_error(method_name));
96
    goto error_common;
97

  
98
error_authorize:
99
    oss.str(authorization_error(method_name, "CREATE", "GROUP", uid, -1));
100
    goto error_common;
101

  
102
error_allocate:
103
    oss << action_error(method_name, "CREATE", "GROUP", -2, 0);
104
    oss << " " << error_str;
105
    goto error_common;
106

  
107
error_common:
108

  
109
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
110
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
111

  
112
    NebulaLog::log("ReM",Log::ERROR,oss);
113

  
114
    xmlrpc_c::value_array arrayresult_error(arrayData);
115

  
116
    *retval = arrayresult_error;
117

  
118
    return;
119
}
120

  
121
/* -------------------------------------------------------------------------- */
122
/* -------------------------------------------------------------------------- */
src/rm/RequestManagerHostAllocate.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 "RequestManager.h"
18
#include "NebulaLog.h"
19

  
20
#include "AuthManager.h"
21

  
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

  
25
void RequestManager::HostAllocate::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string              session;
30

  
31
    string              hostname;
32
    string              im_mad_name;
33
    string              vmm_mad_name;
34
    string              tm_mad_name;
35

  
36
    string              error_str;
37

  
38
    const string  method_name = "HostAllocate";
39

  
40
    int                 hid;
41

  
42
    int                 rc;
43
    ostringstream       oss;
44

  
45
    /*   -- RPC specific vars --  */
46
    vector<xmlrpc_c::value> arrayData;
47
    xmlrpc_c::value_array * arrayresult;
48

  
49
    NebulaLog::log("ReM",Log::DEBUG,"HostAllocate method invoked");
50

  
51
    // Get the parameters
52
    session      = xmlrpc_c::value_string(paramList.getString(0));
53
    hostname     = xmlrpc_c::value_string(paramList.getString(1));
54
    im_mad_name  = xmlrpc_c::value_string(paramList.getString(2));
55
    vmm_mad_name = xmlrpc_c::value_string(paramList.getString(3));
56
    tm_mad_name  = xmlrpc_c::value_string(paramList.getString(4));
57

  
58
    //Authenticate the user
59
    rc = HostAllocate::upool->authenticate(session);
60

  
61
    if ( rc == -1 )
62
    {
63
        goto error_authenticate;
64
    }
65

  
66
    //Authorize the operation
67
    if ( rc != 0 ) // rc == 0 means oneadmin
68
    {
69
        AuthRequest ar(rc);
70

  
71
        ar.add_auth(AuthRequest::HOST,-1,AuthRequest::CREATE,0,false);
72

  
73
        if (UserPool::authorize(ar) == -1)
74
        {
75
            goto error_authorize;
76
        }
77
    }
78

  
79
    // Perform the allocation in the hostpool
80
    rc = HostAllocate::hpool->allocate(&hid,
81
                                       hostname,
82
                                       im_mad_name,
83
                                       vmm_mad_name,
84
                                       tm_mad_name,
85
                                       error_str);
86
    if ( rc == -1 )
87
    {
88
        goto error_host_allocate;
89
    }
90

  
91
    // All nice, return the new hid to client
92
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
93
    arrayData.push_back(xmlrpc_c::value_int(hid));
94
    arrayresult = new xmlrpc_c::value_array(arrayData);
95
    // Copy arrayresult into retval mem space
96
    *retval = *arrayresult;
97
    // and get rid of the original
98
    delete arrayresult;
99

  
100
    return;
101

  
102
error_authenticate:
103
    oss.str(authenticate_error(method_name));
104
    goto error_common;
105

  
106
error_authorize:
107
    oss.str(authorization_error(method_name, "CREATE", "HOST", rc, -1));
108
    goto error_common;
109

  
110
error_host_allocate:
111
    oss << action_error(method_name, "CREATE", "HOST", -2, 0);
112
    oss << " " << error_str;
113
    goto error_common;
114

  
115
error_common:
116
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
117
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
118

  
119
    NebulaLog::log("ReM",Log::ERROR,oss);
120

  
121
    xmlrpc_c::value_array arrayresult_error(arrayData);
122

  
123
    *retval = arrayresult_error;
124
    return;
125
}
126

  
127
/* -------------------------------------------------------------------------- */
128
/* -------------------------------------------------------------------------- */
src/rm/RequestManagerImageAllocate.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 "RequestManager.h"
18

  
19
#include "NebulaLog.h"
20
#include "Nebula.h"
21

  
22
#include "AuthManager.h"
23

  
24
/* -------------------------------------------------------------------------- */
25
/* -------------------------------------------------------------------------- */
26

  
27
void RequestManager::ImageAllocate::execute(
28
    xmlrpc_c::paramList const& paramList,
29
    xmlrpc_c::value *   const  retval)
30
{
31
    string              session;
32
    string              str_template;
33
    string              error_str;
34

  
35
    ImageTemplate *     img_template = 0;
36
    User *              user;
37

  
38
    int                 iid;
39
    int                 uid;
40
    int                 gid;
41
    int                 rc;
42
    char *              error_msg = 0;
43

  
44
    ostringstream       oss;
45

  
46
    const string        method_name = "ImageAllocate";
47

  
48
    vector<xmlrpc_c::value> arrayData;
49
    xmlrpc_c::value_array * arrayresult;
50

  
51
    Nebula&          nd     = Nebula::instance();
52
    ImageManager *   imagem = nd.get_imagem();
53

  
54
    NebulaLog::log("ReM",Log::DEBUG,"ImageAllocate invoked");
55

  
56
    session      = xmlrpc_c::value_string(paramList.getString(0));
57
    str_template = xmlrpc_c::value_string(paramList.getString(1));
58
    str_template += "\n";
59

  
60
    //--------------------------------------------------------------------------
61
    //   Authenticate this request
62
    //--------------------------------------------------------------------------
63
    uid = ImageAllocate::upool->authenticate(session);
64

  
65
    if ( uid == -1 )
66
    {
67
        goto error_authenticate;
68
    }
69

  
70
    //--------------------------------------------------------------------------
71
    //   Authorize this request
72
    //--------------------------------------------------------------------------
73
    img_template = new ImageTemplate;
74

  
75
    rc = img_template->parse(str_template,&error_msg);
76

  
77
    if ( rc != 0 )
78
    {
79
        goto error_parse;
80
    }
81

  
82
    if ( uid != 0 )
83
    {
84
        AuthRequest ar(uid);
85
        string      t64;
86
        string      pub;
87
        string      pub_name = "PUBLIC";
88

  
89
        img_template->get(pub_name, pub);
90
        transform (pub.begin(), pub.end(), pub.begin(),(int(*)(int))toupper);
91

  
92
        ar.add_auth(AuthRequest::IMAGE,
93
                    img_template->to_xml(t64),
94
                    AuthRequest::CREATE,
95
                    uid,
96
                    (pub == "YES"));
97

  
98
        if (UserPool::authorize(ar) == -1)
99
        {
100
            goto error_authorize;
101
        }
102
    }
103

  
104
    //--------------------------------------------------------------------------
105
    //   Get the User Group
106
    //--------------------------------------------------------------------------
107

  
108
    user = ImageAllocate::upool->get(uid,true);
109

  
110
    if ( user == 0 )
111
    {
112
        goto error_user_get;
113
    }
114

  
115
    gid = user->get_gid();
116

  
117
    user->unlock();
118

  
119
    //--------------------------------------------------------------------------
120
    //   Allocate the Image
121
    //--------------------------------------------------------------------------
122

  
123
    rc = ImageAllocate::ipool->allocate(uid,gid, img_template,&iid, error_str);
124

  
125
    if ( rc < 0 )
126
    {
127
        goto error_allocate;
128
    }
129

  
130
    //--------------------------------------------------------------------------
131
    //   Register the Image in the repository
132
    //--------------------------------------------------------------------------
133
    if ( imagem->register_image(rc) == -1 )
134
    {
135
        goto error_register;
136
    }
137

  
138
    arrayData.push_back(xmlrpc_c::value_boolean(true));
139
    arrayData.push_back(xmlrpc_c::value_int(iid));
140

  
141
    // Copy arrayresult into retval mem space
142
    arrayresult = new xmlrpc_c::value_array(arrayData);
143
    *retval = *arrayresult;
144

  
145
    delete arrayresult; // and get rid of the original
146

  
147
    return;
148

  
149

  
150
error_user_get:
151
    oss.str(get_error(method_name, "USER", uid));
152
    delete img_template;
153
    goto error_common;
154

  
155
error_authenticate:
156
    oss.str(authenticate_error(method_name));
157
    goto error_common;
158

  
159
error_authorize:
160
    oss.str(authorization_error(method_name, "CREATE", "IMAGE", uid, -1));
161
    delete img_template;
162
    goto error_common;
163

  
164
error_parse:
165
    oss << action_error(method_name, "PARSE", "IMAGE TEMPLATE",-2,rc);
166
    if (error_msg != 0)
167
    {
168
        oss << ". Reason: " << error_msg;
169
        free(error_msg);
170
    }
171

  
172
    delete img_template;
173
    goto error_common;
174

  
175
error_allocate:
176
    oss << action_error(method_name, "CREATE", "IMAGE", -2, 0);
177
    oss << " " << error_str;
178
    goto error_common;
179

  
180
error_register:
181
    oss << action_error(method_name, "CREATE", "IMAGE", -2, 0);
182
    oss << " Failed to copy image to repository. Image left in ERROR state.";
183
    goto error_common;
184
    
185
error_common:
186
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
187
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
188

  
189
    NebulaLog::log("ReM",Log::ERROR,oss);
190

  
191
    xmlrpc_c::value_array arrayresult_error(arrayData);
192

  
193
    *retval = arrayresult_error;
194

  
195
    return;
196
}
197

  
198
/* -------------------------------------------------------------------------- */
199
/* -------------------------------------------------------------------------- */
src/rm/RequestManagerTemplateAllocate.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 "RequestManager.h"
18
#include "NebulaLog.h"
19

  
20
#include "Nebula.h"
21

  
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

  
25
void RequestManager::TemplateAllocate::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string              session;
30
    string              str_template;
31
    string              error_str;
32

  
33
    const string        method_name = "TemplateAllocate";
34

  
35
    int                 oid, uid, gid;
36
    int                 rc;
37

  
38
    ostringstream       oss;
39

  
40
    vector<xmlrpc_c::value> arrayData;
41
    xmlrpc_c::value_array * arrayresult;
42

  
43
    VirtualMachineTemplate * template_contents;
44
    User *                   user;
45
    char *                   error_msg = 0;
46

  
47

  
48
    NebulaLog::log("ReM",Log::DEBUG,"TemplateAllocate invoked");
49

  
50
    session      = xmlrpc_c::value_string(paramList.getString(0));
51
    str_template = xmlrpc_c::value_string(paramList.getString(1));
52
    str_template += "\n";
53

  
54
    //--------------------------------------------------------------------------
55
    //   Authenticate the user
56
    //--------------------------------------------------------------------------
57
    uid = TemplateAllocate::upool->authenticate(session);
58

  
59
    if (uid == -1)
60
    {
61
        goto error_authenticate;
62
    }
63

  
64
    //--------------------------------------------------------------------------
65
    //   Check the template syntax
66
    //--------------------------------------------------------------------------
67
    template_contents = new VirtualMachineTemplate;
68

  
69
    rc = template_contents->parse(str_template,&error_msg);
70

  
71
    if ( rc != 0 )
72
    {
73
        goto error_parse;
74
    }
75

  
76
    //--------------------------------------------------------------------------
77
    //   Authorize this request
78
    //--------------------------------------------------------------------------
79
    if ( uid != 0 )
80
    {
81
        AuthRequest ar(uid);
82
        string      t64;
83

  
84
        ar.add_auth(AuthRequest::TEMPLATE,
85
                    template_contents->to_xml(t64),
86
                    AuthRequest::CREATE,
87
                    uid,
88
                    false);
89

  
90
        if (UserPool::authorize(ar) == -1)
91
        {
92
            goto error_authorize;
93
        }
94
    }
95

  
96
    //--------------------------------------------------------------------------
97
    //   Get the User Group
98
    //--------------------------------------------------------------------------
99

  
100
    user = TemplateAllocate::upool->get(uid,true);
101

  
102
    if ( user == 0 )
103
    {
104
        goto error_user_get;
105
    }
106

  
107
    gid = user->get_gid();
108

  
109
    user->unlock();
110

  
111
    //--------------------------------------------------------------------------
112
    //   Allocate the VMTemplate
113
    //--------------------------------------------------------------------------
114
    rc = TemplateAllocate::tpool->allocate(uid,
115
                                           gid,
116
                                           template_contents,
117
                                           &oid,
118
                                           error_str);
119

  
120
    if ( rc < 0 )
121
    {
122
        goto error_allocate;
123
    }
124

  
125
    arrayData.push_back(xmlrpc_c::value_boolean(true));
126
    arrayData.push_back(xmlrpc_c::value_int(oid));
127

  
128
    // Copy arrayresult into retval mem space
129
    arrayresult = new xmlrpc_c::value_array(arrayData);
130
    *retval = *arrayresult;
131

  
132
    delete arrayresult; // and get rid of the original
133

  
134
    return;
135

  
136

  
137
error_user_get:
138
    oss.str(get_error(method_name, "USER", uid));
139

  
140
    delete template_contents;
141
    goto error_common;
142

  
143
error_authenticate:
144
    oss.str(authenticate_error(method_name));
145
    goto error_common;
146

  
147
error_authorize:
148
    oss.str(authorization_error(method_name, "CREATE", "TEMPLATE", uid, -1));
149
    delete template_contents;
150
    goto error_common;
151

  
152
error_parse:
153
    oss << action_error(method_name, "PARSE", "VM TEMPLATE",-2,rc);
154
    if (error_msg != 0)
155
    {
156
        oss << ". Reason: " << error_msg;
157
        free(error_msg);
158
    }
159

  
160
    delete template_contents;
161
    goto error_common;
162

  
163
error_allocate:
164
    oss << action_error(method_name, "CREATE", "TEMPLATE", -2, 0);
165
    oss << " " << error_str;
166
    goto error_common;
167

  
168
error_common:
169
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
170
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
171

  
172
    NebulaLog::log("ReM",Log::ERROR,oss);
173

  
174
    xmlrpc_c::value_array arrayresult_error(arrayData);
175

  
176
    *retval = arrayresult_error;
177

  
178
    return;
179
}
180

  
181
/* -------------------------------------------------------------------------- */
182
/* -------------------------------------------------------------------------- */
src/rm/RequestManagerUserAllocate.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 "RequestManager.h"
18
#include "NebulaLog.h"
19

  
20
#include "AuthManager.h"
21

  
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

  
25
void RequestManager::UserAllocate::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string              session;
30

  
31
    string              username;
32
    string              password;
33
    string              error_str;
34

  
35
    int                 uid;
36

  
37
    int                 rc;
38
    ostringstream       oss;
39

  
40
    const string        method_name = "UserAllocate";
41

  
42
    /*   -- RPC specific vars --  */
43
    vector<xmlrpc_c::value> arrayData;
44
    xmlrpc_c::value_array * arrayresult;
45

  
46
    NebulaLog::log("ReM",Log::DEBUG,"UserAllocate method invoked");
47

  
48
    // Get the parameters
49
    session      = xmlrpc_c::value_string(paramList.getString(0));
50

  
51
    username     = xmlrpc_c::value_string(paramList.getString(1));
52
    password     = xmlrpc_c::value_string(paramList.getString(2));
53

  
54
    rc = UserAllocate::upool->authenticate(session);
55

  
56
    if ( rc == -1 )
57
    {
58
        goto error_authenticate;
59
    }
60

  
61
    //Authorize the operation
62
    if ( rc != 0 ) // rc == 0 means oneadmin
63
    {
64
        AuthRequest ar(rc);
65

  
66
        ar.add_auth(AuthRequest::USER,
67
                    -1,
68
                    AuthRequest::CREATE,
69
                    0,
70
                    false);
71

  
72
        if (UserPool::authorize(ar) == -1)
73
        {
74
            goto error_authorize;
75
        }
76
    }
77

  
78
    // Now let's add the user
79
    rc = UserAllocate::upool->allocate(&uid,
80
                                       GroupPool::USERS_ID,
81
                                       username,
82
                                       password,
83
                                       true,
84
                                       error_str);
85
    if ( rc == -1 )
86
    {
87
        goto error_allocate;
88
    }
89

  
90
    // All nice, return the new uid to client
91
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
92
    arrayData.push_back(xmlrpc_c::value_int(uid));
93

  
94
    // Copy arrayresult into retval mem space
95
    arrayresult = new xmlrpc_c::value_array(arrayData);
96
    *retval = *arrayresult;
97

  
98
    delete arrayresult; // and get rid of the original
99

  
100
    return;
101

  
102
error_authenticate:
103
    oss.str(authenticate_error(method_name));
104
    goto error_common;
105

  
106
error_authorize:
107
    oss.str(authorization_error(method_name, "CREATE", "USER", rc, -1));
108
    goto error_common;
109

  
110
error_allocate:
111
    oss << action_error(method_name, "CREATE", "USER", -2, 0);
112
    oss << " " << error_str;
113
    goto error_common;
114

  
115
error_common:
116
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
117
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
118

  
119
    NebulaLog::log("ReM",Log::ERROR,oss);
120

  
121
    xmlrpc_c::value_array arrayresult_error(arrayData);
122

  
123
    *retval = arrayresult_error;
124

  
125
    return;
126
}
127

  
128
/* -------------------------------------------------------------------------- */
129
/* -------------------------------------------------------------------------- */
src/rm/RequestManagerVirtualNetworkAllocate.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 "RequestManager.h"
18
#include "NebulaLog.h"
19
#include "VirtualNetworkTemplate.h"
20

  
21
#include "AuthManager.h"
22

  
23
/* -------------------------------------------------------------------------- */
24
/* -------------------------------------------------------------------------- */
25

  
26
void RequestManager::VirtualNetworkAllocate::execute(
27
    xmlrpc_c::paramList const& paramList,
28
    xmlrpc_c::value *   const  retval)
29
{
30
    string              session;
31
    string              name;
32
    string              str_template;
33
    string              error_str;
34

  
35
    VirtualNetworkTemplate * vn_template;
36
    User *                   user;
37

  
38
    int                 nid;
39
    int                 uid;
40
    int                 rc;
41
    int                 gid;
42
    char *              error_msg = 0;
43

  
44
    ostringstream       oss;
45

  
46
    const string        method_name = "VirtualNetworkAllocate";
47

  
48
    /*   -- RPC specific vars --  */
49
    vector<xmlrpc_c::value> arrayData;
50
    xmlrpc_c::value_array * arrayresult;
51

  
52
    NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkAllocate method invoked");
53

  
54
    // Get the parameters & host
55
    session      = xmlrpc_c::value_string(paramList.getString(0));
56
    str_template = xmlrpc_c::value_string(paramList.getString(1));
57

  
58
    //--------------------------------------------------------------------------
59
    //   Authorize this request
60
    //--------------------------------------------------------------------------
61
    uid = VirtualNetworkAllocate::upool->authenticate(session);
62

  
63
    if ( uid == -1 )
64
    {
65
        goto error_authenticate;
66
    }
67

  
68
    //--------------------------------------------------------------------------
69
    //   Authorize this request
70
    //--------------------------------------------------------------------------
71
    vn_template = new VirtualNetworkTemplate;
72

  
73
    rc = vn_template->parse(str_template,&error_msg);
74

  
75
    if ( rc != 0 )
76
    {
77
        goto error_parse;
78
    }
79

  
80
    if ( uid != 0 )
81
    {
82
        AuthRequest ar(uid);
83
        string      t64;
84
        string      pub;
85
        string      pub_name = "PUBLIC";
86

  
87
        vn_template->get(pub_name, pub);
88
        transform (pub.begin(), pub.end(), pub.begin(),(int(*)(int))toupper);
89

  
90
        ar.add_auth(AuthRequest::NET,
91
                    vn_template->to_xml(t64),
92
                    AuthRequest::CREATE,
93
                    uid,
94
                    (pub == "YES"));
95

  
96
        if (UserPool::authorize(ar) == -1)
97
        {
98
            goto error_authorize;
99
        }
100
    }
101

  
102
    //--------------------------------------------------------------------------
103
    //   Get the User Group
104
    //--------------------------------------------------------------------------
105

  
106
    user = VirtualNetworkAllocate::upool->get(uid,true);
107

  
108
    if ( user == 0 )
109
    {
110
        goto error_user_get;
111
    }
112

  
113
    gid = user->get_gid();
114

  
115
    user->unlock();
116

  
117
    //--------------------------------------------------------------------------
118
    //   Allocate the Virtual Network
119
    //--------------------------------------------------------------------------
120
    rc = vnpool->allocate(uid,gid,vn_template,&nid,error_str);
121

  
122
    if ( rc < 0 )
123
    {
124
        goto error_vn_allocate;
125
    }
126

  
127
    //Result
128
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
129
    arrayData.push_back(xmlrpc_c::value_int(nid));
130
    arrayresult = new xmlrpc_c::value_array(arrayData);
131

  
132
    *retval = *arrayresult;
133

  
134
    delete arrayresult;
135

  
136
    return;
137

  
138

  
139
error_user_get:
140
    oss.str(get_error(method_name, "USER", uid));
141

  
142
    delete vn_template;
143
    goto error_common;
144

  
145
error_authenticate:
146
    oss.str(authenticate_error(method_name));
147
    goto error_common;
148

  
149
error_authorize:
150
    oss.str(authorization_error(method_name, "CREATE", "VNET", uid, -1));
151
    delete vn_template;
152
    goto error_common;
153

  
154
error_parse:
155
    oss << action_error(method_name, "PARSE", "VNET TEMPLATE",-2,rc);
156
    if (error_msg != 0)
157
    {
158
        oss << ". Reason: " << error_msg;
159
        free(error_msg);
160
    }
161

  
162
    delete vn_template;
163
    goto error_common;
164

  
165
error_vn_allocate:
166
    oss << action_error(method_name, "CREATE", "NET", -2, 0);
167
    oss << " " << error_str;
168
    goto error_common;
169

  
170
error_common:
171
    NebulaLog::log("ReM",Log::ERROR,oss);
172

  
173
    arrayData.push_back(xmlrpc_c::value_boolean(false));
174
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
175

  
176
    xmlrpc_c::value_array arrayresult_error(arrayData);
177

  
178
    *retval = arrayresult_error;
179

  
180
    return;
181
}
182

  
183
/* -------------------------------------------------------------------------- */
184
/* -------------------------------------------------------------------------- */

Also available in: Unified diff