Example #1
0
def check_docker_files(host, ssh_obj, files_modified_dict, dict_to_compare, remote_sha_sum_dict):
    """
    check_docker_files assumes there is already a paramiko connection made to the server in question
    It attempts to take a sha256sum of the files in file_list
    """
    for files in dict_to_compare.keys():
        try:
            temp_list = HandleSSHConnections.run_remote_commands(ssh_obj, "sha256sum %s" % files)
            shortened_file_name = files.split("/")[-1]
            for line in temp_list:
                sha_sum = line.split()[0]
                if line.strip().split()[0] == dict_to_compare[files]:
                    modified = False
                    DictionaryHandling.add_to_dictionary(files_modified_dict, host, "%s has been modified" %
                                                         shortened_file_name, modified)
                else:
                    modified = True
                    DictionaryHandling.add_to_dictionary(files_modified_dict, host, "%s has been modified" %
                                                         shortened_file_name, modified)
                # Added the file name and sha sum in the key to be able to associate the sum to modified flag
                # This will help to identify it for colourization
                DictionaryHandling.add_to_dictionary(remote_docker_file_sums_dict, host, "%s sha256sum : %s" %
                                                     (shortened_file_name, sha_sum), modified)
        except socket.error:
            print("No SSH connection is open")
def update_required_query(server_name, package_update_dict, package_list,
                          ssh_obj):
    """
    update_required_query uses the yum to determine if packages have updates available
    Does not return anything, instead uses DictionaryHandling.add_to_dictionary to populate dictionaries
    for processing later in the summation
    """
    packages_to_be_updated = HandleSSHConnections.run_remote_commands(
        ssh_obj, "yum list updates")
    ose_package_needs_update = False
    system_up_to_date = True
    if len(packages_to_be_updated) > 2:
        system_up_to_date = False
        for package in packages_to_be_updated:
            package_name = package.split(".")[0]
            if package_name in package_list:
                ose_package_needs_update = True
                DictionaryHandling.add_to_dictionary(package_update_dict,
                                                     server_name,
                                                     "Update available for",
                                                     package_name)
    if not ose_package_needs_update:
        DictionaryHandling.add_to_dictionary(package_update_dict, server_name,
                                             "System is up to date",
                                             system_up_to_date)
def check_docker_files(host, ssh_obj, files_modified_dict, dict_to_compare, remote_sha_sum_dict):
    """
    check_docker_files assumes there is already a paramiko connection made to the server in question
    It attempts to take a sha256sum of the files in file_list
    """
    for files in dict_to_compare.keys():
        try:
            temp_list = HandleSSHConnections.run_remote_commands(ssh_obj, "sha256sum %s" % files)
            shortened_file_name = files.split("/")[-1]
            for line in temp_list:
                sha_sum = line.split()[0]
                if line.strip().split()[0] == dict_to_compare[files]:
                    modified = False
                    DictionaryHandling.add_to_dictionary(files_modified_dict, host, "%s has been modified" %
                                                         shortened_file_name, modified)
                else:
                    modified = True
                    DictionaryHandling.add_to_dictionary(files_modified_dict, host, "%s has been modified" %
                                                         shortened_file_name, modified)
                # Added the file name and sha sum in the key to be able to associate the sum to modified flag
                # This will help to identify it for colourization
                DictionaryHandling.add_to_dictionary(remote_docker_file_sums_dict, host, "%s sha256sum : %s" %
                                                     (shortened_file_name, sha_sum), modified)
        except socket.error:
            print("No SSH connection is open")
def installed_package_query(server_name, repo_dict_to_modify, package_list,
                            ssh_obj):
    """
    installed_package_query uses the yum to determine if packages exist on the remote system
    Does not return anything, instead uses DictionaryHandling.add_to_dictionary to populate dictionaries
    for processing later in the summation
    """
    ose_required_packages_installed = []
    ose_required_packages_not_installed = []
    temp_list = HandleSSHConnections.run_remote_commands(
        ssh_obj, "yum list installed")
    installed_on_system = []
    for package in temp_list:
        package_name = package.split(".")[0]
        installed_on_system.append(package_name)
    for package in package_list:
        if package in installed_on_system:
            ose_required_packages_installed.append(package)
        else:
            ose_required_packages_not_installed.append(package)
    if len(package_list) != len(ose_required_packages_installed):
        DictionaryHandling.add_to_dictionary(
            repo_dict_to_modify, server_name, "Missing",
            ose_required_packages_not_installed)
    else:
        DictionaryHandling.add_to_dictionary(repo_dict_to_modify, server_name,
                                             "All OSE Packages Installed",
                                             True)
Example #5
0
def check_selinux_booleans(host, ssh_obj, boolean_list, boolean_dict):
    output = HandleSSHConnections.run_remote_commands(ssh_obj, "/usr/sbin/getsebool -a")
    for line in output:
        boolean_name = line.split()[0]
        if boolean_name in boolean_list:
            boolean_status = line.split("> ")[1]
            DictionaryHandling.add_to_dictionary(boolean_dict, host, boolean_name, boolean_status)
Example #6
0
def is_selinux_enabled(host, ssh_obj, dict_to_modify):
    """
    is_selinux_enabled logs into the remote host and runs/parses 'sestatus'
    adds results to a dictionary
    """
    output = HandleSSHConnections.run_remote_commands(ssh_obj, "sestatus")
    for line in output:
        if "SELinux status" in line:
            if "enabled" in line:
                DictionaryHandling.add_to_dictionary(dict_to_modify, host, "SELinux Enabled", True)
            else:
                DictionaryHandling.add_to_dictionary(dict_to_modify, host, "SELinux Enabled", False)
def is_selinux_enabled(host, ssh_obj, dict_to_modify):
    """
    is_selinux_enabled logs into the remote host and runs/parses 'sestatus'
    adds results to a dictionary
    """
    output = HandleSSHConnections.run_remote_commands(ssh_obj, "/usr/sbin/sestatus")
    for line in output:
        if "SELinux status" in line:
            if "enabled" in line:
                DictionaryHandling.add_to_dictionary(dict_to_modify, host, "SELinux Enabled", True)
            else:
                DictionaryHandling.add_to_dictionary(dict_to_modify, host, "SELinux Enabled", False)
Example #8
0
def update_required_query(server_name, package_update_dict, package_list, ssh_obj):
    """
    update_required_query uses the yum to determine if packages have updates available
    Does not return anything, instead uses DictionaryHandling.add_to_dictionary to populate dictionaries
    for processing later in the summation
    """
    packages_to_be_updated = HandleSSHConnections.run_remote_commands(ssh_obj, "yum list updates")
    ose_package_needs_update = False
    system_up_to_date = True
    if len(packages_to_be_updated) > 2:
        system_up_to_date = False
        for package in packages_to_be_updated:
            package_name = package.split(".")[0]
            if package_name in package_list:
                ose_package_needs_update = True
                DictionaryHandling.add_to_dictionary(package_update_dict, server_name, "Update available for",
                                             package_name)
    if not ose_package_needs_update:
         DictionaryHandling.add_to_dictionary(package_update_dict, server_name, "System is up to date",
                                              system_up_to_date)
Example #9
0
def installed_package_query(server_name, repo_dict_to_modify, package_list, ssh_obj):
    """
    installed_package_query uses the yum to determine if packages exist on the remote system
    Does not return anything, instead uses DictionaryHandling.add_to_dictionary to populate dictionaries
    for processing later in the summation
    """
    ose_required_packages_installed = []
    ose_required_packages_not_installed = []
    temp_list = HandleSSHConnections.run_remote_commands(ssh_obj, "yum list installed")
    installed_on_system = []
    for package in temp_list:
        package_name = package.split(".")[0]
        installed_on_system.append(package_name)
    for package in package_list:
        if package in installed_on_system:
            ose_required_packages_installed.append(package)
        else:
            ose_required_packages_not_installed.append(package)
    if len(package_list) != len(ose_required_packages_installed):
        DictionaryHandling.add_to_dictionary(repo_dict_to_modify, server_name, "Missing",
                                             ose_required_packages_not_installed)
    else:
        DictionaryHandling.add_to_dictionary(repo_dict_to_modify, server_name, "All OSE Packages Installed", True)
Example #10
0
remote_docker_file_sums_dict = {}
docker_service_check_dict = {}
# These may need to be updated occasionally in the event that the default options change
original_docker_file_hashes = \
           {"/etc/sysconfig/docker": "1fe04a24430eaefb751bf720353e730aec5641529f0a3b2567f72e6c63433e8b",
            "/etc/sysconfig/docker-storage": "709dca62ac8150aa280fdb4d49d122d78a6a2f4f46ff3f04fe8d698b7035f3a0",
            "/etc/sysconfig/docker-storage-setup": "bf3e1056e8df0dd4fc170a89ac2358f872a17509efa70a3bc56733a488a1e4b2"}

forward_lookup_dict = {}
reverse_lookup_dict = {}
repo_dict = {}
package_updates_available_dict = {}
subscription_dict = {}
ose_package_installed_dict = {}
ose_package_not_installed_dict = {}
ssh_connection = HandleSSHConnections()
selinux_dict = {}
ose_repos = ["rhel-7-server-rpms", "rhel-7-server-extras-rpms", "rhel-7-server-ose-3.1-rpms"]
ose_required_packages_list = ["wget", "git", "net-tools", "bind-utils", "iptables-services", "bridge-utils",
                              "bash-completion", "atomic-openshift-utils", "docker"]

# OptionParser's first argument is what is passed in on the command line.
# the second argument 'dest=' is the variable which holds the value. options.show_sha_sums holds the value for
# --show-sha-sums.
# The final arugment is the text that is printed out when the OptionParser help function is called
parser = OptionParser()
parser.add_option('--ansible-host-file', dest='ansible_host_file', help='Specify location of ansible hostfile')
parser.add_option('--show-sha-sums', dest='show_sha_sums', help='Toggle whether or not to show the sha sum of files'
                                                                'on remote host')
(options, args) = parser.parse_args()
     "/etc/sysconfig/docker-storage": "709dca62ac8150aa280fdb4d49d122d78a6a2f4f46ff3f04fe8d698b7035f3a0"}

original_docker_file_hashes_docker_1_12 = \
    {"/etc/sysconfig/docker": "86ed0dbf5b7c53d827c29f9de703000b720bd23cad06460aa68410c646f61a92",
     "/etc/sysconfig/docker-storage": "709dca62ac8150aa280fdb4d49d122d78a6a2f4f46ff3f04fe8d698b7035f3a0",
     "/etc/sysconfig/docker-storage-setup": "bf3e1056e8df0dd4fc170a89ac2358f872a17509efa70a3bc56733a488a1e4b2"}

forward_lookup_dict = {}
reverse_lookup_dict = {}
repo_dict = {}
package_updates_available_dict = {}
subscription_dict = {}
ose_package_installed_dict = {}
ose_package_not_installed_dict = {}
etcd_partition_dict = {}
ssh_connection = HandleSSHConnections()
selinux_dict = {}
if options.openshift_version:
    if "3.2" in options.openshift_version:
        openshift_server_repo = "rhel-7-server-ose-3.2-rpms"
        default_docker_hashes = original_docker_file_hashes_docker_1_8
    elif "3.1" in options.openshift_version:
        openshift_server_repo = "rhel-7-server-ose-3.1-rpms"
        default_docker_hashes = original_docker_file_hashes_docker_1_8
    elif "3.3" in options.openshift_version:
        openshift_server_repo ="rhel-7-server-ose-3.3-rpms"
        default_docker_hashes = original_docker_file_hashes_docker_1_10
    elif "3.4" in options.openshift_version:
        openshift_server_repo ="rhel-7-server-ose-3.4-rpms"
        default_docker_hashes = original_docker_file_hashes_docker_1_12
else:
Example #12
0
 server_name = sorted_servers_names_to_deploy_to[server_counter][0]
 warfile_list = sorted_servers_names_to_deploy_to[server_counter][1]
 if not warfile_list:
     print("Could not find any warfiles to deploy. Check: " + deployment_parameters[configuration_counter].warfile_path)
     continue
 else:
     continue_with_deploy = True
     if skip_nagios == False:
         if "yes" in nagios_put_in_downtime.lower():
             print("\nAttempting to put %s in downtime on nagios server: %s" % (server_name, nagios_server))
             DownTimeHandler.put_host_in_downtime(username=nagios_user, password=nagios_password,
                                                  nagios_server=nagios_server, hostname=server_name.split(".")[0],
                                                  minutes_in_downtime=nagios_downtime_duration)
             # Put in a delay to allow nagios time to properly register the down time
             time.sleep(8)
     ssh_connection = HandleSSHConnections()
     ssh_connection.open_ssh(server_name, deployment_parameters[configuration_counter].ssh_user)
     for individual_warfile in warfile_list:
         manifest_found = False
         curl = CurlWarfile(server_name, individual_warfile,
                            tomcat_user=deployment_parameters[configuration_counter].tomcatuser,
                            tomcat_password=deployment_parameters[configuration_counter].tomcatpass,
                            tomcat_port=deployment_parameters[configuration_counter].tomcat_port,
                            tomcat_version=deployment_parameters[configuration_counter].tomcat_version)
         remote_warfile = deployment_parameters[configuration_counter].tomcat_directory + os.sep + "webapps" + os.sep + \
                          individual_warfile.split("/")[-1]
         # skip_server is set to true if there is a problem curling warfiles to a given server
         if curl.skip_server:
             break
         else:
             if configuration_counter in already_deployed_warfiles:
Example #13
0
remote_docker_file_sums_dict = {}
docker_service_check_dict = {}
# These may need to be updated occasionally in the event that the default options change
original_docker_file_hashes = \
           {"/etc/sysconfig/docker": "1fe04a24430eaefb751bf720353e730aec5641529f0a3b2567f72e6c63433e8b",
            "/etc/sysconfig/docker-storage": "709dca62ac8150aa280fdb4d49d122d78a6a2f4f46ff3f04fe8d698b7035f3a0",
            "/etc/sysconfig/docker-storage-setup": "bf3e1056e8df0dd4fc170a89ac2358f872a17509efa70a3bc56733a488a1e4b2"}

forward_lookup_dict = {}
reverse_lookup_dict = {}
repo_dict = {}
package_updates_available_dict = {}
subscription_dict = {}
ose_package_installed_dict = {}
ose_package_not_installed_dict = {}
ssh_connection = HandleSSHConnections()
selinux_dict = {}
ose_repos = [
    "rhel-7-server-rpms", "rhel-7-server-extras-rpms",
    "rhel-7-server-ose-3.1-rpms"
]
ose_required_packages_list = [
    "wget", "git", "net-tools", "bind-utils", "iptables-services",
    "bridge-utils", "bash-completion", "atomic-openshift-utils", "docker"
]

# OptionParser's first argument is what is passed in on the command line.
# the second argument 'dest=' is the variable which holds the value. options.show_sha_sums holds the value for
# --show-sha-sums.
# The final arugment is the text that is printed out when the OptionParser help function is called
parser = OptionParser()