import ipaddress import logging from builtins import hasattr from rest_framework import serializers from oca import OpenNebulaException from .exceptions import TemplateNotFoundError from .models import OpenNebulaManager logger = logging.getLogger(__name__) TEMPLATE_NAME_PREFIXES = ('public-', 'ipv6only-') def strip_template_prefix(name): """ Remove the DCL naming prefix ('public-', 'ipv6only-') from a template or VM name. str.lstrip() must not be used here: it strips a character set, so 'public-ubuntu'.lstrip('public-') gives 'ntu'. """ for prefix in TEMPLATE_NAME_PREFIXES: if name.startswith(prefix): return name[len(prefix):] return name def template_name_from_vm_name(vm_name): """ VMs are named '