def get_metric_values(metric_id=None, metric_name=None, resource_id=None, fields='id', fail_ok=False, auth_info=Tenant.get('admin'), con_ssh=None): """ Get metric info via 'openstack metric show' Args: metric_id (str|None): metric_name (str|None): Only used if metric_id is not provided resource_id (str|None): Only used if metric_id is not provided fields (str|list|tuple): field name fail_ok (bool): auth_info: con_ssh: Returns (list): """ if metric_id is None and metric_name is None: raise ValueError("metric_id or metric_name has to be provided.") if metric_id: arg = metric_id else: if resource_id: arg = '--resource-id {} "{}"'.format(resource_id, metric_name) else: if not fail_ok: raise ValueError("resource_id needs to be provided when using metric_name") arg = '"{}"'.format(metric_name) code, output = cli.openstack('openstack metric show', arg, ssh_client=con_ssh, fail_ok=fail_ok, auth_info=auth_info) if code > 0: return output table_ = table_parser.table(output) return table_parser.get_multi_values_two_col_table(table_, fields)
def get_app_values(app_name, fields, con_ssh=None, auth_info=Tenant.get('admin_platform')): """ Get values from system application-show Args: app_name: fields (str|list|tuple): con_ssh: auth_info: Returns: """ if isinstance(fields, str): fields = [fields] table_ = table_parser.table(cli.system('application-show', app_name, ssh_client=con_ssh, auth_info=auth_info)[1], combine_multiline_entry=True) values = table_parser.get_multi_values_two_col_table(table_, fields=fields) return values
def get_flavor_values(flavor, fields, strict=True, con_ssh=None, auth_info=Tenant.get('admin')): """ Get flavor values for given fields via openstack flavor show Args: flavor (str): fields (str|list|tuple): strict (bool): strict search for field name or not con_ssh: auth_info: Returns (list): """ table_ = table_parser.table( cli.openstack('flavor show', flavor, ssh_client=con_ssh, auth_info=auth_info)[1]) return table_parser.get_multi_values_two_col_table( table_, fields, merge_lines=True, evaluate=True, strict=strict, dict_fields=('properties', ))
def get_aggregate_values(aggregate, fields, con_ssh=None, auth_info=Tenant.get('admin'), fail_ok=False): """ Get values of a nova aggregate for given fields Args: aggregate (str): fields (str|list|tuple): con_ssh: auth_info (dict): fail_ok (bool) Returns (list): """ code, out = cli.openstack('aggregate show', aggregate, ssh_client=con_ssh, auth_info=auth_info, fail_ok=fail_ok) if code > 0: return [] table_ = table_parser.table(out) return table_parser.get_multi_values_two_col_table( table_, fields, evaluate=True, dict_fields=('properties', ))
def get_image_values(image, fields, auth_info=Tenant.get('admin'), con_ssh=None, fail_ok=False): """ Get glance image values from openstack image show Args: image: fields: auth_info: con_ssh: fail_ok Returns (list): """ if isinstance(fields, str): fields = (fields, ) code, output = cli.openstack('image show', image, ssh_client=con_ssh, fail_ok=fail_ok, auth_info=auth_info) if code > 0: return [None] * len(fields) table_ = table_parser.table(output) values = table_parser.get_multi_values_two_col_table( table_, fields, merge_lines=True, evaluate=True, dict_fields='properties') return values
def get_stack_values(stack, fields='stack_status_reason', con_ssh=None, auth_info=None, fail_ok=False): code, out = cli.openstack('stack show', stack, ssh_client=con_ssh, auth_info=auth_info, fail_ok=fail_ok) if code > 0: return None table_ = table_parser.table(out) return table_parser.get_multi_values_two_col_table(table_=table_, fields=fields)
def get_endpoints_values(endpoint_id, fields, con_ssh=None, auth_info=Tenant.get('admin')): """ Gets the endpoint target field value for given endpoint Id Args: endpoint_id: the endpoint id to get the value of fields: the target field name to retrieve value of con_ssh: auth_info Returns (list): list of endpoint values """ table_ = table_parser.table( cli.openstack('endpoint show', endpoint_id, ssh_client=con_ssh, auth_info=auth_info)[1]) return table_parser.get_multi_values_two_col_table(table_, fields)