Exemple #1
0
 def body_resourcegroup(self, lines):
     if self.dbobj.resholder:
         for resource in sorted(self.dbobj.resholder.resources,
                                key=attrgetter("resource_type", "name")):
             res_path = self.template_name(resource)
             pan_append(lines, "resources/" + resource.resource_type,
                        StructureTemplate(res_path))
Exemple #2
0
    def body(self, lines):
        pan_assign(lines, "system/metacluster/name", self.dbobj.name)
        pan_assign(lines, "system/metacluster/type", self.dbobj.cluster_type)

        dbloc = self.dbobj.location_constraint
        add_location_info(lines, dbloc, prefix="system/metacluster/")
        pan_assign(lines, "system/metacluster/sysloc/location", dbloc.sysloc())
        if dbloc.campus:
            ## maintaining this so templates dont break
            ## during transtion period.. should be DEPRECATED
            pan_assign(lines, "system/metacluster/campus", dbloc.campus.name)

        lines.append("")

        pan_assign(lines, "system/metacluster/members",
                   sorted([member.name for member in self.dbobj.members]))

        lines.append("")

        pan_assign(lines, "system/build", self.dbobj.status.name)

        lines.append("")
        if self.dbobj.resholder:
            for resource in sorted(self.dbobj.resholder.resources,
                                   key=attrgetter('resource_type', 'name')):
                res_path = PlenaryResource.template_name(resource)
                pan_append(lines, "system/resources/" + resource.resource_type,
                           StructureTemplate(res_path))
Exemple #3
0
 def body_resourcegroup(self, lines):
     pan_assign(lines, "name", self.dbobj.name)
     if self.dbobj.resholder:
         for resource in self.dbobj.resholder.resources:
             pan_append(
                 lines, "resources/" + resource.resource_type, StructureTemplate(resource.template_base + "/config")
             )
Exemple #4
0
 def body_resourcegroup(self, lines):
     pan_assign(lines, "name", self.dbobj.name)
     if self.dbobj.resholder:
         for resource in self.dbobj.resholder.resources:
             pan_append(
                 lines, "resources/" + resource.resource_type,
                 StructureTemplate(resource.template_base + "/config"))
Exemple #5
0
    def body(self, lines):
        pan_variable(lines, "PERSONALITY", self.dbobj.name)

        ## process grns
        eon_id_map = defaultdict(set)

        # own == pers level
        for grn_rec in self.dbobj._grns:
            eon_id_map[grn_rec.target].add(grn_rec.grn.eon_id)

        for (target, eon_id_set) in eon_id_map.iteritems():
            eon_id_list = list(eon_id_set)
            eon_id_list.sort()
            for eon_id in eon_id_list:
                pan_append(lines, "/system/eon_id_maps/%s" % target, eon_id)

        archetype = self.dbobj.archetype.name
        # backward compat for esp reporting
        if self.config.has_option("archetype_" + archetype,
                                  "default_grn_target"):
            default_grn_target = self.config.get("archetype_" + archetype,
                                                 "default_grn_target")

            eon_id_set = eon_id_map[default_grn_target]

            eon_id_list = list(eon_id_set)
            eon_id_list.sort()
            for eon_id in eon_id_list:
                pan_append(lines, "/system/eon_ids", eon_id)

        pan_assign(lines, "/system/personality/owner_eon_id",
                   self.dbobj.owner_eon_id)

        ## include pre features
        path = PlenaryPersonalityPreFeature.template_name(self.dbobj)
        pan_include_if_exists(lines, path)

        ## process parameter templates
        pan_include_if_exists(lines, "personality/config")
        pan_assign(lines, "/system/personality/name", self.dbobj.name)
        if self.dbobj.host_environment.name != 'legacy':
            pan_assign(lines, "/system/personality/host_environment",
                       self.dbobj.host_environment, True)

        ## TODO : This is just to satisfy quattor schema
        ## needs to be removed as soon as the schema allows this
        pan_assign(lines, "/system/personality/systemgrn", [])

        if self.dbobj.config_override:
            pan_include(lines, "features/personality/config_override/config")

        ## include post features
        path = PlenaryPersonalityPostFeature.template_name(self.dbobj)
        pan_include_if_exists(lines, path)
Exemple #6
0
    def body(self, lines):
        pan_assign(lines, "system/cluster/name", self.dbobj.name)
        pan_assign(lines, "system/cluster/type", self.dbobj.cluster_type)

        dbloc = self.dbobj.location_constraint
        add_location_info(lines, dbloc, prefix="system/cluster/")
        pan_assign(lines, "system/cluster/sysloc/location", dbloc.sysloc())
        if dbloc.campus:
            ## maintaining this so templates dont break
            ## during transtion period.. should be DEPRECATED
            pan_assign(lines, "system/cluster/campus", dbloc.campus.name)

        pan_assign(lines, "system/cluster/down_hosts_threshold",
                   self.dbobj.dht_value)
        if self.dbobj.dmt_value is not None:
            pan_assign(lines, "system/cluster/down_maint_threshold",
                       self.dbobj.dmt_value)
        if self.dbobj.down_hosts_percent:
            pan_assign(lines, "system/cluster/down_hosts_percent",
                       self.dbobj.down_hosts_threshold)
            pan_assign(lines, "system/cluster/down_hosts_as_percent",
                       self.dbobj.down_hosts_percent)
        if self.dbobj.down_maint_percent:
            pan_assign(lines, "system/cluster/down_maint_percent",
                       self.dbobj.down_maint_threshold)
            pan_assign(lines, "system/cluster/down_maint_as_percent",
                       self.dbobj.down_maint_percent)
        lines.append("")
        # Only use system names here to avoid circular dependencies.
        # Other templates that needs to look up the underlying values use:
        # foreach(idx; host; value("system/cluster/members")) {
        #     v = value("/" + host + "/system/foo/bar/baz");
        # );
        pan_assign(lines, "system/cluster/members",
                   sorted([member.fqdn for member in self.dbobj.hosts]))

        lines.append("")
        if self.dbobj.resholder:
            for resource in sorted(self.dbobj.resholder.resources,
                                   key=attrgetter('resource_type', 'name')):
                res_path = PlenaryResource.template_name(resource)
                pan_append(lines, "system/resources/" + resource.resource_type,
                           StructureTemplate(res_path))
        pan_assign(lines, "system/build", self.dbobj.status.name)
        if self.dbobj.allowed_personalities:
            pan_assign(lines, "system/cluster/allowed_personalities",
                       sorted(["%s/%s" % (p.archetype.name, p.name)
                               for p in self.dbobj.allowed_personalities]))

        fname = "body_%s" % self.dbobj.cluster_type
        if hasattr(self, fname):
            getattr(self, fname)(lines)
Exemple #7
0
 def body(self, lines):
     pan_assign(lines, "/system/cluster/name", self.name)
     # We could just use a PAN external reference to pull in this value from
     # the cluster template, but since we know that these templates are
     # always in sync, we can duplicate the content here to avoid the
     # possibility of circular external references.
     if self.dbobj.resholder:
         for resource in sorted(self.dbobj.resholder.resources):
             pan_append(lines, "/system/cluster/resources/" +
                        resource.resource_type,
                        StructureTemplate(resource.template_base + '/config'))
     lines.append("include { if_exists('features/' + value('/system/archetype/name') + '/%s/%s/config') };"
                  % (self.dbobj.personality.archetype.name,
                     self.dbobj.personality.name))
Exemple #8
0
    def body(self, lines):
        pan_variable(lines, "PERSONALITY", self.name)

        ## process grns
        eon_id_map = defaultdict(set)

        # own == pers level
        for grn_rec in self.dbobj._grns:
            eon_id_map[grn_rec.target].add(grn_rec.grn.eon_id)

        for (target, eon_id_set) in eon_id_map.iteritems():
            eon_id_list = list(eon_id_set)
            eon_id_list.sort()
            for eon_id in eon_id_list:
                pan_append(lines, "/system/eon_id_maps/%s" % target, eon_id)

        archetype = self.dbobj.archetype.name
        # backward compat for esp reporting
        if self.config.has_option("archetype_" + archetype,
                                  "default_grn_target"):
            default_grn_target = self.config.get("archetype_" + archetype,
                                                 "default_grn_target")

            eon_id_set = eon_id_map[default_grn_target]

            eon_id_list = list(eon_id_set)
            eon_id_list.sort()
            for eon_id in eon_id_list:
                pan_append(lines, "/system/eon_ids", eon_id)

        pan_assign(lines, "/system/personality/owner_eon_id",
                   self.dbobj.owner_eon_id)

        ## include pre features
        pan_include_if_exists(lines, "%s/pre_feature" % self.plenary_core)
        ## process parameter templates
        pan_include_if_exists(lines, "personality/config")
        pan_assign(lines, "/system/personality/name", self.name)
        pan_assign(lines, "/system/personality/host_environment",
                   self.dbobj.host_environment)

        ## TODO : This is just to satisfy quattor schema
        ## needs to be removed as soon as the schema allows this
        pan_assign(lines, "/system/personality/systemgrn", [])

        if self.dbobj.config_override:
            pan_include(lines, "features/personality/config_override/config")

        ## include post features
        pan_include_if_exists(lines, "%s/post_feature" % self.plenary_core)
Exemple #9
0
    def body(self, lines):
        pan_assign(lines, "system/metacluster/name", self.name)
        pan_assign(lines, "system/metacluster/type", self.dbobj.cluster_type)

        dbloc = self.dbobj.location_constraint
        pan_assign(lines, "system/metacluster/sysloc/location", dbloc.sysloc())
        if dbloc.continent:
            pan_assign(lines, "system/metacluster/sysloc/continent",
                       dbloc.continent.name)
        if dbloc.city:
            pan_assign(lines, "system/metacluster/sysloc/city",
                       dbloc.city.name)
        if dbloc.campus:
            pan_assign(lines, "system/metacluster/sysloc/campus",
                       dbloc.campus.name)
            ## maintaining this so templates dont break
            ## during transtion period.. should be DEPRECATED
            pan_assign(lines, "system/metacluster/campus", dbloc.campus.name)
        if dbloc.building:
            pan_assign(lines, "system/metacluster/sysloc/building",
                       dbloc.building.name)
        if dbloc.room:
            pan_assign(lines, "system/cluster/rack/room", dbloc.room)
        if dbloc.bunker:
            pan_assign(lines, "system/cluster/sysloc/bunker",
                       dbloc.bunker.name)
        if dbloc.rack:
            pan_assign(lines, "system/metacluster/rack/row",
                       dbloc.rack.rack_row)
            pan_assign(lines, "system/metacluster/rack/column",
                       dbloc.rack.rack_column)
            pan_assign(lines, "system/metacluster/rack/name", dbloc.rack.name)

        lines.append("")

        pan_assign(lines, "system/metacluster/members",
                   [member.name for member in self.dbobj.members])

        lines.append("")

        pan_assign(lines, "system/build", self.dbobj.status.name)

        lines.append("")
        if self.dbobj.resholder:
            for resource in sorted(self.dbobj.resholder.resources):
                pan_append(
                    lines, "system/resources/" + resource.resource_type,
                    StructureTemplate(resource.template_base + '/config'))
Exemple #10
0
 def body(self, lines):
     pan_assign(lines, "/system/cluster/name", self.name)
     # We could just use a PAN external reference to pull in this value from
     # the cluster template, but since we know that these templates are
     # always in sync, we can duplicate the content here to avoid the
     # possibility of circular external references.
     if self.dbobj.resholder:
         for resource in sorted(self.dbobj.resholder.resources):
             pan_append(
                 lines,
                 "/system/cluster/resources/" + resource.resource_type,
                 StructureTemplate(resource.template_base + '/config'))
     lines.append(
         "include { if_exists('features/' + value('/system/archetype/name') + '/%s/%s/config') };"
         % (self.dbobj.personality.archetype.name,
            self.dbobj.personality.name))
Exemple #11
0
    def body(self, lines):
        pan_assign(lines, "system/metacluster/name", self.name)
        pan_assign(lines, "system/metacluster/type", self.dbobj.cluster_type)

        dbloc = self.dbobj.location_constraint
        pan_assign(lines, "system/metacluster/sysloc/location", dbloc.sysloc())
        if dbloc.continent:
            pan_assign(lines, "system/metacluster/sysloc/continent",
                       dbloc.continent.name)
        if dbloc.city:
            pan_assign(lines, "system/metacluster/sysloc/city", dbloc.city.name)
        if dbloc.campus:
            pan_assign(lines, "system/metacluster/sysloc/campus",
                       dbloc.campus.name)
            ## maintaining this so templates dont break
            ## during transtion period.. should be DEPRECATED
            pan_assign(lines, "system/metacluster/campus", dbloc.campus.name)
        if dbloc.building:
            pan_assign(lines, "system/metacluster/sysloc/building",
                       dbloc.building.name)
        if dbloc.room:
            pan_assign(lines, "system/cluster/rack/room", dbloc.room)
        if dbloc.bunker:
            pan_assign(lines, "system/cluster/sysloc/bunker", dbloc.bunker.name)
        if dbloc.rack:
            pan_assign(lines, "system/metacluster/rack/row",
                       dbloc.rack.rack_row)
            pan_assign(lines, "system/metacluster/rack/column",
                       dbloc.rack.rack_column)
            pan_assign(lines, "system/metacluster/rack/name",
                       dbloc.rack.name)

        lines.append("")

        pan_assign(lines, "system/metacluster/members",
                   [member.name for member in self.dbobj.members])

        lines.append("")

        pan_assign(lines, "system/build", self.dbobj.status.name)

        lines.append("")
        if self.dbobj.resholder:
            for resource in sorted(self.dbobj.resholder.resources):
                pan_append(lines, "system/resources/" + resource.resource_type,
                           StructureTemplate(resource.template_base +
                                             '/config'))
Exemple #12
0
    def body(self, lines):
        pan_assign(lines, "system/cluster/name", self.name)
        pan_assign(lines, "system/cluster/type", self.dbobj.cluster_type)

        dbloc = self.dbobj.location_constraint
        pan_assign(lines, "system/cluster/sysloc/location", dbloc.sysloc())
        if dbloc.continent:
            pan_assign(lines, "system/cluster/sysloc/continent",
                       dbloc.continent.name)
        if dbloc.city:
            pan_assign(lines, "system/cluster/sysloc/city", dbloc.city.name)
        if dbloc.campus:
            pan_assign(lines, "system/cluster/sysloc/campus",
                       dbloc.campus.name)
            ## maintaining this so templates dont break
            ## during transtion period.. should be DEPRECATED
            pan_assign(lines, "system/cluster/campus", dbloc.campus.name)
        if dbloc.building:
            pan_assign(lines, "system/cluster/sysloc/building",
                       dbloc.building.name)
        if dbloc.bunker:
            pan_assign(lines, "system/cluster/sysloc/bunker", dbloc.bunker.name)
        if dbloc.rack:
            pan_assign(lines, "system/cluster/rack/row", dbloc.rack.rack_row)
            pan_assign(lines, "system/cluster/rack/column",
                       dbloc.rack.rack_column)
            pan_assign(lines, "system/cluster/rack/name", dbloc.rack.name)
        if dbloc.room:
            pan_assign(lines, "system/cluster/rack/room", dbloc.room)

        pan_assign(lines, "system/cluster/down_hosts_threshold",
                   self.dbobj.dht_value)
        if self.dbobj.dmt_value is not None:
            pan_assign(lines, "system/cluster/down_maint_threshold",
                       self.dbobj.dmt_value)
        if self.dbobj.down_hosts_percent:
            pan_assign(lines, "system/cluster/down_hosts_percent",
                         self.dbobj.down_hosts_threshold)
            pan_assign(lines, "system/cluster/down_hosts_as_percent",
                       self.dbobj.down_hosts_percent)
        if self.dbobj.down_maint_percent:
            pan_assign(lines, "system/cluster/down_maint_percent",
                       self.dbobj.down_maint_threshold)
            pan_assign(lines, "system/cluster/down_maint_as_percent",
                       self.dbobj.down_maint_percent)
        lines.append("")
        # Only use system names here to avoid circular dependencies.
        # Other templates that needs to look up the underlying values use:
        # foreach(idx; host; value("system/cluster/members")) {
        #     v = value("/" + host + "/system/foo/bar/baz");
        # );
        pan_assign(lines, "system/cluster/members",
                   sorted([member.fqdn for member in self.dbobj.hosts]))

        lines.append("")
        if self.dbobj.resholder:
            for resource in sorted(self.dbobj.resholder.resources):
                pan_append(lines, "system/resources/" + resource.resource_type,
                           StructureTemplate(resource.template_base +
                                             '/config'))
        pan_assign(lines, "system/build", self.dbobj.status.name)
        if self.dbobj.allowed_personalities:
            pan_assign(lines, "system/cluster/allowed_personalities",
                       sorted(["%s/%s" % (p.archetype.name, p.name)
                               for p in self.dbobj.allowed_personalities]))

        fname = "body_%s" % self.dbobj.cluster_type
        if hasattr(self, fname):
            getattr(self, fname)(lines)
Exemple #13
0
    def body(self, lines):
        interfaces = dict()
        routers = {}
        default_gateway = None

        pers = self.dbobj.personality

        # FIXME: Enforce that one of the interfaces is marked boot?
        for dbinterface in self.dbobj.machine.interfaces:
            # Management interfaces are not configured at the host level
            if dbinterface.interface_type == 'management':
                continue

            ifdesc = {}

            if dbinterface.master:
                ifdesc["bootproto"] = "none"
                if isinstance(dbinterface.master, BondingInterface):
                    ifdesc["master"] = dbinterface.master.name
                elif isinstance(dbinterface.master, BridgeInterface):
                    ifdesc["bridge"] = dbinterface.master.name
                else:
                    raise InternalError("Unexpected master interface type: "
                                        "{0}".format(dbinterface.master))
            else:
                if dbinterface.assignments:
                    # TODO: Let the templates select from "static"/"dhcp"
                    ifdesc["bootproto"] = "static"
                else:
                    # Don't try to bring up the interface if there are no
                    # addresses assigned to it
                    ifdesc["bootproto"] = "none"

            if isinstance(dbinterface, VlanInterface):
                ifdesc["vlan"] = True
                ifdesc["physdev"] = dbinterface.parent.name

            static_routes = set()

            for addr in dbinterface.assignments:
                # Service addresses will be handled as resources
                if addr.service_address:
                    continue

                net = addr.network

                if addr.label == "":
                    if net.routers:
                        local_rtrs = select_routers(self.dbobj.machine,
                                                    net.routers)
                        gateway = local_rtrs[0]
                        if is_default_route(dbinterface):
                            routers[dbinterface.name] = local_rtrs
                    else:
                        # No routers defided, fall back to the default
                        gateway = net.network[net.default_gateway_offset]

                    # TODO: generate appropriate routing policy if there are
                    # multiple interfaces marked as default_route
                    if not default_gateway and is_default_route(dbinterface):
                        default_gateway = gateway

                    ifdesc["ip"] = addr.ip
                    ifdesc["netmask"] = net.netmask
                    ifdesc["broadcast"] = net.broadcast
                    ifdesc["gateway"] = gateway
                    ifdesc["network_type"] = net.network_type
                    ifdesc[
                        "network_environment"] = net.network_environment.name
                    if addr.dns_records:
                        ifdesc["fqdn"] = addr.dns_records[0]
                else:
                    aliasdesc = {
                        "ip": addr.ip,
                        "netmask": net.netmask,
                        "broadcast": net.broadcast
                    }
                    if addr.dns_records:
                        aliasdesc["fqdn"] = addr.dns_records[0]
                    if "aliases" in ifdesc:
                        ifdesc["aliases"][addr.label] = aliasdesc
                    else:
                        ifdesc["aliases"] = {addr.label: aliasdesc}

                static_routes |= set(net.static_routes)

            if static_routes:
                if "route" not in ifdesc:
                    ifdesc["route"] = []
                # Enforce a stable order to make it easier to verify changes in
                # the plenaries
                for route in sorted(list(static_routes),
                                    key=attrgetter('destination',
                                                   'gateway_ip')):
                    ifdesc["route"].append({
                        "address": route.destination.ip,
                        "netmask": route.destination.netmask,
                        "gateway": route.gateway_ip
                    })
                if not ifdesc["route"]:
                    del ifdesc["route"]

            interfaces[dbinterface.name] = ifdesc

        # Okay, here's the real content
        pmachine = Plenary.get_plenary(self.dbobj.machine, logger=self.logger)
        pan_assign(lines, "hardware",
                   StructureTemplate(pmachine.plenary_template_name))

        lines.append("")
        pan_assign(lines, "system/network/interfaces", interfaces)
        pan_assign(lines, "system/network/primary_ip",
                   self.dbobj.machine.primary_ip)
        if default_gateway:
            pan_assign(lines, "system/network/default_gateway",
                       default_gateway)
        if routers:
            pan_assign(lines, "system/network/routers", routers)
        lines.append("")

        pan_assign(lines, "system/build", self.dbobj.status.name)
        pan_assign(lines, "system/advertise_status",
                   self.dbobj.advertise_status)

        ## process grns
        eon_id_map = defaultdict(set)

        # own
        for grn_rec in self.dbobj._grns:
            eon_id_map[grn_rec.target].add(grn_rec.grn.eon_id)

        # pers level
        for grn_rec in pers._grns:
            eon_id_map[grn_rec.target].add(grn_rec.grn.eon_id)

        for (target, eon_id_set) in eon_id_map.iteritems():
            eon_id_list = list(eon_id_set)
            eon_id_list.sort()
            pan_assign(lines, "system/eon_id_maps/%s" % target, eon_id_list)

        # backward compat for esp reporting
        archetype = self.dbobj.archetype.name
        if self.config.has_option("archetype_" + archetype,
                                  "default_grn_target"):
            default_grn_target = self.config.get("archetype_" + archetype,
                                                 "default_grn_target")

            eon_id_set = eon_id_map[default_grn_target]

            eon_id_list = list(eon_id_set)
            eon_id_list.sort()
            if eon_id_list:
                pan_assign(lines, "system/eon_ids", eon_id_list)

        pan_assign(lines, "system/owner_eon_id", self.dbobj.owner_eon_id)

        if self.dbobj.cluster:
            pan_assign(lines, "system/cluster/name", self.dbobj.cluster.name)
            pan_assign(lines, "system/cluster/node_index",
                       self.dbobj._cluster.node_index)
        if self.dbobj.resholder:
            lines.append("")
            for resource in sorted(self.dbobj.resholder.resources):
                pan_append(
                    lines, "system/resources/" + resource.resource_type,
                    StructureTemplate(resource.template_base + '/config'))
Exemple #14
0
    def body(self, lines):
        interfaces = dict()
        routers = {}
        default_gateway = None

        # FIXME: Enforce that one of the interfaces is marked boot?
        for dbinterface in self.dbobj.hardware_entity.interfaces:
            # Management interfaces are not configured at the host level
            if dbinterface.interface_type == 'management':
                continue

            ifdesc = {}

            if dbinterface.master:
                ifdesc["bootproto"] = "none"
                if isinstance(dbinterface.master, BondingInterface):
                    ifdesc["master"] = dbinterface.master.name
                elif isinstance(dbinterface.master, BridgeInterface):
                    ifdesc["bridge"] = dbinterface.master.name
                else:
                    raise InternalError("Unexpected master interface type: "
                                        "{0}".format(dbinterface.master))
            else:
                if dbinterface.assignments:
                    # TODO: Let the templates select from "static"/"dhcp"
                    ifdesc["bootproto"] = "static"
                else:
                    # Don't try to bring up the interface if there are no
                    # addresses assigned to it
                    ifdesc["bootproto"] = "none"

            if isinstance(dbinterface, VlanInterface):
                ifdesc["vlan"] = True
                ifdesc["physdev"] = dbinterface.parent.name

            static_routes = set()

            for addr in dbinterface.assignments:
                # Service addresses will be handled as resources
                if addr.service_address:
                    continue

                net = addr.network

                if addr.label == "":
                    if net.routers:
                        local_rtrs = select_routers(self.dbobj.hardware_entity,
                                                    net.routers)
                        gateway = local_rtrs[0]
                        if is_default_route(dbinterface):
                            routers[dbinterface.name] = local_rtrs
                    else:
                        # No routers defided, fall back to the default
                        gateway = net.network[net.default_gateway_offset]

                    # TODO: generate appropriate routing policy if there are
                    # multiple interfaces marked as default_route
                    if not default_gateway and is_default_route(dbinterface):
                        default_gateway = gateway

                    ifdesc["ip"] = addr.ip
                    ifdesc["netmask"] = net.netmask
                    ifdesc["broadcast"] = net.broadcast
                    ifdesc["gateway"] = gateway
                    ifdesc["network_type"] = net.network_type
                    ifdesc["network_environment"] = net.network_environment.name
                    if addr.dns_records:
                        ifdesc["fqdn"] = addr.dns_records[0]
                else:
                    aliasdesc = {"ip": addr.ip,
                                 "netmask": net.netmask,
                                 "broadcast": net.broadcast}
                    if addr.dns_records:
                        aliasdesc["fqdn"] = addr.dns_records[0]
                    if "aliases" in ifdesc:
                        ifdesc["aliases"][addr.label] = aliasdesc
                    else:
                        ifdesc["aliases"] = {addr.label: aliasdesc}

                static_routes |= set(net.personality_static_routes(self.dbobj.personality))

            if static_routes:
                if "route" not in ifdesc:
                    ifdesc["route"] = []
                # Enforce a stable order to make it easier to verify changes in
                # the plenaries
                for route in sorted(list(static_routes),
                                    key=attrgetter('destination', 'gateway_ip')):
                    ifdesc["route"].append({"address": route.destination.ip,
                                            "netmask": route.destination.netmask,
                                            "gateway": route.gateway_ip})
                if not ifdesc["route"]:
                    del ifdesc["route"]

            interfaces[dbinterface.name] = ifdesc

        # Okay, here's the real content
        path = PlenaryMachineInfo.template_name(self.dbobj.hardware_entity)
        pan_assign(lines, "hardware", StructureTemplate(path))

        lines.append("")
        pan_assign(lines, "system/network/interfaces", interfaces)
        pan_assign(lines, "system/network/primary_ip",
                   self.dbobj.hardware_entity.primary_ip)
        if default_gateway:
            pan_assign(lines, "system/network/default_gateway",
                       default_gateway)
        if routers:
            pan_assign(lines, "system/network/routers", routers)
        lines.append("")

        pan_assign(lines, "system/build", self.dbobj.status.name)
        pan_assign(lines, "system/advertise_status", self.dbobj.advertise_status)

        ## process grns
        eon_id_map = self.dbobj.effective_grns

        for (target, eon_id_set) in eon_id_map.iteritems():
            eon_id_list = [grn.eon_id for grn in eon_id_set]
            eon_id_list.sort()
            pan_assign(lines, "system/eon_id_maps/%s" % target, eon_id_list)

        # backward compat for esp reporting
        archetype = self.dbobj.archetype.name
        if self.config.has_option("archetype_" + archetype,
                                  "default_grn_target"):
            default_grn_target = self.config.get("archetype_" + archetype,
                                                 "default_grn_target")

            eon_id_set = eon_id_map[default_grn_target]

            eon_id_list = [grn.eon_id for grn in eon_id_set]
            eon_id_list.sort()
            if eon_id_list:
                pan_assign(lines, "system/eon_ids", eon_id_list)

        pan_assign(lines, "system/owner_eon_id", self.dbobj.effective_owner_grn.eon_id)

        if self.dbobj.cluster:
            pan_assign(lines, "system/cluster/name", self.dbobj.cluster.name)
            pan_assign(lines, "system/cluster/node_index",
                       self.dbobj._cluster.node_index)
        if self.dbobj.resholder:
            lines.append("")
            for resource in sorted(self.dbobj.resholder.resources,
                                   key=attrgetter('resource_type', 'name')):
                res_path = PlenaryResource.template_name(resource)
                pan_append(lines, "system/resources/" + resource.resource_type,
                           StructureTemplate(res_path))
Exemple #15
0
    def body(self, lines):
        pan_assign(lines, "system/cluster/name", self.name)
        pan_assign(lines, "system/cluster/type", self.dbobj.cluster_type)

        dbloc = self.dbobj.location_constraint
        pan_assign(lines, "system/cluster/sysloc/location", dbloc.sysloc())
        if dbloc.continent:
            pan_assign(lines, "system/cluster/sysloc/continent",
                       dbloc.continent.name)
        if dbloc.city:
            pan_assign(lines, "system/cluster/sysloc/city", dbloc.city.name)
        if dbloc.campus:
            pan_assign(lines, "system/cluster/sysloc/campus",
                       dbloc.campus.name)
            ## maintaining this so templates dont break
            ## during transtion period.. should be DEPRECATED
            pan_assign(lines, "system/cluster/campus", dbloc.campus.name)
        if dbloc.building:
            pan_assign(lines, "system/cluster/sysloc/building",
                       dbloc.building.name)
        if dbloc.bunker:
            pan_assign(lines, "system/cluster/sysloc/bunker",
                       dbloc.bunker.name)
        if dbloc.rack:
            pan_assign(lines, "system/cluster/rack/row", dbloc.rack.rack_row)
            pan_assign(lines, "system/cluster/rack/column",
                       dbloc.rack.rack_column)
            pan_assign(lines, "system/cluster/rack/name", dbloc.rack.name)
        if dbloc.room:
            pan_assign(lines, "system/cluster/rack/room", dbloc.room)

        pan_assign(lines, "system/cluster/down_hosts_threshold",
                   self.dbobj.dht_value)
        if self.dbobj.dmt_value is not None:
            pan_assign(lines, "system/cluster/down_maint_threshold",
                       self.dbobj.dmt_value)
        if self.dbobj.down_hosts_percent:
            pan_assign(lines, "system/cluster/down_hosts_percent",
                       self.dbobj.down_hosts_threshold)
            pan_assign(lines, "system/cluster/down_hosts_as_percent",
                       self.dbobj.down_hosts_percent)
        if self.dbobj.down_maint_percent:
            pan_assign(lines, "system/cluster/down_maint_percent",
                       self.dbobj.down_maint_threshold)
            pan_assign(lines, "system/cluster/down_maint_as_percent",
                       self.dbobj.down_maint_percent)
        lines.append("")
        # Only use system names here to avoid circular dependencies.
        # Other templates that needs to look up the underlying values use:
        # foreach(idx; host; value("system/cluster/members")) {
        #     v = value("/" + host + "/system/foo/bar/baz");
        # );
        pan_assign(lines, "system/cluster/members",
                   sorted([member.fqdn for member in self.dbobj.hosts]))

        lines.append("")
        if self.dbobj.resholder:
            for resource in sorted(self.dbobj.resholder.resources):
                pan_append(
                    lines, "system/resources/" + resource.resource_type,
                    StructureTemplate(resource.template_base + '/config'))
        pan_assign(lines, "system/build", self.dbobj.status.name)
        if self.dbobj.allowed_personalities:
            pan_assign(
                lines, "system/cluster/allowed_personalities",
                sorted([
                    "%s/%s" % (p.archetype.name, p.name)
                    for p in self.dbobj.allowed_personalities
                ]))

        fname = "body_%s" % self.dbobj.cluster_type
        if hasattr(self, fname):
            getattr(self, fname)(lines)