Skip to content

Clu #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jan 11, 2016
Merged

Clu #316

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6ad70a5
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
EmmaZhu Sep 2, 2015
5e15c1d
Update AzureRMVMExtensionImage cmdlet name to AzureRmVMExtensionImage
hyonholee Nov 10, 2015
36ff79a
Show Debug contents when cloud exception occurs
hyonholee Nov 10, 2015
f697a1e
Expose SubStatus for Extension instance view
hyonholee Nov 10, 2015
149e5df
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
hyonholee Nov 10, 2015
ad80296
Enable BGInfo Extension by default
hyonholee Nov 11, 2015
e0361c2
Fix a warning message when an OS disk is in a different resource group.
hyonholee Nov 13, 2015
eadb405
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
hyonholee Nov 13, 2015
bec90e3
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
hyonholee Nov 14, 2015
c62c8b5
Add TestVirtualMachineWithEmptyAuc record file
hyonholee Nov 14, 2015
858fe71
Ignore exceptions during end processing
hyonholee Nov 18, 2015
59ab91f
Merge pull request #1294 from hyonholee/dev
markcowl Nov 18, 2015
6721180
Merge branch 'dev' of https://github.com/wastoresh/azure-powershell i…
EmmaZhu Nov 23, 2015
34e5f19
RDBug 5079671:[PSH] Storage data plane aliases are not defined in res…
blueww Nov 26, 2015
9cf7442
Prototype allowing format flags to be passed in
johanste Dec 12, 2015
9a9935c
Change table formatted output to always go to stdout (previously, pri…
johanste Dec 14, 2015
0ca0508
Merge branch 'clu'
johanste Dec 15, 2015
0ca624c
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
EmmaZhu Dec 16, 2015
b1a729c
Fix an issue that throwing exception when some endpoint of storage ac…
EmmaZhu Dec 16, 2015
91d0038
Merge branch 'clu'
johanste Dec 16, 2015
6568986
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
EmmaZhu Dec 17, 2015
5864702
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
EmmaZhu Dec 23, 2015
ea8f84d
Fix issue of the aliases of new storage account and set storage accou…
EmmaZhu Jan 6, 2016
0c02835
Merge remote-tracking branch 'origin/clu' into provide-format-output-…
johanste Jan 7, 2016
415273c
Rename FormatTable to Display
johanste Jan 7, 2016
e284c9d
Replaced #!/bin/bash with #!/bin/env/bash to support OSX
stankovski Jan 11, 2016
1476c6f
Merge pull request #1596 from wastoresh/clu
stankovski Jan 11, 2016
64b6c47
Merge pull request #1602 from johanste/provide-format-output-parameter
stankovski Jan 11, 2016
edb0832
Merge pull request #1623 from stankovski/clu
stankovski Jan 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/compute-management/01-VirtualMachineSizes.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Virtual Machine Sizes in Azure Compute ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/compute-management/02-VirtualMachineCreation.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Virtual Machine Creation in Azure Compute ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/lib/helper.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash

randomName() {
echo "$1$RANDOM"
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/loginService.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/bin/env/bash
az account add --spn --appid "$spn" --secret "$secret" -t "$tenant" -s "$spnSubscription"
2 changes: 1 addition & 1 deletion examples/lib/loginUser.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/bin/env/bash
az account add -u "$azureUser" -p "$password" -s "$userSubscription"
2 changes: 1 addition & 1 deletion examples/lib/testrunner.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
export TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $TESTDIR/helper.sh
export groupName=`randomName testrg`
Expand Down
2 changes: 1 addition & 1 deletion examples/resource-management/01-ResourceGroups.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Resource Groups in Azure ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/resource-management/02-Resource.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Resources in Azure ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/resource-management/03-Deployments.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Provisioning Deployments in Azure ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/resource-management/04-RoleAssignments.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Role Assignments in Azure ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/resource-management/05-RoleDefinitions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Role Definitions in Azure ===\n"

Expand Down
33 changes: 33 additions & 0 deletions examples/storage-management/01-Storage-Accounts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Param(
[string]$rgname,
[string]$resourceGroupLocation
)
Write-Host "=== Managing Storage Accounts Resources in Azure ==="

$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
$loc = 'West US';

New-AzureRmResourceGroup -Name $rgname -Location $resourceGroupLocation;

Write-Host "1. Create a new storage account"
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;

Write-Host "2. Get info of a storage account"
$stos = Get-AzureRmStorageAccount -ResourceGroupName $rgname;

Write-Host "3. Update storage account type"
$stotype = 'Standard_RAGRS';
Set-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Type $stotype;

Write-Host "4. Get account key of a storage account"
$stokeys=Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname;

Write-Host "5. Renew key1 of a storage account"
New-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname -KeyName key1;

Write-Host "6. Renew key2 of a storage account"
New-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname -KeyName key2;

Write-Host "7. Remove storage account"
Remove-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname;
52 changes: 52 additions & 0 deletions examples/storage-management/01-Storage-Accounts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
printf "\n=== Managing Storage Accounts Resources in Azure ===\n"
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

azure group get -n $groupName
if [ $? -ne 0 ]; then
printf "\n Creating group %s in location %s \n" $groupName $location
azure group create -n "$groupName" --location "$location"
fi

set -e
accountName=`randomName $groupName`
accountType="Standard_GRS"

printf "\n1. Creating storage account %s in resrouce group %s with type %s in location %s \n" $accountName $groupName $accountType $location
azure storage account new -g "$groupName" -n "$accountName" -t "$accountType" -l "$location"

printf "\n2. Get account info of storage account %s in group %s\n" $accountName $groupName
azure storage account get -g $groupName -n $accountName > $BASEDIR/$accountName.json
[ $(cat $BASEDIR/$accountName.json | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
[ $(cat $BASEDIR/$accountName.json | jq '.StorageAccountName' --raw-output) == "$accountName" ]
[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType" ]
[ $(cat $BASEDIR/$accountName.json | jq '.Location' --raw-output) == "$location" ]
rm -f $BASEDIR/$accountName.json

accountType1="Standard_RAGRS"
printf "\n3. Set account type from %s to %s of storage account %s in group %s\n" $accountType $accountType1 $accountName $groupName
azure storage account set -g $groupName -n $accountName -t "$accountType1" > $BASEDIR/$accountName.json
[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType1" ]
rm -f $BASEDIR/$accountName.json

printf "\n4. Get account key of storage account %s in group %s\n" $accountName $groupName
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
key1=$(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output)
key2=$(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output)
[ $key1 != $key2 ]
rm -f $BASEDIR/$accountName.json

printf "\n5. Renew account key1 of storage account %s in group %s\n" $accountName $groupName
azure storage account key new -g $groupName -n $accountName -k "key1"
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
[ $(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output) != $key1 ]
rm -f $BASEDIR/$accountName.json

printf "\n6. Renew account key2 of storage account %s in group %s\n" $accountName $groupName
azure storage account key new -g $groupName -n $accountName -k "key2"
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
[ $(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output) != $key2 ]
rm -f $BASEDIR/$accountName.json

printf "\n7. Removing account %s in group %s\n" $accountName $groupName
azure storage account remove -g $groupName -n $accountName
2 changes: 1 addition & 1 deletion examples/virtual-hard-disk/01-VirtualHardDisks.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Virtual Hard Disks in Azure Compute ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/webapp-management/01-AppServicePlan.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing App Service Plans in Azure ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/webapp-management/02-WebAppSlot.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
set -e
printf "\n=== Managing Web App Slot in Azure ===\n"

Expand Down
2 changes: 1 addition & 1 deletion examples/webapp-management/03-WebApp.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/env/bash
printf "\n=== Managing Web Apps in Azure ===\n"

printf "\nSetup: Creating a new resource group: %s at location: %s.\n" "$groupName" "$location"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Globalization;
using System.Management.Automation;
using System.Management.Automation.Host;
using Microsoft.CLU;

namespace Microsoft.Azure.Commands.Common.Test.Mocks
{
Expand Down Expand Up @@ -285,6 +286,8 @@ public override Version Version
}
}

public override OutputFormat RequestedOutputFormat { get; set; }

class MockPSHostUI : PSHostUserInterface
{
public override Dictionary<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public static PSStorageAccount Create(StorageModels.StorageAccount storageAccoun
var credentials = StorageUtilities.GenerateStorageCredentials(client, result.ResourceGroupName, result.StorageAccountName);
CloudStorageAccount account = new CloudStorageAccount(
credentials,
new Uri(storageAccount.PrimaryEndpoints.Blob),
new Uri(storageAccount.PrimaryEndpoints.Queue),
new Uri(storageAccount.PrimaryEndpoints.Table),
new Uri(storageAccount.PrimaryEndpoints.File));
null == storageAccount.PrimaryEndpoints.Blob ? null : new Uri(storageAccount.PrimaryEndpoints.Blob),
null == storageAccount.PrimaryEndpoints.Queue ? null : new Uri(storageAccount.PrimaryEndpoints.Queue),
null == storageAccount.PrimaryEndpoints.Table ? null : new Uri(storageAccount.PrimaryEndpoints.Table),
null == storageAccount.PrimaryEndpoints.File ? null : new Uri(storageAccount.PrimaryEndpoints.File));
result.Context = new AzureStorageContext(account);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class NewAzureStorageAccountCommand : StorageAccountBaseCmdlet
ValueFromPipelineByPropertyName = true,
HelpMessage = "Storage Account Tags.")]
[ValidateNotNull]
[Alias("t")]
public Hashtable[] Tags { get; set; }

protected override void ProcessRecord()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class NewAzureStorageAccountKeyCommand : StorageAccountBaseCmdlet
ValueFromPipelineByPropertyName = true,
HelpMessage = "Storage Account Key StorageAccountName.")]
[ValidateSet(Key1, Key2, IgnoreCase = true)]
[Alias("k")]
public string KeyName { get; set; }

protected override void ProcessRecord()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public class SetAzureStorageAccountCommand : StorageAccountBaseCmdlet
HelpMessage = "Storage Account Tags.")]
[AllowEmptyCollection]
[ValidateNotNull]
[Alias("t")]
public Hashtable[] Tags { get; set; }

protected override void ProcessRecord()
Expand Down
35 changes: 35 additions & 0 deletions src/CLU/Microsoft.CLU.Test/StringGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using System.Management.Automation;

namespace Microsoft.CLU.Test
{
[Cmdlet(VerbsCommon.New, "String")]
public class StringGenerator : PSCmdlet
{
public StringGenerator()
{
Count = 10;
StringFormat = "String {0}";
}

[Parameter()]
public int Count { get; set; }

[Parameter()]
public string StringFormat { get; set; }

protected override void ProcessRecord()
{
base.ProcessRecord();
for (int i = 1; i <= Count; ++i)
{
WriteObject(String.Format(StringFormat, i));
}
}

}
}
2 changes: 1 addition & 1 deletion src/CLU/Microsoft.CLU/CommandModel/CmdletCommandModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CommandModelErrorCode Run(ConfigurationDictionary commandConfiguration, s
// The runtime host is a Cmdlet's path to accessing system features, such as Console I/O
// and session state. The runtime instance is created here and passed into the binder,
// which will be creating the Cmdlet instance.
var runtimeHost = new System.Management.Automation.Host.CLUHost(arguments, hostStreamInfo);
var runtimeHost = new System.Management.Automation.Host.CLUHost(ref arguments, hostStreamInfo);

// Create instance of ICommandBinder and ICommand implementation for cmdlet model
var binderAndCommand = new CmdletBinderAndCommand(commandConfiguration, runtimeHost);
Expand Down
43 changes: 39 additions & 4 deletions src/CLU/Microsoft.CLU/System.Management.Automation/CLUHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class CLUHost : PSHost, ICommandRuntime
/// Creates an instance of CLUHost.
/// </summary>
/// <param name="args">The commandline arguments</param>
internal CLUHost(string[] args, HostStreamInfo hostStreamInfo)
internal CLUHost(ref string[] args, HostStreamInfo hostStreamInfo)
{
Debug.Assert(args != null);
Debug.Assert(hostStreamInfo != null);
Expand All @@ -37,12 +37,29 @@ internal CLUHost(string[] args, HostStreamInfo hostStreamInfo)
if (!string.IsNullOrEmpty(vpref))
_doVerbose = InterpretStreamPreference(Constants.VerbosePreference, vpref, _doVerbose);

var argList = args.ToList();

// Command-line switch overrides environment variable
if (args.Select(arg => arg.ToLowerInvariant()).Where(arg => arg.Equals("--debug") || arg.Equals("/debug")).Any())
if (RemoveArgumentIfFound(argList, "debug"))
{
_doDebug = Constants.CmdletPreferencesInquire;

if (args.Select(arg => arg.ToLowerInvariant()).Where(arg => arg.Equals("--verbose") || arg.Equals("/verbose")).Any())
}

if (RemoveArgumentIfFound(argList, "verbose"))
{
_doVerbose = Constants.CmdletPreferencesContinue;
}

if (RemoveArgumentIfFound(argList, "json"))
{
this.RequestedOutputFormat = OutputFormat.JSON;
}
else if (RemoveArgumentIfFound(argList, "display"))
{
this.RequestedOutputFormat = OutputFormat.Display;
}

args = argList.ToArray();
}

internal CLUHost(string[] args, HostStreamInfo hostStreamInfo, string debugPreference, string verbosePreference)
Expand Down Expand Up @@ -82,6 +99,11 @@ internal HostStreamInfo StreamInfo
/// <remarks>If this is true, your code is not doing console I/O</remarks>
public override bool IsInputRedirected { get { return _hostStreamInfo.IsInputRedirected; } }

/// <summary>
/// Command line override of requested output format...
/// </summary>
public override OutputFormat RequestedOutputFormat { get; set; }

/// <summary>
/// Tells whether the STDOUT byte stream has been redirected to a file or pipe
/// </summary>
Expand Down Expand Up @@ -514,6 +536,19 @@ private string InterpretStreamPreference(string variable, string input, string c
new ChoiceDescription("&Halt Command", "Stop this command.")
};
private HostStreamInfo _hostStreamInfo;
private bool RemoveArgumentIfFound(List<string> args, string argName)
{
int index = args.FindIndex(arg => arg.ToLowerInvariant().Equals($"--{argName}") || arg.ToLowerInvariant().Equals($"/{argName}"));
if (index > -1)
{
args.RemoveAt(index);
return true;
}
else
{
return false;
}
}

#endregion

Expand Down
18 changes: 12 additions & 6 deletions src/CLU/Microsoft.CLU/System.Management.Automation/Cmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ protected void WriteObject(object sendToPipeline)
{
if (sendToPipeline != null)
{
if (CommandRuntime.Host.IsOutputRedirected)
{
if (ShouldWriteJsonOutput())
{
CommandRuntime.WriteObject(sendToPipeline);
}
else
Expand All @@ -78,7 +78,7 @@ protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
if (sendToPipeline != null)
{
if (CommandRuntime.Host.IsOutputRedirected)
if (ShouldWriteJsonOutput())
{
CommandRuntime.WriteObject(sendToPipeline, enumerateCollection);
}
Expand Down Expand Up @@ -142,15 +142,21 @@ internal void FlushPipeline(LocalPackage package)
formattedType = obj.GetType();
if (!wroteHeader)
{
CommandRuntime.WriteCommandDetail(view.FormatHeader(CLUEnvironment.Console.WindowWidth));
CommandRuntime.WriteCommandDetail("");
CommandRuntime.WriteObject(view.FormatHeader(CLUEnvironment.Console.WindowWidth));
CommandRuntime.WriteObject("");
wroteHeader = true;
}
CommandRuntime.WriteCommandDetail(view.FormatObject(obj));
CommandRuntime.WriteObject(view.FormatObject(obj));
}
}
}

internal bool ShouldWriteJsonOutput()
{
var requestedOutputFormat = CommandRuntime.Host.RequestedOutputFormat;
return (CommandRuntime.Host.IsOutputRedirected && requestedOutputFormat == OutputFormat.Auto)
|| requestedOutputFormat == OutputFormat.JSON;
}
protected void WriteProgress(ProgressRecord progressRecord) { if (progressRecord != null) CommandRuntime.WriteProgress(progressRecord); }

protected void WriteVerbose(string text) { if (!string.IsNullOrEmpty(text)) CommandRuntime.WriteVerbose(text); }
Expand Down
Loading