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))
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)
def body(self, lines): pan_assign(lines, "/system/cluster/name", self.dbobj.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, key=attrgetter('resource_type', 'name')): res_path = PlenaryResource.template_name(resource) pan_append(lines, "/system/cluster/resources/" + resource.resource_type, StructureTemplate(res_path)) lines.append("include { if_exists('features/' + value('/system/archetype/name') + '/%s/%s/config') };" % (self.dbobj.personality.archetype.name, self.dbobj.personality.name))
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))