use of com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage in project azure-tools-for-java by Microsoft.
the class SelectImageStep method createSettingsPanel.
private void createSettingsPanel(Composite container) {
final Composite composite = new Composite(container, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = GridData.BEGINNING;
gridData.grabExcessHorizontalSpace = true;
// gridData.widthHint = 350;
composite.setLayout(gridLayout);
composite.setLayoutData(gridData);
regionLabel = new Label(composite, SWT.LEFT);
regionLabel.setText("Location:");
// regionLabel.setLayoutData(getGridDataForLabel());
regionComboBox = new Combo(composite, SWT.READ_ONLY);
regionComboBox.setLayoutData(getGridData(1));
regionComboBox.setToolTipText("Specifies the location where your virtual machine will be created");
knownImageBtn = new Button(composite, SWT.RADIO);
knownImageBtn.setText("Recommended image:");
knownImageBtn.setLayoutData(getGridData(2));
knownImageComboBox = new Combo(composite, SWT.READ_ONLY);
knownImageComboBox.setLayoutData(getGridData(2));
for (KnownWindowsVirtualMachineImage image : KnownWindowsVirtualMachineImage.values()) {
knownImageComboBox.add(image.offer() + " - " + image.sku());
knownImageComboBox.setData(image.offer() + " - " + image.sku(), image);
}
for (KnownLinuxVirtualMachineImage image : KnownLinuxVirtualMachineImage.values()) {
knownImageComboBox.add(image.offer() + " - " + image.sku());
knownImageComboBox.setData(image.offer() + " - " + image.sku(), image);
}
knownImageComboBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent selectionEvent) {
wizard.setKnownMachineImage(knownImageComboBox.getData(knownImageComboBox.getText()));
validateNext();
}
});
knownImageComboBox.select(0);
customImageBtn = new Button(composite, SWT.RADIO);
customImageBtn.setText("Custom image:");
customImageBtn.setLayoutData(getGridData(2));
publisherLabel = new Label(composite, SWT.LEFT);
publisherLabel.setText("Publisher:");
publisherComboBox = new Combo(composite, SWT.READ_ONLY);
publisherComboBox.setLayoutData(getGridData(1));
publisherComboBox.setToolTipText("Specifies the publisher which created the image which you will use to create your virtual machine");
offerLabel = new Label(composite, SWT.LEFT);
offerLabel.setText("Offer:");
offerComboBox = new Combo(composite, SWT.READ_ONLY);
offerComboBox.setLayoutData(getGridData(1));
offerComboBox.setToolTipText("Specifies which the virtual machine which offering to use from the selected publisher");
skuLabel = new Label(composite, SWT.LEFT);
skuLabel.setText("Sku:");
// skuLabel.setLayoutData(getGridDataForLabel());
skuComboBox = new Combo(composite, SWT.READ_ONLY);
skuComboBox.setLayoutData(getGridData(1));
skuComboBox.setToolTipText("Specifies the Stockkeeping Unit (SKU) to use from the selected offering");
versionLabel = new Label(composite, SWT.LEFT);
versionLabel.setText("Version #:");
imageLabelList = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
// gridData = new GridData();
// gridData.widthHint = 300;
gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.verticalIndent = 10;
imageLabelList.setLayoutData(gridData);
imageLabelList.setToolTipText("Specifies the label for the specific image to use from the selected SKU; this is often the version for an image");
}
use of com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage in project azure-tools-for-java by Microsoft.
the class AzureSDKManager method createVirtualMachine.
public static VirtualMachine createVirtualMachine(String subscriptionId, @NotNull String name, @NotNull String resourceGroup, boolean withNewResourceGroup, @NotNull String size, @NotNull String region, final VirtualMachineImage vmImage, Object knownImage, boolean isKnownImage, final StorageAccount storageAccount, com.microsoft.tooling.msservices.model.storage.StorageAccount newStorageAccount, boolean withNewStorageAccount, final Network network, VirtualNetwork newNetwork, boolean withNewNetwork, @NotNull String subnet, @Nullable PublicIPAddress pip, boolean withNewPip, @Nullable AvailabilitySet availabilitySet, boolean withNewAvailabilitySet, @NotNull final String username, @Nullable final String password, @Nullable String publicKey) throws Exception {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
Azure azure = azureManager.getAzure(subscriptionId);
boolean isWindows;
if (isKnownImage) {
isWindows = knownImage instanceof KnownWindowsVirtualMachineImage;
} else {
isWindows = vmImage.osDiskImage().operatingSystem().equals(OperatingSystemTypes.WINDOWS);
}
// ------ Resource Group ------
VirtualMachine.DefinitionStages.WithGroup withGroup = azure.virtualMachines().define(name).withRegion(region);
Creatable<ResourceGroup> newResourceGroup = null;
VirtualMachine.DefinitionStages.WithNetwork withNetwork;
if (withNewResourceGroup) {
newResourceGroup = azure.resourceGroups().define(resourceGroup).withRegion(region);
withNetwork = withGroup.withNewResourceGroup(newResourceGroup);
} else {
withNetwork = withGroup.withExistingResourceGroup(resourceGroup);
}
// ------ Virtual Network -----
VirtualMachine.DefinitionStages.WithPublicIPAddress withPublicIpAddress;
if (withNewNetwork) {
Network.DefinitionStages.WithGroup networkWithGroup = azure.networks().define(newNetwork.name).withRegion(region);
Creatable<Network> newVirtualNetwork;
if (withNewResourceGroup) {
newVirtualNetwork = networkWithGroup.withNewResourceGroup(newResourceGroup).withAddressSpace(newNetwork.addressSpace).withSubnet(newNetwork.subnet.name, newNetwork.subnet.addressSpace);
} else {
newVirtualNetwork = networkWithGroup.withExistingResourceGroup(resourceGroup).withAddressSpace(newNetwork.addressSpace).withSubnet(newNetwork.subnet.name, newNetwork.subnet.addressSpace);
}
withPublicIpAddress = withNetwork.withNewPrimaryNetwork(newVirtualNetwork).withPrimaryPrivateIPAddressDynamic();
// withPublicIpAddress = withNetwork.withNewPrimaryNetwork("10.0.0.0/28").
// .withPrimaryPrivateIpAddressDynamic();
} else {
withPublicIpAddress = withNetwork.withExistingPrimaryNetwork(network).withSubnet(subnet).withPrimaryPrivateIPAddressDynamic();
}
// ------ Public IP Address------
VirtualMachine.DefinitionStages.WithOS withOS;
if (pip == null) {
if (withNewPip) {
withOS = withPublicIpAddress.withNewPrimaryPublicIPAddress(name + "pip");
} else {
withOS = withPublicIpAddress.withoutPrimaryPublicIPAddress();
}
} else {
withOS = withPublicIpAddress.withExistingPrimaryPublicIPAddress(pip);
}
// ------ OS and credentials -----
VirtualMachine.DefinitionStages.WithCreate withCreate;
if (isWindows) {
VirtualMachine.DefinitionStages.WithWindowsAdminUsernameManagedOrUnmanaged withWindowsAdminUsername;
if (isKnownImage) {
withWindowsAdminUsername = withOS.withPopularWindowsImage((KnownWindowsVirtualMachineImage) knownImage);
} else {
withWindowsAdminUsername = withOS.withSpecificWindowsImageVersion(vmImage.imageReference());
}
withCreate = withWindowsAdminUsername.withAdminUsername(username).withAdminPassword(password).withUnmanagedDisks();
} else {
VirtualMachine.DefinitionStages.WithLinuxRootPasswordOrPublicKeyManagedOrUnmanaged withLinuxRootPasswordOrPublicKey;
if (isKnownImage) {
withLinuxRootPasswordOrPublicKey = withOS.withPopularLinuxImage((KnownLinuxVirtualMachineImage) knownImage).withRootUsername(username);
} else {
withLinuxRootPasswordOrPublicKey = withOS.withSpecificLinuxImageVersion(vmImage.imageReference()).withRootUsername(username);
}
VirtualMachine.DefinitionStages.WithLinuxCreateManagedOrUnmanaged withLinuxCreate;
// we assume either password or public key is not empty
if (password != null && !password.isEmpty()) {
withLinuxCreate = withLinuxRootPasswordOrPublicKey.withRootPassword(password);
if (publicKey != null) {
withLinuxCreate = withLinuxCreate.withSsh(publicKey);
}
} else {
withLinuxCreate = withLinuxRootPasswordOrPublicKey.withSsh(publicKey);
}
withCreate = withLinuxCreate.withUnmanagedDisks();
}
withCreate = withCreate.withSize(size);
// ---- Storage Account --------
if (withNewStorageAccount) {
StorageAccount.DefinitionStages.WithCreate newAccount;
StorageAccount.DefinitionStages.WithGroup withGroupAccount = azure.storageAccounts().define(newStorageAccount.getName()).withRegion(newStorageAccount.getLocation());
if (newStorageAccount.isNewResourceGroup()) {
newAccount = withGroupAccount.withNewResourceGroup(newStorageAccount.getResourceGroupName());
} else {
newAccount = withGroupAccount.withExistingResourceGroup(newStorageAccount.getResourceGroupName());
}
// only general purpose accounts used to create vm
newAccount.withGeneralPurposeAccountKind().withSku(SkuName.fromString(newStorageAccount.getType()));
withCreate = withCreate.withNewStorageAccount(newAccount);
} else {
withCreate = withCreate.withExistingStorageAccount(storageAccount);
}
if (withNewAvailabilitySet) {
withCreate = withCreate.withNewAvailabilitySet(name + "as");
} else if (availabilitySet != null) {
withCreate = withCreate.withExistingAvailabilitySet(availabilitySet);
}
return withCreate.create();
}
Aggregations