Statistics
| Branch: | Tag: | Revision:

one / src / scheduler / include / DatastoreXML.h @ 621a1869

History | View | Annotate | Download (3.8 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

    
18
#ifndef DATASTORE_XML_H_
19
#define DATASTORE_XML_H_
20

    
21
#include "ObjectXML.h"
22
#include "PoolObjectAuth.h"
23

    
24
using namespace std;
25

    
26
class DatastoreXML : public ObjectXML
27
{
28
public:
29
    DatastoreXML(const string &xml_doc):ObjectXML(xml_doc)
30
    {
31
        init_attributes();
32
    };
33

    
34
    DatastoreXML(const xmlNodePtr node):ObjectXML(node)
35
    {
36
        init_attributes();
37
    };
38

    
39
    /**
40
     *  Tests whether a new VM can be hosted by the datastore
41
     *    @param vm_disk_mb capacity needed by the VM
42
     *    @param error error message
43
     *    @return true if the datastore can host the VM
44
     */
45
    bool test_capacity(long long vm_disk_mb, string & error) const;
46

    
47
    /**
48
     *  Tests whether a new VM can be hosted by the datastore
49
     *    @param vm_disk_mb capacity needed by the VM
50
     *    @return true if the datastore can host the VM
51
     */
52
    bool test_capacity(long long vm_disk_mb) const
53
    {
54
        string tmp_st;
55
        return test_capacity(vm_disk_mb, tmp_st);
56
    }
57

    
58
    /**
59
     *  Adds a new VM to the datastore
60
     *    @param vm_disk_mb capacity needed by the VM
61
     *    @return 0 on success
62
     */
63
    void add_capacity(long long vm_disk_mb)
64
    {
65
        free_mb  -= vm_disk_mb;
66
    };
67

    
68
    int get_oid() const
69
    {
70
        return oid;
71
    };
72

    
73
    bool is_in_cluster(const set<int> &cids) const
74
    {
75
        set<int>::const_iterator i;
76

    
77
        for (i = cids.begin(); i != cids.end(); i++)
78
        {
79
            if (cluster_ids.find(*i) != cluster_ids.end())
80
            {
81
                return true;
82
            }
83
        }
84

    
85
        return false;
86
    };
87

    
88
    /**
89
     * Returns true if the DS contains the SHARED = YES attribute
90
     * @return true if the DS is shared
91
     */
92
    bool is_shared()
93
    {
94
        return shared;
95
    };
96

    
97
    /**
98
     * Returns true if the DS free_mb is not 0. Only for shared DS
99
     * @return true if the DS is monitored
100
     */
101
    bool is_monitored()
102
    {
103
        return monitored;
104
    };
105

    
106
    /**
107
     *  Fills a auth class to perform an authZ/authN request based on the object
108
     *  attributes
109
     *    @param auths to be filled
110
     */
111
    void get_permissions(PoolObjectAuth& auth);
112

    
113
private:
114

    
115
    int oid;
116
    set<int> cluster_ids;
117

    
118
    int uid;
119
    int gid;
120

    
121
    int owner_u;
122
    int owner_m;
123
    int owner_a;
124

    
125
    int group_u;
126
    int group_m;
127
    int group_a;
128

    
129
    int other_u;
130
    int other_m;
131
    int other_a;
132

    
133
    long long free_mb; /**< Free disk for VMs (in MB). */
134

    
135
    bool monitored;
136

    
137
    bool shared;
138

    
139
    static const char *ds_paths[]; /**< paths for search function */
140

    
141
    static int ds_num_paths; /**< number of paths*/
142

    
143
    void init_attributes();
144
};
145

    
146
#endif /* DATASTORE_XML_H_ */