<commit_before>#!/bin/bash

hammer domain create --name "bmc.iaas.intern"
hammer domain info --name "bmc.iaas.intern"
hammer domain create --name "mgmt.iaas.intern"
hammer domain info --name "mgmt.iaas.intern"

hammer subnet create --name "mgmt" \
  --network "172.16.32.0" \
  --mask "255.255.248.0" \
  --gateway "172.16.32.1" \
  --dns-primary "172.16.17.32" \
  --dns-secondary "172.16.58.3"

hammer subnet update --name "mgmt" \
  --domain-ids $(hammer domain list | grep "mgmt.iaas.intern" | head -c1)
hammer subnet update --name "mgmt" \
  --dhcp-id $(hammer proxy list | grep foreman | head -c2)
hammer subnet update --name "mgmt" \
  --tftp-id $(hammer proxy list | grep foreman | head -c2)
hammer subnet update --name "mgmt" \
  --dns-id $(hammer proxy list | grep foreman | head -c2)
hammer subnet info --name "mgmt"
hammer subnet update --name "mgmt" --from 172.16.32.200 --to 172.16.32.250

hammer subnet create --name "bmc" \
  --network "172.16.24.0" \
  --mask "255.255.248.0" \
  --gateway "172.16.24.1" \
  --dns-primary "172.16.17.32" \
  --dns-secondary "172.16.58.3"

hammer subnet update --name "bmc" \
  --domain-ids $(hammer domain list | grep "bmc.iaas.intern" | head -c1)

hammer environment create --name "production"
hammer environment info --name "production"

wget -P /tmp http://folk.uib.no/edpto/provision_openstack.erb
wget -P	/tmp http://folk.uib.no/edpto/provision_kickstart_ifs.erb

hammer template create --name "Kickstart_openstack" --type provision --file /tmp/provision_openstack.erb
hammer template create --name "Kickstart default PXELinux ifs" --type PXELinux --file /tmp/provision_kickstart_ifs.erb

hammer os create --name CentOS --major 7 --minor 0.1406 --description "CentOS 7.0" --family Redhat \
  --architecture-ids 1 \
  --medium-ids $(hammer medium list | grep CentOS | head -c1) \
  --ptable-ids $(hammer partition-table list | grep "Kickstart default" | head -c1) 

hammer template update --name "Kickstart default PXELinux ifs" --operatingsystem-ids 1
hammer template update --name "Kickstart_openstack" --operatingsystem-ids 1

hammer os set-default-template --id 1 \
  --config-template-id $(hammer template list --per-page 10000 | grep "Kickstart_openstack"|cut -d" " -f1) 
hammer os set-default-template --id 1 \
  --config-template-id $(hammer template list --per-page 10000 | grep "Kickstart default PXELinux ifs" | cut -d" " -f1)
hammer os update --id 1 \
  --ptable-ids $(hammer partition-table list --per-page 10000 | grep "Kickstart default" | cut -d" " -f1)

hammer proxy import-classes --environment "production" --id $(hammer proxy list | grep 127 | head -c2) 

# Get our custom provision templates
foreman-rake templates:sync repo="https://github.com/norcams/community-templates.git" branch="norcams"

# Set Safemode_render to true or false - return true or false
settingid=$(echo $(curl -s -S -k -u admin:changeme http://127.0.0.1/api/v2/settings/28/?search="Safemode_render"?page="true") | cut -d ',' -f1 | sed 's/[^0-9]*//g') && myresult=$(curl -s -S -k -u admin:changeme -X PUT -H "Content-Type:application/json" -H "Accept:application/json,version=2" -d "{\"setting\": {\"value\": \"false\"}}" http://127.0.0.1/api/v2/settings/$settingid) && echo "$myresult" | sed -e 's/.*value//g' | tr -dc '[:alnum:]\n\r'

# Deploy new default pxe config to smart proxy
curl -k -u admin:changeme http://127.0.0.1/api/v2/config_templates/build_pxe_default

settingid=$(echo $(curl -s -S -k -u admin:changeme http://127.0.0.1/api/v2/settings/28/?search="Safemode_render"?page="true") | cut -d ',' -f1 | sed 's/[^0-9]*//g') && myresult=$(curl -s -S -k -u admin:changeme -X PUT -H "Content-Type:application/json" -H "Accept:application/json,version=2" -d "{\"setting\": {\"value\": \"true\"}}" http://127.0.0.1/api/v2/settings/$settingid) && echo "$myresult" | sed -e 's/.*value//g' | tr -dc '[:alnum:]\n\r'<commit_msg>Dynamically find id for the safemode_render setting<commit_after>#!/bin/bash

hammer domain create --name "bmc.iaas.intern"
hammer domain info --name "bmc.iaas.intern"
hammer domain create --name "mgmt.iaas.intern"
hammer domain info --name "mgmt.iaas.intern"

hammer subnet create --name "mgmt" \
  --network "172.16.32.0" \
  --mask "255.255.248.0" \
  --gateway "172.16.32.1" \
  --dns-primary "172.16.17.32" \
  --dns-secondary "172.16.58.3"

hammer subnet update --name "mgmt" \
  --domain-ids $(hammer domain list | grep "mgmt.iaas.intern" | head -c1)
hammer subnet update --name "mgmt" \
  --dhcp-id $(hammer proxy list | grep foreman | head -c2)
hammer subnet update --name "mgmt" \
  --tftp-id $(hammer proxy list | grep foreman | head -c2)
hammer subnet update --name "mgmt" \
  --dns-id $(hammer proxy list | grep foreman | head -c2)
hammer subnet info --name "mgmt"
hammer subnet update --name "mgmt" --from 172.16.32.200 --to 172.16.32.250

hammer subnet create --name "bmc" \
  --network "172.16.24.0" \
  --mask "255.255.248.0" \
  --gateway "172.16.24.1" \
  --dns-primary "172.16.17.32" \
  --dns-secondary "172.16.58.3"

hammer subnet update --name "bmc" \
  --domain-ids $(hammer domain list | grep "bmc.iaas.intern" | head -c1)

hammer environment create --name "production"
hammer environment info --name "production"

wget -P /tmp http://folk.uib.no/edpto/provision_openstack.erb
wget -P	/tmp http://folk.uib.no/edpto/provision_kickstart_ifs.erb

hammer template create --name "Kickstart_openstack" --type provision --file /tmp/provision_openstack.erb
hammer template create --name "Kickstart default PXELinux ifs" --type PXELinux --file /tmp/provision_kickstart_ifs.erb

hammer os create --name CentOS --major 7 --minor 0.1406 --description "CentOS 7.0" --family Redhat \
  --architecture-ids 1 \
  --medium-ids $(hammer medium list | grep CentOS | head -c1) \
  --ptable-ids $(hammer partition-table list | grep "Kickstart default" | head -c1) 

hammer template update --name "Kickstart default PXELinux ifs" --operatingsystem-ids 1
hammer template update --name "Kickstart_openstack" --operatingsystem-ids 1

hammer os set-default-template --id 1 \
  --config-template-id $(hammer template list --per-page 10000 | grep "Kickstart_openstack"|cut -d" " -f1) 
hammer os set-default-template --id 1 \
  --config-template-id $(hammer template list --per-page 10000 | grep "Kickstart default PXELinux ifs" | cut -d" " -f1)
hammer os update --id 1 \
  --ptable-ids $(hammer partition-table list --per-page 10000 | grep "Kickstart default" | cut -d" " -f1)

hammer proxy import-classes --environment "production" --id $(hammer proxy list | grep 127 | head -c2) 

# Get our custom provision templates
foreman-rake templates:sync repo="https://github.com/norcams/community-templates.git" branch="norcams"

# Find id for safemode_render
safemode=$(curl -s -S -k -u admin:changeme http://127.0.0.1/api/v2/settings/?search="Safemode_render" | grep id | cut -d ',' -f1 | sed 's/[^0-9]*//g')

# Set Safemode_render to true or false - return true or false
settingid=$(echo $(curl -s -S -k -u admin:changeme http://127.0.0.1/api/v2/settings/$safemode/?search="Safemode_render"?page="true") | cut -d ',' -f1 | sed 's/[^0-9]*//g') && myresult=$(curl -s -S -k -u admin:changeme -X PUT -H "Content-Type:application/json" -H "Accept:application/json,version=2" -d "{\"setting\": {\"value\": \"false\"}}" http://127.0.0.1/api/v2/settings/$settingid) && echo "$myresult" | sed -e 's/.*value//g' | tr -dc '[:alnum:]\n\r'

# Deploy new default pxe config to smart proxy
curl -k -u admin:changeme http://127.0.0.1/api/v2/config_templates/build_pxe_default

settingid=$(echo $(curl -s -S -k -u admin:changeme http://127.0.0.1/api/v2/settings/$safemode/?search="Safemode_render"?page="true") | cut -d ',' -f1 | sed 's/[^0-9]*//g') && myresult=$(curl -s -S -k -u admin:changeme -X PUT -H "Content-Type:application/json" -H "Accept:application/json,version=2" -d "{\"setting\": {\"value\": \"true\"}}" http://127.0.0.1/api/v2/settings/$settingid) && echo "$myresult" | sed -e 's/.*value//g' | tr -dc '[:alnum:]\n\r'
{'fraction_non_alphanumeric': 0.17960921843687375, 'fraction_numerical': 0.049849699398797596, 'mean_word_length': 3.2976318622174383, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 35, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5506297', 'n_tokens_mistral': 3275, 'n_tokens_neox': 2928, 'n_words': 805}