diff --git a/sky/clouds/utils/oci_utils.py b/sky/clouds/utils/oci_utils.py index 581d4d72d3c..46d4454d866 100644 --- a/sky/clouds/utils/oci_utils.py +++ b/sky/clouds/utils/oci_utils.py @@ -10,6 +10,8 @@ from ubuntu 20.04 to ubuntu 22.04, including: - GPU: skypilot:gpu-ubuntu-2004 -> skypilot:gpu-ubuntu-2204 - CPU: skypilot:cpu-ubuntu-2004 -> skypilot:cpu-ubuntu-2204 + - Hysun He (hysun.he@oracle.com) @ Jan.01, 2025: Support reuse existing + VCN for SkyServe. """ import os @@ -109,8 +111,15 @@ def get_compartment(cls, region): ('oci', region, 'compartment_ocid'), default_compartment_ocid) return compartment + @classmethod + def get_vcn_ocid(cls, region): + # Will reuse the regional VCN if specified. + vcn = skypilot_config.get_nested(('oci', region, 'vcn_ocid'), None) + return vcn + @classmethod def get_vcn_subnet(cls, region): + # Will reuse the subnet if specified. vcn = skypilot_config.get_nested(('oci', region, 'vcn_subnet'), None) return vcn diff --git a/sky/provision/oci/query_utils.py b/sky/provision/oci/query_utils.py index 3037fcc2703..3f545aca4ba 100644 --- a/sky/provision/oci/query_utils.py +++ b/sky/provision/oci/query_utils.py @@ -7,6 +7,8 @@ find_compartment: allow search subtree when find a compartment. - Hysun He (hysun.he@oracle.com) @ Nov.12, 2024: Add methods to Add/remove security rules: create_nsg_rules & remove_nsg + - Hysun He (hysun.he@oracle.com) @ Jan.01, 2025: Support reuse existing + VCN for SkyServe. """ from datetime import datetime import functools @@ -17,7 +19,6 @@ import typing from typing import List, Optional, Tuple -from sky import exceptions from sky import sky_logging from sky.adaptors import common as adaptors_common from sky.adaptors import oci as oci_adaptor @@ -496,26 +497,25 @@ def find_nsg(cls, region: str, nsg_name: str, compartment = cls.find_compartment(region) - list_vcns_resp = net_client.list_vcns( - compartment_id=compartment, - display_name=oci_utils.oci_config.VCN_NAME, - lifecycle_state='AVAILABLE', - ) - - if not list_vcns_resp: - raise exceptions.ResourcesUnavailableError( - 'The VCN is not available') + vcn_id = oci_utils.oci_config.get_vcn_ocid(region) + if vcn_id is None: + list_vcns_resp = net_client.list_vcns( + compartment_id=compartment, + display_name=oci_utils.oci_config.VCN_NAME, + lifecycle_state='AVAILABLE', + ) - # Get the primary vnic. The vnic might be an empty list for the - # corner case when the cluster was exited during provision. - if not list_vcns_resp.data: - return None + # Get the primary vnic. The vnic might be an empty list for the + # corner case when the cluster was exited during provision. + if not list_vcns_resp.data: + return None - vcn = list_vcns_resp.data[0] + vcn = list_vcns_resp.data[0] + vcn_id = vcn.id list_nsg_resp = net_client.list_network_security_groups( compartment_id=compartment, - vcn_id=vcn.id, + vcn_id=vcn_id, limit=1, display_name=nsg_name, ) @@ -532,7 +532,7 @@ def find_nsg(cls, region: str, nsg_name: str, create_network_security_group_details=oci_adaptor.oci.core.models. CreateNetworkSecurityGroupDetails( compartment_id=compartment, - vcn_id=vcn.id, + vcn_id=vcn_id, display_name=nsg_name, )) get_nsg_resp = net_client.get_network_security_group( diff --git a/sky/utils/schemas.py b/sky/utils/schemas.py index a424ae074b9..3194dc79da5 100644 --- a/sky/utils/schemas.py +++ b/sky/utils/schemas.py @@ -886,6 +886,9 @@ def get_config_schema(): 'image_tag_gpu': { 'type': 'string', }, + 'vcn_ocid': { + 'type': 'string', + }, 'vcn_subnet': { 'type': 'string', },