Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
parasj committed Jun 28, 2022
1 parent d0669c7 commit a4a6a5e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions skyplane/compute/azure/azure_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def network_tier(self):
def terminate_instance_impl(self):
compute_client = self.auth.get_compute_client()
network_client = self.auth.get_network_client()

# remove any role assignments to the VM's system assigned identity
auth_client = self.auth.get_authorization_client()
vm = self.get_virtual_machine()
Expand All @@ -177,13 +177,13 @@ def terminate_instance_impl(self):
_ = nsg_poller.result()
vnet_poller = network_client.virtual_networks.begin_delete(AzureServer.resource_group_name, self.vnet_name(self.name))
_ = vnet_poller.result()

def authorize_subscription(self):
# Authorize system MSI to access subscription
auth_client = self.auth.get_authorization_client()
subscription_scope = "/subscriptions/{}".format(self.auth.subscription_id)
principal_id = self.get_virtual_machine().identity.principal_id

def grant_vm_role(principal_id, scope, role_name):
prefix = f"grant_vm_role({principal_id}, {scope.split('/')[-1]}, {role_name})"
try:
Expand All @@ -207,11 +207,13 @@ def grant_vm_role(principal_id, scope, role_name):
def check_role(role):
if role is None:
return True
for assignment in auth_client.role_assignments.list_for_scope(subscription_scope, filter="principalId eq '{}'".format(principal_id)):
for assignment in auth_client.role_assignments.list_for_scope(
subscription_scope, filter="principalId eq '{}'".format(principal_id)
):
if assignment.role_definition_id == role.id:
return True
return False

wait_for(lambda: all(check_role(role) for role in [r1, r2, r3, r4]), timeout=60, desc="authorize_subscription")
logger.fs.debug(f"Authorized subscription for VM {self.name}")

Expand Down

0 comments on commit a4a6a5e

Please sign in to comment.