Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm cache: shorten vm description by stripping .xva suffix #251

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading