|
1 | 1 | #!/usr/bin/env python |
2 | 2 | # -*- coding: utf-8; -*- |
| 3 | +from ads.common.decorator.utils import class_or_instance_method |
3 | 4 |
|
4 | 5 | # Copyright (c) 2023 Oracle and/or its affiliates. |
5 | 6 | # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ |
@@ -77,3 +78,44 @@ def init_client( |
77 | 78 | @property |
78 | 79 | def client(self) -> oci.feature_store.feature_store_client.FeatureStoreClient: |
79 | 80 | return super().client |
| 81 | + |
| 82 | + @class_or_instance_method |
| 83 | + def list_resource( |
| 84 | + cls, compartment_id: str = None, limit: int = 0, **kwargs |
| 85 | + ) -> list: |
| 86 | + """Generic method to list OCI resources |
| 87 | +
|
| 88 | + Parameters |
| 89 | + ---------- |
| 90 | + compartment_id : str |
| 91 | + Compartment ID of the OCI resources. Defaults to None. |
| 92 | + If compartment_id is not specified, |
| 93 | + the value of NB_SESSION_COMPARTMENT_OCID in environment variable will be used. |
| 94 | + limit : int |
| 95 | + The maximum number of items to return. Defaults to 0, All items will be returned |
| 96 | + **kwargs : |
| 97 | + Additional keyword arguments to filter the resource. |
| 98 | + The kwargs are passed into OCI API. |
| 99 | +
|
| 100 | + Returns |
| 101 | + ------- |
| 102 | + list |
| 103 | + A list of OCI resources |
| 104 | +
|
| 105 | + Raises |
| 106 | + ------ |
| 107 | + NotImplementedError |
| 108 | + List method is not supported or implemented. |
| 109 | +
|
| 110 | + """ |
| 111 | + if limit: |
| 112 | + items = cls._find_oci_method("list")( |
| 113 | + cls.check_compartment_id(compartment_id), limit=limit, **kwargs |
| 114 | + ).data.items |
| 115 | + else: |
| 116 | + items = oci.pagination.list_call_get_all_results( |
| 117 | + cls._find_oci_method("list"), |
| 118 | + cls.check_compartment_id(compartment_id), |
| 119 | + **kwargs, |
| 120 | + ).data |
| 121 | + return [cls.from_oci_model(item) for item in items] |
0 commit comments