Repository navigation
Expand file tree
/
Copy pathvpool.py
More file actions
217 lines (195 loc) · 10 KB
/
Copy pathvpool.py
File metadata and controls
217 lines (195 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Copyright (C) 2016 iNuron NV
#
# This file is part of Open vStorage Open Source Edition (OSE),
# as available from
#
# http://www.openvstorage.org and
# http://www.openvstorage.com.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3)
# as published by the Free Software Foundation, in version 3 as it comes
# in the LICENSE.txt file of the Open vStorage OSE distribution.
#
# Open vStorage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY of any kind.
"""
VPool module
"""
import time
from ovs.dal.dataobject import DataObject
from ovs.dal.structures import Dynamic, Property
from ovs.extensions.generic.configuration import Configuration, NotFoundException
from ovs.extensions.storageserver.storagedriver import ClusterRegistryClient, StorageDriverClient, ObjectRegistryClient, StorageDriverConfiguration,\
LocalStorageRouterClient
from ovs.log.log_handler import LogHandler
class VPool(DataObject):
"""
The VPool class represents a vPool. A vPool is a Virtual Storage Pool, a Filesystem, used to
deploy vDisks. a vPool can span multiple Storage Drivers and connects to a single Storage BackendType.
"""
_logger = LogHandler.get('dal', name='hybrid')
STATUSES = DataObject.enumerator('Status', ['DELETING', 'EXTENDING', 'FAILURE', 'INSTALLING', 'RUNNING', 'SHRINKING'])
CACHES = DataObject.enumerator('Cache', {'BLOCK': 'block',
'FRAGMENT': 'fragment'})
__properties = [Property('name', str, unique=True, indexed=True, doc='Name of the vPool'),
Property('description', str, mandatory=False, doc='Description of the vPool'),
Property('login', str, mandatory=False, doc='Login/Username for the Storage BackendType.'),
Property('password', str, mandatory=False, doc='Password for the Storage BackendType.'),
Property('connection', str, mandatory=False, doc='Connection (IP, URL, Domain name, Zone, ...) for the Storage BackendType.'),
Property('metadata', dict, mandatory=False, doc='Metadata for the backends, as used by the Storage Drivers.'),
Property('rdma_enabled', bool, default=False, doc='Has the vpool been configured to use RDMA for DTL transport, which is only possible if all storagerouters are RDMA capable'),
Property('status', STATUSES.keys(), doc='Status of the vPool'),
Property('metadata_store_bits', int, mandatory=False, doc='StorageDrivers deployed for this vPool will make use of this amount of metadata store bits'),
Property('snapshot_retention_policy', list, mandatory=False, doc='Snapshot retention policy configuration')]
__relations = []
__dynamics = [Dynamic('configuration', dict, 3600),
Dynamic('statistics', dict, 4),
Dynamic('identifier', str, 120),
Dynamic('extensible', tuple, 60),
Dynamic('volume_potentials', dict, 60)]
_fixed_properties = ['storagedriver_client', 'objectregistry_client', 'clusterregistry_client']
def __init__(self, *args, **kwargs):
"""
Initializes a vPool, setting up its additional helpers
"""
DataObject.__init__(self, *args, **kwargs)
self._frozen = False
self._storagedriver_client = None
self._objectregistry_client = None
self._clusterregistry_client = None
self._frozen = True
@property
def storagedriver_client(self):
"""
Client used for communication between Storage Driver and framework
:return: StorageDriverClient
"""
if self._storagedriver_client is None:
self.reload_client('storagedriver')
return self._storagedriver_client
@property
def objectregistry_client(self):
"""
Client used for communication between Storage Driver OR and framework
:return: ObjectRegistryClient
"""
if self._objectregistry_client is None:
self.reload_client('objectregistry')
return self._objectregistry_client
@property
def clusterregistry_client(self):
"""
Client used for making changes to the StorageDriver's Cluster Registry
:return: ClusterRegistry client
"""
if self._clusterregistry_client is None:
self.reload_client('clusterregistry')
return self._clusterregistry_client
def reload_client(self, client):
"""
Reloads the StorageDriverClient, ObjectRegistryClient or ClusterRegistry client
"""
self._frozen = False
if client == 'storagedriver':
self._storagedriver_client = StorageDriverClient.load(self)
elif client == 'objectregistry':
self._objectregistry_client = ObjectRegistryClient.load(self)
elif client == 'clusterregistry':
self._clusterregistry_client = ClusterRegistryClient.load(self)
self._frozen = True
def _configuration(self):
"""
VPool configuration
"""
if not self.storagedrivers or not self.storagedrivers[0].storagerouter:
return {}
storagedriver_config = StorageDriverConfiguration('storagedriver', self.guid, self.storagedrivers[0].storagedriver_id)
storagedriver_config.load()
for expected_key in ['distributed_transaction_log', 'filesystem', 'volume_router', 'volume_manager']:
if expected_key not in storagedriver_config.configuration:
return {}
dtl = storagedriver_config.configuration['distributed_transaction_log']
file_system = storagedriver_config.configuration['filesystem']
volume_router = storagedriver_config.configuration['volume_router']
volume_manager = storagedriver_config.configuration['volume_manager']
dtl_host = file_system['fs_dtl_host']
dtl_mode = file_system.get('fs_dtl_mode', StorageDriverClient.VOLDRV_DTL_ASYNC)
cluster_size = volume_manager['default_cluster_size'] / 1024
dtl_transport = dtl['dtl_transport']
sco_multiplier = volume_router['vrouter_sco_multiplier']
dtl_config_mode = file_system['fs_dtl_config_mode']
tlog_multiplier = volume_manager['number_of_scos_in_tlog']
non_disposable_sco_factor = volume_manager['non_disposable_scos_factor']
sco_size = sco_multiplier * cluster_size / 1024 # SCO size is in MiB ==> SCO multiplier * cluster size (4 KiB by default)
write_buffer = tlog_multiplier * sco_size * non_disposable_sco_factor
dtl_enabled = not (dtl_config_mode == StorageDriverClient.VOLDRV_DTL_MANUAL_MODE and dtl_host == '')
try:
mds_config = Configuration.get('/ovs/vpools/{0}/mds_config'.format(self.guid))
except NotFoundException:
mds_config = {}
return {'sco_size': sco_size,
'dtl_mode': StorageDriverClient.REVERSE_DTL_MODE_MAP[dtl_mode] if dtl_enabled is True else 'no_sync',
'mds_config': mds_config,
'dtl_enabled': dtl_enabled,
'cluster_size': cluster_size,
'write_buffer': write_buffer,
'dtl_transport': StorageDriverClient.REVERSE_DTL_TRANSPORT_MAP[dtl_transport],
'dtl_config_mode': dtl_config_mode,
'tlog_multiplier': tlog_multiplier}
def _statistics(self, dynamic):
"""
Aggregates the Statistics (IOPS, Bandwidth, ...) of each vDisk served by the vPool.
"""
from ovs.dal.hybrids.vdisk import VDisk
statistics = {}
for storagedriver in self.storagedrivers:
for key, value in storagedriver.fetch_statistics().iteritems():
if isinstance(value, dict):
if key not in statistics:
statistics[key] = {}
for subkey, subvalue in value.iteritems():
if subkey not in statistics[key]:
statistics[key][subkey] = 0
statistics[key][subkey] += subvalue
else:
if key not in statistics:
statistics[key] = 0
statistics[key] += value
statistics['timestamp'] = time.time()
VDisk.calculate_delta(self._key, dynamic, statistics)
return statistics
def _identifier(self):
"""
An identifier of this vPool in its current configuration state
"""
return '{0}_{1}'.format(self.guid, '_'.join(self.storagedrivers_guids))
def _extensible(self):
"""
Verifies whether this vPool can be extended or not
"""
reasons = []
if self.status != VPool.STATUSES.RUNNING:
reasons.append('non_running')
if self.metadata_store_bits is None:
reasons.append('voldrv_missing_info')
return len(reasons) == 0, reasons
def _volume_potentials(self):
# type: () -> Dict[str, int]
"""
Get an overview of all volume potentials for every Storagedriver in this vpool
A possible -1 can be returned for the volume potential which indicates that the potential could not be retrieved
:return: The overview with the volume potential
:rtype: dict
"""
volume_potentials = {}
for storagedriver in self.storagedrivers:
volume_potential = -1
try:
std_config = StorageDriverConfiguration('storagedriver', storagedriver.vpool_guid, storagedriver.storagedriver_id)
client = LocalStorageRouterClient(std_config.remote_path)
volume_potential = client.volume_potential(str(storagedriver.storagedriver_id))
except Exception:
self._logger.exception('Unable to retrieve configuration for storagedriver {0}'.format(storagedriver.storagedriver_id))
volume_potentials[storagedriver.storagerouter.guid] = volume_potential
return volume_potentials