def _create_resources(ios_instances=None, s3_instances=None, mgmt_info=None, node_count=None) -> None: '''create required resources''' create_all_resources(ios_instances=ios_instances, s3_instances=s3_instances, mgmt_info=mgmt_info, node_count=node_count)
def _create_resource(self, s3_instances, mgmt_info): Log.info("Creating pacemaker resources") try: # TODO: create resource if not already exists. create_all_resources(s3_instances=s3_instances, mgmt_info=mgmt_info) except Exception as e: Log.info(f"Resource creation failed. Error {e}") raise HaConfigException("Resource creation failed.") Log.info("Created pacemaker resources successfully")
def _main(): Log.init(service_name="create_pacemaker_resources", log_path="/var/log/seagate/cortx/ha", level="INFO") args = _parse_input_args() create_all_resources(args.cib_xml, vip=args.vip, cidr=args.cidr, iface=args.iface, s3_instances=args.s3_instances, push=not args.dry_run, uds=args.with_uds)
def process(self): """ Process config command. """ Log.info("Processing config command") # Read machine-id and using machine-id read minion name from confstore # This minion name will be used for adding the node to the cluster. nodelist = [] command = "cat /etc/machine-id" machine_id, err, rc = self._execute.run_cmd(command, check_error=True) Log.info(f"Read machine-id. Output: {machine_id}, Err: {err}, RC: {rc}") minion_name = Conf.get(self._index, f"cluster.server_nodes.{machine_id.strip()}") nodelist.append(minion_name) # The config step will be called from primary node alwasys, # see how to get and use the node name then. # Read cluster name and cluster user cluster_name = Conf.get(self._index, 'corosync-pacemaker.cluster_name') cluster_user = Conf.get(self._index, 'corosync-pacemaker.user') # Read cluster user password and decrypt the same cluster_id = Conf.get(self._index, 'cluster.cluster_id') cluster_secret = Conf.get(self._index, 'corosync-pacemaker.secret') key = Cipher.generate_key(cluster_id, 'corosync-pacemaker') cluster_secret = Cipher.decrypt(key, cluster_secret.encode('ascii')).decode() # Get s3 instance count try: s3_instances = Conf.get(self._index, f"cluster.{minion_name}.s3_instances") if int(s3_instances) < 1: raise HaConfigException(f"Found {s3_instances} which is invalid s3 instance count.") except Exception as e: Log.error(f"Found {s3_instances} which is invalid s3 instance count. Error: {e}") raise HaConfigException(f"Found {s3_instances} which is invalid s3 instance count.") # Check if the cluster exists already, if yes skip creating the cluster. output, err, rc = self._execute.run_cmd(const.PCS_CLUSTER_STATUS, check_error=False) Log.info(f"Cluster status. Output: {output}, Err: {err}, RC: {rc}") if rc != 0: if(err.find("No such file or directory: 'pcs'") != -1): Log.error("Cluster config failed; pcs not installed") raise HaConfigException("Cluster config failed; pcs not installed") # If cluster is not created; create a cluster. elif(err.find("cluster is not currently running on this node") != -1): try: Log.info(f"Creating cluster: {cluster_name} with node: {minion_name}") cluster_auth(cluster_user, cluster_secret, nodelist) cluster_create(cluster_name, nodelist) Log.info(f"Created cluster: {cluster_name} successfully") Log.info("Creating pacemaker resources") create_all_resources(s3_instances=s3_instances) Log.info("Created pacemaker resources successfully") except Exception as e: Log.error(f"Cluster creation failed; destroying the cluster. Error: {e}") output = self._execute.run_cmd(const.PCS_CLUSTER_DESTROY, check_error=True) Log.info(f"Cluster destroyed. Output: {output}") raise HaConfigException("Cluster creation failed") else: pass # Nothing to do else: # Cluster exists already, check if it is a new node and add it to the existing cluster. Log.info("The cluster exists already, check and add new node") Log.info("config command is successful")
def _create_resources(_s3instances=None) -> None: '''create required resources''' create_all_resources(s3_instances=_s3instances)