epcim of DevOps
1/13/2017 - 6:07 PM

query openstack nova instances

query openstack nova instances

# CTL
source keystonerc;
function nova-show-vm() { 
nova show $(nova list --all-tenants |grep $@ | tee /dev/fd/2 |awk '{print $2}')
};

function instance-placement() { 
nova-show-vm $1 |egrep  "hypervisor|network| id" | awk  -F"|" '{print $3}'\
  | sed "s,\s*,,g" | xargs
};


# CFG
function instance-check() {
 salt $1 cmd.run "tail -n30 /var/lib/nova/instances/*-*-*/console.log;";
 salt $1 cmd.run "virsh list --all";
 ping -c3 $2;
}
instance-check $(instance-placement $IP)



function getip () 
{ 
    getent hosts $1 | awk '{ print $1 }'
}

nova-show-vm-cache() {
  TEMPCAHCE=/tmp/nova-vm-list.$(date "+%Y-%m-%d-%h")
  test -e $TEMPCAHCE || {
    nova-manage vm list | column -t > $TEMPCAHCE
  }
  egrep $@ "$TEMPCAHCE" | egrep -v deleted | awk '{print $7,$2,$1,$4}'
}

  
  
  
## associate Floating IPs by instance name
declare PORTS=($(nova list  --all-tenants|egrep -i '(gb-ss-vos-node-iyvooqnuxvqj-4jqzkrgqbcbx-r3ey62hav3ge|gb-ss-vos-node-iyvooqnuxvqj-zi3eglyjffrd-n7xcuwcgkjlg|gb-ss-.....)' |awk -F"|" '{print $2}' | xargs neutron port-list --device-id  |awk -F"|" '{print $2}'|xargs))
declare -a FFIPS=($(nova floating-ip-list |egrep egress |grep '| -                                    | -'|awk -F"|" '{print $2}'|xargs))
for i in $(seq 1 ${#PORTS[@]}); do echo neutron floatingip-associate ${FFIPS[$i]} ${PORTS[$i]};done


## get logs from stack
nova console-log $(openstack stack resource show 87dd6864-f004-467f-9725-39e67e59dbd2 mcp_salt_master -f json | jq -cr '.attributes.instance')