Skip to content

Commit dab45f1

Browse files
committed
Merge pull request #135 from huangpf/clu
Clu
2 parents db20058 + 09ddafe commit dab45f1

File tree

724 files changed

+15848
-7509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

724 files changed

+15848
-7509
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ src/Publish/
33
src/Package/
44
drop/
55

6+
# external tools
7+
tools/CLU/7zip/
8+
69
obj
710
TestResults
811
*.orig

clu-getstart.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Work on CLU cmdlets
1+
# Work on CLU cmdlets
22

33
## Prerequsites
44

55
* Visual Studio 2015 RTM with ASP.NET. For details, check out the [installation doc](http://docs.asp.net/en/latest/getting-started/installing-on-windows.html).
66

77
Note, after done, run `dnvm list` command to check the 'coreclr' runtime is installed with right version of `1.0.0-rc1-final`. If not, run `dnvm install 1.0.0-rc1-final -r coreclr -a x64 -p`. Remember always use `-p` flag, so the selection can persist.
88

9-
* Get the latest dotnet from "https://azureclu.blob.core.windows.net/tools/dotnet-win-x64.latest.zip", unzip, then add its bin folder to the PATH
9+
* Get the latest dotnet from "https://azureclu.blob.core.windows.net/tools/dotnet-win-x64.latest.zip", unzip, then add its bin folder to the PATH. NOTE: With this version of dotnet, the path to dotnet.exe must not contain any spaces.
1010

1111
## Project Artifacts
1212

@@ -25,7 +25,7 @@ CLUPackages require some additional files to direct generation of indexing, and
2525
| ------------- |:-------------:|
2626
| CommandAssemblies | File name of cmdlets assembly(ies) |
2727
| NounPrefix | ‘AzureRm’ The part of the cmdlet noun to remove in clu commands|
28-
| NounFirst | if true, the verb comes at the end of the command (e.g. az resource get)|
28+
| NounFirst | if true, the verb comes at the end of the command (e.g. az resource ls)|
2929

3030
* \<modulename\>.nuspec.template, which contains nuspec format metadata about the package – the base temaplate is in tools\clu\Microsoft.Azure.Commands.nuspec.template. Here are the special fields defined in this template:
3131
* %PackageId% - replace with the module name (Microsoft.Azure.Commands.\<rp-name\>)
@@ -60,19 +60,26 @@ There is also `<repo-root>\tools\CLU\SetupEnv.bat` which is a windows batch wrap
6060

6161
To test on osx/linux boxes, do #1, open `<repo-root>\drop\clurun`, copy the flavor folder to your target machine, and run the "az.sh" inside. Make sure set execution permission using `chmod +x az.sh clurun`
6262

63-
(All of those are subject to change, contact yugangw or adxsdkdev for any questions)
63+
### Nightly Builds
64+
You can also consume tarballs from the nightly build. The latest drops are available at:
65+
- ubuntu: [download](https://azurecludrops.blob.core.windows.net/drops/ubuntu.14.04-x64.latest.tar.gz)
66+
- osx: [download](https://azurecludrops.blob.core.windows.net/drops/osx.10.10-x64.latest.tar.gz)
67+
- windows: [download](https://azurecludrops.blob.core.windows.net/drops/win7-x64.latest.tar.gz)
68+
69+
70+
(All of those are subject to change, contact adxsdkdev for any questions)
6471

6572
## Quick introductions on cmdlets
66-
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env get` maps to the cmdlet `Get-AzureRmEnvironment`
67-
* Cmdlet parameters use the double dash (--) so for example, getting a subscription with a particular name would be: `az subscription get –-SubscriptionName “name of subscription"`
73+
* Run commands using the ‘az’ prefix, cmdlet nouns, and cmdlet verbs, for example, `az env ls` maps to the cmdlet `Get-AzureRmEnvironment`
74+
* Cmdlet parameters use the double dash (--) so for example, getting a subscription with a particular name would be: `az subscription ls –-SubscriptionName “name of subscription"`
6875
* To log in, 3 options
69-
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az account add`
70-
* login with user and password, this works on org-id w/o 2fa enforced, example: `az account add --Username [email protected] --Password password1`
71-
* login as service principal. Example: `az account add --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
76+
* login interactively using device flow, this is the only option for msa account or any org-id with 2fa enforced, example: `az login`
77+
* login with user and password, this works on org-id w/o 2fa enforced, example: `az login --Username [email protected] --Password password1`
78+
* login as service principal. Example: `az login --ServicePrincipal --TenantId <tenant> --ApplicationId <id> --Secret <secret>`
7279
* Piping between cmdlets should work the same way that Powerhell piping works
73-
```az subscription get --SubscriptionName | az context set```
80+
```az subscription ls --SubscriptionName | az context set```
7481
* You can capture piped output using redirection to a file - the result will be the json serialization of the output object.
75-
```az subscription get > subscriptions.json```
82+
```az subscription ls > subscriptions.json```
7683
* You can use file input to a parameter using '@' notation:
7784
```az command --param1 @file1.json```
7885
Reads input from file1.json and attempts to deserialize the .net object that is the Parameter type for ```param1```

dockerfiles/latest-trusty/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ubuntu:14.04
2+
3+
# all in one RUN to produce less, smaller layers
4+
RUN bash -c "\
5+
sudo apt-get -qqy update && \
6+
sudo apt-get -qqy upgrade && \
7+
sudo apt-get -qqy install wget libicu-dev libunwind8-dev libcurl3 libcurl4-gnutls-dev && \
8+
sudo apt-get clean && \
9+
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*"
10+
11+
RUN bash -c "\
12+
mkdir /opt/az && \
13+
cd /opt/az && \
14+
wget https://azurecludrops.blob.core.windows.net/drops/ubuntu.14.04-x64.latest.tar.gz && \
15+
tar xvzf ubuntu.14.04-x64.latest.tar.gz"
16+
17+
ENV PATH "$PATH:/opt/az/ubuntu.14.04-x64/"
18+
19+
WORKDIR /opt/az/ubuntu.14.04-x64/

dockerfiles/stable-trusty/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ubuntu:14.04
2+
3+
# all in one RUN to produce less, smaller layers
4+
RUN bash -c "\
5+
sudo apt-get -qqy update && \
6+
sudo apt-get -qqy upgrade && \
7+
sudo apt-get -qqy install wget libicu-dev libunwind8-dev libcurl3 libcurl4-gnutls-dev && \
8+
sudo apt-get clean && \
9+
sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*"
10+
11+
RUN bash -c "\
12+
mkdir /opt/az && \
13+
cd /opt/az && \
14+
wget https://azurecludrops.blob.core.windows.net/blessed/ubuntu.14.04-x64.latest.tar.gz && \
15+
tar xvzf ubuntu.14.04-x64.latest.tar.gz"
16+
17+
ENV PATH "$PATH:/opt/az/ubuntu.14.04-x64/"
18+
19+
WORKDIR /opt/az/ubuntu.14.04-x64/

examples/compute-management/02-VirtualMachineCreation.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName"
66
az resource group create -n "$groupName" --location "$location"
77

88
printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
9-
az storage account create--resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
9+
az storage account create --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
1010

1111
printf "\n3. Create virtual network.\n"
12-
result=`az vnet create--resourcegroupname "$groupName" --name test --location "$location" --addressprefix "[\"10.0.0.0/16\"]" --subnet "[{\"Name\":\"test\",\"AddressPrefix\":\"10.0.0.0/24\"}]" --force`
12+
result=`az vnet create --resourcegroupname "$groupName" --name test --location "$location" --addressprefix "[\"10.0.0.0/16\"]" --subnet "[{\"Name\":\"test\",\"AddressPrefix\":\"10.0.0.0/24\"}]" --force`
1313

1414
contextResult=`az context ls`
1515

1616
subId=`echo $contextResult | jq '.Subscription.SubscriptionId' --raw-output`
1717

1818
subnetId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/virtualNetworks/test/subnets/test"
1919

20-
printf "\n4. Create network interface with:\r\nsubId='%s' \r\n& \r\nsubnetId='$subnetId'.\n" "$subId"
20+
printf "\n4. Create network interface with:\r\nsubId='%s' \r\n& \r\nsubnet='$subnetId'.\n" "$subId"
2121
export MSYS_NO_PATHCONV=1
22-
az vnet create--name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
22+
az network interface create --name test --resourcegroupname "$groupName" --location "$location" --subnetId "$subnetId"
2323
export MSYS_NO_PATHCONV=
2424

2525
nicId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/networkInterfaces/test"
@@ -28,9 +28,8 @@ vhdUri="https://$storageAccountName.blob.core.windows.net/$storageAccountName/$s
2828

2929
vmStr="{\"Name\":\"test\",\"HardwareProfile\":{\"VmSize\":\"Standard_A1\"},\"NetworkProfile\":{\"NetworkInterfaces\":[{\"Id\":\"$nicId\"}]},\"OSProfile\":{\"ComputerName\":\"test\",\"AdminPassword\":\"BaR@1234\",\"AdminUsername\":\"Foo12\"},\"StorageProfile\":{\"ImageReference\":{\"Offer\":\"WindowsServer\",\"Publisher\":\"MicrosoftWindowsServer\",\"Sku\":\"2008-R2-SP1\",\"Version\":\"latest\"},\"OSDisk\":{\"Caching\":\"ReadWrite\",\"CreateOption\":\"FromImage\",\"Name\":\"osDisk\",\"Vhd\":{\"Uri\":\"$vhdUri\"}}}}"
3030

31-
printf "\n5. Create virtual machine with\r\nnicId='%s'\r\nvhdUri='%s'\r\nvmStr='%s'\n" "$nicId" "$vhdUri" "$vmStr"
32-
33-
az vm create--resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
31+
printf "\n5. Create virtual machine with\r\nnicId='%s'\r\nvhdUri='$vhdUri'\r\nvmStr='$vmStr'\n" "$nicId"
32+
az vm create --resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
3433

3534
printf "\n6. Removing resource group: %s.\n" "$groupName"
3635
az resource group rm -n "$groupName" -f

examples/resource-management/02-Resource.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ printf "\n7. Move Resource to resource group: %s.\n" "$destinationGroupName"
3535
az resource group create --name "$destinationGroupName" --location "$location"
3636
resourceId=$(echo $resourceInfo | jq '.ResourceId')
3737
arrayId="[$resourceId]"
38-
az resource move -g "$destinationGroupName" --ResourceId "$arrayId" -f
38+
az resource mv -g "$destinationGroupName" --ResourceId "$arrayId" -f
3939

4040
printf "\n8. Removing resource: %s.\n" "$resourceName"
4141
foundResource=$(az resource find -n "$resourceName" -t $resourceType)

examples/resource-management/04-RoleAssignments.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ az resource group create --name "$groupName" --location "$location"
77

88
printf "\n2. Creating a new Role Assignment.\n"
99
export MSYS_NO_PATHCONV=1
10-
users=$(az ad users ls)
10+
users=$(az ad user ls)
1111
userId=$(echo $users | cat | jq '.[0].Id' -s --raw-output)
1212
echo "UserID: $userId"
1313
roleDefinitions=$(az resource role definition ls)

examples/resource-management/roleDefinition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"Microsoft.Support/*"
77
],
88
"NotActions": [],
9-
"AssignableScopes": [ "/subscriptions/2c224e7e-3ef5-431d-a57b-e71f4662e3a6" ]
9+
"AssignableScopes": [ "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590" ]
1010
}

src/CLU/CLUCoreCLR.sln

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.24720.0
4+
VisualStudioVersion = 14.0.23107.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commands.Common", "Commands.Common\Commands.Common.xproj", "{5F567ACA-595E-436D-83DB-A21E08F82DF6}"
77
EndProject
@@ -66,6 +66,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sync", "Sync\Sync.xproj", "
6666
EndProject
6767
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Network", "Microsoft.Azure.Commands.Network\Microsoft.Azure.Commands.Network.xproj", "{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}"
6868
EndProject
69+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{13C34370-51A4-4726-81B8-BE0996FC9CF0}"
70+
EndProject
71+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "StaticAnalysis", "StaticAnalysis\StaticAnalysis.xproj", "{84F9573A-449E-4159-8493-EFD6C3C8F0A5}"
72+
EndProject
6973
Global
7074
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7175
Debug|Any CPU = Debug|Any CPU
@@ -166,6 +170,14 @@ Global
166170
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
167171
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
168172
{C4DCF4EA-62E7-431E-ADB5-16FD6CFEA5D6}.Release|Any CPU.Build.0 = Release|Any CPU
173+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
174+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
175+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
176+
{13C34370-51A4-4726-81B8-BE0996FC9CF0}.Release|Any CPU.Build.0 = Release|Any CPU
177+
{84F9573A-449E-4159-8493-EFD6C3C8F0A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
178+
{84F9573A-449E-4159-8493-EFD6C3C8F0A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
179+
{84F9573A-449E-4159-8493-EFD6C3C8F0A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
180+
{84F9573A-449E-4159-8493-EFD6C3C8F0A5}.Release|Any CPU.Build.0 = Release|Any CPU
169181
EndGlobalSection
170182
GlobalSection(SolutionProperties) = preSolution
171183
HideSolutionNode = FALSE

src/CLU/Commands.Common.Authentication/Models/AzureRMProfile.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,21 @@ public AzureRMProfile(IDataStore dataStore)
7171
[JsonIgnore]
7272
public string ProfilePath { get; private set; }
7373

74+
/// <summary>
75+
/// When set to true, collects telemetry information.
76+
/// </summary>
77+
public bool? IsTelemetryCollectionEnabled { get; set; }
78+
7479
private void Load(string path)
7580
{
7681
this.ProfilePath = path;
7782
if (_dataStore.FileExists(ProfilePath))
7883
{
7984
string contents = _dataStore.ReadFileAsText(ProfilePath);
80-
AzureRMProfile profile = JsonConvert.DeserializeObject<AzureRMProfile>(contents);
81-
Debug.Assert(profile != null);
82-
this.Context = profile.Context;
83-
this.Environments = profile.Environments;
85+
JsonConvert.PopulateObject(contents, this);
8486
}
8587
}
8688

87-
8889
/// <summary>
8990
/// Writes profile to the disk it was opened from disk.
9091
/// </summary>
@@ -102,11 +103,22 @@ public void Save()
102103
/// <param name="path">File path on disk to save profile to</param>
103104
public void Save(string path)
104105
{
106+
Save(_dataStore, path);
107+
}
108+
109+
public void Save(IDataStore store, string path)
110+
{
111+
105112
if (string.IsNullOrEmpty(path))
106113
{
107114
return;
108115
}
109116

117+
if (store == null)
118+
{
119+
return;
120+
}
121+
110122
// Removing predefined environments
111123
foreach (string env in AzureEnvironment.PublicEnvironments.Keys)
112124
{
@@ -117,14 +129,14 @@ public void Save(string path)
117129
{
118130
string contents = ToString();
119131
string diskContents = string.Empty;
120-
if (_dataStore.FileExists(path))
132+
if (store.FileExists(path))
121133
{
122-
diskContents = _dataStore.ReadFileAsText(path);
134+
diskContents = store.ReadFileAsText(path);
123135
}
124136

125137
if (diskContents != contents)
126138
{
127-
_dataStore.WriteFile(path, contents);
139+
store.WriteFile(path, contents);
128140
}
129141
}
130142
finally

src/CLU/Commands.Common.ScenarioTest/ExamplesTests/ResourceManagementTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public void DeploymentsTest()
5454
[Fact]
5555
public void RoleAssignmentsTest()
5656
{
57+
// Must login as a user due to restricted use of old graph api
5758
var helper = _collectionState
58-
.LoginAsService()
59+
.LoginAsUser()
5960
.GetRunner("resource-management")
6061
.RunScript("04-RoleAssignments");
6162
}
@@ -64,7 +65,6 @@ public void RoleAssignmentsTest()
6465
public void RoleDefinitionsTest()
6566
{
6667
var helper = _collectionState
67-
.LoginAsService()
6868
.GetRunner("resource-management")
6969
.RunScript("05-RoleDefinitions");
7070
}

src/CLU/Commands.Common/AzureDataCmdlet.cs

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -60,64 +60,11 @@ public AzureRMProfile RMProfile
6060
get { return GetSessionVariableValue<PSAzureProfile>(AzurePowerShell.ProfileVariable, null); }
6161
}
6262

63-
protected override void SaveDataCollectionProfile()
63+
protected override bool IsTelemetryCollectionEnabled
6464
{
65-
if (_dataCollectionProfile == null)
66-
{
67-
InitializeDataCollectionProfile();
68-
}
69-
70-
string fileFullPath = Path.Combine(AzurePowerShell.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
71-
var contents = JsonConvert.SerializeObject(_dataCollectionProfile);
72-
if (!DataStore.DirectoryExists(AzurePowerShell.ProfileDirectory))
73-
{
74-
DataStore.CreateDirectory(AzurePowerShell.ProfileDirectory);
75-
}
76-
DataStore.WriteFile(fileFullPath, contents);
77-
WriteWarning(string.Format(Resources.DataCollectionSaveFileInformation, fileFullPath));
78-
}
79-
80-
protected override void PromptForDataCollectionProfileIfNotExists()
81-
{
82-
// Initialize it from the environment variable or profile file.
83-
InitializeDataCollectionProfile();
84-
85-
if (!_dataCollectionProfile.EnableAzureDataCollection.HasValue && CheckIfInteractive())
65+
get
8666
{
87-
WriteWarning(Resources.DataCollectionPrompt);
88-
89-
const double timeToWaitInSeconds = 60;
90-
var status = string.Format(Resources.DataCollectionConfirmTime, timeToWaitInSeconds);
91-
ProgressRecord record = new ProgressRecord(0, Resources.DataCollectionActivity, status);
92-
93-
var startTime = DateTime.Now;
94-
var endTime = DateTime.Now;
95-
//double elapsedSeconds = 0;
96-
97-
//while (!this.Host.UI.RawUI.KeyAvailable && elapsedSeconds < timeToWaitInSeconds)
98-
//{
99-
// Thread.Sleep(TimeSpan.FromMilliseconds(10));
100-
// endTime = DateTime.Now;
101-
102-
// elapsedSeconds = (endTime - startTime).TotalSeconds;
103-
// record.PercentComplete = ((int) elapsedSeconds*100/(int) timeToWaitInSeconds);
104-
// WriteProgress(record);
105-
//}
106-
107-
bool enabled = false;
108-
//if (this.Host.UI.RawUI.KeyAvailable)
109-
//{
110-
// KeyInfo keyInfo =
111-
// this.Host.UI.RawUI.ReadKey(ReadKeyOptions.NoEcho | ReadKeyOptions.AllowCtrlC |
112-
// ReadKeyOptions.IncludeKeyDown);
113-
// enabled = (keyInfo.Character == 'Y' || keyInfo.Character == 'y');
114-
//}
115-
116-
_dataCollectionProfile.EnableAzureDataCollection = enabled;
117-
118-
WriteWarning(enabled ? Resources.DataCollectionConfirmYes : Resources.DataCollectionConfirmNo);
119-
120-
SaveDataCollectionProfile();
67+
return false;
12168
}
12269
}
12370

0 commit comments

Comments
 (0)