forked from aliyun/aliyun-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliyun-common
executable file
·33 lines (30 loc) · 1.43 KB
/
aliyun-common
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
#!/bin/bash
#set -x
function lookup_any()
{
instanceId=${1}
for region in $(cat ./region_ids);
do
aliyun Ecs DescribeInstances --RegionId $region --PageSize 100 |jq '.Instances.Instance'| jq '.[] | select(.InstanceId == "'$instanceId'" or .PublicIpAddress.IpAddress[0] == "'$instanceId'" or .NetworkInterfaces.NetworkInterface[0].PrimaryIpAddress == "'$instanceId'" or .HostName == "'$instanceId'")' > .instance_temp
if [[ $(cat .instance_temp | wc -l) -gt 0 ]];
then
mv .instance_temp .instance_found
[[ $DEBUG == true ]] && cat .instance_found
export instance_id=$(jq -r '.InstanceId' .instance_found)
export region_id=$(jq -r '.RegionId' .instance_found)
export image_id=$(jq -r '.ImageId' .instance_found)
export instance_status=$(jq -r '.Status' .instance_found)
jq -r '["ID ", "Hostname ", "Public IP", "Internal IP", "ZoneId", " Status", "ImageId"], ["---------------------", "---------------------", "-------------", "-------------", "-------------", "------", "------------------"], ( [.InstanceId, .HostName, .PublicIpAddress.IpAddress[0], .NetworkInterfaces.NetworkInterface[0].PrimaryIpAddress, .ZoneId, .Status, .ImageId]) | @tsv' .instance_found
break
fi
done
}
function wait_until()
{
expected_status=${1-Running}
while [[ $instance_status != $expected_status ]];
do
sleep 5
lookup_any $instance_id
done
}