Skip to content

Commit 894250e

Browse files
Use coriolis-writer v2 API
The v1 coriolis-writer API only accepts device names such as /dev/vdb. Device names are unreliable and can change depending on the order in which the devices are identified. For this reason, most Coriolis providers attach one device at a time and then check the device name that was identified by the VM. This is unnecessary for providers that can predentermine the SCSI ID or address of the device and use that instead of device names. As such, we'll use the v2 API of the Coriolis writer, which also accepts udev links such as /dev/disk/by-id/<disk-id>. The Coriolis writer will still resolve those links to ensure that there aren't multiple lock owners of the same device. The main difference is that the disk path is passed as a b64 encoded string. Also, the lock acquire/release now became POST requests, which are more appropriate than using GET for this purpose.
1 parent a9b70ff commit 894250e

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

coriolis/providers/backup_writers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# All Rights Reserved.
33

44
import abc
5+
import base64
56
import contextlib
67
import copy
78
import datetime
@@ -574,16 +575,17 @@ def _set_info(self, info):
574575

575576
@property
576577
def _uri(self):
577-
return "https://%s:%s/api/v1/%s" % (
578-
self._ip, self._port, self._path.lstrip('/')
578+
b64_path = base64.b64encode(self._path.encode()).decode()
579+
return "https://%s:%s/api/v2/device/%s" % (
580+
self._ip, self._port, b64_path
579581
)
580582

581583
@utils.retry_on_error()
582584
def _acquire(self):
583585
self._ensure_session()
584586
uri = "%s/acquire" % self._uri
585587
headers = {"X-Client-Token": self._id}
586-
resp = self._session.get(
588+
resp = self._session.post(
587589
uri, headers=headers, timeout=CONF.default_requests_timeout)
588590
LOG.debug("Returned code: %d. Msg: %s" % (
589591
resp.status_code, resp.content))
@@ -594,7 +596,7 @@ def _release(self):
594596
self._ensure_session()
595597
uri = "%s/release" % self._uri
596598
headers = {"X-Client-Token": self._id}
597-
resp = self._session.get(
599+
resp = self._session.post(
598600
uri, headers=headers, timeout=CONF.default_requests_timeout)
599601
LOG.debug("Returned code: %d. Msg: %s" %
600602
(resp.status_code, resp.content))

coriolis/tests/providers/test_backup_writers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ def test__uri(self):
743743

744744
result = self.writer._uri
745745

746-
self.assertEqual(result, "https://%s:%s/api/v1/%s" % (
747-
self.writer._ip, self.writer._port, self.writer._path))
746+
self.assertEqual(result, "https://%s:%s/api/v2/device/%s" % (
747+
self.writer._ip, self.writer._port, "cGF0aC90ZXN0X3BhdGg="))
748748

749749
@mock.patch.object(backup_writers.HTTPBackupWriterImpl, '_ensure_session')
750750
@mock.patch.object(backup_writers.HTTPBackupWriterImpl, '_uri')
@@ -757,7 +757,7 @@ def test__acquire(self, mock_session_class, mock_conf, mock_uri,
757757
mock_response.content = 'OK'
758758

759759
mock_session = mock_session_class.return_value
760-
mock_session.get.return_value = mock_response
760+
mock_session.post.return_value = mock_response
761761

762762
self.writer._session = mock_session
763763

@@ -783,7 +783,7 @@ def test__release(self, mock_session_class, mock_conf, mock_uri,
783783
mock_response.content = 'OK'
784784

785785
mock_session = mock_session_class.return_value
786-
mock_session.get.return_value = mock_response
786+
mock_session.post.return_value = mock_response
787787

788788
self.writer._session = mock_session
789789

0 commit comments

Comments
 (0)