Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OCI] Support reuse existing VCN for SkyServe #4530

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sky/clouds/utils/oci_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected]) @ Jan.01, 2025: Support reuse existing
VCN for SkyServe.
"""
import os

Expand Down Expand Up @@ -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

Expand Down
34 changes: 17 additions & 17 deletions sky/provision/oci/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
find_compartment: allow search subtree when find a compartment.
- Hysun He ([email protected]) @ Nov.12, 2024: Add methods to
Add/remove security rules: create_nsg_rules & remove_nsg
- Hysun He ([email protected]) @ Jan.01, 2025: Support reuse existing
VCN for SkyServe.
"""
from datetime import datetime
import functools
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
Expand All @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions sky/utils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ def get_config_schema():
'image_tag_gpu': {
'type': 'string',
},
'vcn_ocid': {
'type': 'string',
},
'vcn_subnet': {
'type': 'string',
},
Expand Down
Loading