Skip to content

Commit

Permalink
Merge pull request #688 from jianghaolu/master
Browse files Browse the repository at this point in the history
Add some VM image code
  • Loading branch information
anuchandy committed May 9, 2016
2 parents 607a661 + e3e2c2e commit e06fb56
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 3 deletions.
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;
}
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");

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

0 comments on commit e06fb56

Please sign in to comment.