WindowsAzure/azure-sdk-tools-xplat — pull request #1075 by fernandoacorreia (2014-01-11 20:23:06+00:00)
Title: Fix PersistentVMRole detection on vm create

### Description

The command `vm create` aborts with this error message:

```
the given affinity group 'example' does not support PersistentVMRole service
```

This happens for an affinity group that has the `PersistentVMRole` capability and that allows VM creation through the management console.

This error didn't happen in a previous version of the tools.

### Steps to reproduce

1) Set up the account with `azure account`.

2) Create an affinity group.

3) Confirm that the affinity group has the `PersistentVMRole` capability:

```
$ azure account affinity-group show example
info: Executing command account affinity-group show
+ Getting affinity groups
data: capabilities: PersistentVMRole
data: hostedServices: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
data: storageServices: [object Object],[object Object]
data: statusCode: 200
data: requestId: 08d403f7988d5547b6387c433e466bb0
data: name: example
data: label: example
data: description: Main example affinity group
data: location: East US
info: account affinity-group show command OK
```

4) Try to create a VM with this script:

```
#!/bin/bash

current_time=`date +%Y%m%d%H%M%S`
vm_name="tmp$current_time"
image="0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.4-x64-v13.5.0.2"
user="azureuser"
affinity_group_name="example"

function fail { [ $# -eq 0 ] || echo "ERROR: $@"; exit 1; }

echo "Creating key $vm_name"

keyname="$HOME/.ssh/$vm_name"
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$keyname.key" -out "$keyname.pem" -subj '/CN=www.example.com/O=Example/C=US'
chmod 600 $keyname.*

echo "Creating VM $vm_name"

azure vm create "$vm_name" "$image" "$user" \
--vm-name "$vm_name" \
--affinity-group "$affinity_group_name" \
--ssh \
--ssh-cert "$keyname.pem" \
--no-ssh-password \
|| fail "Error creating virtual machine."

echo "Showing VM details"

azure vm show "$vm_name"
```

### Expected result

The VM should be created and its details should be shown.

### Actual result

```
error: the given affinity group 'example' does not support PersistentVMRole service
error: vm create command failed
```

### Root cause

[This commit](https://github.com/WindowsAzure/azure-sdk-tools-xplat/commit/9defbee227350953d65d95f8f705aa543f42918d#diff-e6f197a5c87479251ed90637e30233f4R1533) introduced code that looks for `PersistentVMRole` in `foundAffinityGroup.Capabilities.Capability`, but it should look for it in the collection `foundAffinityGroup.Capabilities`.

### Affected version

Tested with version `0.7.4`.

### Additional notes

* I'll send the signed CLA shortly.
* A similar bug was probably introduced [here](https://github.com/WindowsAzure/azure-sdk-tools-xplat/blob/f670578e503b34e944d80faacb2a90d8ca920a8f/lib/commands/vm._js#L1367) (not fixed by this pull request).