use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method createDeploymentWithAvailabilitySet.
@Test
public void createDeploymentWithAvailabilitySet() throws Exception {
azureClient.resourceGroups().define(testEnv.azureResourceGroup).withRegion(testEnv.azureLocation).create();
AvailabilitySet availabilitySet = azureClient.availabilitySets().define("test-av-set").withRegion(testEnv.azureLocation).withExistingResourceGroup(testEnv.azureResourceGroup).withFaultDomainCount(2).withUpdateDomainCount(4).withSku(AvailabilitySetSkuTypes.ALIGNED).create();
Assert.assertNotNull("Failed to create availability set in resourceGroup " + testEnv.azureResourceGroup, availabilitySet);
testEnv.availabilityType = AvailabilityType.AVAILABILITY_SET.getName();
testEnv.availabilitySet = availabilitySet.name();
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
AzureVMDeploymentInfo deploymentInfo;
deploymentInfo = createDefaultDeployment(1, deploymentRegistrar);
verify(deploymentRegistrar).registerDeployment("testCloud", testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
Network actualVNet = null;
StorageAccount actualStorageAcc = null;
try {
actualVNet = azureClient.networks().getByResourceGroup(testEnv.azureResourceGroup, "jenkinsarm-vnet");
actualStorageAcc = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, testEnv.azureStorageAccountName);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VNet doesn't exist: " + testEnv.azureResourceGroup, actualVNet);
Assert.assertNotNull("The deployed Storage Account doesn't exist: " + testEnv.azureResourceGroup, actualStorageAcc);
final String baseName = deploymentInfo.getVmBaseName() + "0";
final String commonAssertMsg = testEnv.azureResourceGroup + ":" + baseName;
VirtualMachine actualVM = null;
NetworkInterface actualNetIface = null;
PublicIpAddress actualIP = null;
try {
actualVM = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, baseName);
actualNetIface = azureClient.networkInterfaces().getByResourceGroup(testEnv.azureResourceGroup, baseName + "NIC");
actualIP = azureClient.publicIpAddresses().getByResourceGroup(testEnv.azureResourceGroup, baseName + "IPName");
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VM doesn't exist: " + commonAssertMsg, actualVM);
Assert.assertNotNull("The deployed Network interface doesn't exist: " + commonAssertMsg, actualNetIface);
Assert.assertNotNull("The deployed public IP doesn't exist: " + commonAssertMsg, actualIP);
assertThat(availabilitySet.id(), is(equalToIgnoringCase(actualVM.availabilitySetId())));
}
use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method createDeploymentTest.
@Test
public void createDeploymentTest() throws Exception {
Random rand = new Random();
final int numberOfAgents = rand.nextInt(4) + 1;
AzureVMDeploymentInfo deploymentInfo = null;
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
deploymentInfo = createDefaultDeployment(numberOfAgents, deploymentRegistrar);
verify(deploymentRegistrar).registerDeployment("testCloud", testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
Network actualVNet = null;
StorageAccount actualStorageAcc = null;
try {
actualVNet = azureClient.networks().getByResourceGroup(testEnv.azureResourceGroup, "jenkinsarm-vnet");
actualStorageAcc = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, testEnv.azureStorageAccountName);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VNet doesn't exist: " + testEnv.azureResourceGroup, actualVNet);
Assert.assertNotNull("The deployed Storage Account doesn't exist: " + testEnv.azureResourceGroup, actualStorageAcc);
for (int i = 0; i < numberOfAgents; i++) {
final String baseName = deploymentInfo.getVmBaseName() + i;
final String commonAssertMsg = testEnv.azureResourceGroup + ":" + baseName;
VirtualMachine actualVM = null;
NetworkInterface actualNetIface = null;
PublicIpAddress actualIP = null;
try {
actualVM = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, baseName);
actualNetIface = azureClient.networkInterfaces().getByResourceGroup(testEnv.azureResourceGroup, baseName + "NIC");
actualIP = azureClient.publicIpAddresses().getByResourceGroup(testEnv.azureResourceGroup, baseName + "IPName");
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VM doesn't exist: " + commonAssertMsg, actualVM);
Assert.assertNotNull("The deployed Network interface doesn't exist: " + commonAssertMsg, actualNetIface);
Assert.assertNotNull("The deployed public IP doesn't exist: " + commonAssertMsg, actualIP);
Assert.assertFalse(actualVM.isManagedServiceIdentityEnabled());
Assert.assertEquals(getDefaultOsDiskSize(OS_TYPE), actualVM.osDiskSize());
Assert.assertEquals("gavin", actualVM.tags().get("author"));
Assert.assertEquals("test", actualVM.tags().get("env"));
Assert.assertEquals("gavin", actualIP.tags().get("author"));
Assert.assertEquals("test", actualIP.tags().get("env"));
Assert.assertEquals("gavin", actualNetIface.tags().get("author"));
Assert.assertEquals("test", actualNetIface.tags().get("env"));
Assert.assertEquals("gavin", actualStorageAcc.tags().get("author"));
Assert.assertEquals("test", actualStorageAcc.tags().get("env"));
Assert.assertEquals("gavin", actualVNet.tags().get("author"));
Assert.assertEquals("test", actualVNet.tags().get("env"));
}
}
use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method createDeploymentWithSpecificOsDiskSize.
@Test
public void createDeploymentWithSpecificOsDiskSize() throws Exception {
int osDiskSize = 100;
testEnv.osDiskSize = osDiskSize;
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
AzureVMDeploymentInfo deploymentInfo;
deploymentInfo = createDefaultDeployment(1, deploymentRegistrar);
verify(deploymentRegistrar).registerDeployment("testCloud", testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
Network actualVNet = null;
StorageAccount actualStorageAcc = null;
try {
actualVNet = azureClient.networks().getByResourceGroup(testEnv.azureResourceGroup, "jenkinsarm-vnet");
actualStorageAcc = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, testEnv.azureStorageAccountName);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VNet doesn't exist: " + testEnv.azureResourceGroup, actualVNet);
Assert.assertNotNull("The deployed Storage Account doesn't exist: " + testEnv.azureResourceGroup, actualStorageAcc);
final String baseName = deploymentInfo.getVmBaseName() + "0";
final String commonAssertMsg = testEnv.azureResourceGroup + ":" + baseName;
VirtualMachine actualVM = null;
NetworkInterface actualNetIface = null;
PublicIpAddress actualIP = null;
try {
actualVM = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, baseName);
actualNetIface = azureClient.networkInterfaces().getByResourceGroup(testEnv.azureResourceGroup, baseName + "NIC");
actualIP = azureClient.publicIpAddresses().getByResourceGroup(testEnv.azureResourceGroup, baseName + "IPName");
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VM doesn't exist: " + commonAssertMsg, actualVM);
Assert.assertNotNull("The deployed Network interface doesn't exist: " + commonAssertMsg, actualNetIface);
Assert.assertNotNull("The deployed public IP doesn't exist: " + commonAssertMsg, actualIP);
Assert.assertEquals(osDiskSize, actualVM.osDiskSize());
}
use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-maven-plugins by microsoft.
the class DraftVirtualMachine method create.
VirtualMachine create(final AzureVirtualMachine module) {
this.module = module;
final NetworkInterface.DefinitionStages.WithCreate interfaceWithCreate = module.getVirtualMachinesManager(subscriptionId).manager().networkManager().networkInterfaces().define(name + "-interface-" + Utils.getTimestamp()).withRegion(this.getRegion().getName()).withExistingResourceGroup(this.getResourceGroup()).withExistingPrimaryNetwork(this.getNetworkClient()).withSubnet(subnet.getName()).withPrimaryPrivateIPAddressDynamic();
if (ipAddress != null) {
final com.azure.resourcemanager.network.models.PublicIpAddress publicIpAddressClient = getPublicIpAddressClient();
if (publicIpAddressClient.hasAssignedNetworkInterface()) {
AzureMessager.getMessager().warning(AzureString.format("Can not assign public ip %s to vm %s, which has been assigned to %s", ipAddress.getName(), name, publicIpAddressClient.getAssignedNetworkInterfaceIPConfiguration().name()));
} else {
interfaceWithCreate.withExistingPrimaryPublicIPAddress(getPublicIpAddressClient());
}
}
if (securityGroup != null) {
interfaceWithCreate.withExistingNetworkSecurityGroup(getSecurityGroupClient());
}
final NetworkInterface networkInterface = interfaceWithCreate.create();
final WithProximityPlacementGroup withProximityPlacementGroup = module.getVirtualMachinesManager(subscriptionId).define(this.getName()).withRegion(this.getRegion().getName()).withExistingResourceGroup(this.getResourceGroup()).withExistingPrimaryNetworkInterface(networkInterface);
final WithCreate withCreate = configureImage(withProximityPlacementGroup);
if (StringUtils.isNotEmpty(availabilitySet)) {
withCreate.withExistingAvailabilitySet(getAvailabilitySetClient());
}
if (storageAccount != null) {
withCreate.withExistingStorageAccount(getStorageAccountClient());
}
if (azureSpotConfig != null) {
final VirtualMachineEvictionPolicyTypes evictionPolicyTypes = azureSpotConfig.getPolicy() == StopAndDeallocate ? DEALLOCATE : DELETE;
withCreate.withSpotPriority(evictionPolicyTypes).withMaxPrice(azureSpotConfig.getMaximumPrice());
}
try {
this.remote = withCreate.create();
} catch (Exception e) {
// clean up resource once creation failed
networkInterface.manager().networkInterfaces().deleteById(networkInterface.id());
throw e;
}
refreshStatus();
module.refresh();
return this;
}
use of com.azure.resourcemanager.network.models.NetworkInterface in project azure-vm-agents-plugin by jenkinsci.
the class ITAzureVMManagementServiceDelegate method createDeploymentWithPurchasePlan.
/**
* This test requires legal terms accepted in order for it to pass
* You can run: az vm image accept-terms --urn kali-linux:kali-linux:kali:2018.4.0
*/
@Test
public void createDeploymentWithPurchasePlan() throws Exception {
testEnv.azureImagePublisher = "kali-linux";
testEnv.azureImageOffer = "kali-linux";
testEnv.azureImageSku = "kali";
AzureVMAgentCleanUpTask.DeploymentRegistrar deploymentRegistrar = mock(AzureVMAgentCleanUpTask.DeploymentRegistrar.class);
when(deploymentRegistrar.getDeploymentTag()).thenReturn(new AzureUtil.DeploymentTag("some_tag/123"));
AzureVMDeploymentInfo deploymentInfo;
deploymentInfo = createDefaultDeployment(1, deploymentRegistrar);
verify(deploymentRegistrar).registerDeployment("testCloud", testEnv.azureResourceGroup, deploymentInfo.getDeploymentName(), null);
Network actualVNet = null;
StorageAccount actualStorageAcc = null;
try {
actualVNet = azureClient.networks().getByResourceGroup(testEnv.azureResourceGroup, "jenkinsarm-vnet");
actualStorageAcc = azureClient.storageAccounts().getByResourceGroup(testEnv.azureResourceGroup, testEnv.azureStorageAccountName);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VNet doesn't exist: " + testEnv.azureResourceGroup, actualVNet);
Assert.assertNotNull("The deployed Storage Account doesn't exist: " + testEnv.azureResourceGroup, actualStorageAcc);
final String baseName = deploymentInfo.getVmBaseName() + "0";
final String commonAssertMsg = testEnv.azureResourceGroup + ":" + baseName;
VirtualMachine actualVM = null;
NetworkInterface actualNetIface = null;
PublicIpAddress actualIP = null;
try {
actualVM = azureClient.virtualMachines().getByResourceGroup(testEnv.azureResourceGroup, baseName);
actualNetIface = azureClient.networkInterfaces().getByResourceGroup(testEnv.azureResourceGroup, baseName + "NIC");
actualIP = azureClient.publicIpAddresses().getByResourceGroup(testEnv.azureResourceGroup, baseName + "IPName");
} catch (Exception e) {
LOGGER.log(Level.SEVERE, null, e);
}
Assert.assertNotNull("The deployed VM doesn't exist: " + commonAssertMsg, actualVM);
Assert.assertNotNull("The deployed Network interface doesn't exist: " + commonAssertMsg, actualNetIface);
Assert.assertNotNull("The deployed public IP doesn't exist: " + commonAssertMsg, actualIP);
}
Aggregations