def get_or_create_workspace(subscription, resource_group, workspace_name,
                            location, **kwargs):
    print("Info: {}, {}, {}, {}".format(subscription, resource_group,
                                        workspace_name, location))

    try:
        workspace = Workspace.get(name=workspace_name,
                                  subscription_id=subscription,
                                  resource_group=resource_group)
        cprint('Using existing workspace "{}"'.format(workspace_name), "green")
    except WorkspaceException:
        cprint(
            'Creating new workspace "{}":'.format(workspace_name),
            "green",
            attrs=["bold"],
        )
        workspace = Workspace.create(name=workspace_name,
                                     subscription_id=subscription,
                                     resource_group=resource_group,
                                     location=location,
                                     **kwargs)

    cprint("Using Workspace name={}, resource_group={}, subscription_id={}".
           format(workspace.name, workspace.resource_group,
                  workspace.subscription_id))

    return workspace
def main(name: str, subscription_id: str, resource_group: str, location: str):
    """Create Workspace on Azure ML Service

        - https://docs.microsoft.com/pt-br/azure/machine-learning
        /how-to-manage-workspace?tab=python&tabs=python#create-multi-tenant
    """
    print(location)
    click.secho("[ML SERVICE] - Creating Workspace...", fg="green")

    cli_auth = AzureCliAuthentication()
    ws = Workspace.create(
        name=name,
        subscription_id=subscription_id,
        resource_group=resource_group,
        create_resource_group=True,
        location=location,
        auth=cli_auth,
    )

    ws.write_config(".azureml")
    print(
        "\tWorkspace name: " + ws.name,
        "Azure region: " + ws.location,
        "Subscription id: " + ws.subscription_id,
        "Resource group: " + ws.resource_group,
        sep="\n\t",
    )
Example #3
0
def create_workspace(subscription_id, resource_group, workspace_name, region):
    if subscription_id is None:
        subscription_id = input("enter your subscription id : ")
    else:
        print("working on subscription :", subscription_id)
    if resource_group is None:
        resource_group = input("enter your resource groupe id : ")
    else:
        print("working on resource group :", resource_group)
    if workspace_name is None:
        workspace_name = input("enter your workspace name : ")
    else:
        print("working on workspace :", workspace_name)
    from azureml.core import Workspace
    try:
        ws = Workspace(subscription_id=subscription_id,
                       resource_group=resource_group,
                       workspace_name=workspace_name)
        # write the details of the workspace to a configuration file to the notebook library
        ws.write_config()
        print(
            "Workspace configuration succeeded. Skip the workspace creation steps below"
        )
    except:
        ws = Workspace.create(name=workspace_name,
                              subscription_id=subscription_id,
                              resource_group=resource_group,
                              location=region,
                              create_resource_group=True,
                              exist_ok=True)
        ws.get_details()
        # write the details of the workspace to a configuration file to the notebook library
        ws.write_config()
    return ws
Example #4
0
def main(argv):  
  try:
     opts, args = getopt.getopt(argv,"hs:rg:wn:wr:",["subscription_id=","resource_group=","workspace_name=", "workspace_region="])
  except getopt.GetoptError:
     print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
     sys.exit(2)
  for opt, arg in opts:
     if opt == '-h':
        print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
        sys.exit()
     elif opt in ("-s", "--subscription_id"):
        subscription_id = arg
     elif opt in ("-rg", "--resource_group"):
        resource_group = arg
     elif opt in ("-wn", "--workspace_name"):
        workspace_name = arg
     elif opt in ("-wr", "--workspace_region"):
        workspace_region = arg
        
    env_path = find_dotenv()
    if env_path == "":
        Path(".env").touch()
        env_path = find_dotenv()

    ws = Workspace.create(
      name=workspace_name,
      subscription_id=subscription_id,
      resource_group=resource_group,
      location=workspace_region,
      create_resource_group=True,
      auth=get_auth(env_path),
      exist_ok=True,
    )
Example #5
0
def get_or_create_workspace(
    subscription_id: str,
    resource_group: str,
    workspace_name: str,
    workspace_region: str,
) -> Workspace:
    try:
        ws = Workspace(
            subscription_id=subscription_id,
            resource_group=resource_group,
            workspace_name=workspace_name,
        )
        # write the details of the workspace to a configuration file to the notebook library
        ws.write_config()
        logger.info(
            "Workspace configuration succeeded. Skip the workspace creation steps below"
        )
    except ProjectSystemException as e:
        logger.exception(e)
        # Create the workspace using the specified parameters
        ws = Workspace.create(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            location=workspace_region,
            create_resource_group=True,
            sku="basic",
            exist_ok=True,
        )
        ws.get_details()
        # write the details of the workspace to a configuration file to the notebook library
        ws.write_config()
    return ws
Example #6
0
def get_workspace(compute_name=None, compute_config=None):
    if TENANT_ID is None or \
            SERVICE_PRINCIPAL_ID is None or \
            SERVICE_PRINCIPAL_PASSWORD is None or \
            SUBSCRIPTION_ID is None or \
            RESOURCE_GROUP_NAME is None or \
            WORKSPACE_NAME is None or \
            WORKSPACE_LOCATION is None:
        print("One of the required environment variables is not set. "
              "Running locally instead.")
        return None

    logger.info("Logging in as service principal.")
    auth = ServicePrincipalAuthentication(TENANT_ID,
                                          SERVICE_PRINCIPAL_ID,
                                          SERVICE_PRINCIPAL_PASSWORD)
    logger.info("Successfully logged in as service principal.")

    logger.info("Ensuring resource group {} exists.".format(RESOURCE_GROUP_NAME))
    resource_management_client = resource_client_factory(auth, SUBSCRIPTION_ID)
    resource_group_properties = ResourceGroup(location=WORKSPACE_LOCATION)
    resource_management_client.resource_groups.create_or_update(WORKSPACE_NAME,
                                                                resource_group_properties)
    logger.info("Ensured resource group {} exists.".format(RESOURCE_GROUP_NAME))

    logger.info("Ensuring workspace {} exists.".format(WORKSPACE_NAME))
    workspace = Workspace.create(name=WORKSPACE_NAME, auth=auth, subscription_id=SUBSCRIPTION_ID,
                                 resource_group=RESOURCE_GROUP_NAME, location=WORKSPACE_LOCATION,
                                 create_resource_group=False, exist_ok=True)
    logger.info("Ensured workspace {} exists.".format(WORKSPACE_NAME))
    logger.info("Ensuring compute exists.")
    get_or_create_compute_cluster(workspace, compute_name, compute_config)
    logger.info("Ensured compute exists.")
    return workspace
Example #7
0
def get_or_create_workspace(subscription_id: str, resource_group: str,
                            workspace_name: str,
                            workspace_region: str) -> Workspace:
    """
    Returns workspace if one exists already with the name
    otherwise creates a new one.

    Args
    subscription_id: Azure subscription id
    resource_group: Azure resource group to create workspace and related resources  
    workspace_name: name of azure ml workspace  
    workspace_region: region for workspace 
    """

    try:
        # get existing azure ml workspace
        ws = Workspace.get(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            auth=get_auth(),
        )

    except:
        # this call might take a minute or two.
        print("Creating new workspace")
        ws = Workspace.create(name=workspace_name,
                              subscription_id=subscription_id,
                              resource_group=resource_group,
                              create_resource_group=True,
                              location=workspace_region,
                              auth=get_auth())

    return ws
Example #8
0
def setUpAzureMLWorkspace(subscription_id, resource_group, location):
    ws = Workspace.create(
        name='myworkspace',
        subscription_id=subscription_id,
        resource_group=resource_group,
        location=location  # Or other supported Azure region  
    )
    ws.write_config("azure_ml.cfg")
def create_workspace(azureml_path: str = Path("..", "..", ".azureml")):
    ws = Workspace.create(name='TravelInsurance',
                          subscription_id=os.environ["SUBSCRIPTION_ID"],
                          resource_group=os.environ["RESOURCE_GROUP"],
                          create_resource_group=True,
                          location=os.environ["SERVER_LOCATION"])

    # write out the workspace details to a configuration file: .azureml/config.json
    ws.write_config(path=azureml_path)
Example #10
0
def get_or_create_workspace(
    workspace_name: str,
    subscription_id: str,
    resource_group: str,
    workspace_region: str,
    auth: Union[
        InteractiveLoginAuthentication,
        ServicePrincipalAuthentication] = InteractiveLoginAuthentication(),
    log=True,
) -> Workspace:
    """
    Create a new Azure Machine Learning workspace. If the workspace already exists, the existing workspace will be
    returned. Also create a CONFIG file to quickly reload the workspace.

    This uses the :class:`azureml.core.authentication.InteractiveLoginAuthentication` or will default to use the
    :class:`azureml.core.authentication.AzureCliAuthentication` for logging into Azure.

    Run az login from the CLI in the project directory to avoid authentication when running the program.

    :param workspace_name: Name of Azure Machine Learning Workspace to get or create within the Azure Subscription
    :type workspace_name: str
    :param subscription_id: Azure subscription id
        Azure Subscription ID
    :type subscription_id: str
    :param resource_group: Azure Resource Group to get or create the workspace within. If the resource group does not
    exist it will be created.
    :type resource_group: str
    :param workspace_region: The Azure region to deploy the workspace.
    :type workspace_region: str
    :param auth: Derived classes provide different means to authenticate and acquire a token based on their targeted
    use case.
    For examples of authentication, see https://aka.ms/aml-notebook-auth.
    :type auth: azureml.core.authentication.AbstractAuthentication
    :param log: enable print output
    :return: Returns a :class:`azureml.core.Workspace` object, a pointer to Azure Machine Learning Workspace
    Learning Workspace
    :rtype: azureml.core.Workspace
    """
    if log:
        print("AML SDK Version:", azureml.core.VERSION)

    workspace = Workspace.create(
        name=workspace_name,
        subscription_id=subscription_id,
        resource_group=resource_group,
        location=workspace_region,
        auth=auth,
        exist_ok=True,
    )

    workspace.write_config()

    if log:
        ws_json = json.dumps(workspace.get_details(), indent=2)
        print(ws_json)

    return workspace
Example #11
0
def main(name, resource_group, location, subscription_id):
    ws = Workspace.create(name=name,
                          resource_group=resource_group,
                          subscription_id=subscription_id,
                          location=location,
                          exist_ok=True,
                          show_output=True)

    ws.write_config()
Example #12
0
def getOrCreateWorkspace(subscription_id, resource_group, workspace_name,
                         workspace_region):
    # By using the exist_ok param, if the workspace already exists we get a reference to the existing workspace instead of an error
    ws = Workspace.create(name=workspace_name,
                          subscription_id=subscription_id,
                          resource_group=resource_group,
                          location=workspace_region,
                          exist_ok=True)
    return ws
Example #13
0
def get_workspace(
    name: str,
    resource_group: str,
    subscription_id: str,
    tenant_id: str,
    app_id: str,
    app_secret: str,
    region: str,
    create_if_not_exist=False,
):
    """

    Parameters:
      name (str): name of the workspace
      resource_group (str): resource group name
      subscription_id (str): subscription id
      tenant_id (str): tenant id (aad id)
      app_id (str): service principal id
      app_secret (str): service principal password
      region (str): location of the workspace
      create_if_not_exist (bool): Default value is False

    Returns:
      Workspace: a reference to a workspace
    """
    service_principal = ServicePrincipalAuthentication(
        tenant_id=tenant_id,
        service_principal_id=app_id,
        service_principal_password=app_secret,
    )

    try:
        aml_workspace = Workspace.get(
            name=name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            auth=service_principal,
        )

    except WorkspaceException as exp_var:
        log.error("Error while retrieving Workspace...: %s", exp_var)
        if create_if_not_exist:
            log.info("Creating AzureML Workspace: %s", name)
            aml_workspace = Workspace.create(
                name=name,
                subscription_id=subscription_id,
                resource_group=resource_group,
                create_resource_group=True,
                location=region,
                auth=service_principal,
            )
            log.info("Workspace %s created.", aml_workspace.name)
        else:
            sys.exit(-1)

    return aml_workspace
Example #14
0
 def create_workspace(self, workspace_name):
     # Create the workspace using the specified parameters
     self.ws = Workspace.create(name=workspace_name,
                                subscription_id=self.subscription_id,
                                resource_group=self.rg_name,
                                location=self.location,
                                create_resource_group=True,
                                exist_ok=True)
     self.ws.get_details()
     return self.ws
Example #15
0
def create_workspace(subscription_id,ws_name='myworkspace',create_resource_group=True,resource_group='myresourcegroup',location='eastus2'):
    ws = Workspace.create(
               name=ws_name,            
               subscription_id=subscription_id,           
               resource_group=resource_group,                 
               create_resource_group=create_resource_group,                 
               location=location                
               )
    print('Created Workspace')
    ws.write_config()
    print("Saved config file")
Example #16
0
def get_or_create_workspace(
    config_path="./.azureml",
    subscription_id=None,
    resource_group=None,
    workspace_name=None,
    workspace_region=None,
):
    """
    Method to get or create workspace.

    Args:
        config_path: optional directory to look for / store config.json file (defaults to current
            directory)
        subscription_id: Azure subscription id
        resource_group: Azure resource group to create workspace and related resources
        workspace_name: name of azure ml workspace
        workspace_region: region for workspace

    Returns:
        obj: AzureML workspace if one exists already with the name otherwise creates a new one.
    """
    config_file_path = "."

    if config_path is not None:
        config_dir, config_file_name = os.path.split(config_path)
        if config_file_name != "config.json":
            config_file_path = os.path.join(config_path, "config.json")

    try:
        # get existing azure ml workspace
        if os.path.isfile(config_file_path):
            ws = Workspace.from_config(config_file_path, auth=get_auth())
        else:
            ws = Workspace.get(
                name=workspace_name,
                subscription_id=subscription_id,
                resource_group=resource_group,
                auth=get_auth(),
            )

    except ProjectSystemException:
        # this call might take a minute or two.
        print("Creating new workspace")
        ws = Workspace.create(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            create_resource_group=True,
            location=workspace_region,
            auth=get_auth(),
        )

        ws.write_config(path=config_path)
    return ws
Example #17
0
def azureml_workspace(auth_type='interactive'):
    if auth_type == 'interactive':
        auth = interactive_auth()
    elif auth_type == 'service_princpal':
        auth = service_principal_auth()

    ws = Workspace.create(name=workspace_name,
                          resource_group=resource_group,
                          subscription_id=subscription_id,
                          exist_ok=True,
                          auth=auth)
    return ws
Example #18
0
def getWorkspace(authentication, subscription_id, resource_group,
                 workspace_name, workspace_region):
    '''
        Obtains an existing workspace, or creates a new one. If a workspace exists in the subscription
        in the same resource group, with the same name it is returned, otherwise, a new one is created.

        PARAMS: 
            authentication   : azureml.core.authentication   : User Authentication with rights to sub 
            subscription_id  : String                        : Azure Subscription ID
            resource_group   : String                        : Azure Resource Group Name
            workspace_name   : String                        : AMLS workspace name
            workspace_region : String                        : Azure Region


        RETURNS: 
            azureml.core.Workspace
    '''
    return_workspace = None
    useExistingWorkspace = False
    workspaces = None
    '''
        If resource group doesn't exist, this will throw a ProjectSystemException  
    '''
    try:
        workspaces = Workspace.list(subscription_id, authentication,
                                    resource_group)
    except Exception as ex:
        workspaces = None
    '''
        See if it already exists
    '''
    if workspaces:
        for ws in workspaces.keys():
            if ws == workspace_name:
                useExistingWorkspace = True
    '''
        Return existing or create new
    '''
    if useExistingWorkspace:
        print("Loading existing workspace ....", workspace_name)
        return_workspace = Workspace.get(name=workspace_name,
                                         subscription_id=subscription_id,
                                         resource_group=resource_group)
    else:
        # Create one
        print("Creating new workspace ....", workspace_name)
        return_workspace = Workspace.create(name=workspace_name,
                                            subscription_id=subscription_id,
                                            resource_group=resource_group,
                                            create_resource_group=True,
                                            location=workspace_region)

    return return_workspace  #  program_context.workspace.get_details()
Example #19
0
def create_workspace(workspace_name,
                     subscription_id,
                     resource_group,
                     location='westeurope',
                     create_resource_group=False):

    ws = Workspace.create(name=workspace_name,
                          subscription_id=subscription_id,
                          resource_group=resource_group,
                          create_resource_group=create_resource_group,
                          location=location)

    ws.write_config()
Example #20
0
def main(argv):  
  try:
     opts, args = getopt.getopt(argv,"hs:rg:wn:wr:dsn:cn:an:ak:drg:",
      ["subscription_id=","resource_group=","workspace_name=", "workspace_region=","blob_datastore_name=","container_name=","account_name=","account_key=","datastore_rg="])
  except getopt.GetoptError:
     print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
     sys.exit(2)
  for opt, arg in opts:
     if opt == '-h':
        print 'aml_creation.py -s <subscription_id> -rg <resource_group> -wn <workspace_name> -wr <workspace_region>'
        sys.exit()
     elif opt in ("-s", "--subscription_id"):
        subscription_id = arg
     elif opt in ("-rg", "--resource_group"):
        resource_group = arg
     elif opt in ("-wn", "--workspace_name"):
        workspace_name = arg
     elif opt in ("-wr", "--workspace_region"):
        workspace_region = arg
     elif opt in ("-dsn", "--blob_datastore_name"):
        workspace_region = arg
     elif opt in ("-cn", "--container_name"):
        workspace_region = arg
     elif opt in ("-an", "--account_name"):
        workspace_region = arg
     elif opt in ("-ak", "--account_key"):
        workspace_region = arg
     elif opt in ("-drg", "--datastore_rg"):
        workspace_region = arg
        
    env_path = find_dotenv()
    if env_path == "":
        Path(".env").touch()
        env_path = find_dotenv()

    ws = Workspace.create(
      name=workspace_name,
      subscription_id=subscription_id,
      resource_group=resource_group,
      location=workspace_region,
      create_resource_group=True,
      auth=get_auth(env_path),
      exist_ok=True,
    )
    blob_datastore = Datastore.register_azure_blob_container(workspace=ws, 
                                                         datastore_name=blob_datastore_name, 
                                                         container_name=container_name, 
                                                         account_name=account_name,
                                                         account_key=account_key,
                                                         resource_group=datastore_rg)
Example #21
0
def load_workspace():
    load_dotenv()

    try:
        ws = Workspace.get(subscription_id=os.getenv("subscription_id"),
                           resource_group=os.getenv("resource_group"),
                           name=os.getenv("workspace_name"))
    except:
        ws = Workspace.create(subscription_id=os.getenv("subscription_id"),
                              resource_group=os.getenv("resource_group"),
                              name=os.getenv("workspace_name"),
                              location=os.getenv("location"))

    return ws
def create_ws(subscription_id, name):
    '''Creates an azure workspace'''

    subscription_id = subscription_id
    # resource_group = 'birdsong_classification'
    # workspace_name = 'birdsong_classification'

    workspace = Workspace.create(name=name,
                                 subscription_id=subscription_id,
                                 resource_group=name,
                                 create_resource_group=True,
                                 location='northcentralus')

    workspace.write_config(path='.azureml')
 def _get_workspace(self):
     self.log.info(f"Setting workspace {self.workspace_name}.")
     self._add_event(f"Setting workspace {self.workspace_name}", 1)
     self.workspace = Workspace.create(
         name=self.workspace_name,
         subscription_id=self.subscription_id,
         resource_group=self.resource_group_name,
         create_resource_group=False,
         location=self.location,
         sku='enterprise',
         show_output=False,
         exist_ok=True,
         auth=self.sp_auth)
     self.log.info(f"Using workspace: {self.workspace_name}.")
     self._add_event(f"Using workspace: {self.workspace_name}.", 10)
Example #24
0
def setup_workspace(workspace_name, subscription_id, resource_group, cli_auth,
                    location):
    """
    This sets up an Azure Workspace.
    An existing Azure Workspace is used or a new one is created if needed for
    the pytest run.

    Args:
        workspace_name  (str): Centralized location on Azure to work
                               with all the artifacts used by AzureML
                               service
        subscription_id (str): the Azure subscription id
        resource_group  (str): Azure Resource Groups are logical collections of
                         assets associated with a project. Resource groups
                         make it easy to track or delete all resources
                         associated with a project by tracking or deleting
                         the Resource group.
        cli_auth         Azure authentication
        location        (str): workspace reference

    Returns:
        ws: workspace reference
    """
    logger.debug("setup: workspace_name is {}".format(workspace_name))
    logger.debug("setup: resource_group is {}".format(resource_group))
    logger.debug("setup: subid is {}".format(subscription_id))
    logger.debug("setup: location is {}".format(location))

    try:
        # use existing workspace if there is one
        ws = Workspace.get(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            auth=cli_auth,
        )
    except WorkspaceException:
        # this call might take a minute or two.
        logger.debug("Creating new workspace")
        ws = Workspace.create(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            # create_resource_group=True,
            location=location,
            auth=cli_auth,
        )
    return ws
Example #25
0
 def create_workspace(self,
                      workspace_name,
                      location,
                      resource_group,
                      subscription_id,
                      container_registry=None,
                      app_insights=None):
     return Workspace.create(
         workspace_name,
         auth=self.auth,
         subscription_id=subscription_id,
         location=location,
         resource_group=resource_group,
         create_resource_group=True,
         app_insights=app_insights,
         container_registry=container_registry)
Example #26
0
def setup(num):
    workspace_name = '%s-%s-%02d' % (workspace_prefix, location, num)

    try:
        ws = Workspace.get(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group)
        print('Found existing workspace %s' % workspace_name)
    except WorkspaceException:
        print('Creating new workspace %s...' % workspace_name)

        ws = Workspace.create(
            name=workspace_name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            location=location)

    try:
        compute_target = AmlCompute(ws, compute_name)
        print('Found existing compute %s' % compute_name)

        compute_target.update(min_nodes=min_nodes, max_nodes=max_nodes)
    except ComputeTargetException:
        print('Creating new compute target %s...' % compute_name)

        compute_config = AmlCompute.provisioning_configuration(vm_size=vm_size, min_nodes=min_nodes, max_nodes=max_nodes)
        compute_target = ComputeTarget.create(ws, compute_name, compute_config)
        compute_target.wait_for_completion(show_output=True, timeout_in_minutes=20)

    ds = ws.get_default_datastore()
    ds.upload("testdata")

    dataset_name = 'sample_dataset'

    if dataset_name not in ws.datasets:
        data = Dataset.File.from_files(path=[(ds, 'testdata.txt')])

        data.register(
            workspace = ws,
            name = dataset_name,
            description = 'Sample data for load test')

        print('Dataset successfully registered')
    else:
        print('Dataset already exists')
Example #27
0
    def create(self, name):
        name = self._get_name(name)
        region = self.ctx.config.get('cluster/region', 'eastus2')
        resource_group = self.ctx.config.get(
            'resource_group', name+'-resources')
        self.ctx.log('Creating %s' % name)

        self.ws = Workspace.create(
            name=name,
            subscription_id=self.credentials.subscription_id,
            resource_group=resource_group,
            create_resource_group=True,
            location=region,
            auth=self.credentials.get_serviceprincipal_auth())
        self._select(name)
        self.ctx.log('%s created' % name)
        return {'created': name}
Example #28
0
def main():
    """
    Create workspace
    """
    config = json.load(open("config/azureml.json", "r"))
    work_space = Workspace.create(
        name="mltibame",  # provide a name for your workspace
        subscription_id=config[
            "subscription_id"],  # provide your subscription ID
        resource_group="Tibame",  # provide a resource group name
        create_resource_group=True,
        location=
        "eastus2",  # For example: 'westeurope', 'eastus2', 'westus2' or 'southeastasia'.
    )

    # write out the workspace details to a configuration file: .azureml/config.json
    work_space.write_config(path=".azureml")
Example #29
0
    def create(self, name):
        name = self._get_name(name)
        subscription_id = self.ctx.config.get('subscription_id', None)
        if subscription_id is None:
            raise AzureException('Please provide Azure subscription id...')
        region = self.ctx.config.get('cluster/region', 'eastus2')
        resource_group = self.ctx.config.get('resource_group',
                                             name + '-resources')
        self.ctx.log('Creating %s' % name)

        self.ws = Workspace.create(name=name,
                                   subscription_id=subscription_id,
                                   resource_group=resource_group,
                                   create_resource_group=True,
                                   location=region,
                                   auth=self._get_ws_auth())
        self._select(name)
        self.ctx.log('%s created' % name)
        return {'created': name}
Example #30
0
def get_workspace(workspace_location, workspace_name, resource_group,
                  subscription_id):
    svc_pr = ServicePrincipalAuthentication(
        tenant_id=dbutils.secrets.get(scope="azure-key-vault",
                                      key="tenant-id"),
        service_principal_id=dbutils.secrets.get(scope="azure-key-vault",
                                                 key="client-id"),
        service_principal_password=dbutils.secrets.get(scope="azure-key-vault",
                                                       key="client-secret"))

    workspace = Workspace.create(name=workspace_name,
                                 location=workspace_location,
                                 resource_group=resource_group,
                                 subscription_id=subscription_id,
                                 auth=svc_pr,
                                 exist_ok=True)

    print('Workspace: {} disponibilizada com sucesso'.format(workspace_name))
    return workspace