def if_block_exists(mnode, volname, blockname): """Check if block already exists Args: mnode (str): Node on which commands has to be executed volname (str): Name of the volume. blockname(str): block name Returns: bool : True if block exists. False Otherwise """ # Get block list for the volname ret, out, err = block_list(mnode, volname) if ret != 0: g.log.error("Failed to get block list for the volume %s: %s", volname, err) return False # Check if block exists for the volname block_list_dict = g.load_json_string(out) if blockname in block_list_dict['blocks']: return True else: g.log.error("Block '%s' doesn't exists on volume %s", blockname, volname) return False
def get_block_info(mnode, volname, blockname): """Get Block Info Args: mnode (str): Node on which commands has to be executed volname (str): Name of the volume. blockname(str): block name Returns: dict if successful in getting block info, None if block doesn't exists """ ret, out, err = block_info(mnode, volname, blockname) if ret != 0: g.log.error("Failed to get block info of block: %s/%s : %s", volname, blockname, err) return None return g.load_json_string(out)
def get_block_list(mnode, volname): """ Get list of all blocks for the volume Args: mnode (str): Node on which commands has to be executed volname (str): Name of the volume. Returns: list of block names if successful in getting block list, None if block list command errors """ # get block list for the volname ret, out, err = block_list(mnode, volname) if ret != 0: g.log.error("Failed to get block list for the volume %s: %s", volname, err) return None block_list_dict = g.load_json_string(out) blocknames = block_list_dict.get('blocks', None) if blocknames is None: g.log.error("No blocks present on volume %s", volname) return blocknames