Skip to content

Conversation

@sergey-shandar
Copy link
Contributor

@sergey-shandar sergey-shandar commented Mar 10, 2018

Description

New-AzureRmVm: Custom image.

Currently, only an image in the same resource group is supported. Id is not supported yet.

Issue #5660

Depends on PR #5722

Checklist

@sergey-shandar sergey-shandar changed the title [Do NOT merge] New-AzureRmVm: Custom image [Do NOT merge] New-AzureRmVm/Vmss: Custom image Mar 12, 2018
|| providerNamespace != ComputeStrategy.Namespace
|| provider != "images")
{
throw new ArgumentException("Invalid image resource id '" + imageName + "'.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a resource string

var compute = client.GetClient<ComputeManagementClient>();
if (compute.SubscriptionId != subscriptionId)
{
throw new ArgumentException("The image subscription doesn't math the current subscription.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource string, also 'math' -> 'match'

{
// get image
return Images
var compute = client.GetClient<ComputeManagementClient>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't duplicate this code -it feels like this should be in the same if case as if the image contains a '/'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest first checking if the name contains a ':', then a single case for '/' or no '/'.

{
throw new ArgumentException("Invalid image resource id '" + imageName + "'.");
}
// has to be ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move image resource id parsing into a helper method, or better yet, use this common code, and simply ensure that the properties are what you expect: https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Common/Commands.ResourceManager.Common/Utilities/Models/ResourceIdentifier.cs

This will give you subscription, resourceGroupName, resourceName and resourceType (Microsoft.Comute/images)

if (result == null)
{
// TODO: move it to resource.
throw new ArgumentException("Can't find the image '" + imageName + "'");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please move to resource

@markcowl markcowl removed their assignment Mar 14, 2018
@sergey-shandar sergey-shandar changed the title [Do NOT merge] New-AzureRmVm/Vmss: Custom image New-AzureRmVm/Vmss: Custom image Mar 14, 2018
@sergey-shandar sergey-shandar self-assigned this Mar 15, 2018
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IResourceId TryParse(string id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergey-shandar any reason you implemented this class instead of using the existing ResourceIdentifier class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need this interface in template implementation. The ARM template implementation is inside a Strategy library which doesn't depend on a library which implements ResourceIdentifier class.

return Images
try
{
var localImage = await compute.Images.GetAsync(resourceGroupName, imageName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergey-shandar does this address Mark's comments?

We shouldn't duplicate this code -it feels like this should be in the same if case as if the image contains a '/'. I would suggest first checking if the name contains a ':', then a single case for '/' or no '/'.

From the comment, it seems like the above else if should just be an else.

Copy link
Contributor Author

@sergey-shandar sergey-shandar Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementations are quite different and we don't want invalid image ids to pass as image names.

@cormacpayne
Copy link
Member

@markcowl markcowl removed their assignment Mar 20, 2018
@markcowl markcowl merged commit 1faaacd into Azure:preview Mar 20, 2018
@sergey-shandar sergey-shandar deleted the sergey-vmss-custom-image branch March 20, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants