Skip to content

Commit

Permalink
[OCI] 1. Support specify OS with custom image id. 2. Corner case fix (#…
Browse files Browse the repository at this point in the history
…4524)

* Support specify os type with custom image id.

* trim space

* nit

* comment
  • Loading branch information
HysunHe authored Jan 3, 2025
1 parent 6a6d667 commit 459c5ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
29 changes: 20 additions & 9 deletions sky/clouds/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ def make_deploy_resources_variables(
listing_id = None
res_ver = None

os_type = None
if ':' in image_id:
# OS type provided in the --image-id. This is the case where
# custom image's ocid provided in the --image-id parameter.
# - ocid1.image...aaa:oraclelinux (os type is oraclelinux)
# - ocid1.image...aaa (OS not provided)
image_id, os_type = image_id.replace(' ', '').split(':')

cpus = resources.cpus
instance_type_arr = resources.instance_type.split(
oci_utils.oci_config.INSTANCE_TYPE_RES_SPERATOR)
Expand Down Expand Up @@ -297,15 +305,18 @@ def make_deploy_resources_variables(
cpus=None if cpus is None else float(cpus),
disk_tier=resources.disk_tier)

image_str = self._get_image_str(image_id=resources.image_id,
instance_type=resources.instance_type,
region=region.name)

# pylint: disable=import-outside-toplevel
from sky.clouds.service_catalog import oci_catalog
os_type = oci_catalog.get_image_os_from_tag(tag=image_str,
region=region.name)
logger.debug(f'OS type for the image {image_str} is {os_type}')
if os_type is None:
# OS type is not determined yet. So try to get it from vms.csv
image_str = self._get_image_str(
image_id=resources.image_id,
instance_type=resources.instance_type,
region=region.name)

# pylint: disable=import-outside-toplevel
from sky.clouds.service_catalog import oci_catalog
os_type = oci_catalog.get_image_os_from_tag(tag=image_str,
region=region.name)
logger.debug(f'OS type for the image {image_id} is {os_type}')

return {
'instance_type': instance_type,
Expand Down
7 changes: 5 additions & 2 deletions sky/provision/oci/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,11 @@ def find_nsg(cls, region: str, nsg_name: str,
raise exceptions.ResourcesUnavailableError(
'The VCN is not available')

# Get the primary vnic.
assert len(list_vcns_resp.data) > 0
# 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]

list_nsg_resp = net_client.list_network_security_groups(
Expand Down

0 comments on commit 459c5ae

Please sign in to comment.