def chpasswd(distro, plist_in, hashed=False): if util.is_BSD(): for pentry in plist_in.splitlines(): u, p = pentry.split(":") distro.set_passwd(u, p, hashed=hashed) else: cmd = ["chpasswd"] + (["-e"] if hashed else []) subp.subp(cmd, plist_in)
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_BSD(): 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