#/bin/sh # # A utility to take some of the manual labor out of the non-Vagrant # based chef-bcpc bringup procedure on VMs # echo "this is not working yet" exit # bash imports source ./virtualbox_env.sh global UP := $[$VBM showvminfo bcpc-bootstrap | grep -i State] if [[ ! $UP =~ running ]] { # This just doesn't seem to work # $VBM modifyvm bcpc-bootstrap --nic1 bridged --bridgeadapter1 en0 $VBM startvm bcpc-bootstrap sleep 30 } else { echo "bcpc-bootstrap is running" } ./vm-to-cluster.sh bloomberg.com while read HOSTNAME MACADDR IPADDR ILOIPADDR DOMAIN ROLE { if [[ $HOSTNAME = "end" ]] { break; } if [[ "$HOSTNAME" = bcpc-bootstrap ]] { global NATADDR := $IPADDR echo "bcpc-bootstrap is currently at (NAT) address $NATADDR" break } } < cluster.txt if [[ -z $NATADDR ]] { echo "Couldn't find the bootstrap node's IP address" exit 1 } else { for ATTEMPT in [A B C D E F G] { if [[ "$1" ]] { global HOST := $1 } else { global HOST := $NATADDR } if hash fping !2 >/dev/null { global UP := $[fping -aq $(HOST) | awk '{print $1}] } else { global UP := $[ping -c 1 $(HOST) | grep ttl |cut -f4 -d" " | cut -f1 -d":] } if [[ -z "$UP" ]] { echo "VM is not up yet or is unreachable" if [[ $ATTEMPT = G ]] { echo "Maybe machine needs rework. Rerun this when it's up" exit 1 } sleep 5 } else { break } } global SSHCOMMON := '"-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o VerifyHostKeyDNS=no'" global SSHCMD := ""ssh $SSHCOMMON"" global SCPCMD := ""scp $SSHCOMMON"" if hash sshpass !2 >/dev/null { global EDITED := $[sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S grep 'Static interfaces' /etc/network/interfaces] echo "EDITED = $EDITED" } else { echo "please install sshpass" exit 1 } if [[ "$EDITED" =~ "Static interfaces" ]] { echo "interfaces file appears adjusted already" exit 0 } else { echo "copy interfaces file fragment..." sshpass -p ubuntu $SCPCMD -p "vm-eth.txt" "ubuntu@$HOST:/tmp" echo "add the network definitions" # can't simply cat file >> file when updating the interfaces, due to the permissions # rename does work to atomically replace the file sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S cp -p /etc/network/interfaces /etc/network/interfaces.orig" sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S cat /etc/network/interfaces /tmp/vm-eth.txt > /tmp/combined.txt" sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S mv /tmp/combined.txt /etc/network/interfaces" echo "restart networking" sshpass -p ubuntu $SSHCMD -t ubuntu@$HOST "echo ubuntu | sudo -S service networking restart" } } (CommandList children: [ (C {(echo)} {(DQ ("this is not working yet"))}) (C {(exit)}) (C {(source)} {(./virtualbox_env.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UP) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {($ VSub_Name "$VBM")} {(showvminfo)} {(bcpc-bootstrap)}) (C {(grep)} {(-i)} {(State)}) ] negated: False ) ] ) left_token: spids: [34 48] ) } spids: [33] ) ] spids: [33] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolBinary op_id: BoolBinary_EqualTilde left: {($ VSub_Name "$UP")} right: {(running)} ) ) ) terminator: ) ] action: [(C {($ VSub_Name "$VBM")} {(startvm)} {(bcpc-bootstrap)}) (C {(sleep)} {(30)})] spids: [-1 65] ) ] else_action: [(C {(echo)} {(DQ ("bcpc-bootstrap is running"))})] spids: [86 95] ) (C {(./vm-to-cluster.sh)} {(bloomberg.com)}) (While cond: [ (Sentence child: (C {(read)} {(HOSTNAME)} {(MACADDR)} {(IPADDR)} {(ILOIPADDR)} {(DOMAIN)} {(ROLE)}) terminator: ) ] body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobEqual left: {($ VSub_Name "$HOSTNAME")} right: {(DQ (end))} ) ) terminator: ) ] action: [ (Sentence child: (ControlFlow token:) terminator: ) ] spids: [-1 136] ) ] spids: [-1 143] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobEqual left: {(DQ ($ VSub_Name "$HOSTNAME"))} right: {(bcpc-bootstrap)} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NATADDR) op: Equal rhs: {($ VSub_Name "$IPADDR")} spids: [164] ) ] spids: [164] ) (C {(echo)} { (DQ ("bcpc-bootstrap is currently at (NAT) address ") ($ VSub_Name "$NATADDR")) } ) (ControlFlow token:) ] spids: [-1 161] ) ] spids: [-1 179] ) ] spids: [118 181] ) redirects: [(Redir op_id:Redir_Less fd:-1 arg_word:{(cluster.txt)} spids:[183])] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_z child:{($ VSub_Name "$NATADDR")})) terminator: ) ] action: [ (C {(echo)} {(DQ ("Couldn't find the bootstrap node's IP address"))}) (C {(exit)} {(1)}) ] spids: [-1 198] ) ] else_action: [ (ForEach iter_name: ATTEMPT iter_words: [{(A)} {(B)} {(C)} {(D)} {(E)} {(F)} {(G)}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(WordTest w:{(DQ ($ VSub_Number "$1"))})) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOST) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [254] ) ] spids: [254] ) ] spids: [-1 251] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOST) op: Equal rhs: {(DQ ($ VSub_Name "$NATADDR"))} spids: [263] ) ] spids: [263] ) ] spids: [260 269] ) (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(hash)} {(fping)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [278] ) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UP) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(fping)} {(-aq)} {(${ VSub_Name HOST)}) (C {(awk)} {(SQ <"{print $1}">)}) ] negated: False ) ] ) left_token: spids: [286 302] ) } spids: [285] ) ] spids: [285] ) ] spids: [-1 282] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UP) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(ping)} {(-c)} {(1)} {(${ VSub_Name HOST)}) (C {(grep)} {(ttl)}) (C {(cut)} {(-f4)} {(-d) (DQ (" "))}) (C {(cut)} {(-f1)} {(-d) (DQ (":"))}) ] negated: False ) ] ) left_token: spids: [309 346] ) } spids: [308] ) ] spids: [308] ) ] spids: [305 349] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{(DQ ($ VSub_Name "$UP"))}) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("VM is not up yet or is unreachable"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobEqual left: {($ VSub_Name "$ATTEMPT")} right: {(G)} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Maybe machine needs rework. Rerun this when it's up"))} ) (C {(exit)} {(1)}) ] spids: [-1 388] ) ] spids: [-1 403] ) (C {(sleep)} {(5)}) ] spids: [-1 365] ) ] else_action: [(ControlFlow token:)] spids: [411 417] ) ] spids: [237 420] ) spids: [221 235] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SSHCOMMON) op: Equal rhs: { (DQ ( "-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o VerifyHostKeyDNS=no" ) ) } spids: [423] ) ] spids: [423] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SSHCMD) op: Equal rhs: {(DQ ("ssh ") ($ VSub_Name "$SSHCOMMON"))} spids: [429] ) ] spids: [429] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SCPCMD) op: Equal rhs: {(DQ ("scp ") ($ VSub_Name "$SSHCOMMON"))} spids: [436] ) ] spids: [436] ) (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(hash)} {(sshpass)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[449])] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:EDITED) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(sshpass)} {(-p)} {(ubuntu)} {($ VSub_Name "$SSHCMD")} {(-t)} {(ubuntu) (Lit_Other "@") ($ VSub_Name "$HOST")} {(DQ ("echo ubuntu | sudo -S grep 'Static interfaces' /etc/network/interfaces"))} ) ] ) left_token: spids: [457 475] ) } spids: [456] ) ] spids: [456] ) (C {(echo)} {(DQ ("EDITED = ") ($ VSub_Name "$EDITED"))}) ] spids: [-1 453] ) ] else_action: [(C {(echo)} {(DQ ("please install sshpass"))}) (C {(exit)} {(1)})] spids: [486 501] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_EqualTilde left: {(DQ ($ VSub_Name "$EDITED"))} right: {(DQ ("Static interfaces"))} ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("interfaces file appears adjusted already"))}) (C {(exit)} {(0)}) ] spids: [-1 521] ) ] else_action: [ (C {(echo)} {(DQ ("copy interfaces file fragment..."))}) (C {(sshpass)} {(-p)} {(ubuntu)} {($ VSub_Name "$SCPCMD")} {(-p)} {(DQ (vm-eth.txt))} {(DQ ("ubuntu@") ($ VSub_Name "$HOST") (":/tmp"))} ) (C {(echo)} {(DQ ("add the network definitions"))}) (C {(sshpass)} {(-p)} {(ubuntu)} {($ VSub_Name "$SSHCMD")} {(-t)} {(ubuntu) (Lit_Other "@") ($ VSub_Name "$HOST")} {(DQ ("echo ubuntu | sudo -S cp -p /etc/network/interfaces /etc/network/interfaces.orig"))} ) (C {(sshpass)} {(-p)} {(ubuntu)} {($ VSub_Name "$SSHCMD")} {(-t)} {(ubuntu) (Lit_Other "@") ($ VSub_Name "$HOST")} {(DQ ("echo ubuntu | sudo -S cat /etc/network/interfaces /tmp/vm-eth.txt > /tmp/combined.txt"))} ) (C {(sshpass)} {(-p)} {(ubuntu)} {($ VSub_Name "$SSHCMD")} {(-t)} {(ubuntu) (Lit_Other "@") ($ VSub_Name "$HOST")} {(DQ ("echo ubuntu | sudo -S mv /tmp/combined.txt /etc/network/interfaces"))} ) (C {(echo)} {(DQ ("restart networking"))}) (C {(sshpass)} {(-p)} {(ubuntu)} {($ VSub_Name "$SSHCMD")} {(-t)} {(ubuntu) (Lit_Other "@") ($ VSub_Name "$HOST")} {(DQ ("echo ubuntu | sudo -S service networking restart"))} ) ] spids: [536 665] ) ] spids: [212 667] ) ] )