* Added, as fallback "hostnamectl set-hostname" for actor renamers for linux

* Upgraded OpenNebula service to better check hostname
* added versatile hostname validator for hostnames
* Fixed sample settings.py
This commit is contained in:
Adolfo Gómez García 2020-02-19 15:30:35 +01:00
parent 34d47bdda9
commit 2b912b035d
6 changed files with 30 additions and 7 deletions

View File

@ -45,7 +45,8 @@ def rename(newName: str) -> bool:
hostname.write(newName) hostname.write(newName)
# Force system new name # Force system new name
os.system('/bin/hostname %s' % newName) os.system('/bin/hostname {}'.format(newName))
os.system('/usr/bin/hostnamectl set-hostname {}'.format(newName))
# add name to "hosts" # add name to "hosts"
with open('/etc/hosts', 'r') as hosts: with open('/etc/hosts', 'r') as hosts:

View File

@ -46,7 +46,8 @@ def rename(newName: str) -> bool:
hostname.write(newName) hostname.write(newName)
# Force system new name # Force system new name
os.system('/bin/hostname %s' % newName) os.system('/bin/hostname {}'.format(newName))
os.system('/usr/bin/hostnamectl set-hostname {}'.format(newName))
# add name to "hosts" # add name to "hosts"
with open('/etc/hosts', 'r') as hosts: with open('/etc/hosts', 'r') as hosts:

View File

@ -46,7 +46,8 @@ def rename(newName: str) -> bool:
hostname.write(newName) hostname.write(newName)
# Force system new name # Force system new name
os.system('/bin/hostname %s' % newName) os.system('/bin/hostname {}'.format(newName))
os.system('/usr/bin/hostnamectl set-hostname {}'.format(newName))
# add name to "hosts" # add name to "hosts"
with open('/etc/hosts', 'r') as hosts: with open('/etc/hosts', 'r') as hosts:

View File

@ -19,9 +19,10 @@ DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'OPTIONS': { 'OPTIONS': {
'init_command': 'SET default_storage_engine=INNODB; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;', # 'init_command': 'SET default_storage_engine=INNODB; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;',
# 'init_command': 'SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', # 'init_command': 'SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
# 'init_command': 'SET storage_engine=MYISAM, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', # 'init_command': 'SET storage_engine=MYISAM, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
'isolation_level': 'read committed',
}, },
'NAME': 'dbuds', # Or path to database file if using sqlite3. 'NAME': 'dbuds', # Or path to database file if using sqlite3.
'USER': 'dbuds', # Not used with sqlite3. 'USER': 'dbuds', # Not used with sqlite3.

View File

@ -76,6 +76,23 @@ def validateNumeric(
return numericStr return numericStr
def validateHostname(hostname: str, maxLength: int, asPattern: bool) -> str:
if len(hostname) > maxLength:
raise Module.ValidationException(_('{} exceeds maximum host name length.').format(hostname))
if hostname[-1] == ".":
hostname = hostname[:-1] # strip exactly one dot from the right, if present
if asPattern:
allowed = re.compile("(?!-)[A-Z\d-]{1,63}$", re.IGNORECASE)
else:
allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
if not all(allowed.match(x) for x in hostname.split(".")):
raise Module.ValidationException(_('{} is not a valid hostname').format(hostname))
return hostname
def validatePort(portStr: str) -> int: def validatePort(portStr: str) -> int:
""" """

View File

@ -36,7 +36,7 @@ import typing
from django.utils.translation import ugettext_noop as _ from django.utils.translation import ugettext_noop as _
from uds.core.transports import protocols from uds.core.transports import protocols
from uds.core.services import Service, types as serviceTypes from uds.core.services import Service, types as serviceTypes
from uds.core.util import tools from uds.core.util import validators
from uds.core.ui import gui from uds.core.ui import gui
from .publication import LivePublication from .publication import LivePublication
@ -140,8 +140,10 @@ class LiveService(Service):
Note that we check them throught FROM variables, that already has been Note that we check them throught FROM variables, that already has been
initialized by __init__ method of base class, before invoking this. initialized by __init__ method of base class, before invoking this.
""" """
if values: if not values:
tools.checkValidBasename(self.baseName.value, self.lenName.num()) return
self.baseName.value = validators.validateHostname(self.baseName.value, maxLength=15-self.lenName.num(), asPattern=True)
def parent(self) -> 'OpenNebulaProvider': def parent(self) -> 'OpenNebulaProvider':
return typing.cast('OpenNebulaProvider', super().parent()) return typing.cast('OpenNebulaProvider', super().parent())