use of com.microsoft.tooling.msservices.model.vm.VirtualNetwork in project azure-tools-for-java by Microsoft.
the class SettingsStep method showNewVirtualNetworkForm.
private void showNewVirtualNetworkForm() {
final String resourceGroupName = createNewRadioButton.isSelected() ? resourceGrpField.getText() : resourceGrpCombo.getSelectedItem().toString();
final CreateVirtualNetworkForm form = new CreateVirtualNetworkForm(project, model.getSubscription().getSubscriptionId(), model.getRegion(), model.getName());
form.setOnCreate(new Runnable() {
@Override
public void run() {
VirtualNetwork newVirtualNetwork = form.getNetwork();
if (newVirtualNetwork != null) {
model.setNewNetwork(newVirtualNetwork);
model.setWithNewNetwork(true);
((DefaultComboBoxModel) networkComboBox.getModel()).insertElementAt(newVirtualNetwork.name + " (New)", 0);
networkComboBox.setSelectedIndex(0);
} else {
networkComboBox.setSelectedItem(null);
}
}
});
form.show();
}
use of com.microsoft.tooling.msservices.model.vm.VirtualNetwork 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();
}
use of com.microsoft.tooling.msservices.model.vm.VirtualNetwork 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, 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 --------
com.microsoft.azure.management.storage.StorageAccount existedStorageAccount = azure.storageAccounts().getById(storageAccount.id());
withCreate = withCreate.withExistingStorageAccount(existedStorageAccount);
if (withNewAvailabilitySet) {
withCreate = withCreate.withNewAvailabilitySet(name + "as");
} else if (availabilitySet != null) {
withCreate = withCreate.withExistingAvailabilitySet(availabilitySet);
}
return withCreate.create();
}
use of com.microsoft.tooling.msservices.model.vm.VirtualNetwork in project azure-tools-for-java by Microsoft.
the class CreateVirtualNetworkForm method okPressed.
@Override
protected void okPressed() {
network = new VirtualNetwork(nameField.getText().trim(), addressSpaceField.getText().trim(), subnetNameField.getText().trim(), subnetAddressRangeField.getText().trim());
if (onCreate != null) {
DefaultLoader.getIdeHelper().invokeLater(onCreate);
}
super.okPressed();
}
use of com.microsoft.tooling.msservices.model.vm.VirtualNetwork in project azure-tools-for-java by Microsoft.
the class CreateVirtualNetworkForm method doOKAction.
@Override
protected void doOKAction() {
network = new VirtualNetwork(nameField.getText().trim(), addressSpaceField.getText().trim(), subnetNameField.getText().trim(), subnetAddressRangeField.getText().trim());
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
if (onCreate != null) {
onCreate.run();
}
}
});
sendTelemetry(OK_EXIT_CODE);
close(DialogWrapper.OK_EXIT_CODE, true);
// ProgressManager.getInstance().run(
// new Task.Modal(project, "Creating virtual network", true) {
// @Override
// public void run(@NotNull ProgressIndicator indicator) {
// indicator.setIndeterminate(true);
// boolean success = createVirtualNetwork();
// if (success) {
// AzureTaskManager.getInstance().runLater(new Runnable() {
// @Override
// public void run() {
// close(DialogWrapper.OK_EXIT_CODE, true);
// }
// }, ModalityState.any());
//
// }
// }
// }
// );
}
Aggregations