Skip to content

Commit

Permalink
Merge pull request #251 from xcp-ng/strip-xva-suffix
Browse files Browse the repository at this point in the history
vm cache: shorten vm description by stripping .xva suffix
  • Loading branch information
ydirson authored Sep 3, 2024
2 parents 6b4e59e + b630970 commit 4db061d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import getpass
import inspect
import logging
import sys
import time
import traceback
from enum import Enum
Expand Down Expand Up @@ -75,6 +76,20 @@ def safe_split(text, sep=','):
""" A split function that returns an empty list if the input string is empty. """
return text.split(sep) if len(text) > 0 else []

def strip_prefix(string, prefix):
if sys.version_info >= (3, 9):
return string.removeprefix(prefix)
if string.startswith(prefix):
return string[len(prefix):]
return string

def strip_suffix(string, suffix):
if sys.version_info >= (3, 9):
return string.removesuffix(suffix)
if string.endswith(suffix):
return string[:-len(suffix)]
return string

def setup_formatted_and_mounted_disk(host, sr_disk, fs_type, mountpoint):
if fs_type == 'ext4':
option_force = '-F'
Expand Down
4 changes: 2 additions & 2 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import lib.commands as commands

from lib.common import _param_get, safe_split, to_xapi_bool, wait_for, wait_for_not
from lib.common import _param_get, safe_split, strip_suffix, to_xapi_bool, wait_for, wait_for_not
from lib.common import prefix_object_name
from lib.netutil import wrap_ip
from lib.sr import SR
Expand Down Expand Up @@ -202,7 +202,7 @@ def xo_server_reconnect(self):

@staticmethod
def vm_cache_key(uri):
return f"[Cache for {uri}]"
return f"[Cache for {strip_suffix(uri, '.xva')}]"

def cached_vm(self, uri, sr_uuid):
assert sr_uuid, "A SR UUID is necessary to use import cache"
Expand Down

0 comments on commit 4db061d

Please sign in to comment.