예제 #1
0
def __unpack_dpk():
    # Unpack setup scripts
    timing_key = "dpk deploy __unpack_dpk"
    util.start_timing(timing_key)
    if this.config.get('unpacked_setup_scripts'):
        logging.debug("DPK setup scripts are already unpacked")
    else:
        logging.debug("Unpacking DPK setup scripts")

        try:
            for p in Path(this.config.get('dpk_files_dir')).glob("*_1of*.zip"):
                with zipfile.ZipFile(p, 'r') as zip_ref:
                    zip_ref.extractall(this.config.get('dpk_files_dir'))
        except:
            logging.error("Issue unpacking setup scripts")
            util.error_timings(timing_key)
            exit(2)

        try:
            # Change permissions on setup folder
            for root, dirs, files in os.walk(
                    this.config.get('dpk_files_dir') + "/setup"):
                for momo in files:
                    os.chmod(os.path.join(root, momo), 775)
        except:
            logging.error(
                "Issue setting permissions on unpacked setup scripts")
            util.error_timings(timing_key)
            raise
            exit(2)

        logging.debug("Update DPK status - unpacked_setup_scripts: true")
        update_dpk_status('unpacked_setup_scripts', True)

    util.end_timing(timing_key)
예제 #2
0
def mount_file_system():
    logging.debug("Mounting")
    timing_key = "oci block mount"
    util.start_timing(timing_key)

    try:
        Path(config.get('--block-path')).mkdir(parents=True, exist_ok=True)

        mount_tmp_sh = config.get("--home") + "/ioco-oci-block-mount.sh"
        f = open(mount_tmp_sh, "w")
        f.write("#!/bin/bash\n")
        f.write("if ! grep -q '" + part + "' /etc/fstab ; then\n")
        f.write("    echo '# ioco-oci-block-mount' >> /etc/fstab\n")
        f.write("    echo '" + part + " " + config.get("--block-path") + " " +
                fs_type + " defaults 0 2' >> /etc/fstab\n")
        f.write("fi")
        f.close()

        subprocess.run(["sudo", "sh", mount_tmp_sh], check=True)
        subprocess.run(["sudo", "mount", "-a"], check=True)
    except:
        logging.error("Issue mounting partion")
        util.error_timings(timing_key)
        raise

    util.end_timing(timing_key)
예제 #3
0
파일: oci.py 프로젝트: peytonlc/ioco
def make_file_system():
    logging.debug("Making file system for block volume")
    timing_key = "oci block make_file_system"
    util.start_timing(timing_key)

    # Create partition, if needed
    if os.path.exists(this.part):
        logging.debug("Partition on " + this.config.get("--block-disk") + " is already created")        
    else:
        logging.debug("Creating partition on " + this.config.get("--block-disk"))        
        try:
            fdisk_tmp_sh = config.get("--home") + "/ioco-oci-block-partition.sh"
            f = open(fdisk_tmp_sh,"w")
            f.write("sudo fdisk " + this.config.get("--block-disk") + " <<EOF\nn\np\n\n\n\nw\nEOF")
            f.close()
        except:
            logging.error("Issue creating temp partition setup script")
            util.error_timings(timing_key)

        try:    
            subprocess.run(["sudo","sh", fdisk_tmp_sh], check=True)
        except:
            logging.error("Issue creating partion")
            util.error_timings(timing_key)

    # Create file system, if needed
    logging.debug("Creating file sytem using " + this.part)        
    try:
        subprocess.run(["sudo","mkfs." + this.fs_type, this.part], check=True)
    except:
        logging.info("File system did NOT create, assuming already created")
        util.error_timings(timing_key)
    
    util.end_timing(timing_key)
예제 #4
0
def install(config):
    timing_key = "rundeck install"
    util.start_timing(timing_key)

    try:
        logging.debug("Setting up for install")
        rd_base = "/u01/app/rundeck"  # TODO - assume this location?
        Path(rd_base).mkdir(parents=True, exist_ok=True)
        shutil.chown(rd_base, user="******", group="opc")  # TODO - assuming opc?

        logging.debug("Adding rundeck rpm")
        subprocess.run(
            ["sudo", "rpm", "-Uvh", "https://repo.rundeck.org/latest.rpm"])

        logging.debug("Installing java and rundeck")
        subprocess.run(
            ["sudo", "yum", "-y", "install", "java-1.8.0", "rundeck"])

        logging.debug("Starting rundeck service")
        subprocess.run(["sudo", "service", "rundeckd", "start"])

        logging.debug("Open firewall")
        subprocess.run(
            ["sudo", "firewall-cmd", "--zone=public", "--add-port=4440/tcp"],
            check=True)
    except:
        logging.error("Error setting up Rundeck")
        util.error_timings(timing_key)

    util.end_timing(timing_key)
예제 #5
0
def __install_packages():
    logging.info("Installing packages")
    timing_key = "dpk deploy install_packages"
    util.start_timing(timing_key)
    try:
        packages = ["oracle-database-preinstall-19c", "glibc-devel"]
        subprocess.run(["sudo","yum", "-y", "install"] + packages, \
            check=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
        logging.debug("Installing packages completed.")
    except:
        logging.error("Installing packages failed.")

    util.end_timing(timing_key)
예제 #6
0
def main(config):
    this.config = config
    if this.config.get("block"):
        timing_key = "oci block"
        util.start_timing(timing_key)

        logging.debug("Processing block command")
        this.part = this.config.get("--block-disk") + "1"
        this.fs_type = "xfs"

        # If no specific oci block options are set, then set all
        all = not this.config['--make-file-system'] \
            and not this.config['--mount']

        if all or this.config.get('--make-file-system'):
            make_file_system()
        if all or this.config.get('--mount'):
            mount_file_system()
        util.end_timing(timing_key)
예제 #7
0
def undeploy():
    # TODO - Issue #3 convert this to more python based, not just bash in sub-process
    timing_key = "dpk undeploy"
    util.start_timing(timing_key)
    try:
        subprocess.run(['sudo','pkill', '-9', '-u', 'psadm2'], \
            stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
        subprocess.run(['sudo','pkill', '-9', '-u', 'oracle2'], \
            stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
        subprocess.run(['sudo','rm','-rf',this.config.get('psft_base_dir')], \
            stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
        subprocess.run(['sudo','rm','-rf','/opt/oracle/psft/db/oraInventory'], \
            stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
        subprocess.run(['sudo','rm','-f','/etc/oraInst.loc'], \
            stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
        logging.info(
            'Done undeploying. An instance reboot may be required before next deploy.'
        )
    except:
        logging.error('Issue undeploying')
        util.error_timings(timing_key)
        raise

    util.end_timing(timing_key)
예제 #8
0
def __get_dpk_mos():
    logging.info(" - Downloading files from MOS")
    timing_key = "dpk deploy __get_dpk_mos"
    util.start_timing(timing_key)

    logging.debug("Creating auth cookie from MOS")
    cookie_file = this.config.get('dpk_files_dir') + "/mos.cookie"

    # eat any old cookies
    if os.path.exists(cookie_file):
        os.remove(cookie_file)

    try:
        # Create a session and update headers
        s = requests.session()
        s.headers.update({'User-Agent': 'Mozilla/5.0'})

        # Initiate updates.oracle.com request to get login redirect URL
        logging.debug('Requesting downloads page')
        r = s.get("https://updates.oracle.com/Orion/Services/download",
                  allow_redirects=False)
        login_url = r.headers['Location']
        if not login_url:
            logging.error("Location was empty so login URL can't be set")
            util.error_timings(timing_key)
            exit(2)

        # Create a NEW session, then send Basic Auth to login redirect URL
        logging.debug('Sending Basic Auth to login, using new session')
        s = requests.session()
        logging.debug("Using MOS username: "******"MOS login was successful")
        else:
            logging.error("MOS login was NOT successful.")
            util.error_timings(timing_key)
            exit(2)
    except:
        logging.error("Issue getting MOS auth token")
        util.end_timing(timing_key)
        raise

    try:
        # Use same session to search for downloads
        logging.debug('Search for list of downloads, using same session')
        mos_uri_search = "https://updates.oracle.com/Orion/SimpleSearch/process_form?search_type=patch&patch_number=" + this.config.get(
            'patch_id') + "&plat_lang=226P"
        r = s.get(mos_uri_search)
        search_results = r.content.decode('utf-8')

        # Validate search results
        if r.ok:
            logging.debug("Search results return success")
        else:
            logging.error("Search results did NOT return success")
            util.error_timings(timing_key)
            exit(2)
    except:
        logging.error("Issue getting MOS search results")
        util.end_timing(timing_key)
        raise

    try:
        # Extract download links to list
        pattern = "https://.+?Download/process_form/[^\"]*.zip[^\"]*"
        download_links = re.findall(pattern, search_results)
        download_links_file = this.config.get(
            'dpk_files_dir') + "/mos-download.links"
        # Write download links to file
        f = open(download_links_file, "w")
        for link in download_links:
            # Write download links list to file
            logging.debug(link)
            f.write(link + os.linesep)
        f.close()

        # Validate download links
        if len(download_links) > 0:
            logging.info(" - Downloading " + str(len(download_links)) +
                         " files")
        else:
            logging.error("No download links found")
            util.error_timings(timing_key)
            exit(2)
    except:
        logging.error("Issue creating download links file")
        util.end_timing(timing_key)
        raise

    # multi thread download
    results = ThreadPool(this.config.get('download_threads')).imap_unordered(
        __download_file, download_links)
    for r in results:
        logging.info("    [DONE] " + r)

    logging.debug("Update DPK status - downloaded_patch_files: true")
    update_dpk_status('downloaded_patch_files', True)
    util.end_timing(timing_key)
예제 #9
0
def __get_dpk_cm():
    logging.info(" - Getting files from DPK repo")
    timing_key = "dpk deploy __get_dpk_cm"
    util.start_timing(timing_key)

    # Get dpk source dir
    try:
        repo = Path(this.config.get('cm_dpk_files_dir'))
        dpk_path = repo / 'dpk' / this.config.get(
            '--dpk-platform') / this.config.get('--dpk-type')
        logging.debug("DPK type base: " + str(dpk_path))
    except TypeError:
        logging.error(
            "Issue generating dpk path. Are --dpk-platform and --dpk-type set correctly?"
        )
        exit(5)
    except:
        logging.error("Unknown issue generating dpk path")
        raise

    # Get DPK version
    if this.config.get('--dpk-version'):
        dpk_version = this.config.get('--dpk-version')
    else:
        # Get max DPK version
        try:
            versions = [
                f.name for f in os.scandir(dpk_path)
                if f.is_dir() and f.name.isdigit()
            ]
            logging.debug("DPK versions found: " + str(versions))
        except FileNotFoundError as e:
            logging.error(
                str(e) +
                ". Use CM to subscribe and download this type and platform.")
            util.error_timings(timing_key)
            exit(5)

        versions.sort(reverse=True)
        dpk_version = versions[0]

    dpk_path = dpk_path / dpk_version
    logging.debug(
        this.config.get('--dpk-platform') + " " +
        this.config.get('--dpk-type') + " DPK version found: " +
        str(dpk_version))

    if this.config.get('--dpk-type') == 'tools':
        # Get DPK patch
        if this.config.get('--dpk-patch'):
            dpk_patch = this.config.get('--dpk-patch')
        else:
            # Get max DPK tools patch
            try:
                versions = [
                    f.name for f in os.scandir(dpk_path)
                    if f.is_dir() and f.name.isdigit()
                ]
                logging.debug("DPK tools patches found: " + str(versions))
            except FileNotFoundError as e:
                logging.error(
                    str(e) +
                    ". Use CM to subscribe and download this type and platform."
                )
                util.end_timing(timing_key)
                util.print_timings()
                exit(5)

            versions.sort(reverse=True)
            dpk_patch = versions[0]

        dpk_path = dpk_path / dpk_patch
        logging.debug(
            this.config.get('--dpk-platform') + " " +
            "DPK tools patch found: " + str(dpk_patch))

    # copy dpk files
    try:
        logging.debug("Copying " + str(dpk_path) + " to " +
                      this.config.get('dpk_files_dir'))
        source_dpks = os.listdir(dpk_path)
        for f in source_dpks:
            full_f = os.path.join(dpk_path, f)
            if os.path.isfile(full_f):  #TODO - only zip?
                shutil.copy(full_f, this.config.get('dpk_files_dir'))

        logging.debug("Update DPK status - downloaded_patch_files: true")
        update_dpk_status('downloaded_patch_files', True)

    except FileExistsError:
        logging.error("DPK files in working directory already exist")
        exit(2)
    except:
        logging.error(
            "Issue copying DPK files from source to tmp working directory")
        util.end_timing(timing_key)
        util.print_timings()
        raise

    util.end_timing(timing_key)
예제 #10
0
파일: oci.py 프로젝트: peytonlc/ioco
        this.fs_type = "xfs"

        # If no specific oci block options are set, then set all
        all = not this.config['--make-file-system'] \
            and not this.config['--mount'] 
        
        if all or this.config.get('--make-file-system'):
            make_file_system()
        if all or this.config.get('--mount'):
<<<<<<< HEAD
            mount_file_system

=======
            mount_file_system()
>>>>>>> 9301974fb1ec0a5352f6edb5a3400d9eb4ee392f
        util.end_timing(timing_key)

def make_file_system():
    logging.debug("Making file system for block volume")
    timing_key = "oci block make_file_system"
    util.start_timing(timing_key)

    # Create partition, if needed
    if os.path.exists(this.part):
        logging.debug("Partition on " + this.config.get("--block-disk") + " is already created")        
    else:
        logging.debug("Creating partition on " + this.config.get("--block-disk"))        
        try:
            fdisk_tmp_sh = config.get("--home") + "/ioco-oci-block-partition.sh"
            f = open(fdisk_tmp_sh,"w")
            f.write("sudo fdisk " + this.config.get("--block-disk") + " <<EOF\nn\np\n\n\n\nw\nEOF")