Skip to content

Commit 4c60f32

Browse files
vedkaleVed Kalewyunchi-ms
authored
update connectedmachine (#24064)
* update connectedmachine * Update src/ConnectedMachine/ConnectedMachine.Autorest/custom/New-AzConnectedMachineRunCommand_ScriptLocalPath.ps1 Co-authored-by: Yunchi Wang <[email protected]> * rename to tags * fix tests --------- Co-authored-by: Ved Kale <[email protected]> Co-authored-by: Yunchi Wang <[email protected]>
1 parent 93f3d90 commit 4c60f32

File tree

6 files changed

+392
-25
lines changed

6 files changed

+392
-25
lines changed

src/ConnectedMachine/ConnectedMachine.Autorest/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ directive:
265265
parameter-name: AgentUpgradeEnableAutomaticUpgrade
266266
set:
267267
parameter-name: AgentUpgradeEnableAutomatic
268+
269+
# Rename Tag to Tags
270+
- where:
271+
property-name: Tag
272+
set:
273+
property-name: Tags
268274

269275
# Formatting
270276
- where:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models
2+
{
3+
using static Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Runtime.Extensions;
4+
5+
public partial class MachineExtension
6+
{
7+
public string MachineName
8+
{
9+
get => (new global::System.Text.RegularExpressions.Regex("^/subscriptions/(?<subscriptionId>[^/]+)/resourceGroups/(?<resourceGroupName>[^/]+)/providers/Microsoft.HybridCompute/machines/(?<machineName>[^/]+)",
10+
global::System.Text.RegularExpressions.RegexOptions.IgnoreCase).Match(this.Id).Success ?
11+
new global::System.Text.RegularExpressions.Regex("^/subscriptions/(?<subscriptionId>[^/]+)/resourceGroups/(?<resourceGroupName>[^/]+)/providers/Microsoft.HybridCompute/machines/(?<machineName>[^/]+)",
12+
global::System.Text.RegularExpressions.RegexOptions.IgnoreCase).Match(this.Id).Groups["machineName"].Value : null);
13+
}
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models
2+
{
3+
using static Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Runtime.Extensions;
4+
5+
public partial class MachineRunCommand
6+
{
7+
public string MachineName
8+
{
9+
get => (new global::System.Text.RegularExpressions.Regex("^/subscriptions/(?<subscriptionId>[^/]+)/resourceGroups/(?<resourceGroupName>[^/]+)/providers/Microsoft.HybridCompute/machines/(?<machineName>[^/]+)",
10+
global::System.Text.RegularExpressions.RegexOptions.IgnoreCase).Match(this.Id).Success ?
11+
new global::System.Text.RegularExpressions.Regex("^/subscriptions/(?<subscriptionId>[^/]+)/resourceGroups/(?<resourceGroupName>[^/]+)/providers/Microsoft.HybridCompute/machines/(?<machineName>[^/]+)",
12+
global::System.Text.RegularExpressions.RegexOptions.IgnoreCase).Match(this.Id).Groups["machineName"].Value : null);
13+
}
14+
}
15+
16+
}
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
# ----------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
13+
# is regenerated.
14+
# ----------------------------------------------------------------------------------
15+
16+
function New-AzConnectedMachineRunCommand_ScriptLocalPath {
17+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.IMachineRunCommand])]
18+
[CmdletBinding(PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')]
19+
param(
20+
[Parameter(Mandatory)]
21+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Path')]
22+
[System.String]
23+
# The name of the hybrid machine.
24+
${MachineName},
25+
26+
[Parameter(Mandatory)]
27+
[ArgumentCompleter({ Get-AzResourceGroup | Select-Object -ExpandProperty ResourceGroupName })]
28+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Path')]
29+
[System.String]
30+
# The name of the resource group.
31+
# The name is case insensitive.
32+
${ResourceGroupName},
33+
34+
[Parameter(Mandatory)]
35+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Path')]
36+
[System.String]
37+
# The name of the run command.
38+
${RunCommandName},
39+
40+
[Parameter(Mandatory)]
41+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Path')]
42+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Runtime.DefaultInfo(Script = '(Get-AzContext).Subscription.Id')]
43+
[System.String]
44+
# The ID of the target subscription.
45+
${SubscriptionId},
46+
47+
[Parameter(Mandatory)]
48+
[ArgumentCompleter({ Get-AzLocation | Where-Object Providers -Contains "Microsoft.HybridCompute" | Select-Object -ExpandProperty Location })]
49+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
50+
[System.String]
51+
# The geo-location where the resource lives
52+
${Location},
53+
54+
[Parameter()]
55+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
56+
[System.Management.Automation.SwitchParameter]
57+
# Optional.
58+
# If set to true, provisioning will complete as soon as script starts and will not wait for script to complete.
59+
${AsyncExecution},
60+
61+
[Parameter()]
62+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
63+
[System.String]
64+
# Client Id (GUID value) of the user-assigned managed identity.
65+
# ObjectId should not be used if this is provided.
66+
${ErrorBlobManagedIdentityClientId},
67+
68+
[Parameter()]
69+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
70+
[System.String]
71+
# Object Id (GUID value) of the user-assigned managed identity.
72+
# ClientId should not be used if this is provided.
73+
${ErrorBlobManagedIdentityObjectId},
74+
75+
[Parameter()]
76+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
77+
[System.String]
78+
# Specifies the Azure storage blob where script error stream will be uploaded.
79+
# Use a SAS URI with read, append, create, write access OR use managed identity to provide the VM access to the blob.
80+
# Refer errorBlobManagedIdentity parameter.
81+
${ErrorBlobUri},
82+
83+
[Parameter()]
84+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
85+
[System.String]
86+
# Client Id (GUID value) of the user-assigned managed identity.
87+
# ObjectId should not be used if this is provided.
88+
${OutputBlobManagedIdentityClientId},
89+
90+
[Parameter()]
91+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
92+
[System.String]
93+
# Object Id (GUID value) of the user-assigned managed identity.
94+
# ClientId should not be used if this is provided.
95+
${OutputBlobManagedIdentityObjectId},
96+
97+
[Parameter()]
98+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
99+
[System.String]
100+
# Specifies the Azure storage blob where script output stream will be uploaded.
101+
# Use a SAS URI with read, append, create, write access OR use managed identity to provide the VM access to the blob.
102+
# Refer outputBlobManagedIdentity parameter.
103+
${OutputBlobUri},
104+
105+
[Parameter()]
106+
[AllowEmptyCollection()]
107+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
108+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.IRunCommandInputParameter[]]
109+
# The parameters used by the script.
110+
# To construct, see NOTES section for PARAMETER properties and create a hash table.
111+
${Parameter},
112+
113+
[Parameter()]
114+
[AllowEmptyCollection()]
115+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
116+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.IRunCommandInputParameter[]]
117+
# The parameters used by the script.
118+
# To construct, see NOTES section for PROTECTEDPARAMETER properties and create a hash table.
119+
${ProtectedParameter},
120+
121+
[Parameter()]
122+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
123+
[System.String]
124+
# Specifies the user account password on the machine when executing the run command.
125+
${RunAsPassword},
126+
127+
[Parameter()]
128+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
129+
[System.String]
130+
# Specifies the user account on the machine when executing the run command.
131+
${RunAsUser},
132+
133+
[Parameter()]
134+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
135+
[System.String]
136+
# Client Id (GUID value) of the user-assigned managed identity.
137+
# ObjectId should not be used if this is provided.
138+
${ScriptUriManagedIdentityClientId},
139+
140+
[Parameter()]
141+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
142+
[System.String]
143+
# Object Id (GUID value) of the user-assigned managed identity.
144+
# ClientId should not be used if this is provided.
145+
${ScriptUriManagedIdentityObjectId},
146+
147+
[Parameter()]
148+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
149+
[System.String]
150+
# Specifies the commandId of predefined built-in script.
151+
${SourceCommandId},
152+
153+
[Parameter()]
154+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
155+
[System.String]
156+
# Specifies the script content to be executed on the machine.
157+
${SourceScript},
158+
159+
[Parameter()]
160+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
161+
[System.String]
162+
# Specifies the script download location.
163+
# It can be either SAS URI of an Azure storage blob with read access or public URI.
164+
${SourceScriptUri},
165+
166+
[Parameter()]
167+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
168+
[System.String]
169+
# Specifies the commandId of predefined built-in script.
170+
${ScriptLocalPath},
171+
172+
[Parameter()]
173+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
174+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Runtime.Info(PossibleTypes = ([Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Models.ITrackedResourceTags]))]
175+
[System.Collections.Hashtable]
176+
# Resource tags.
177+
${Tag},
178+
179+
[Parameter()]
180+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Body')]
181+
[System.Int32]
182+
# The timeout in seconds to execute the run command.
183+
${TimeoutInSecond},
184+
185+
[Parameter()]
186+
[Alias('AzureRMContext', 'AzureCredential')]
187+
[ValidateNotNull()]
188+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Azure')]
189+
[System.Management.Automation.PSObject]
190+
# The DefaultProfile parameter is not functional.
191+
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
192+
${DefaultProfile},
193+
194+
[Parameter()]
195+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
196+
[System.Management.Automation.SwitchParameter]
197+
# Run the command as a job
198+
${AsJob},
199+
200+
[Parameter(DontShow)]
201+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
202+
[System.Management.Automation.SwitchParameter]
203+
# Wait for .NET debugger to attach
204+
${Break},
205+
206+
[Parameter(DontShow)]
207+
[ValidateNotNull()]
208+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
209+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Runtime.SendAsyncStep[]]
210+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
211+
${HttpPipelineAppend},
212+
213+
[Parameter(DontShow)]
214+
[ValidateNotNull()]
215+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
216+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Runtime.SendAsyncStep[]]
217+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
218+
${HttpPipelinePrepend},
219+
220+
[Parameter()]
221+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
222+
[System.Management.Automation.SwitchParameter]
223+
# Run the command asynchronously
224+
${NoWait},
225+
226+
[Parameter(DontShow)]
227+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
228+
[System.Uri]
229+
# The URI for the proxy server to use
230+
${Proxy},
231+
232+
[Parameter(DontShow)]
233+
[ValidateNotNull()]
234+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
235+
[System.Management.Automation.PSCredential]
236+
# Credentials for a proxy server to use for the remote call
237+
${ProxyCredential},
238+
239+
[Parameter(DontShow)]
240+
[Microsoft.Azure.PowerShell.Cmdlets.ConnectedMachine.Category('Runtime')]
241+
[System.Management.Automation.SwitchParameter]
242+
# Use the default credentials for the proxy
243+
${ProxyUseDefaultCredentials}
244+
)
245+
246+
process {
247+
if ($PSBoundParameters.ContainsKey("ScriptLocalPath"))
248+
{
249+
# Read Local File and add
250+
$script = ""
251+
if ((Get-ChildItem $scriptLocalPath | Select-Object Extension).Extension -eq ".sh"){
252+
foreach ($line in Get-Content -Path $scriptLocalPath){
253+
$words = $line.trim().split()
254+
$commentFound = $false
255+
foreach ($word in $words){
256+
if ($word[0] -eq "#" -and $commentFound -eq $false){
257+
$commentFound = $true
258+
$script += "``" + $word + " "
259+
}
260+
else{
261+
$script += $word + " "
262+
}
263+
}
264+
$script = $script.trim()
265+
#close
266+
if ($commentFound){
267+
$script += "``"
268+
}
269+
$script += ";"
270+
}
271+
}
272+
else{
273+
foreach ($line in Get-Content -Path $scriptLocalPath){
274+
$words = $line.trim().split()
275+
$commentFound = $false
276+
foreach ($word in $words){
277+
if ($word[0] -eq "#" -and $commentFound -eq $false){
278+
$commentFound = $true
279+
$script += "<" + $word + " "
280+
}
281+
else{
282+
$script += $word + " "
283+
}
284+
}
285+
$script = $script.trim()
286+
#close
287+
if ($commentFound){
288+
$script += "#>"
289+
}
290+
$script += ";"
291+
}
292+
}
293+
294+
$PSBoundParameters.Add("SourceScript", $script)
295+
# If necessary, remove the -ParameterA parameter from the dictionary of bound parameters
296+
$null = $PSBoundParameters.Remove("ScriptLocalPath")
297+
}
298+
Az.ConnectedMachine\New-AzConnectedMachineRunCommand @PSBoundParameters
299+
}
300+
}

0 commit comments

Comments
 (0)