-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy_azure.sh
executable file
·85 lines (72 loc) · 2.03 KB
/
deploy_azure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Call with
# paper/deploy_azure.sh --ip=51.140.32.47
# or, with options:
# paper/deploy_azure.sh --ip=51.140.32.47 --user=name -k=~/.ssh/azure
KEY="~/.ssh/azure" # SSH key
RG=PB # Resource Group
#!/bin/bash
for i in "$@"
do
case $i in
-k=*|--key=*)
KEY="${i#*=}"
;;
-i=*|--ip=*)
IP="${i#*=}"
;;
-r=*|--rg=*)
RG="${i#*=}"
;;
-u=*|--user=*)
USER="${i#*=}"
;;
*)
# unknown option
;;
esac
done
if [ -z "$IP" ]; then
NEW=true
else
NEW=false
fi
echo KEY = ${KEY}
echo IP = ${IP}
echo NEW = ${NEW}
echo USER = ${USER}
echo RG = ${RG}
KEY_FLAG="-i $KEY"
echo KEYFLAG = ${KEY_FLAG}
if $NEW; then
# Create new virtual machine
az_cmd="az vm create
--resource-group ${RG}
--name MM
--image microsoft-dsvm:linux-data-science-vm-ubuntu:linuxdsvmubuntu:19.04.00
--size Standard_NV6_Promo
--admin-username ${USER}
--ssh-key-value ${KEY}.pub"
# Parse the result to get the IP address
result=$($az_cmd)
echo $result
ip_line=$(echo $result | grep -o '"publicIpAddress": "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"')
echo $ip_line
IP=$(echo $ip_line | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
# Wait a bit before connecting
sleep 60
fi
# Copy local files
ssh -o StrictHostKeyChecking=no ${KEY_FLAG} ${USER}@${IP} "rm -r repro2020; mkdir repro2020"
scp ${KEY_FLAG} -r * ${USER}@${IP}:repro2020
# reset the GPU
ssh ${KEY_FLAG} ${USER}@${IP} "sudo nvidia-smi -rac"
# This heredoc activates conda
ssh ${KEY_FLAG} ${USER}@${IP} bash -l <<HERE
cd repro2020
cp /data/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/training.py training.py_backup
cp /data/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/training_arrays.py training_arrays.py_backup
cp training.py /data/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/
cp training_arrays.py /data/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/
conda activate py35
python control.py
HERE