def _inject_admin_password_into_fs(admin_passwd, fs): """Set the root password to admin_passwd admin_password is a root password fs is the path to the base of the filesystem into which to inject the key. This method modifies the instance filesystem directly, and does not require a guest agent running in the instance. """ # The approach used here is to copy the password and shadow # files from the instance filesystem to local files, make any # necessary changes, and then copy them back. LOG.debug("Inject admin password fs=%(fs)s " "admin_passwd=<SANITIZED>", {'fs': fs}) admin_user = '******' passwd_path = os.path.join('etc', 'passwd') shadow_path = os.path.join('etc', 'shadow') passwd_data = fs.read_file(passwd_path) shadow_data = fs.read_file(shadow_path) new_shadow_data = _set_passwd(admin_user, admin_passwd, passwd_data, shadow_data) fs.replace_file(shadow_path, new_shadow_data)
def _inject_file_into_fs(fs, path, contents, append=False): LOG.debug("Inject file fs=%(fs)s path=%(path)s append=%(append)s", {'fs': fs, 'path': path, 'append': append}) if append: fs.append_file(path, contents) else: fs.replace_file(path, contents)