Statistics
| Branch: | Tag: | Revision:

one / src / scheduler / src / pool / DatastoreXML.cc @ 621a1869

History | View | Annotate | Download (4.7 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems                */
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 <sstream>
18

    
19
#include "DatastoreXML.h"
20
#include "NebulaUtil.h"
21
#include "NebulaLog.h"
22
#include "ObjectCollection.h"
23

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

    
27
int DatastoreXML::ds_num_paths = 2;
28

    
29
const char * DatastoreXML::ds_paths[] = {
30
    "/DATASTORE/TEMPLATE/",
31
    "/DATASTORE/"
32
};
33

    
34
/* -------------------------------------------------------------------------- */
35
/* -------------------------------------------------------------------------- */
36

    
37
void DatastoreXML::init_attributes()
38
{
39
    xpath(oid,  "/DATASTORE/ID",          -1);
40

    
41
    ObjectCollection cluster_collection("CLUSTERS");
42
    cluster_collection.from_xml(this, "/DATASTORE/");
43

    
44
    cluster_ids = cluster_collection.clone();
45

    
46
    xpath(uid,      "/DATASTORE/UID",  -1);
47
    xpath(gid,      "/DATASTORE/GID",  -1);
48

    
49
    xpath(owner_u, "/DATASTORE/PERMISSIONS/OWNER_U", 0);
50
    xpath(owner_m, "/DATASTORE/PERMISSIONS/OWNER_M", 0);
51
    xpath(owner_a, "/DATASTORE/PERMISSIONS/OWNER_A", 0);
52

    
53
    xpath(group_u, "/DATASTORE/PERMISSIONS/GROUP_U", 0);
54
    xpath(group_m, "/DATASTORE/PERMISSIONS/GROUP_M", 0);
55
    xpath(group_a, "/DATASTORE/PERMISSIONS/GROUP_A", 0);
56

    
57
    xpath(other_u, "/DATASTORE/PERMISSIONS/OTHER_U", 0);
58
    xpath(other_m, "/DATASTORE/PERMISSIONS/OTHER_M", 0);
59
    xpath(other_a, "/DATASTORE/PERMISSIONS/OTHER_A", 0);
60

    
61
    xpath<long long>(free_mb, "/DATASTORE/FREE_MB", 0);
62

    
63
    long long total_mb, used_mb, limit_mb;
64

    
65
    xpath<long long>(total_mb, "/DATASTORE/TOTAL_MB", 0);
66
    xpath<long long>(used_mb,  "/DATASTORE/USED_MB",  0);
67

    
68
    monitored = (free_mb != 0 || total_mb != 0 || used_mb != 0);
69

    
70
    int rc = xpath<long long>(limit_mb, "/DATASTORE/TEMPLATE/LIMIT_MB", 0);
71

    
72
    if (rc == 0)
73
    {
74
        long long free_limited = limit_mb - used_mb;
75

    
76
        if (free_limited < 0)
77
        {
78
            free_mb = 0;
79
        }
80
        else if (free_limited < free_mb)
81
        {
82
            free_mb = free_limited;
83
        }
84
    }
85

    
86
    string shared_st;
87
    this->xpath(shared_st, "/DATASTORE/TEMPLATE/SHARED", "YES");
88

    
89
    shared = one_util::toupper(shared_st) == "YES";
90

    
91
    ObjectXML::paths     = ds_paths;
92
    ObjectXML::num_paths = ds_num_paths;
93
}
94

    
95
/* -------------------------------------------------------------------------- */
96
/* -------------------------------------------------------------------------- */
97

    
98
bool DatastoreXML::test_capacity(long long vm_disk_mb, string & error) const
99
{
100
    bool fits = (vm_disk_mb < free_mb) || (vm_disk_mb == 0);
101

    
102
    if (!fits)
103
    {
104
        if (NebulaLog::log_level() >= Log::DDEBUG)
105
        {
106
            ostringstream oss;
107

    
108
            oss << "Not enough capacity. "
109
                << "Requested: " << vm_disk_mb << " MB, "
110
                << "Available: " << free_mb << " MB";
111

    
112
            error = oss.str();
113
        }
114
        else
115
        {
116
            error = "Not enough capacity.";
117
        }
118
    }
119

    
120
    return fits;
121
}
122

    
123
/* -------------------------------------------------------------------------- */
124
/* -------------------------------------------------------------------------- */
125

    
126
void DatastoreXML::get_permissions(PoolObjectAuth& auth)
127
{
128
    auth.obj_type = PoolObjectSQL::DATASTORE;
129

    
130
    auth.oid = oid;
131
    auth.uid = uid;
132
    auth.gid = gid;
133
    auth.cids = cluster_ids;
134

    
135
    auth.owner_u = owner_u;
136
    auth.owner_m = owner_m;
137
    auth.owner_a = owner_a;
138

    
139
    auth.group_u = group_u;
140
    auth.group_m = group_m;
141
    auth.group_a = group_a;
142

    
143
    auth.other_u = other_u;
144
    auth.other_m = other_m;
145
    auth.other_a = other_a;
146
}