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

        printUsage()
        exit(1)

clusterId = sys.argv[1]
config_file_path = sys.argv[2]

user = raw_input('OpenStack User: '******'OpenStack Password: '******'exec_local_path')
publicKeyPath = json_parser.get('public_key_path')
keypairPath = json_parser.get('private_keypair_path')
project_name = json_parser.get('project_name')
project_id = json_parser.get('project_id')
main_ip = json_parser.get('main_ip')
input_file_path = json_parser.get('input_file_path')

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

instancesIps = sahara_util.get_instances_ips(clusterId)
masterIp = sahara_util.get_master_ip(clusterId)

#configureInstances(instancesIps)
#copyFileToInstances(execLocalPath,instancesIps)
putFileInHDFS(input_file_path, masterIp)
cluster_name = sys.argv[1]
config_file_path = sys.argv[2]

user = raw_input('OpenStack User: '******'OpenStack Password: '******'project_name')
project_id = json_parser.get('project_id')
main_ip = json_parser.get('main_ip')
image_id = json_parser.get('image_id')
net_id = json_parser.get('net_id')
template_id = json_parser.get('cluster_template_id')
key_pair = json_parser.get('keypair_name')
public_keypair_path = json_parser.get('public_keypair_path')
private_keypair_path = json_parser.get('private_keypair_path')
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)
#cluster_id = "e5b33c1a-a6af-430d-bc0d-531c982f8017"
print cluster_id
instancesIps = sahara_util.get_instances_ips(cluster_id)
configureInstances(instancesIps,public_keypair_path,private_keypair_path)
master_ip = sahara_util.get_master_ip(cluster_id)

exec_local_path = json_parser.get('exec_local_path')
public_keypair_path = json_parser.get('public_keypair_path')
private_keypair_path = json_parser.get('private_keypair_path')
private_keypair_name = json_parser.get('private_keypair_name')


net_id = json_parser.get('net_id')
image_id = json_parser.get('image_id')

#------------ GETTING CONNECTION WITH OPENSTACK -----------------
connector = ConnectionGetter(user, password, project_name, project_id, main_ip)

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