Skip to content

Instantly share code, notes, and snippets.

@zancas
Last active February 22, 2017 17:58
Show Gist options
  • Save zancas/810bc3b5e1c0f8c5818e50eb1a2d15dc to your computer and use it in GitHub Desktop.
Save zancas/810bc3b5e1c0f8c5818e50eb1a2d15dc to your computer and use it in GitHub Desktop.
from pprint import pprint as pp
def _get_functions(funcsfilename):
'''return a list the bash functions in the codebase'''
return open(funcsfilename).readlines()
def _populate_function_set(functions):
'''create set of declare-derived "function" strings'''
func_set = set()
current_function = ''
for line in functions:
current_function += line
if line.startswith('}'):
#end of function
func_set.add((current_function,))
current_function = ''
return func_set
ref_func_list = _get_functions('refactored_functions.txt')
ref_function_set = _populate_function_set(ref_func_list)
mono_func_list = _get_functions('monolithic_functions.txt')
mono_function_set = _populate_function_set(mono_func_list)
pp(mono_function_set & ref_function_set)
#! /bin/bash
source monolithic
declare -F | awk '{print $3}' > monolithic_functionnames.txt
declare -f > monolithic_functions.txt
#! /bin/bash
source os-functions/openstack-datasource.sh
source os-functions/openstack-network.sh
source os-functions/openstack-license.sh
source os-functions/openstack-ssh.sh
source os-functions/openstack-password.sh
source startup
declare -F | awk '{print $3}' > refactored_functionnames.txt
declare -f > refactored_functions.txt
python ./compare_function_sets.py
set([('cleanup_user_data () \n{ \n [[ $OS_USER_DATA_CLEANUP == true ]] && rm -f $OS_USER_DATA_TMP_FILE;\n [[ $OS_META_DATA_CLEANUP == true ]] && rm -f $OS_META_DATA_TMP_FILE\n}\n',),
('generate_sha512_passwd_hash () \n{ \n salt=$(openssl rand -base64 8);\n echo -n $(perl -e "print crypt(q[$1], \\"\\\\\\$6\\\\\\$$salt\\\\\\$\\")")\n}\n',),
('get_json_value () \n{ \n echo -n $(perl -MJSON -ne "\\$value = decode_json(\\$_)->$1; \\$value =~ s/([^a-zA-Z0-9])/\\$1/g; print \\$value" $2)\n}\n',),
("get_supported_modules () \n{ \n echo -n $(tmsh list sys provision one-line | awk '/^sys/ { print $3 }')\n}\n",),
('get_user_data_firstboot_cmds () \n{ \n echo -n $(perl -MJSON -ne "print join(\';;\', @{decode_json(\\$_)->{bigip}{firstboot_cmds}})" $OS_USER_DATA_TMP_FILE)\n}\n',),
('get_user_data_network_routes () \n{ \n echo -n $(perl -MJSON -ne "\\$data = decode_json(\\$_); foreach \\$route (@{\\$data->{\'bigip\'}->{\'network\'}->{\'routes\'}}) { print \\$route->{\'destination\'}.\\";\\".\\$route->{\'gateway\'}.\\"|\\"; }" $OS_USER_DATA_TMP_FILE)\n}\n',),
('get_user_data_system_cmds () \n{ \n echo -n $(perl -MJSON -ne "print join(\';;\', @{decode_json(\\$_)->{bigip}{system_cmds}})" $OS_USER_DATA_TMP_FILE)\n}\n',),
('get_user_data_value () \n{ \n echo -n $(get_json_value $1 $OS_USER_DATA_TMP_FILE)\n}\n',),
("is_false () \n{ \n val=$1;\n if [[ ! -n $val ]]; then\n echo 0;\n return 0;\n fi;\n if [[ $(upcase $val) == 'NONE' ]]; then\n echo 0;\n return 0;\n fi;\n if [[ $(upcase $val) == 'FALSE' ]]; then\n echo 0;\n return 0;\n fi;\n if [[ $(upcase $val) == '0' ]]; then\n echo 0;\n return 0;\n fi\n}\n",),
('log () \n{ \n echo "$1" | eval "$LOGGER_CMD"\n}\n',),
('randomize_base_passwords () \n{ \n admin_password=`< /dev/urandom tr -dc A-Z | head -c10`;\n root_password=`< /dev/urandom tr -dc A-Z | head -c10`;\n /usr/bin/passwd admin $admin_password > /dev/null 2>&1;\n /usr/bin/passwd root $root_password > /dev/null 2>&1;\n echo "" >> /dev/kmsg;\n echo "" >> /dev/kmsg;\n echo "########################################################" >> /dev/kmsg;\n echo "# #" >> /dev/kmsg;\n echo "# random root password: $root_password #" >> /dev/kmsg;\n echo "# random admin password: $admin_password #" >> /dev/kmsg;\n echo "# #" >> /dev/kmsg;\n echo "########################################################" >> /dev/kmsg;\n echo "" >> /dev/kmsg;\n echo "" >> /dev/kmsg;\n echo " r: $root_password a: $admin_password" >> /etc/issue;\n echo "" >> /etc/issue\n}\n',),
('restore_issue () \n{ \n cat /etc/issue | head -n 2 > /etc/issue\n}\n',),
('upcase () \n{ \n echo "$1" | tr \'[a-z]\' \'[A-Z]\'\n}\n',)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment