Raise error if instances are created with names > 63 chars
The maximum hostname on Linux is 64 characters. DHCP is limited to this host maximum. Unfortunately Nova allows the creation of servers with names > 63 characters in length. This patch is a short-term solution to improve the failure condition, so we draw attention to the problem, enabling the user to work around with shorter names. A subsequent patch will be required which mangles names such that we truncate or compact names automatically. Closes-Bug: 1238272 Change-Id: I2114135b7f4b649a906c3adaea1869d1a1290a3b
This commit is contained in:
@@ -335,6 +335,19 @@ class Instance(resource.Resource):
|
||||
security_groups=security_groups,
|
||||
subnet_id=self.properties['SubnetId'])
|
||||
server = None
|
||||
|
||||
# TODO(sdake/shardy) ensure physical_resource_name() never returns a
|
||||
# string longer than 63 characters, as this is pretty inconvenient
|
||||
# behavior for autoscaling groups and nested stacks where instance
|
||||
# names can easily become quite long even with terse names.
|
||||
physical_resource_name_len = len(self.physical_resource_name())
|
||||
if physical_resource_name_len > 63:
|
||||
raise exception.Error(_('Server %(server)s length %(length)d > 63'
|
||||
' characters, please reduce the length of'
|
||||
' stack or resource names') %
|
||||
dict(server=self.physical_resource_name(),
|
||||
length=physical_resource_name_len))
|
||||
|
||||
try:
|
||||
server = self.nova().servers.create(
|
||||
name=self.physical_resource_name(),
|
||||
|
||||
@@ -206,6 +206,18 @@ class Server(resource.Resource):
|
||||
config_drive = self.properties.get('config_drive')
|
||||
disk_config = self.properties.get('diskConfig')
|
||||
|
||||
# TODO(sdake/shardy) ensure physical_resource_name() never returns a
|
||||
# string longer than 63 characters, as this is pretty inconvenient
|
||||
# behavior for autoscaling groups and nested stacks where instance
|
||||
# names can easily become quite long even with terse names.
|
||||
physical_resource_name_len = len(self.physical_resource_name())
|
||||
if physical_resource_name_len > 63:
|
||||
raise exception.Error(_('Server %(server)s length %(length)d > 63'
|
||||
' characters, please reduce the length of'
|
||||
' stack or resource names') %
|
||||
dict(server=self.physical_resource_name(),
|
||||
length=physical_resource_name_len))
|
||||
|
||||
server = None
|
||||
try:
|
||||
server = self.nova().servers.create(
|
||||
|
||||
Reference in New Issue
Block a user