lxd: remove outdated monkey patch

This commit is contained in:
Julian Dehm 2023-03-20 12:59:50 +01:00 committed by Megan Wilhite
parent 4730bea00b
commit a17239e607
2 changed files with 1 additions and 40 deletions

1
changelog/59514.fixed.md Normal file
View file

@ -0,0 +1 @@
Make the LXD module work with pyLXD > 2.10

View file

@ -3606,43 +3606,3 @@ def _pylxd_model_to_dict(obj):
if hasattr(obj, key):
marshalled[key] = getattr(obj, key)
return marshalled
#
# Monkey patching for missing functionality in pylxd
#
if HAS_PYLXD:
import pylxd.exceptions # NOQA
if not hasattr(pylxd.exceptions, "NotFound"):
# Old version of pylxd
class NotFound(pylxd.exceptions.LXDAPIException):
"""An exception raised when an object is not found."""
pylxd.exceptions.NotFound = NotFound
try:
from pylxd.container import Container
except ImportError:
from pylxd.models.container import Container
def put(self, filepath, data, mode=None, uid=None, gid=None):
headers = {}
if mode is not None:
if isinstance(mode, int):
mode = oct(mode)
elif not mode.startswith("0"):
mode = "0{}".format(mode)
headers["X-LXD-mode"] = mode
if uid is not None:
headers["X-LXD-uid"] = str(uid)
if gid is not None:
headers["X-LXD-gid"] = str(gid)
response = self._client.api.containers[self._container.name].files.post(
params={"path": filepath}, data=data, headers=headers
)
return response.status_code == 200
Container.FilesManager.put = put