def get_workspace(self, workspace_name): """ Authenticates and returns the AzureML workspace handle :param workspace_name: The workspace's name :return The workspace handle. None on failure """ if not self.valid_config: print("Please configure your Service Principal before trying to access the workspace") print("\nVisit this URL for further details about setting up a Service Principal in your own subscription:") print("https://docs.microsoft.com/en-us/azure/machine-learning/how-to-setup-authentication") return None # Authenticate via principal's credentials config_data = self.config_data svc_pr = ServicePrincipalAuthentication( tenant_id=config_data['tenantId'], service_principal_id=config_data['clientId'], service_principal_password=config_data['clientSecret']) workspaces = [key for key in Workspace.list(config_data['subscriptionId'], auth=svc_pr).keys()] if workspace_name not in workspaces: print(f"Workspace {workspace_name} not found in workspace list. Please create the workspace or adjust the scripts accordingly.") print("\nFollowing workspaces could be found:") for workspace in workspaces: print(f"- {workspace}") return None if self.workspace==None: self.workspace = Workspace.get(name=workspace_name, auth=svc_pr, resource_group=config_data['resourceGroup'], subscription_id=config_data['subscriptionId']) return self.workspace
def list_workspace(resource_group_name=None): from azureml._base_sdk_common.cli_wrapper._common import get_cli_specific_auth, get_default_subscription_id, \ get_resource_group_or_default_name auth = get_cli_specific_auth() default_subscription_id = get_default_subscription_id(auth) # resource group can be None, as we create on user's behalf. resource_group_name = get_resource_group_or_default_name( resource_group_name, auth=auth) workspaces_dict = Workspace.list(default_subscription_id, auth=auth, resource_group=resource_group_name) serialized_workspace_list = list() for workspace_name in workspaces_dict: for workspace_object in workspaces_dict[workspace_name]: serialized_workspace_list.append(workspace_object._to_dict()) return serialized_workspace_list