def cli_util_func(ctx, param_name): iam_tenancy_defaults = get_iam_commands_that_use_tenancy_defaults() if ctx.parent.command.name in iam_tenancy_defaults.keys(): if ctx.command.name in iam_tenancy_defaults[ctx.parent.command.name]: if param_name in ['compartment-id', 'tenancy-id']: value = get_tenancy_from_config(ctx) return value
def get_availability_domains(ctx, word_before_cursor, bottom_toolbar, sub_string=""): compartment_id = cli_util.get_tenancy_from_config(ctx) completions = [] try: identity_client = cli_util.build_client("identity", "identity", ctx) response = identity_client.list_availability_domains( compartment_id=compartment_id) if len(response.data) == 0: bottom_toolbar.set_toolbar_text( get_error_message("no_items_found"), is_error=True) else: items = response.data for item in items: if not sub_string or sub_string.lower() in item.name.lower(): completions.append( Completion(item.name, -len(word_before_cursor), display=item.name)) except Exception: bottom_toolbar.set_toolbar_text( get_error_message("resource_search_failed"), is_error=True, ) return completions
def get_compute_images(ctx, word_before_cursor, bottom_toolbar, sub_string=""): compartment_id = cli_util.get_tenancy_from_config(ctx) completions = [] try: compute_client = cli_util.build_client("core", "compute", ctx) kwargs = {"lifecycle_state": "AVAILABLE"} response = compute_client.list_images(compartment_id=compartment_id, **kwargs) items = response.data for item in items: if not sub_string or sub_string.lower() in item.display_name.lower( ): completions.append( Completion(item.id, -len(word_before_cursor), display=item.display_name)) if not completions: bottom_toolbar.set_toolbar_text( get_error_message("no_items_found"), is_error=True) except Exception: bottom_toolbar.set_toolbar_text( get_error_message("resource_search_failed"), is_error=True) return completions
def list_compartments(ctx, from_json, all_pages, page_size, compartment_id, page, limit, access_level, compartment_id_in_subtree, name, sort_by, sort_order, lifecycle_state, with_root): if all_pages and limit: raise click.UsageError('If you provide the --all option you cannot provide the --limit option') kwargs = {} if page is not None: kwargs['page'] = page if limit is not None: kwargs['limit'] = limit if access_level is not None: kwargs['access_level'] = access_level if compartment_id_in_subtree is not None: kwargs['compartment_id_in_subtree'] = compartment_id_in_subtree if name is not None: kwargs['name'] = name if sort_by is not None: kwargs['sort_by'] = sort_by if sort_order is not None: kwargs['sort_order'] = sort_order if lifecycle_state is not None: kwargs['lifecycle_state'] = lifecycle_state client = cli_util.build_client('identity', 'identity', ctx) if all_pages: if page_size: kwargs['limit'] = page_size result = cli_util.list_call_get_all_results( client.list_compartments, compartment_id=compartment_id, **kwargs ) elif limit is not None: result = cli_util.list_call_get_up_to_limit( client.list_compartments, limit, page_size, compartment_id=compartment_id, **kwargs ) else: result = client.list_compartments( compartment_id=compartment_id, **kwargs ) if with_root: tenancy_id = get_tenancy_from_config(ctx) tenancy_result = client.get_compartment( compartment_id=tenancy_id, ) if limit is not None and result.data: # remove from list as root will be one compartment result.data.pop() result.data.insert(0, tenancy_result.data) cli_util.render_response(result, ctx)