You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refresh snippets based on API changes (Azure#27064)
* refresh snippets based on API changes
* remove one var
* update snippet for var
* update RI ctor consistency
* remove section on tryget RI methods
* remove getallasync
* update comment on getall
Copy file name to clipboardExpand all lines: sdk/resourcemanager/Azure.ResourceManager/README.md
+39-43Lines changed: 39 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,12 +34,13 @@ The default option to create an authenticated client is to use `DefaultAzureCred
34
34
To authenticate to Azure and create an `ArmClient`, do the following:
35
35
36
36
```C# Snippet:Readme_AuthClient
37
-
usingAzure.Identity;
38
-
usingAzure.ResourceManager;
39
-
usingAzure.ResourceManager.Resources;
40
37
usingSystem;
41
38
usingSystem.Threading.Tasks;
42
39
usingAzure.Core;
40
+
usingAzure.Identity;
41
+
usingAzure.ResourceManager;
42
+
usingAzure.ResourceManager.Compute;
43
+
usingAzure.ResourceManager.Resources;
43
44
44
45
// Code omitted for brevity
45
46
@@ -61,16 +62,16 @@ This represents a full resource client object which contains a **Data** property
61
62
It also has access to all of the operations on that resource without needing to pass in scope parameters such as subscription ID or resource name. This makes it very convenient to directly execute operations on the result of list calls
62
63
since everything is returned as a full resource client now.
//previously we would have to take the resourceGroupName and the vmName from the vm object
72
73
//and pass those into the powerOff method as well as we would need to execute that on a separate compute client
73
-
awaitvm.StartPowerOff().WaitForCompletionAsync();
74
+
awaitvm.PowerOffAsync(true);
74
75
}
75
76
```
76
77
@@ -96,9 +97,9 @@ For most things, the parent will be a **ResourceGroup**. However, each parent /
96
97
## Putting it all together
97
98
Imagine that our company requires all virtual machines to be tagged with the owner. We're tasked with writing a program to add the tag to any missing virtual machines in a given resource group.
Resource IDs contain useful information about the resource itself, but they are plain strings that have to be parsed. Instead of implementing your own parsing logic, you can use a `ResourceIdentifier` object which will do the parsing for you: `new ResourceIdentifer("myid");`.
127
128
128
129
### Example: Parsing an ID using a ResourceIdentifier object
However, keep in mind that some of those properties could be null. You can usually tell by the id string itself which type a resource ID is, but if you are unsure, check if the properties are null or use the Try methods to retrieve the values as it's shown below:
// Parent is only null when we reach the top of the chain which is a Tenant
146
-
Console.WriteLine($"Vnet: {id.Parent.Name}");
147
-
// Name will never be null
148
-
Console.WriteLine($"Subnet: {id.Name}");
149
-
```
150
137
151
138
## Managing Existing Resources By Id
152
139
Performing operations on resources that already exist is a common use case when using the management client libraries. In this scenario you usually have the identifier of the resource you want to work on as a string. Although the new object hierarchy is great for provisioning and working within the scope of a given parent, it is not the most efficient when it comes to this specific scenario.
153
140
154
141
Here is an example how you to access an `AvailabilitySet` object and manage it directly with its id:
// At this point availabilitySet.Data will be null and trying to access it will throw
167
+
// If we want to retrieve the objects data we can simply call get
168
+
availabilitySet=awaitavailabilitySet.GetAsync();
169
+
// we now have the data representing the availabilitySet
170
+
Console.WriteLine(availabilitySet.Data.Name);
171
+
```
172
+
173
+
We also provide an option that if you only know the pieces that make up the `ResourceIdentifier` each resource provides a static method to construct the full string from those pieces.
0 commit comments