def body_virtual_machine(self, lines): machine = self.dbobj.machine path = PlenaryMachineInfo.template_name(machine) pan_assign(lines, "hardware", StructureTemplate(path)) # One day we may get to the point where this will be required. # FIXME: read the data from the host data template if machine.host: # we fill this in manually instead of just assigning # 'system' = value("hostname:/system") # because the target host might not actually have a profile. arch = machine.host.archetype os = machine.host.operating_system pn = machine.primary_name.fqdn system = {'archetype': {'name': arch.name, 'os': os.name, 'osversion': os.version}, 'build': machine.host.status.name, 'network': {'hostname': pn.name, 'domainname': pn.dns_domain}} pan_assign(lines, "system", system)
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))