parent
8d389a79e0
commit
adc592c096
@ -1,22 +1,30 @@ |
|||||||
import argparse |
import argparse |
||||||
|
import os |
||||||
import sys |
import sys |
||||||
|
|
||||||
from utils import utils |
from utils import utils |
||||||
|
|
||||||
if __name__ == "__main__": |
if __name__ == "__main__": |
||||||
parser = argparse.ArgumentParser(description='This script helps you to collect public ips') |
parser = argparse.ArgumentParser(description='This script helps you to collect public ips') |
||||||
parser.add_argument('--region', type=str, dest='region_number', |
parser.add_argument('--instance_output', type=str, dest='instance_output', |
||||||
default="4", help="region number") |
default='instance_output.txt', |
||||||
parser.add_argument('--node_name_tag', type=str, |
help='the file contains node_name_tag and region number of created instances.') |
||||||
dest='node_name_tag', default='4-NODE-23-36-01-2018-07-05') |
|
||||||
parser.add_argument('--region_config', type=str, |
parser.add_argument('--region_config', type=str, |
||||||
dest='region_config', default='configuration.txt') |
dest='region_config', default='configuration.txt') |
||||||
parser.add_argument('--file_output', type=str, |
parser.add_argument('--file_output', type=str, |
||||||
dest='file_output', default='raw_ip.txt') |
dest='file_output', default='raw_ip.txt') |
||||||
args = parser.parse_args() |
args = parser.parse_args() |
||||||
|
|
||||||
ip_list = utils.collect_public_ips(args.region_number, args.node_name_tag, args.region_config) |
if not args.instance_output or not args.instance_output or not os.path.isfile(args.instance_output): |
||||||
with open(args.file_output, "w") as fout: |
print "%s or %s are not existed" % (args.file_output, args.instance_output) |
||||||
|
sys.exit(1) |
||||||
|
if args.instance_output: |
||||||
|
with open(args.instance_output, "r") as fin, open(args.file_output, "w") as fout: |
||||||
|
for line in fin.readlines(): |
||||||
|
items = line.split(" ") |
||||||
|
region_number = items[1].strip() |
||||||
|
node_name_tag = items[0].strip() |
||||||
|
ip_list = utils.collect_public_ips(region_number, node_name_tag, args.region_config) |
||||||
for ip in ip_list: |
for ip in ip_list: |
||||||
fout.write(ip + " " + args.node_name_tag + "\n") |
fout.write(ip + " " + node_name_tag + "\n") |
||||||
print "Done writing %s" % args.file_output |
print "Done collecting public ips %s" % args.file_output |
||||||
|
Loading…
Reference in new issue