Skip to content

Commit f014243

Browse files
Merge pull request #213088 from Blackmist/sdk-links
v1 -> v2 work
2 parents f417653 + 102b1d3 commit f014243

File tree

5 files changed

+416
-74
lines changed

5 files changed

+416
-74
lines changed

articles/machine-learning/how-to-manage-workspace-terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The configuration below creates a workspace in an isolated network environment u
6767

6868
Some resources in Azure require globally unique names. Before deploying your resources using the following templates, set the `resourceprefix` variable to a value that is unique.
6969

70-
When using private link endpoints for both Azure Container Registry and Azure Machine Learning, Azure Container Registry tasks cannot be used for building [environment](/python/api/azureml-core/azureml.core.environment.environment?view=azure-ml-py&preserve-view=true) images. Instead you can build images using an Azure Machine Learning compute cluster. To configure the cluster name of use, set the [image_build_compute_name](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/machine_learning_workspace) argument. You can configure to [allow public access](./how-to-configure-private-link.md?tabs=python#enable-public-access) to a workspace that has a private link endpoint using the [public_network_access_enabled](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/machine_learning_workspace) argument.
70+
When using private link endpoints for both Azure Container Registry and Azure Machine Learning, Azure Container Registry tasks cannot be used for building [environment](/python/api/azure-ai-ml/azure.ai.ml.entities.environment) images. Instead you can build images using an Azure Machine Learning compute cluster. To configure the cluster name of use, set the [image_build_compute_name](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/machine_learning_workspace) argument. You can configure to [allow public access](./how-to-configure-private-link.md?tabs=python#enable-public-access) to a workspace that has a private link endpoint using the [public_network_access_enabled](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/machine_learning_workspace) argument.
7171

7272
**variables.tf**:
7373
:::code language="terraform" source="~/terraform/quickstart/201-machine-learning-moderately-secure/variables.tf":::

articles/machine-learning/how-to-secure-workspace-vnet.md

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ ms.author: jhirono
1010
author: jhirono
1111
ms.date: 06/17/2022
1212
ms.topic: how-to
13-
ms.custom: contperf-fy20q4, tracking-python, contperf-fy21q1, security, cliv2, sdkv1, event-tier1-build-2022
13+
ms.custom: contperf-fy20q4, tracking-python, contperf-fy21q1, security, cliv2, sdkv2, event-tier1-build-2022
1414
---
1515

1616
# Secure an Azure Machine Learning workspace with virtual networks
1717

18+
[!INCLUDE [sdk/cli v2](../../includes/machine-learning-dev-v2.md)]
19+
20+
> [!div class="op_single_selector" title1="Select the version of Azure Machine Learning SDK/CLI extension you are using:"]
21+
> * [v1](v1/how-to-secure-workspace-vnet.md)
22+
> * [v2 (current version)](how-to-secure-workspace-vnet.md)
23+
1824
In this article, you learn how to secure an Azure Machine Learning workspace and its associated resources in a virtual network.
1925

2026
> [!TIP]
@@ -34,7 +40,6 @@ In this article you learn how to enable the following workspaces resources in a
3440
> [!div class="checklist"]
3541
> - Azure Machine Learning workspace
3642
> - Azure Storage accounts
37-
> - Azure Machine Learning datastores and datasets
3843
> - Azure Key Vault
3944
> - Azure Container Registry
4045
@@ -66,7 +71,7 @@ In this article you learn how to enable the following workspaces resources in a
6671

6772
## Limitations
6873

69-
### Azure Storage Account
74+
### Azure storage account
7075

7176
* If you plan to use Azure Machine Learning studio and the storage account is also in the VNet, there are extra validation requirements:
7277

@@ -221,18 +226,26 @@ Azure Container Registry can be configured to use a private endpoint. Use the fo
221226
222227
# [Python SDK](#tab/python)
223228
224-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
229+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
225230
226-
The following code snippet demonstrates how to get the container registry information using the [Azure Machine Learning SDK](/python/api/overview/azure/ml/):
231+
The following code snippet demonstrates how to get the container registry information using the [Azure Machine Learning SDK](/python/api/overview/azure/ai-ml-readme):
227232
228-
```python
229-
from azureml.core import Workspace
230-
# Load workspace from an existing config file
231-
ws = Workspace.from_config()
232-
# Get details on the workspace
233-
details = ws.get_details()
234-
# Print container registry information
235-
print(details['containerRegistry'])
233+
```python
234+
# import required libraries
235+
from azure.ai.ml import MLClient
236+
from azure.identity import DefaultAzureCredential
237+
238+
subscription_id = "<your subscription ID>"
239+
resource_group = "<your resource group name>"
240+
workspace = "<your workspace name>"
241+
242+
ml_client = MLClient(
243+
DefaultAzureCredential(), subscription_id, resource_group, workspace
244+
)
245+
246+
# Get workspace info
247+
ws=ml_client.workspaces.get(name=workspace)
248+
print(ws.container_registry)
236249
```
237250
238251
This code returns a value similar to `"/subscriptions/{GUID}/resourceGroups/{resourcegroupname}/providers/Microsoft.ContainerRegistry/registries/{ACRname}"`. The last part of the string is the name of the Azure Container Registry for the workspace.
@@ -268,21 +281,35 @@ Azure Container Registry can be configured to use a private endpoint. Use the fo
268281
269282
# [Python SDK](#tab/python)
270283
271-
The following code snippet demonstrates how to update the workspace to set a build compute using the [Azure Machine Learning SDK](/python/api/overview/azure/ml/). Replace `mycomputecluster` with the name of the cluster to use:
284+
The following code snippet demonstrates how to update the workspace to set a build compute using the [Azure Machine Learning SDK](/python/api/overview/azure/ai-ml-readme). Replace `mycomputecluster` with the name of the cluster to use:
272285
273-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
286+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
274287
275288
```python
276-
from azureml.core import Workspace
277-
# Load workspace from an existing config file
278-
ws = Workspace.from_config()
279-
# Update the workspace to use an existing compute cluster
280-
ws.update(image_build_compute = 'mycomputecluster')
289+
# import required libraries
290+
from azure.ai.ml import MLClient
291+
from azure.identity import DefaultAzureCredential
292+
293+
subscription_id = "<your subscription ID>"
294+
resource_group = "<your resource group name>"
295+
workspace = "<your workspace name>"
296+
297+
ml_client = MLClient(
298+
DefaultAzureCredential(), subscription_id, resource_group, workspace
299+
)
300+
301+
# Get workspace info
302+
ws=ml_client.workspaces.get(name=workspace)
303+
# Update to use cpu-cluster for image builds
304+
ws.image_build_compute="cpu-cluster"
305+
ml_client.workspaces.begin_update(ws)
281306
# To switch back to using ACR to build (if ACR is not in the VNet):
282-
# ws.update(image_build_compute = '')
307+
# ws.image_build_compute = ''
308+
# ml_client.workspaces.begin_update(ws)
283309
```
310+
284311
285-
For more information, see the [update()](/python/api/azureml-core/azureml.core.workspace.workspace#update-friendly-name-none--description-none--tags-none--image-build-compute-none--enable-data-actions-none-) method reference.
312+
For more information, see the [begin_update](/python/api/azure-ai-ml/azure.ai.ml.operations.workspaceoperations#azure-ai-ml-operations-workspaceoperations-begin-update) method reference.
286313
287314
# [Portal](#tab/portal)
288315
@@ -293,54 +320,6 @@ Azure Container Registry can be configured to use a private endpoint. Use the fo
293320
> [!TIP]
294321
> When ACR is behind a VNet, you can also [disable public access](../container-registry/container-registry-access-selected-networks.md#disable-public-network-access) to it.
295322
296-
## Datastores and datasets
297-
The following table lists the services that you need to skip validation for:
298-
299-
| Service | Skip validation required? |
300-
| ----- |:-----:|
301-
| Azure Blob storage | Yes |
302-
| Azure File share | Yes |
303-
| Azure Data Lake Store Gen1 | No |
304-
| Azure Data Lake Store Gen2 | No |
305-
| Azure SQL Database | Yes |
306-
| PostgreSql | Yes |
307-
308-
> [!NOTE]
309-
> Azure Data Lake Store Gen1 and Azure Data Lake Store Gen2 skip validation by default, so you don't have to do anything.
310-
311-
The following code sample creates a new Azure Blob datastore and sets `skip_validation=True`.
312-
313-
```python
314-
blob_datastore = Datastore.register_azure_blob_container(workspace=ws,
315-
316-
datastore_name=blob_datastore_name,
317-
318-
container_name=container_name,
319-
320-
account_name=account_name,
321-
322-
account_key=account_key,
323-
324-
skip_validation=True ) // Set skip_validation to true
325-
```
326-
327-
### Use datasets
328-
329-
The syntax to skip dataset validation is similar for the following dataset types:
330-
- Delimited file
331-
- JSON
332-
- Parquet
333-
- SQL
334-
- File
335-
336-
The following code creates a new JSON dataset and sets `validate=False`.
337-
338-
```python
339-
json_ds = Dataset.Tabular.from_json_lines_files(path=datastore_paths,
340-
341-
validate=False)
342-
```
343-
344323
## Securely connect to your workspace
345324
346325
[!INCLUDE [machine-learning-connect-secure-workspace](../../includes/machine-learning-connect-secure-workspace.md)]

articles/machine-learning/v1/how-to-create-register-datasets.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Create a TabularDataset with [the Python SDK](#create-a-tabulardataset) or [Azur
9595
9696
## Access datasets in a virtual network
9797

98-
If your workspace is in a virtual network, you must configure the dataset to skip validation. For more information on how to use datastores and datasets in a virtual network, see [Secure a workspace and associated resources](../how-to-secure-workspace-vnet.md#datastores-and-datasets).
98+
If your workspace is in a virtual network, you must configure the dataset to skip validation. For more information on how to use datastores and datasets in a virtual network, see [Secure a workspace and associated resources](how-to-secure-workspace-vnet.md#datastores-and-datasets).
9999

100100

101101
## Create datasets from datastores
@@ -119,7 +119,7 @@ To create datasets from a datastore with the Python SDK:
119119

120120
Use the [`from_files()`](/python/api/azureml-core/azureml.data.dataset_factory.filedatasetfactory#from-files-path--validate-true-) method on the `FileDatasetFactory` class to load files in any format and to create an unregistered FileDataset.
121121

122-
If your storage is behind a virtual network or firewall, set the parameter `validate=False` in your `from_files()` method. This bypasses the initial validation step, and ensures that you can create your dataset from these secure files. Learn more about how to [use datastores and datasets in a virtual network](../how-to-secure-workspace-vnet.md#datastores-and-datasets).
122+
If your storage is behind a virtual network or firewall, set the parameter `validate=False` in your `from_files()` method. This bypasses the initial validation step, and ensures that you can create your dataset from these secure files. Learn more about how to [use datastores and datasets in a virtual network](how-to-secure-workspace-vnet.md#datastores-and-datasets).
123123

124124
```Python
125125
from azureml.core import Workspace, Datastore, Dataset
@@ -156,7 +156,7 @@ Use the [`from_delimited_files()`](/python/api/azureml-core/azureml.data.dataset
156156

157157
See the [TabularDatasetFactory reference documentation](/python/api/azureml-core/azureml.data.dataset_factory.tabulardatasetfactory) for information about supported file formats, as well as syntax and design patterns such as [multiline support](/python/api/azureml-core/azureml.data.dataset_factory.tabulardatasetfactory#from-delimited-files-path--validate-true--include-path-false--infer-column-types-true--set-column-types-none--separator------header-true--partition-format-none--support-multi-line-false--empty-as-string-false--encoding--utf8--).
158158

159-
If your storage is behind a virtual network or firewall, set the parameter `validate=False` in your `from_delimited_files()` method. This bypasses the initial validation step, and ensures that you can create your dataset from these secure files. Learn more about how to use [datastores and datasets in a virtual network](../how-to-secure-workspace-vnet.md#datastores-and-datasets).
159+
If your storage is behind a virtual network or firewall, set the parameter `validate=False` in your `from_delimited_files()` method. This bypasses the initial validation step, and ensures that you can create your dataset from these secure files. Learn more about how to use [datastores and datasets in a virtual network](how-to-secure-workspace-vnet.md#datastores-and-datasets).
160160

161161
The following code gets the existing workspace and the desired datastore by name. And then passes the datastore and file locations to the `path` parameter to create a new TabularDataset, `weather_ds`.
162162

0 commit comments

Comments
 (0)