Skip to content

Commit 4e5d238

Browse files
Onboard BYOR feature
1 parent 845ec6d commit 4e5d238

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

ads/aqua/extension/ui_handler.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ads.aqua.extension.utils import validate_function_parameters
1616
from ads.aqua.model.entities import ImportModelDetails
1717
from ads.aqua.ui import AquaUIApp
18-
from ads.config import COMPARTMENT_OCID
18+
from ads.config import COMPARTMENT_OCID, IS_BYOR_ENABLED
1919

2020

2121
@dataclass
@@ -82,6 +82,10 @@ def get(self, id=""):
8282
return self.is_bucket_versioned()
8383
elif paths.startswith("aqua/containers"):
8484
return self.list_containers()
85+
elif paths.startswith("aqua/capacityreservations/enabled"):
86+
return self.is_capacity_reservations_enabled()
87+
elif paths.startswith("aqua/capacityreservations"):
88+
return self.list_capacity_reservations()
8589
else:
8690
raise HTTPError(400, f"The request {self.request.path} is invalid.")
8791

@@ -103,6 +107,17 @@ def list_log_groups(self, **kwargs):
103107
AquaUIApp().list_log_groups(compartment_id=compartment_id, **kwargs)
104108
)
105109

110+
def is_capacity_reservations_enabled(self, **kwargs):
111+
return self.finish({"status": str(IS_BYOR_ENABLED).strip().lower() == "true"})
112+
113+
def list_capacity_reservations(self, **kwargs):
114+
compartment_id = self.get_argument("compartment_id", default=COMPARTMENT_OCID)
115+
return self.finish(
116+
AquaUIApp().list_capacity_reservations(
117+
compartment_id=compartment_id, **kwargs
118+
)
119+
)
120+
106121
def list_logs(self, log_group_id: str, **kwargs):
107122
"""Lists the specified log group's log objects."""
108123
return self.finish(AquaUIApp().list_logs(log_group_id=log_group_id, **kwargs))
@@ -279,4 +294,5 @@ def post(self, *args, **kwargs):
279294
("bucket/versioning/?([^/]*)", AquaUIHandler),
280295
("containers/?([^/]*)", AquaUIHandler),
281296
("cli/?([^/]*)", AquaCLIHandler),
297+
("capacityreservations/?([^/]*)", AquaUIHandler),
282298
]

ads/aqua/ui.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def list_logs(self, **kwargs) -> str:
9090
res = self.logging_client.list_logs(log_group_id=log_group_id, **kwargs).data
9191
return sanitize_response(oci_client=self.logging_client, response=res)
9292

93+
@telemetry(entry_point="plugin=ui&action=list_capacity_reservations", name="aqua")
94+
def list_capacity_reservations(self, **kwargs):
95+
compartment_id = kwargs.pop("compartment_id", COMPARTMENT_OCID)
96+
logger.info(f"Loading Capacity reservations from compartment: {compartment_id}")
97+
compute_client = oc.OCIClientFactory(**default_signer()).compute
98+
reservations = compute_client.list_compute_capacity_reservations(
99+
compartment_id=compartment_id
100+
)
101+
return reservations.data
102+
93103
@telemetry(entry_point="plugin=ui&action=list_compartments", name="aqua")
94104
def list_compartments(self) -> str:
95105
"""Lists the compartments in a tenancy specified by TENANCY_OCID env variable. This is a pass through the OCI list_compartments

ads/common/oci_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8; -*-
32

43
# Copyright (c) 2021, 2024 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
@@ -9,20 +8,20 @@
98
import oci.artifacts
109
from oci.ai_language import AIServiceLanguageClient
1110
from oci.artifacts import ArtifactsClient
11+
from oci.core import ComputeClient, VirtualNetworkClient
1212
from oci.data_catalog import DataCatalogClient
1313
from oci.data_flow import DataFlowClient
1414
from oci.data_labeling_service import DataLabelingManagementClient
1515
from oci.data_labeling_service_dataplane import DataLabelingClient
1616
from oci.data_science import DataScienceClient
1717
from oci.identity import IdentityClient
18+
from oci.limits import LimitsClient
19+
from oci.logging import LoggingManagementClient
1820
from oci.marketplace import MarketplaceClient
1921
from oci.object_storage import ObjectStorageClient
2022
from oci.resource_search import ResourceSearchClient
2123
from oci.secrets import SecretsClient
2224
from oci.vault import VaultsClient
23-
from oci.logging import LoggingManagementClient
24-
from oci.core import VirtualNetworkClient
25-
from oci.limits import LimitsClient
2625

2726
logger = logging.getLogger(__name__)
2827

@@ -69,6 +68,7 @@ def _client_impl(client):
6968
"secret": SecretsClient,
7069
"vault": VaultsClient,
7170
"identity": IdentityClient,
71+
"compute": ComputeClient,
7272
"ai_language": AIServiceLanguageClient,
7373
"data_labeling_dp": DataLabelingClient,
7474
"data_labeling_cp": DataLabelingManagementClient,
@@ -114,6 +114,10 @@ def create_client(self, client_name):
114114
def object_storage(self):
115115
return self.create_client("object_storage")
116116

117+
@property
118+
def compute(self):
119+
return self.create_client("compute")
120+
117121
@property
118122
def identity(self):
119123
return self.create_client("identity")

ads/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
OCI_IDENTITY_SERVICE_ENDPOINT = os.environ.get("OCI_IDENTITY_SERVICE_ENDPOINT")
1515
NB_SESSION_COMPARTMENT_OCID = os.environ.get("NB_SESSION_COMPARTMENT_OCID")
1616
PROJECT_OCID = os.environ.get("PROJECT_OCID") or os.environ.get("PIPELINE_PROJECT_OCID")
17+
IS_BYOR_ENABLED = os.environ.get("ALLOWLISTED_FOR_BYOR")
1718
NB_SESSION_OCID = os.environ.get("NB_SESSION_OCID")
1819
USER_OCID = os.environ.get("USER_OCID")
1920
OCI_RESOURCE_PRINCIPAL_VERSION = os.environ.get("OCI_RESOURCE_PRINCIPAL_VERSION")

0 commit comments

Comments
 (0)