sh 查询openstack nova实例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 查询openstack nova实例相关的知识,希望对你有一定的参考价值。


cat <<-EOF > token-request.json
{
    "auth": {
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                    "domain": {
                        "name": "$OS_USER_DOMAIN_NAME"
                    },
                    "name": "$OS_USERNAME",
                    "password": "$OS_PASSWORD"
                }
            }
        }
    }
}
EOF
source .keystonerc
export TOKEN=$(envsubst <token-request.json | curl -si -d @/dev/stdin -H "Content-type: application/json" $OS_AUTH_URL/auth/tokens | awk '/X-Subject-Token/ {print $2}')
# Prereq.
#ubuntu:  
apt-get install -y direnv python-pip python-pipenv

# download or set your keystone/openrc in .envrc
OS_USERNAME=XYZ 
OS_PASSWORD=XYZ 
cat <<-EOF > ./.envrc
# rc
export OS_AUTH_URL=https://lab.mirantis.com:5000/v3
export OS_PROJECT_ID=${OS_PROJECT_ID:-52536594831e4071b3e47fc2732235c9}
export OS_PROJECT_NAME="${OS_PROJECT:-upgrade-demo-1}"
export OS_USER_DOMAIN_NAME="default"
export OS_USERNAME=${OS_USERNAME}
export OS_PASSWORD=${OS_PASSWORD}
export OS_REGION_NAME="RegionOne"
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
# use virtualenv
pipenv --py && pipenv shell
EOF

#Install openstack client libs in isolated environment:
## first time only 
direnv allow .
pipenv --three install python-openstackclient

## later
pipenv shell
openstack project list

openstack-inventory --list > inventory.json

# inspect with
jq -r '.[]|"\(.location.region_name)@\(.location.project.name)@\(.key_name)@\(.properties."OS-EXT-SRV-ATTR:host")/\(.properties."OS-EXT-SRV-ATTR:instance_name")/\(.name|split(".")[0]) (\(.properties."OS-EXT-STS:vm_state"))"' inventory.json |column -t -s '@' | sort 

RegionOne  upgrade-demo-1  lmercl-other-1    cmp006/instance-00000c5b/cfg01 (active)
RegionOne  upgrade-demo-1  lmercl-test-2     cmp002/instance-00000c49/kvm06 (active)
RegionOne  upgrade-demo-1  lmercl-test-2     cmp003/instance-00000c4f/kvm02 (active)
RegionOne  upgrade-demo-1  pcizinsky-test11  cmp001/instance-00000be6/kvm03 (active)
RegionOne  upgrade-demo-1  pcizinsky-test11  cmp001/instance-00000be9/kvm01 (active)
# 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
};

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}'
}


# 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)
  
  
  
  
## 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


  

以上是关于sh 查询openstack nova实例的主要内容,如果未能解决你的问题,请参考以下文章

##5.1 Nova控制节点--openstack

OpenStack 安装:nova服务

##5.2 Nova计算节点--openstack

openstack之nova

如何删除 OpenStack Nova 僵尸实例

在OpenStack环境中创建一个VM实例