submit_azureml_pytest_1.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. def setup_workspace(workspace_name, subscription_id, resource_group, cli_auth,
  2. location):
  3. """
  4. This sets up an Azure Workspace.
  5. An existing Azure Workspace is used or a new one is created if needed for
  6. the pytest run.
  7. Args:
  8. workspace_name (str): Centralized location on Azure to work
  9. with all the artifacts used by AzureML
  10. service
  11. subscription_id (str): the Azure subscription id
  12. resource_group (str): Azure Resource Groups are logical collections of
  13. assets associated with a project. Resource groups
  14. make it easy to track or delete all resources
  15. associated with a project by tracking or deleting
  16. the Resource group.
  17. cli_auth Azure authentication
  18. location (str): workspace reference
  19. Returns:
  20. ws: workspace reference
  21. """
  22. logger.debug('setup: workspace_name is {}'.format(workspace_name))
  23. logger.debug('setup: resource_group is {}'.format(resource_group))
  24. logger.debug('setup: subid is {}'.format(subscription_id))
  25. logger.debug('setup: location is {}'.format(location))
  26. try:
  27. # use existing workspace if there is one
  28. ws = Workspace.get(
  29. name=workspace_name,
  30. subscription_id=subscription_id,
  31. resource_group=resource_group,
  32. auth=cli_auth
  33. )
  34. except WorkspaceException:
  35. # this call might take a minute or two.
  36. logger.debug('Creating new workspace')
  37. ws = Workspace.create(
  38. name=workspace_name,
  39. subscription_id=subscription_id,
  40. resource_group=resource_group,
  41. # create_resource_group=True,
  42. location=location,
  43. auth=cli_auth
  44. )
  45. return ws