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

Add some VM image code #688

Merged
merged 3 commits into from
May 9, 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
@@ -1,12 +1,109 @@
package com.microsoft.azure.management.compute;

import com.microsoft.azure.management.compute.implementation.api.AvailabilitySetInner;
import com.microsoft.azure.SubResource;
import com.microsoft.azure.management.compute.implementation.KnownVirtualMachineImage;
import com.microsoft.azure.management.compute.implementation.api.*;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource;
import com.microsoft.azure.management.resources.fluentcore.model.Refreshable;
import com.microsoft.azure.management.resources.fluentcore.model.Wrapper;

import java.util.List;

public interface VirtualMachine extends
GroupableResource,
Refreshable<AvailabilitySet>,
Wrapper<AvailabilitySetInner> {
Refreshable<VirtualMachine>,
Wrapper<VirtualMachineInner> {
/**
* Get the plan value.
*
* @return the plan value
*/
Plan plan();

/**
* Get the hardwareProfile value.
*
* @return the hardwareProfile value
*/
HardwareProfile hardwareProfile();

/**
* Get the storageProfile value.
*
* @return the storageProfile value
*/
StorageProfile storageProfile();

/**
* Get the osProfile value.
*
* @return the osProfile value
*/
OSProfile osProfile();

/**
* Get the networkProfile value.
*
* @return the networkProfile value
*/
NetworkProfile networkProfile();

/**
* Get the diagnosticsProfile value.
*
* @return the diagnosticsProfile value
*/
DiagnosticsProfile diagnosticsProfile();

/**
* Get the availabilitySet value.
*
* @return the availabilitySet value
*/
SubResource availabilitySet();

/**
* Get the provisioningState value.
*
* @return the provisioningState value
*/
String provisioningState();

/**
* Get the instanceView value.
*
* @return the instanceView value
*/
VirtualMachineInstanceView instanceView();

/**
* Get the licenseType value.
*
* @return the licenseType value
*/
String licenseType();

/**
* Get the resources value.
*
* @return the resources value
*/
List<VirtualMachineExtensionInner> resources();

interface DefinitionBlank extends GroupableResource.DefinitionWithRegion<DefinitionWithRegion> {
}

interface DefinitionWithRegion extends GroupableResource.DefinitionWithGroup<DefinitionWithGroup> {
}

interface DefinitionWithGroup {
DefinitionWithImage withImage(Region location, String publisher, String offer, String sku, String version);
DefinitionWithImage withImage(VirtualMachineImage image);
DefinitionWithImage withLatestImage(Region location, String publisher, String offer, String sku);
DefinitionWithImage withKnownImage(Region location, KnownVirtualMachineImage image);
}

interface DefinitionWithImage {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.microsoft.azure.management.compute;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.management.compute.implementation.api.DataDiskImage;
import com.microsoft.azure.management.compute.implementation.api.OSDiskImage;
import com.microsoft.azure.management.compute.implementation.api.PurchasePlan;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineImageInner;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.model.Wrapper;

import java.io.IOException;
import java.util.List;

public interface VirtualMachineImage extends
Wrapper<VirtualMachineImageInner> {
Region location();
String publisher();
String offer();
String sku();
String version();
PurchasePlan plan();
OSDiskImage osDiskImage();
List<DataDiskImage> dataDiskImages();

interface Publisher {
Region location();
String publisher();
List<Offer> listOffers() throws CloudException, IOException;
}

interface Offer {
Region location();
String publisher();
String offer();
List<Sku> listSkus() throws CloudException, IOException;
}

interface Sku {
Region location();
String publisher();
String offer();
String sku();
List<VirtualMachineImage> listImages() throws CloudException, IOException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.microsoft.azure.management.compute;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListingByLocation;

import java.io.IOException;
import java.util.List;

public interface VirtualMachineImages extends
SupportsListingByLocation<VirtualMachineImage> {
List<VirtualMachineImage.Publisher> listPublishers(final Region location) throws CloudException, IOException;
}
Copy link
Member

Choose a reason for hiding this comment

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

The template parameter type should be "VirtualMachineImage" instead of "VirtualMachine"

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.microsoft.azure.management.compute.implementation;

public enum KnownVirtualMachineImage {
/** Linux */
UBUNTU_14_04_LTS("Canonical", "UbuntuServer", "14.04.4-LTS", "14.04.201604060"),
UBUNTU_16_04_LTS("Canonical", "UbuntuServer", "16.04.0-LTS", "16.04.201604203"),
DEBIAN_8("credativ", "Debian", "8", "8.0.201604200"),
CENTOS_7_2("OpenLogic", "CentOS", "7.2", "7.2.20160308"),
OPENSUSE_LEAP_42_1("SUSE", "openSUSE-Leap", "42.1", "2016.04.15"),
SLES_12_SP1("SUSE", "SLES", "12-SP1", "2016.04.14"),
/** WINDOWS */
WINDOWS_SERVER_2008_R2_SP1("MicrosoftWindowsServer", "WindowsServer", "2008-R2-SP1", "2.0.20160430"),
WINDOWS_SERVER_2012_DATACENTER("MicrosoftWindowsServer", "WindowsServer", "2012-Datacenter", "3.0.20160430"),
WINDOWS_SERVER_2012_R2_DATACENTER("MicrosoftWindowsServer", "WindowsServer", "2012-R2-Datacenter", "4.0.20160430"),
WINDOWS_SERVER_2016_TECHNICAL_PREVIEW_WITH_CONTAINIERS("MicrosoftWindowsServer", "WindowsServer", "2016-Technical-Preview-with-Containers", "2016.0.20151118"),
WINDOWS_SERVER_TECHNICAL_PREVIEW("MicrosoftWindowsServer", "WindowsServer", "Windows-Server-Technical-Preview", "5.0.20160420");

Copy link
Member

Choose a reason for hiding this comment

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

if we set version to 'latest', then server picks the latest image from the specific sku.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's cool. But still I wonder if we should do that... If latest changes in the middle of a user deploying 100 VMs they will actually get different images.

Copy link
Contributor

Choose a reason for hiding this comment

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

Setting the version to "latest" by default is ok as long as the user has an option to overwrite that/specify something different later on.
The scenario I'm thinking is when the user has a web app that he verified/tested against a particular version; he might not want to default "upgrade" to the latest version of the image because that is something he did not tested for and he does not want the risk associated with that.

Copy link
Member

@anuchandy anuchandy May 9, 2016

Choose a reason for hiding this comment

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

Few caveats with KnownVirtualMachineImage enum that we all aware of:

  1. This enum entries are likely to grow as Azure rollout support for new skus ( UBUNTU_16_04_LTS, UBUNTU_16_06_LTS, UBUNTU_17_01_LTS)
  2. If Azure drop support for a sku then we will have to remove it from the enum, that's a breaking change. (WINDOWS_SERVER_TECHNICAL_PREVIEW seems a candidate for this)

But anyway we have an enum for "regions" which also has the same issues, but rollout/removal of new regions is less often compared to skus.

private final String publisher;
private final String offer;
private final String sku;
private final String verion;

KnownVirtualMachineImage(String publisher, String offer, String sku, String version) {
this.publisher = publisher;
this.offer = offer;
this.sku = sku;
this.verion = version;
}

public String publisher() {
return this.publisher;
}

public String offer() {
return this.offer;
}

public String sku() {
return this.sku;
}

public String version() {
return this.verion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.management.compute.VirtualMachineImage;
import com.microsoft.azure.management.compute.implementation.api.*;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableWrapperImpl;

import java.util.List;

class VirtualMachineImageImpl
extends IndexableWrapperImpl<VirtualMachineImageInner>
implements VirtualMachineImage {
private final VirtualMachineImagesInner client;
private final Region location;
private String publisher;
private String offer;
private String sku;
private String version;

VirtualMachineImageImpl(Region location, String publisher, String offer, String sku, String version, VirtualMachineImagesInner client) {
super(null, null);
this.location = location;
this.publisher = publisher;
this.offer = offer;
this.sku = sku;
this.version = version;
this.client = client;
}

VirtualMachineImageImpl(Region location, String publisher, String offer, String sku, String version, VirtualMachineImageInner innerModel, VirtualMachineImagesInner client) {
super(innerModel.id(), innerModel);
this.location = location;
this.publisher = publisher;
this.offer = offer;
this.sku = sku;
this.version = version;
this.client = client;
}

@Override
public Region location() {
return location;
}

@Override
public String publisher() {
return publisher;
}

@Override
public String offer() {
return offer;
}

@Override
public String sku() {
return sku;
}

@Override
public String version() {
return version;
}

@Override
public PurchasePlan plan() {
return inner().plan();
}

@Override
public OSDiskImage osDiskImage() {
return inner().osDiskImage();
}

@Override
public List<DataDiskImage> dataDiskImages() {
return inner().dataDiskImages();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.management.compute.VirtualMachineImage;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineImageResourceInner;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineImagesInner;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

class VirtualMachineImageOfferImpl
implements VirtualMachineImage.Offer {
private final VirtualMachineImagesInner client;
private final VirtualMachineImage.Publisher publisher;
private final String offer;

VirtualMachineImageOfferImpl(VirtualMachineImage.Publisher publisher, String offer, VirtualMachineImagesInner client) {
this.publisher = publisher;
this.offer = offer;
this.client = client;
}

@Override
public Region location() {
return publisher.location();
}

@Override
public String publisher() {
return publisher.publisher();
}

@Override
public String offer() {
return this.offer;
}

@Override
public List<VirtualMachineImage.Sku> listSkus() throws CloudException, IOException {
List<VirtualMachineImage.Sku> skus = new ArrayList<>();
for (VirtualMachineImageResourceInner inner :
client.listSkus(location().toString(), publisher(), offer()).getBody()) {
skus.add(new VirtualMachineImageSkuImpl(this, inner.name(), client));
}
return skus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.microsoft.azure.management.compute.implementation;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.management.compute.VirtualMachineImage;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineImageResourceInner;
import com.microsoft.azure.management.compute.implementation.api.VirtualMachineImagesInner;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

class VirtualMachineImagePublisherImpl
implements VirtualMachineImage.Publisher {
private final VirtualMachineImagesInner client;
private final Region location;
private String publisher;

VirtualMachineImagePublisherImpl(Region location, String publisher, VirtualMachineImagesInner client) {
this.location = location;
this.publisher = publisher;
this.client = client;
}

@Override
public Region location() {
return location;
}

@Override
public String publisher() {
return publisher;
}

@Override
public List<VirtualMachineImage.Offer> listOffers() throws CloudException, IOException {
List<VirtualMachineImage.Offer> offers = new ArrayList<>();
for (VirtualMachineImageResourceInner inner :
client.listOffers(location().toString(), publisher()).getBody()) {
offers.add(new VirtualMachineImageOfferImpl(this, inner.name(), client));
}
return offers;
}
}
Loading