Skip to content
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

Support for VM size #716

Merged
merged 2 commits into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ interface DefinitionOSDiskSettings<T extends DefinitionCreatable> {
T withOSDiskName(String name);
}

interface DefinitionWithVMSize<T extends DefinitionCreatable> {
/**
* @param sizeName The name of the size for the virtual machine as text
* @return The stage representing creatable VM definition
*/
T withSize(String sizeName);

/**
* @param size A size from the list of available sizes for the virtual machine
* @return The stage representing creatable VM definition
*/
T withSize(VirtualMachineSizeTypes size);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently the 'withSize(..)' setters are optional and default to "Basic_A0".

In portal this is something user needs to explicitly specify, so we need to decide whether to make it required or optional for user.


interface DefinitionStorageAccount<T extends DefinitionCreatable> {
/**
* Specifies the name of the storage account to create, the OS disk for VM created from a market-place
Expand Down Expand Up @@ -294,6 +308,7 @@ interface DefinitionStorageAccount<T extends DefinitionCreatable> {
interface DefinitionCreatable extends
DefinitionPassword<DefinitionCreatable>,
DefinitionOSDiskSettings<DefinitionCreatable>,
DefinitionWithVMSize<DefinitionCreatable>,
DefinitionStorageAccount<DefinitionCreatable>,
Creatable<VirtualMachine> {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.microsoft.azure.management.compute;

public interface VirtualMachineSize {
/**
* Gets the VM size name.
*/
String name();

/**
* Gets the Number of cores supported by a VM size.
*/
Integer numberOfCores();

/**
* Gets the OS disk size allowed by a VM size.
*/
Integer osDiskSizeInMB();

/**
* Gets Resource disk size allowed by a VM size.
*/
Integer resourceDiskSizeInMB();

/**
* Gets the Memory size supported by a VM size.
*/
Integer memoryInMB();

/**
* Gets or the Maximum number of data disks allowed by a VM size.
*/
Integer maxDataDiskCount();
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
package com.microsoft.azure.management.compute;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;

import java.io.IOException;

public interface VirtualMachines extends
SupportsListing<VirtualMachine>,
SupportsListingByGroup<VirtualMachine>,
SupportsGettingByGroup<VirtualMachine>,
SupportsCreating<VirtualMachine.DefinitionBlank>,
SupportsDeleting,
SupportsDeletingByGroup {
/**
* Lists all available virtual machine sizes in a region.
* @param region The region upon which virtual-machine-sizes is queried.
* @return the List&lt;VirtualMachineSize&gt; if successful.
* @throws CloudException
* @throws IOException
*/
PagedList<VirtualMachineSize> listSizes(String region) throws CloudException, IOException;
interface InGroup extends
SupportsListing<VirtualMachine>,
SupportsCreating<VirtualMachine.DefinitionBlank>,
SupportsDeleting {}
SupportsDeleting {
/**
* Lists all available virtual machine sizes in a region.
* @param region The region upon which virtual-machine-sizes is queried.
* @return the List&lt;VirtualMachineSize&gt; if successful.
* @throws CloudException
* @throws IOException
*/
PagedList<VirtualMachineSize> listSizes(String region) throws CloudException, IOException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public AvailabilitySets availabilitySets() {

public VirtualMachines virtualMachines() {
if (virtualMachines == null) {
virtualMachines = new VirtualMachinesImpl(computeManagementClient.virtualMachines());
virtualMachines = new VirtualMachinesImpl(computeManagementClient.virtualMachines(), computeManagementClient.virtualMachineSizes());
}
return virtualMachines;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class VirtualMachineImpl
this.innerModel.setStorageProfile(new StorageProfile());
this.innerModel.storageProfile().setOsDisk(new OSDisk());
this.innerModel.setOsProfile(new OSProfile());
this.innerModel.setHardwareProfile(new HardwareProfile());
}

@Override
Expand Down Expand Up @@ -176,7 +177,6 @@ public DefinitionWithAdminUserName withWindowsOS() {
return this;
}


@Override
public DefinitionLinuxCreatable withRootUserName(String rootUserName) {
this.innerModel.osProfile().setAdminUsername(rootUserName);
Expand Down Expand Up @@ -243,6 +243,18 @@ public DefinitionCreatable withPassword(String password) {
return this;
}

@Override
public DefinitionCreatable withSize(String sizeName) {
this.innerModel.hardwareProfile().setVmSize(sizeName);
return this;
}

@Override
public DefinitionCreatable withSize(VirtualMachineSizeTypes size) {
this.innerModel.hardwareProfile().setVmSize(size.toString());
return this;
}

@Override
public DefinitionCreatable withOSDiskCaching(CachingTypes cachingType) {
this.innerModel.storageProfile().osDisk().setCaching(cachingType);
Expand Down Expand Up @@ -335,5 +347,10 @@ private void setDefaults() {
if (osDisk.name() == null) {
withOSDiskName(null /*TODO generate random OSDisk name */);
}

HardwareProfile hardwareProfile = this.innerModel.hardwareProfile();
if (hardwareProfile.vmSize() == null) {
hardwareProfile.setVmSize(VirtualMachineSizeTypes.BASIC_A0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.management.compute.VirtualMachineSize;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineSizeInner;

public class VirtualMachineSizeImpl implements VirtualMachineSize {
private VirtualMachineSizeInner innerModel;

public VirtualMachineSizeImpl(VirtualMachineSizeInner innerModel) {
this.innerModel = innerModel;
}

@Override
public String name() {
return innerModel.name();
}

@Override
public Integer numberOfCores() {
return innerModel.numberOfCores();
}

@Override
public Integer osDiskSizeInMB() {
return innerModel.osDiskSizeInMB();
}

@Override
public Integer resourceDiskSizeInMB() {
return innerModel.resourceDiskSizeInMB();
}

@Override
public Integer memoryInMB() {
return innerModel.memoryInMB();
}

@Override
public Integer maxDataDiskCount() {
return innerModel.maxDataDiskCount();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.Page;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.compute.VirtualMachine;
import com.microsoft.azure.management.compute.VirtualMachineSize;
import com.microsoft.azure.management.compute.VirtualMachines;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineSizeInner;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineSizesInner;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachinesInner;
import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;
import com.microsoft.azure.management.resources.implementation.api.PageImpl;
import com.microsoft.rest.RestException;

import java.io.IOException;

class VirtualMachinesImpl
implements VirtualMachines {
private final VirtualMachinesInner client;
private final VirtualMachineSizesInner virtualMachineSizesClient;

VirtualMachinesImpl(VirtualMachinesInner client) {
VirtualMachinesImpl(VirtualMachinesInner client, VirtualMachineSizesInner virtualMachineSizesClient) {
this.client = client;
this.virtualMachineSizesClient = virtualMachineSizesClient;
}

@Override
Expand Down Expand Up @@ -45,4 +54,25 @@ public void delete(String id) throws Exception {
public PagedList<VirtualMachine> list() throws CloudException, IOException {
return null;
}

@Override
public PagedList<VirtualMachineSize> listSizes(String region) throws CloudException, IOException {
PagedListConverter<VirtualMachineSizeInner, VirtualMachineSize> converter =
new PagedListConverter<VirtualMachineSizeInner, VirtualMachineSize>() {
@Override
public VirtualMachineSize typeConvert(VirtualMachineSizeInner virtualMachineSizeInner) {
return new VirtualMachineSizeImpl(virtualMachineSizeInner);
}
};

PageImpl<VirtualMachineSizeInner> page = new PageImpl<>();
page.setItems(virtualMachineSizesClient.list(region).getBody());
page.setNextPageLink(null);
return converter.convert(new PagedList<VirtualMachineSizeInner>(page) {
@Override
public Page<VirtualMachineSizeInner> nextPage(String nextPageLink) throws RestException, IOException {
return null;
}
});
}
}