<commit_before>#!/usr/bin/env bash

. /vagrant/vsim.conf

if [ -n "$1" ]; then
  NODE_MGMT_IP=$1
fi

# Please use vsim.conf for configuration instead of this file
CLUSTER_BASE_LICENSE=$CLUSTER_BASE_LICENSE
NODE_MGMT_IP=${NODE_MGMT_IP:-10.0.155.3}
CLUSTER_USERNAME=${CLUSTER_USERNAME:-vagrant}
PASSWORD=${PASSWORD:-<PASSWORD>}
API_ENDPOINT="http://admin@$NODE_MGMT_IP/servlets/netapp.servlets.admin.XMLrequest_filer"

sudo iptables -t nat -D PREROUTING -i eth1 -p tcp --dport 22222 -j REDIRECT --to-port 22 

sudo echo "1" > /proc/sys/net/ipv4/ip_forward

sudo iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 22222 -j DNAT --to-destination $NODE_MGMT_IP:22

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

sudo iptables-save > /dev/null

echo "Awaiting Pre-Cluster mode. This can take a few minutes ..."
rc=1; 
while [ $rc -ne 0 ]; do 
  /usr/bin/wget --no-proxy $NODE_MGMT_IP/na_admin > /dev/null 2>&1
  rc=$?
  sleep 1  
  echo -n '.' 
done
echo "Pre-Cluster mode available"

read -d '' CLUSTER_SETUP << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <cluster-create>
    <license>$CLUSTER_BASE_LICENSE</license>
    <cluster-name>VSIM</cluster-name>
  </cluster-create>
</netapp>
EOF

read -d '' SSH_ENABLE << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <security-login-create>
    <vserver>VSIM</vserver>
    <user-name>$CLUSTER_USERNAME</user-name>
    <application>ssh</application>
    <authentication-method>password</authentication-method>
    <role-name>admin</role-name>
    <password>$PASSWORD</password>
  </security-login-create>
</netapp>
EOF

read -d '' SSH_ENABLE_PUBLICKEY << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <security-login-create>
    <vserver>VSIM</vserver>
    <user-name>$CLUSTER_USERNAME</user-name>
    <application>ssh</application>
    <authentication-method>publickey</authentication-method>
    <role-name>admin</role-name>
  </security-login-create>
</netapp>
EOF

read -d '' DISK_ASSIGN << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <disk-sanown-assign>
    <all>true</all>
    <node-name>VSIM-01</node-name>
  </disk-sanown-assign>
</netapp>
EOF

read -d '' ADD_LICENSES << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <license-v2-add>
    <codes>
      <license-code-v2>$LICENSES</license-code-v2>
    </codes>
  </license-v2-add>
</netapp>
EOF

read -d '' AGGR_CREATE << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <aggr-create>
    <aggregate>aggr1</aggregate>
    <disk-count>25</disk-count>
  </aggr-create>
</netapp>
EOF

sleep 5
echo "Starting cluster setup on $NODE_MGMT_IP"
/usr/bin/curl -X POST -d "$CLUSTER_SETUP"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 25
echo "Enabling SSH access for $CLUSTER_USERNAME"
/usr/bin/curl -X POST -d "$SSH_ENABLE"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 10
echo "Enabling SSH public key auth"
/usr/bin/curl -X POST -d "$SSH_ENABLE_PUBLICKEY" -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 5
echo "Assigning disks"
/usr/bin/curl -X POST -d "$DISK_ASSIGN"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 20

if [ -n "$LICENSES" ]; then
  echo "Adding additional licenses $LICENSES"
  /usr/bin/curl -X POST -d "$ADD_LICENSES" -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
  sleep 5
fi

echo "Creating additional aggregate"
/usr/bin/curl -X POST -d "$AGGR_CREATE"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 15
echo "Adding public key for $CLUSTER_USERNAME"
sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $CLUSTER_USERNAME@$NODE_MGMT_IP -t 'security login publickey create -username vagrant -index 0 -publickey "ssh-rsa <KEY>' 2>/dev/null

echo "Running additional commands"
while read -u 3 p; do
  echo $p
  sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $CLUSTER_USERNAME@$NODE_MGMT_IP -t "$p" 2>/dev/null
  sleep 10
done 3</vagrant/vsim.cmds

echo "SSH is available at $NODE_MGMT_IP. username $CLUSTER_USERNAME, password $PASSWORD"
echo "VSim ready. Run 'vagrant ssh vsim' for console access."<commit_msg>Fixing permissions for ip_forward<commit_after>#!/usr/bin/env bash

. /vagrant/vsim.conf

if [ -n "$1" ]; then
  NODE_MGMT_IP=$1
fi

# Please use vsim.conf for configuration instead of this file
CLUSTER_BASE_LICENSE=$CLUSTER_BASE_LICENSE
NODE_MGMT_IP=${NODE_MGMT_IP:-10.0.155.3}
CLUSTER_USERNAME=${CLUSTER_USERNAME:-vagrant}
PASSWORD=${PASSWORD:-<PASSWORD>}
API_ENDPOINT="http://admin@$NODE_MGMT_IP/servlets/netapp.servlets.admin.XMLrequest_filer"

sudo iptables -t nat -D PREROUTING -i eth1 -p tcp --dport 22222 -j REDIRECT --to-port 22 

sudo sh -c 'echo "1" > /proc/sys/net/ipv4/ip_forward'

sudo iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 22222 -j DNAT --to-destination $NODE_MGMT_IP:22

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

sudo iptables-save > /dev/null

echo "Awaiting Pre-Cluster mode. This can take a few minutes ..."
rc=1; 
while [ $rc -ne 0 ]; do 
  /usr/bin/wget --no-proxy $NODE_MGMT_IP/na_admin > /dev/null 2>&1
  rc=$?
  sleep 1  
  echo -n '.' 
done
echo "Pre-Cluster mode available"

read -d '' CLUSTER_SETUP << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <cluster-create>
    <license>$CLUSTER_BASE_LICENSE</license>
    <cluster-name>VSIM</cluster-name>
  </cluster-create>
</netapp>
EOF

read -d '' SSH_ENABLE << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <security-login-create>
    <vserver>VSIM</vserver>
    <user-name>$CLUSTER_USERNAME</user-name>
    <application>ssh</application>
    <authentication-method>password</authentication-method>
    <role-name>admin</role-name>
    <password><PASSWORD></password>
  </security-login-create>
</netapp>
EOF

read -d '' SSH_ENABLE_PUBLICKEY << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <security-login-create>
    <vserver>VSIM</vserver>
    <user-name>$CLUSTER_USERNAME</user-name>
    <application>ssh</application>
    <authentication-method>publickey</authentication-method>
    <role-name>admin</role-name>
  </security-login-create>
</netapp>
EOF

read -d '' DISK_ASSIGN << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <disk-sanown-assign>
    <all>true</all>
    <node-name>VSIM-01</node-name>
  </disk-sanown-assign>
</netapp>
EOF

read -d '' ADD_LICENSES << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <license-v2-add>
    <codes>
      <license-code-v2>$LICENSES</license-code-v2>
    </codes>
  </license-v2-add>
</netapp>
EOF

read -d '' AGGR_CREATE << EOF
<?xml version="1.0" encoding="UTF-8"?>

<netapp xmlns="http://www.netapp.com/filer/admin" version="1.21">
  <aggr-create>
    <aggregate>aggr1</aggregate>
    <disk-count>25</disk-count>
  </aggr-create>
</netapp>
EOF

sleep 5
echo "Starting cluster setup on $NODE_MGMT_IP"
/usr/bin/curl -X POST -d "$CLUSTER_SETUP"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 25
echo "Enabling SSH access for $CLUSTER_USERNAME"
/usr/bin/curl -X POST -d "$SSH_ENABLE"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 10
echo "Enabling SSH public key auth"
/usr/bin/curl -X POST -d "$SSH_ENABLE_PUBLICKEY" -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 5
echo "Assigning disks"
/usr/bin/curl -X POST -d "$DISK_ASSIGN"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 20

if [ -n "$LICENSES" ]; then
  echo "Adding additional licenses $LICENSES"
  /usr/bin/curl -X POST -d "$ADD_LICENSES" -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
  sleep 5
fi

echo "Creating additional aggregate"
/usr/bin/curl -X POST -d "$AGGR_CREATE"  -sS --noproxy $NODE_MGMT_IP $API_ENDPOINT
sleep 15
echo "Adding public key for $CLUSTER_USERNAME"
sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $CLUSTER_USERNAME@$NODE_MGMT_IP -t 'security login publickey create -username vagrant -index 0 -publickey "ssh-rsa <KEY>' 2>/dev/null

echo "Running additional commands"
while read -u 3 p; do
  echo $p
  sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $CLUSTER_USERNAME@$NODE_MGMT_IP -t "$p" 2>/dev/null
  sleep 10
done 3</vagrant/vsim.cmds

echo "SSH is available at $NODE_MGMT_IP. username $CLUSTER_USERNAME, password $PASSWORD"
echo "VSim ready. Run 'vagrant ssh vsim' for console access."
{'fraction_non_alphanumeric': 0.15752558353455215, 'fraction_numerical': 0.021846613774864895, 'mean_word_length': 4.137625516834023, 'pattern_counts': {'":': 0, '<': 170, '<?xml version=': 12, '>': 156, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 24}, 'pii_count': 2, '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': '3117912', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3421, 'n_words': 764}