MIN_NUM_ARGS = 4

def printUsage():
    print "python create_cluster.py <cluster_name> <key_pair> <config_file_path>"

if (len(sys.argv) < MIN_NUM_ARGS):
    print "Wrong number of arguments"
    printUsage()
    exit(1)

cluster_name = sys.argv[1]
key_pair = sys.argv[2]
config_file_path = sys.argv[3]

user = raw_input('OpenStack User: '******'OpenStack Password: '******'project_name')
project_id = json_parser.get('project_id')
main_ip = json_parser.get('main_ip')
connector = ConnectionGetter(user, key, project_name, project_id, main_ip)

keystone_util = UtilKeystone(connector.keystone())
token_ref_id = keystone_util.getTokenRef(user, key, project_name).id
sahara_util = UtilSahara(connector.sahara(token_ref_id))

cluster_id = sahara_util.createClusterHadoop(cluster_name, image_id, template_id, net_id,key_pair)
print cluster_id

keystone_util = UtilKeystone(connector.keystone())
token_ref_id = keystone_util.getTokenRef(user, password, project_name).id
sahara_util = UtilSahara(connector.sahara(token_ref_id))

#----------------------- EXECUTING EXPERIMENT ------------------------------

for cluster_template in json_parser.get('cluster_templates'):
	
	cluster_template_id = cluster_template['id']
	cluster_size = cluster_template['n_slaves']
	cluster_name = DEF_CLUSTER_NAME + '-' +  str(cluster_size)

	######### CREATING CLUSTER #############
	try:
		cluster_id = sahara_util.createClusterHadoop(cluster_name, image_id, cluster_template_id, net_id, private_keypair_name)
		#cluster_id = "182afd54-e621-438c-977d-a7a543325714"
	except RuntimeError as err:
		print err.args
		break
		
	######### CONFIGURING CLUSTER ##########
	instancesIps = sahara_util.get_instances_ips(cluster_id)
	configureInstances(instancesIps, public_keypair_path, private_keypair_path)
	copyExecFileToInstances(exec_local_path, instancesIps, private_keypair_path)

	######### CREATING DATASOURCES ##########
	output_ds_id = createOutputDataSource(DEF_OUTPUT_CONTAINER_NAME,user,password)

	######### RUNNING JOB ##########
	for i in xrange(number_execs):