def create_bare_cluster(self): """ This function of our script takes the arguments given and calls the check_quota function. Also, calls get_flavor_id to find the matching flavor_ids from the arguments given and finds the image id of the image given as argument. Then instantiates the Cluster and creates the virtual machine cluster of one master and clustersize-1 slaves. Calls the function to install hadoop to the cluster. """ logging.log(REPORT, ' 1.Credentials and Endpoints') # Finds user public ssh key USER_HOME = expanduser('~') pub_keys_path = join(USER_HOME, ".ssh/id_rsa.pub") auth = check_credentials(self.opts['token'], self.opts['auth_url']) endpoints, user_id = endpoints_and_user_id(auth) cyclades = init_cyclades(endpoints['cyclades'], self.opts['token']) flavor_master = self.get_flavor_id_master(cyclades) flavor_slaves = self.get_flavor_id_slave(cyclades) if flavor_master == 0 or flavor_slaves == 0: logging.error('Combination of cpu, ram, disk and disk_template do' ' not match an existing id') exit(error_flavor_id) # Total cpu,ram and disk needed for cluster cpu = self.opts['cpu_master'] + (self.opts['cpu_slave']) * (self.opts['clustersize'] - 1) ram = self.opts['ram_master'] + (self.opts['ram_slave']) * (self.opts['clustersize'] - 1) cyclades_disk = self.opts['disk_master'] + (self.opts['disk_slave']) * (self.opts['clustersize'] - 1) # The resources requested by user in a dictionary req_quotas = {'cpu': cpu, 'ram': ram, 'cyclades_disk': cyclades_disk, 'vms': self.opts['clustersize']} self.check_quota(auth, req_quotas) plankton = init_plankton(endpoints['plankton'], self.opts['token']) list_current_images = plankton.list_public(True, 'default') # Find image id of the arg given for lst in list_current_images: if lst['name'] == self.opts['image']: chosen_image = lst break else: logging.error(self.opts['image'] + ' is not a valid image option') exit(error_image_id) logging.log(REPORT, ' 2.Create virtual cluster') cluster = Cluster(cyclades, prefix=self.opts['name'], flavor_id_master=flavor_master, flavor_id_slave=flavor_slaves, image_id=chosen_image['id'], size=self.opts['clustersize'], net_client=init_cyclades_netclient(endpoints['network'], self.opts['token']), auth_cl=auth) self.HOSTNAME_MASTER_IP, self.server_dict = cluster.create('', pub_keys_path, '') sleep(15) # wait for the machines to be pingable logging.log(REPORT, ' Bare cluster has been created.') # Return master node ip and server dict return self.HOSTNAME_MASTER_IP, self.server_dict
def create_bare_cluster(self): """Creates a bare ~okeanos cluster.""" server_home_path = expanduser('~') server_ssh_keys = join(server_home_path, ".ssh/id_rsa.pub") pub_keys_path = '' logging.log(SUMMARY, 'Authentication verified') current_task.update_state(state="Authenticated") flavor_master, flavor_slaves, image_id = self.check_user_resources() # Create name of cluster with [orka] prefix cluster_name = '%s%s%s' % ('[orka]', '-', self.opts['cluster_name']) self.opts['cluster_name'] = cluster_name # Update db with cluster status as pending task_id = current_task.request.id self.cluster_id = db_cluster_create(self.opts, task_id) # Append the cluster_id in the cluster name to create a unique name # used later for naming various files, e.g. ansible_hosts file and # create_cluster_debug file. self.cluster_name_postfix_id = '%s%s%s' % (self.opts['cluster_name'], '-', self.cluster_id) # Check if user chose ssh keys or not. if self.opts['ssh_key_selection'] is None or self.opts[ 'ssh_key_selection'] == 'no_ssh_key_selected': self.ssh_file = 'no_ssh_key_selected' else: self.ssh_key_file(self.cluster_name_postfix_id) pub_keys_path = self.ssh_file try: cluster = Cluster(self.cyclades, self.opts['cluster_name'], flavor_master, flavor_slaves, image_id, self.opts['cluster_size'], self.net_client, self.auth, self.project_id) set_cluster_state(self.opts['token'], self.cluster_id, "Creating ~okeanos cluster (1/3)") self.HOSTNAME_MASTER_IP, self.server_dict = \ cluster.create(server_ssh_keys, pub_keys_path, '') sleep(15) except Exception, e: # If error in bare cluster, update cluster status as destroyed set_cluster_state(self.opts['token'], self.cluster_id, 'Error', status='Failed', error=str(e.args[0])) os.system('rm ' + self.ssh_file) raise
def create_bare_cluster(self): """Creates a bare ~okeanos cluster.""" server_home_path = expanduser('~') server_ssh_keys = join(server_home_path, ".ssh/id_rsa.pub") pub_keys_path = '' logging.log(SUMMARY, ' Authentication verified') current_task.update_state(state="Authenticated") flavor_master, flavor_slaves, image_id = self.check_user_resources() # Create name of cluster with [orka] prefix cluster_name = '%s%s%s' % ('[orka]', '-', self.opts['cluster_name']) self.opts['cluster_name'] = cluster_name # Update db with cluster status as pending task_id = current_task.request.id self.cluster_id = db_cluster_create(self.opts, task_id) # Append the cluster_id in the cluster name to create a unique name # used later for naming various files, e.g. ansible_hosts file and # create_cluster_debug file. self.cluster_name_postfix_id = '%s%s%s' % (self.opts['cluster_name'], '-', self.cluster_id) # Check if user chose ssh keys or not. if self.opts['ssh_key_selection'] is None or self.opts['ssh_key_selection'] == 'no_ssh_key_selected': self.ssh_file = 'no_ssh_key_selected' else: self.ssh_key_file(self.cluster_name_postfix_id) pub_keys_path = self.ssh_file try: cluster = Cluster(self.cyclades, self.opts['cluster_name'], flavor_master, flavor_slaves, image_id, self.opts['cluster_size'], self.net_client, self.auth, self.project_id) set_cluster_state(self.opts['token'], self.cluster_id, " Creating ~okeanos cluster (1/3)") self.HOSTNAME_MASTER_IP, self.server_dict = \ cluster.create(server_ssh_keys, pub_keys_path, '') sleep(15) except Exception: # If error in bare cluster, update cluster status as destroyed set_cluster_state(self.opts['token'], self.cluster_id, 'Error', status='Destroyed') os.system('rm ' + self.ssh_file) raise # Get master VM root password self.master_root_pass = self.server_dict[0]['adminPass'] # Return master node ip and server dict return self.HOSTNAME_MASTER_IP, self.server_dict