Skip to content

Commit

Permalink
Allow resource group specifiation for Azure instance provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
landscapepainter committed Jul 19, 2024
1 parent c0246ab commit 06fe6c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sky/clouds/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from sky import clouds
from sky import exceptions
from sky import skypilot_config
from sky import sky_logging
from sky.adaptors import azure
from sky.clouds import service_catalog
Expand Down Expand Up @@ -318,6 +319,12 @@ def make_deploy_resources_variables(
need_nvidia_driver_extension = (acc_dict is not None and
'A10' in acc_dict)

# Determine resource group for deploying the instance.
config_resource_group = skypilot_config.get_nested(
('azure', 'resource_group'), None)
if config_resource_group is None:
resource_group_name = f'{cluster_name.name_on_cloud}-{region_name}'

# Setup commands to eliminate the banner and restart sshd.
# This script will modify /etc/ssh/sshd_config and add a bash script
# into .bashrc. The bash script will restart sshd if it has not been
Expand Down Expand Up @@ -373,7 +380,7 @@ def _failover_disk_tier() -> Optional[resources_utils.DiskTier]:
'disk_tier': Azure._get_disk_type(_failover_disk_tier()),
'cloud_init_setup_commands': cloud_init_setup_commands,
'azure_subscription_id': self.get_project_id(dryrun),
'resource_group': f'{cluster_name.name_on_cloud}-{region_name}',
'resource_group': resource_group_name,
}

def _get_feasible_launchable_resources(
Expand Down
4 changes: 4 additions & 0 deletions sky/provision/azure/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ def terminate_instances(
assert provider_config is not None, cluster_name_on_cloud

resource_group_client = azure.get_client('resource', subscription_id)
# Get delete_resource_group method if the resource_group is not from the user.
# If the resource group is from the user through config.yaml, get delete_virtual_machine method.
# May need more discussion on how to differentiate user provided resource group name and the name
# we generate by default.
delete_resource_group = _get_azure_sdk_function(
client=resource_group_client.resource_groups, function_name='delete')

Expand Down
6 changes: 6 additions & 0 deletions sky/provision/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def _bulk_provision(
# Omit the region name for Kubernetes.
logger.info(f'{style.BRIGHT}Launching on {cloud}{style.RESET_ALL} '
f'{cluster_name!r}.')
elif isinstance(cloud, clouds.Azure):
# Specify launched resource group for Azure.
resource_group = bootstrap_config.provider_config.get('resource_group')
logger.info(f'{style.BRIGHT}Launching on {cloud} {region_name} at '
f' resource group {resource_group!r}{style.RESET_ALL} '
f'({zone_str})')
else:
logger.info(f'{style.BRIGHT}Launching on {cloud} '
f'{region_name}{style.RESET_ALL} ({zone_str})')
Expand Down
3 changes: 3 additions & 0 deletions sky/utils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ def get_config_schema():
'storage_account': {
'type': 'string',
},
'resource_group': {
'type': 'string',
},
}
},
'kubernetes': {
Expand Down

0 comments on commit 06fe6c7

Please sign in to comment.