def do_transfer(): '''Call libtransfer to transfer the bits to the system via cpio.''' # transfer the bits tm_argslist = [(TM_ATTR_MECHANISM, TM_PERFORM_CPIO), (TM_CPIO_ACTION, TM_CPIO_ENTIRE), (TM_CPIO_SRC_MNTPT, "/"), (TM_CPIO_DST_MNTPT, INSTALLED_ROOT_DIR)] # if it is running on x86, need to unpack the root archive from # the architecture that's not booted from. if platform.processor() == "i386": (status, inst_set) = commands.getstatusoutput("/bin/isainfo -k") if (status != 0): logging.error("Unable to determine instruction set.") raise ti_utils.InstallationError if (inst_set == "amd64"): # Running 64 bit kernel, need to unpack 32 bit archive tm_argslist.extend([(TM_UNPACK_ARCHIVE, X86_BOOT_ARCHIVE_PATH % "") ]) else: # Running 32 bit kernel, need to unpack 64 bit archive tm_argslist.extend([(TM_UNPACK_ARCHIVE, X86_BOOT_ARCHIVE_PATH % "amd64")]) logging.debug("Going to call TM with this list: %s", tm_argslist) try: status = tm_perform_transfer(tm_argslist, callback=transfer_mod_callback) except Exception, ex: logging.exception(ex) status = 1
def ips_validate_auth(url, auth, mntpt, mirr_cmd=None, pref_flag=None): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Validate the given publisher, URL or mirror. This is done on an alternate mount point that's passed into this function so the original package image area's catalog file doesn't get polluted. Input: url: URL for the repo to validate auth: publisher to validate mntpt: Mount point for the pkg image area. mirr_cmd: -m if you want to validate a mirror pref_flag: indicate whether this is a preferred publisher or not Returns: Return code from the TM calls """ if (pref_flag): return (tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_INIT), (TM_IPS_PKG_URL, url), (TM_IPS_PKG_AUTH, auth), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)])) else: return (ips_set_auth(url, auth, mntpt, mirr_cmd, pref_flag=False, refresh_flag=True))
def do_transfer(): '''Call libtransfer to transfer the bits to the system via cpio.''' # transfer the bits tm_argslist = [(TM_ATTR_MECHANISM, TM_PERFORM_CPIO), (TM_CPIO_ACTION, TM_CPIO_ENTIRE), (TM_CPIO_SRC_MNTPT, "/"), (TM_CPIO_DST_MNTPT, INSTALLED_ROOT_DIR)] # if it is running on x86, need to unpack the root archive from # the architecture that's not booted from. if platform.processor() == "i386": (status, inst_set) = commands.getstatusoutput("/bin/isainfo -k") if (status != 0): logging.error("Unable to determine instruction set.") raise ti_utils.InstallationError if (inst_set == "amd64"): # Running 64 bit kernel, need to unpack 32 bit archive tm_argslist.extend([(TM_UNPACK_ARCHIVE, X86_BOOT_ARCHIVE_PATH % "")]) else: # Running 32 bit kernel, need to unpack 64 bit archive tm_argslist.extend([(TM_UNPACK_ARCHIVE, X86_BOOT_ARCHIVE_PATH % "amd64")]) logging.debug("Going to call TM with this list: %s", tm_argslist) try: status = tm_perform_transfer(tm_argslist, callback=transfer_mod_callback) except Exception, ex: logging.exception(ex) status = 1
def ips_init(pkg_url, pkg_auth, mntpt): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Perform an initialization of the specified IPS area. Returns: 0 Success >0 Failure """ status = tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_INIT), (TM_IPS_PKG_URL, pkg_url), (TM_IPS_PKG_AUTH, pkg_auth), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)]) if status: return status return (tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_SET_PROP), (TM_IPS_PROP_NAME, "flush-content-cache-on-success"), (TM_IPS_PROP_VALUE, "True"), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)]))
def do_transfer(): '''Call libtransfer to transfer the bits to the system via cpio.''' # transfer the bits tm_argslist = [(TM_ATTR_MECHANISM, TM_PERFORM_CPIO), (TM_CPIO_ACTION, TM_CPIO_ENTIRE), (TM_CPIO_SRC_MNTPT, "/"), (TM_CPIO_DST_MNTPT, INSTALLED_ROOT_DIR)] logging.debug("Going to call TM with this list: %s", tm_argslist) try: status = tm_perform_transfer(tm_argslist, callback=transfer_mod_callback) except Exception, ex: logging.exception(ex) status = 1
def ips_purge_hist(mntpt): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Initiate an IPS pkg purge-history Inputs: mntpt: mount point of the pkg image area Returns: Return code from the tm_perform_transfer call. """ return tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_PURGE_HIST), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)])
def do_transfer(): '''Call libtransfer to transfer the bits to the system via cpio.''' # transfer the bits tm_argslist = [(TM_ATTR_MECHANISM, TM_PERFORM_CPIO), (TM_CPIO_ACTION, TM_CPIO_ENTIRE), (TM_CPIO_SRC_MNTPT, "/"), (TM_CPIO_DST_MNTPT, INSTALLED_ROOT_DIR)] logging.debug("Going to call TM with this list: %s", tm_argslist) try: status = tm_perform_transfer(tm_argslist, callback=transfer_mod_callback) except Exception as ex: logging.exception(ex) status = 1 if status != TM_SUCCESS: logging.error("Failed to transfer bits to the target") raise ti_utils.InstallationError
def ips_set_auth(alt_url, alt_auth, mntpt, mirr_cmd=None, pref_flag=None, refresh_flag=None): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Calls "pkg set-publisher" to set the specified publisher/url/mirror on the specified mount point. Input: alt_url: URL for the publisher alt_auth: publisher to set mntpt: Mount point for the pkg image area. mirr_cmd: -m or -M if set. This indicates whether to set or unset a mirror. pref_flag: indicate whether this is a preferred publisher or not refresh_flag: indicate whether the catalog should be refreshed while doing the set-publisher call. Returns: Return code from the TM calls """ # If both mirr_cmd and pref_flag are set that's an error. We # can't do both at once. if mirr_cmd is not None and pref_flag: print("Failed to set-publisher on the IPS " \ "image at " + mntpt + "It is illegal to specify " \ "setting a mirror and the preferred publisher in the " \ " same command", file=sys.stderr) return -1 tm_argslist = [(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_SET_AUTH), (TM_IPS_ALT_URL, alt_url), (TM_IPS_ALT_AUTH, alt_auth), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)] if pref_flag: tm_argslist.extend([(TM_IPS_PREF_FLAG, TM_IPS_PREFERRED_AUTH)]) elif mirr_cmd is not None: tm_argslist.extend([(TM_IPS_MIRROR_FLAG, mirr_cmd)]) elif refresh_flag: tm_argslist.extend([(TM_IPS_REFRESH_CATALOG, "true")]) return (tm.tm_perform_transfer(tm_argslist))
def ips_unset_auth(alt_auth, mntpt): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Calls "pkg unset-publisher" to unset the specified publisher/url/mirror on the specified mount point. Input: alt_auth: alternate publisher to unset. mntpt: Mount point for the pkg image area. Returns: Return code from the tm_perform_transfer call. """ return (tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_UNSET_AUTH), (TM_IPS_ALT_AUTH, alt_auth), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)]))
def ips_contents_verify(file_name, mntpt): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Verifies that the packages listed in the designated file are in the IPS repository associated with the pkg image area. Inputs: file_name: file containing the list of pkgs to verify mntpt: Mount point for the pkg image area. Returns: Return code from the tm_perform_transfer call. """ return tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, TM_IPS_REPO_CONTENTS_VERIFY), (TM_IPS_PKGS, file_name), (TM_IPS_INIT_MNTPT, mntpt), (TM_PYTHON_LOG_HANDLER, DC_LOG)])
def ips_pkg_op(file_name, mntpt, ips_pkg_op, generate_ips_index): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Initiate a IPS pkg install/uninstall of the packages specified in the designated file. Inputs: file_name: file containing the list of pkgs to verify mntpt: Mount point for the pkg image area. ips_pkg_op: Install or uninstall generate_ips_index: true or false indicating whether to generate the ips index or not. Returns: Return code from the tm_perform_transfer call. """ return tm.tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_IPS), (TM_IPS_ACTION, ips_pkg_op), (TM_IPS_PKGS, file_name), (TM_IPS_INIT_MNTPT, mntpt), (TM_IPS_GENERATE_SEARCH_INDEX, generate_ips_index), (TM_PYTHON_LOG_HANDLER, DC_LOG)])
# get list of files in boot archive from contents file BA_FILELIST = get_manifest_list(MANIFEST_READER_OBJ, BOOT_ARCHIVE_CONTENTS_BASE_INCLUDE_TO_TYPE_FILE) # write the list of files to a file for use by the transfer module try: for item in BA_FILELIST: FILELIST.write(item + '\n') finally: FILELIST.close() # use transfer module to copy files from pkg image area to the boot archive # staging area STATUS = tm_perform_transfer([(TM_ATTR_MECHANISM, TM_PERFORM_CPIO), (TM_CPIO_ACTION, TM_CPIO_LIST), (TM_CPIO_LIST_FILE, FILELIST_NAME), (TM_CPIO_DST_MNTPT, BA_BUILD), (TM_CPIO_SRC_MNTPT, PKG_IMG_PATH)]) os.remove(FILELIST_NAME) # verify that copy suceeded if (STATUS != 0): raise Exception("boot_archive_initialize: copying files to " + "boot_archive failed: tm_perform_transfer returned %d" % STATUS) # use transfer module to copy directories from pkg image area to boot archive # TBD: use os.system() and cpio to copy directories from pkg image area # to boot archive until transfer module issues are addressed