3 from opnfv.deployment import factory
7 parser = argparse.ArgumentParser(description='OPNFV POD Info Generator')
9 parser.add_argument("-t", "--INSTALLER_TYPE", help="Give INSTALLER_TYPE")
10 parser.add_argument("-i", "--INSTALLER_IP", help="Give INSTALLER_IP")
11 parser.add_argument("-u", "--user", help="Give username of this pod")
12 parser.add_argument("-k", "--key", help="Give key file of the user")
13 parser.add_argument("-p", "--password", help="Give password of the user")
14 parser.add_argument("-f", "--filepath", help="Give dest path of output file")
15 parser.add_argument("-s", "--sshkey", default="/root/.ssh/id_rsa",
16 help="Give the path for ssh key")
17 args = parser.parse_args()
22 Check all the CLI inputs. Must give INSTALLER_TYPE, INSTALLER_IP, user
23 and filepath of the output file.
24 Need to give key or password.
26 if not args.INSTALLER_TYPE or not args.INSTALLER_IP or not args.user:
27 print("INSTALLER_TYPE, INSTALLER_IP and user are all needed.")
29 if not args.key and not args.password:
30 print("key and password are all None. At least providing one.")
33 print("Must give the dest path of the output file.")
40 Get handler of the nodes info with key file.
42 return factory.Factory.get_handler(args.INSTALLER_TYPE, args.INSTALLER_IP,
43 args.user, pkey_file=args.key)
46 def get_with_passwd():
48 Get handler of the nodes info with password.
50 return factory.Factory.get_handler(args.INSTALLER_TYPE, args.INSTALLER_IP,
51 args.user, installer_pwd=args.password)
54 def create_file(handler, INSTALLER_TYPE):
56 Create the yaml file of nodes info.
57 As Yardstick required, node name must be node1, node2, ... and node1 must
59 Compass uses password of each node.
60 Other installers use key file of each node.
62 if not os.path.exists(os.path.dirname(args.filepath)):
63 os.makedirs(os.path.dirname(args.filepath))
68 if INSTALLER_TYPE == 'apex':
72 if node.roles[0].lower() == "controller":
73 node_info = {'name': "node%s" % index, 'role': node.roles[0],
74 'ip': node.ip, 'user': user}
75 node_list.append(node_info)
78 node_info = {'name': node.name, 'role': 'unknown', 'ip': node.ip,
80 node_list.append(node_info)
83 if node.roles[0].lower() == "compute":
84 node_info = {'name': "node%s" % index, 'role': node.roles[0],
85 'ip': node.ip, 'user': user}
86 node_list.append(node_info)
89 node_info = {'name': node.name, 'role': 'unknown', 'ip': node.ip,
91 node_list.append(node_info)
92 if args.INSTALLER_TYPE == 'compass':
93 for item in node_list:
94 item['password'] = 'root'
95 elif args.INSTALLER_TYPE == 'daisy':
96 for item in node_list:
97 item['key_filename'] = '/root/.ssh/id_dsa'
99 for item in node_list:
100 item['key_filename'] = args.sshkey
101 data = {'nodes': node_list}
102 with open(args.filepath, "w") as fw:
107 if not check_params():
110 handler = get_with_key()
112 handler = get_with_passwd()
114 print("Error: failed to get the node's handler.")
116 create_file(handler, args.INSTALLER_TYPE)
119 if __name__ == '__main__':