def get_interfaces_by_mac(): if util.is_FreeBSD(): return get_interfaces_by_mac_on_freebsd() elif util.is_NetBSD(): return get_interfaces_by_mac_on_netbsd() else: return get_interfaces_by_mac_on_linux()
def _get_devices(self, label): if util.is_FreeBSD(): devlist = [ p for p in ['/dev/msdosfs/' + label, '/dev/iso9660/' + label] if os.path.exists(p) ] elif util.is_NetBSD(): out, _err = util.subp(['sysctl', '-n', 'hw.disknames'], rcs=[0]) devlist = [] for dev in out.split(): mscdlabel_out, _ = util.subp(['mscdlabel', dev], rcs=[0, 1]) if ('label "%s"' % label) in mscdlabel_out: devlist.append('/dev/' + dev) devlist.append('/dev/' + dev + 'a') # NetBSD 7 else: # Query optical drive to get it in blkid cache for 2.6 kernels util.find_devs_with(path="/dev/sr0") util.find_devs_with(path="/dev/sr1") fslist = util.find_devs_with("TYPE=vfat") fslist.extend(util.find_devs_with("TYPE=iso9660")) label_list = util.find_devs_with("LABEL=%s" % label.upper()) label_list.extend(util.find_devs_with("LABEL=%s" % label.lower())) devlist = list(set(fslist) & set(label_list)) devlist.sort(reverse=True) return devlist
def find_fallback_nic(blacklist_drivers=None): """Return the name of the 'fallback' network device.""" if util.is_FreeBSD(): return find_fallback_nic_on_freebsd(blacklist_drivers) elif util.is_NetBSD() or util.is_OpenBSD(): return find_fallback_nic_on_netbsd_or_openbsd(blacklist_drivers) else: return find_fallback_nic_on_linux(blacklist_drivers)
def find_fallback_nic( blacklist_drivers: Optional[List[str]] = None, ) -> Optional[str]: """Get the name of the 'fallback' network device.""" if util.is_FreeBSD() or util.is_DragonFlyBSD(): return find_fallback_nic_on_freebsd(blacklist_drivers) elif util.is_NetBSD() or util.is_OpenBSD(): return find_fallback_nic_on_netbsd_or_openbsd(blacklist_drivers) else: return find_fallback_nic_on_linux(blacklist_drivers)
def find_candidate_nics( blacklist_drivers: Optional[List[str]] = None, ) -> List[str]: """Get the list of network interfaces viable for networking. @return List of interfaces, sorted naturally. """ if util.is_FreeBSD() or util.is_DragonFlyBSD(): return find_candidate_nics_on_freebsd(blacklist_drivers) elif util.is_NetBSD() or util.is_OpenBSD(): return find_candidate_nics_on_netbsd_or_openbsd(blacklist_drivers) else: return find_candidate_nics_on_linux(blacklist_drivers)
def get_interfaces_by_mac(blacklist_drivers=None) -> dict: if util.is_FreeBSD(): return get_interfaces_by_mac_on_freebsd( blacklist_drivers=blacklist_drivers) elif util.is_NetBSD(): return get_interfaces_by_mac_on_netbsd( blacklist_drivers=blacklist_drivers) elif util.is_OpenBSD(): return get_interfaces_by_mac_on_openbsd( blacklist_drivers=blacklist_drivers) else: return get_interfaces_by_mac_on_linux( blacklist_drivers=blacklist_drivers)
def netdev_info(empty=""): devs = {} if util.is_NetBSD(): (ifcfg_out, _err) = subp.subp(["ifconfig", "-a"], rcs=[0, 1]) devs = _netdev_info_ifconfig_netbsd(ifcfg_out) elif subp.which("ip"): # Try iproute first of all try: (ipaddr_out, _err) = subp.subp(["ip", "--json", "addr"]) devs = _netdev_info_iproute_json(ipaddr_out) except subp.ProcessExecutionError: # Can be removed when "ip --json" is available everywhere (ipaddr_out, _err) = subp.subp(["ip", "addr", "show"]) devs = _netdev_info_iproute(ipaddr_out) elif subp.which("ifconfig"): # Fall back to net-tools if iproute2 is not present (ifcfg_out, _err) = subp.subp(["ifconfig", "-a"], rcs=[0, 1]) devs = _netdev_info_ifconfig(ifcfg_out) else: LOG.warning( "Could not print networks: missing 'ip' and 'ifconfig' commands") if empty == "": return devs recurse_types = (dict, tuple, list) def fill(data, new_val="", empty_vals=("", b"")): """Recursively replace 'empty_vals' in data (dict, tuple, list) with new_val""" if isinstance(data, dict): myiter = data.items() elif isinstance(data, (tuple, list)): myiter = enumerate(data) else: raise TypeError("Unexpected input to fill") for key, val in myiter: if val in empty_vals: data[key] = new_val elif isinstance(val, recurse_types): fill(val, new_val) fill(devs, new_val=empty) return devs
def available(target=None): return util.is_NetBSD()
def _get_data(self): found = None md = {} results = {} for sdir in (self.seed_dir, "/config-drive"): if not os.path.isdir(sdir): continue try: results = read_config_drive(sdir) found = sdir break except openstack.NonReadable: util.logexc(LOG, "Failed reading config drive from %s", sdir) if not found: dslist = self.sys_cfg.get('datasource_list') for dev in find_candidate_devs(dslist=dslist): mtype = None if (util.is_FreeBSD() or util.is_NetBSD()): if dev.startswith("/dev/cd"): mtype = "cd9660" try: results = util.mount_cb(dev, read_config_drive, mtype=mtype) found = dev except openstack.NonReadable: pass except util.MountFailedError: pass except openstack.BrokenMetadata: util.logexc(LOG, "Broken config drive: %s", dev) if found: break if not found: return False md = results.get('metadata', {}) md = util.mergemanydict([md, DEFAULT_METADATA]) self.dsmode = self._determine_dsmode([ results.get('dsmode'), self.ds_cfg.get('dsmode'), sources.DSMODE_PASS if results['version'] == 1 else None ]) if self.dsmode == sources.DSMODE_DISABLED: return False prev_iid = get_previous_iid(self.paths) cur_iid = md['instance-id'] if prev_iid != cur_iid: # better would be to handle this centrally, allowing # the datasource to do something on new instance id # note, networking is only rendered here if dsmode is DSMODE_PASS # which means "DISABLED, but render files and networking" on_first_boot(results, distro=self.distro, network=self.dsmode == sources.DSMODE_PASS) # This is legacy and sneaky. If dsmode is 'pass' then do not claim # the datasource was used, even though we did run on_first_boot above. if self.dsmode == sources.DSMODE_PASS: LOG.debug("%s: not claiming datasource, dsmode=%s", self, self.dsmode) return False self.source = found self.metadata = md self.ec2_metadata = results.get('ec2-metadata') self.userdata_raw = results.get('userdata') self.version = results['version'] self.files.update(results.get('files', {})) vd = results.get('vendordata') self.vendordata_pure = vd try: self.vendordata_raw = sources.convert_vendordata(vd) except ValueError as e: LOG.warning("Invalid content in vendor-data: %s", e) self.vendordata_raw = None # network_config is an /etc/network/interfaces formated file and is # obsolete compared to networkdata (from network_data.json) but both # might be present. self.network_eni = results.get("network_config") self.network_json = results.get('networkdata') return True