Skip to content

Commit

Permalink
machine plenary templates: allow to use the rack fullname
Browse files Browse the repository at this point in the history
- If config option machine_ns_rack_fullname is true (default is false
to maintain backward compatibility, use the rack fullname instead of
the rack name to build the machine namespace in the plenary templates.
- When the option is true, also export the rack fullname instead of
the rack name in /hardware/rack/name.

Fixes quattor#105 (GitHub issue quattor#105)

Change-Id: I99dd2d0af0091dca588e576d45b18bd833100fbc
  • Loading branch information
jouvin authored and Aquilon main user committed Jul 9, 2018
1 parent 0d46646 commit f991825
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions etc/aqd.conf.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ gzip_output = false
transparent_gzip = true
template_extension = .tpl
object_declarations_template = false
# Use rack name in machine namespace
machine_ns_rack_fullname = False

[tool_timeout]
# If set to True, timeout will be set to 'default_value' for any tools run via subprocess
Expand Down
3 changes: 3 additions & 0 deletions etc/aqd.conf.noms
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ template_extension = .pan
# Include a preface template in the object template if true
object_declarations_template = true

# Use rack fullname in machine namespace
machine_ns_rack_fullname = True


###############################################################################

Expand Down
8 changes: 6 additions & 2 deletions lib/aquilon/worker/templates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def transaction(self, verbose=False):
raise


def add_location_info(lines, dblocation, prefix=""):
def add_location_info(lines, dblocation, prefix="", use_rack_fullname=False):
# FIXME: sort out hub/region
for parent_type in ["continent", "country", "city", "campus", "building",
"bunker"]:
Expand All @@ -637,7 +637,11 @@ def add_location_info(lines, dblocation, prefix=""):
pan_assign(lines, prefix + "sysloc/" + parent_type, dbparent.name)

if dblocation.rack:
pan_assign(lines, prefix + "rack/name", dblocation.rack.name)
# If use_rack_fullname is True, use the rack_fullname instead of the generated rack name
if use_rack_fullname:
pan_assign(lines, prefix + "rack/name", dblocation.rack.fullname.lower())
else:
pan_assign(lines, prefix + "rack/name", dblocation.rack.name)
if dblocation.rack_row:
pan_assign(lines, prefix + "rack/row", dblocation.rack_row)
if dblocation.rack_column:
Expand Down
20 changes: 18 additions & 2 deletions lib/aquilon/worker/templates/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,28 @@

class PlenaryMachineInfo(StructurePlenary):
prefix = "machine"
rack_name_is_fullname = Plenary.config.getboolean("panc", "machine_ns_rack_fullname")

@classmethod
def use_rack_fullname(cls):
"""
Set class variable rack_name_is_fullname, used to determine what is used as the rack name
when building templante names and namespaces, to True.
"""
cls.rack_name_is_fullname = True

@classmethod
def get_rack_name(cls, dbmachine):
if cls.rack_name_is_fullname:
return dbmachine.location.rack.fullname.lower()
else:
return dbmachine.location.rack.name

@classmethod
def template_name(cls, dbmachine):
loc = dbmachine.location
return "%s/%s/%s/%s/%s" % (cls.prefix, loc.hub.fullname.lower(),
loc.building, loc.rack, dbmachine.label)
loc.building, cls.get_rack_name(dbmachine), dbmachine.label)

def __init__(self, dbobj, **kwargs):
super(PlenaryMachineInfo, self).__init__(dbobj, **kwargs)
Expand Down Expand Up @@ -158,7 +174,7 @@ def body(self, lines):
interfaces[interface.name] = StructureTemplate(path, ifinfo)

# Firstly, location
add_location_info(lines, self.dbobj.location)
add_location_info(lines, self.dbobj.location, use_rack_fullname=PlenaryMachineInfo.rack_name_is_fullname)
pan_assign(lines, "location", self.dbobj.location.sysloc())

# And a chassis location?
Expand Down

0 comments on commit f991825

Please sign in to comment.