-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0039-feat-LinstorSR-add-optional-ips-parameter.patch
120 lines (112 loc) · 4.9 KB
/
0039-feat-LinstorSR-add-optional-ips-parameter.patch
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
From c888113ede59c03474468767d28df14cb0e0bf73 Mon Sep 17 00:00:00 2001
From: Ronan Abhamon <[email protected]>
Date: Wed, 24 Mar 2021 10:06:58 +0100
Subject: [PATCH 039/179] feat(LinstorSR): add optional ips parameter
Signed-off-by: Ronan Abhamon <[email protected]>
---
drivers/LinstorSR.py | 30 ++++++++++++++++++++-----
drivers/linstorvolumemanager.py | 40 ++++++++++++++++++++++-----------
2 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/drivers/LinstorSR.py b/drivers/LinstorSR.py
index 9f2be58c..4b761b56 100755
--- a/drivers/LinstorSR.py
+++ b/drivers/LinstorSR.py
@@ -77,6 +77,7 @@ CAPABILITIES = [
CONFIGURATION = [
['group-name', 'LVM group name'],
['hosts', 'host names to use'],
+ ['ips', 'ips to use (optional, defaults to management networks)'],
['redundancy', 'replication count'],
['provisioning', '"thin" or "thick" are accepted (optional, defaults to thin)'],
['monitor-db-quorum', 'disable controller when only one host is online (optional, defaults to true)']
@@ -325,6 +326,10 @@ class LinstorSR(SR.SR):
self.sr_vditype = SR.DEFAULT_TAP
self._hosts = list(set(self.dconf['hosts'].split(',')))
+ if 'ips' not in self.dconf or not self.dconf['ips']:
+ self._ips = None
+ else:
+ self._ips = self.dconf['ips'].split(',')
self._redundancy = int(self.dconf['redundancy'] or 1)
self._linstor = None # Ensure that LINSTOR attribute exists.
self._journaler = None
@@ -533,11 +538,26 @@ class LinstorSR(SR.SR):
)
ips = {}
- for host in online_hosts:
- record = self.session.xenapi.host.get_record(host)
- hostname = record['hostname']
- if hostname in self._hosts:
- ips[hostname] = record['address']
+ if not self._ips:
+ for host in online_hosts:
+ record = self.session.xenapi.host.get_record(host)
+ hostname = record['hostname']
+ if hostname in self._hosts:
+ ips[hostname] = record['address']
+ elif len(self._ips) != len(self._hosts):
+ raise xs_errors.XenError(
+ 'LinstorSRCreate',
+ opterr='ips must be equal to host count'
+ )
+ else:
+ for host in online_hosts:
+ record = self.session.xenapi.host.get_record(host)
+ hostname = record['hostname']
+ try:
+ index = self._hosts.index(hostname)
+ ips[hostname] = self._ips[index]
+ except ValueError as e:
+ pass
if len(ips) != len(self._hosts):
raise xs_errors.XenError(
diff --git a/drivers/linstorvolumemanager.py b/drivers/linstorvolumemanager.py
index 3aaffdf4..5c04d028 100755
--- a/drivers/linstorvolumemanager.py
+++ b/drivers/linstorvolumemanager.py
@@ -1313,22 +1313,36 @@ class LinstorVolumeManager(object):
for node_name in node_names:
ip = ips[node_name]
- result = lin.node_create(
- node_name,
- linstor.consts.VAL_NODE_TYPE_CMBD,
- ip
- )
- errors = cls._filter_errors(result)
- if cls._check_errors(errors, [linstor.consts.FAIL_EXISTS_NODE]):
- continue
- if errors:
- raise LinstorVolumeManagerError(
- 'Failed to create node `{}` with ip `{}`: {}'.format(
- node_name, ip, cls._get_error_str(errors)
- )
+ while True:
+ # Try to create node.
+ result = lin.node_create(
+ node_name,
+ linstor.consts.VAL_NODE_TYPE_CMBD,
+ ip
)
+ errors = cls._filter_errors(result)
+ if cls._check_errors(
+ errors, [linstor.consts.FAIL_EXISTS_NODE]
+ ):
+ # If it already exists, remove, then recreate.
+ result = lin.node_delete(node_name)
+ error_str = cls._get_error_str(result)
+ if error_str:
+ raise LinstorVolumeManagerError(
+ 'Failed to remove old node `{}`: {}'
+ .format(node_name, error_str)
+ )
+ elif not errors:
+ break # Created!
+ else:
+ raise LinstorVolumeManagerError(
+ 'Failed to create node `{}` with ip `{}`: {}'.format(
+ node_name, ip, cls._get_error_str(errors)
+ )
+ )
+
driver_pool_name = group_name
group_name = cls._build_group_name(group_name)
pools = lin.storage_pool_list_raise(filter_by_stor_pools=[group_name])