use of com.microsoft.azure.management.compute.VirtualMachine in project cloudbreak by hortonworks.
the class TagsUtil method checkTagsAzure.
protected static void checkTagsAzure(String accesKey, String tenantId, String secretKey, String subscriptionId, CharSequence stackName, Map<String, String> tagsToCheckMap) {
ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(accesKey, tenantId, secretKey, null);
Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(subscriptionId);
PagedList<VirtualMachine> virtualMachinesList = azure.virtualMachines().list();
for (VirtualMachine vm : virtualMachinesList) {
if (vm.name().contains(stackName)) {
Map<String, String> extractedTags = vm.tags();
checkTags(tagsToCheckMap, extractedTags);
}
}
}
use of com.microsoft.azure.management.compute.VirtualMachine in project azure-sdk-for-java by Azure.
the class TestVirtualMachineNics method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
// Prepare the resource group definition
final String rgName = "rg" + this.testId;
Creatable<ResourceGroup> resourceGroupCreatable = virtualMachines.manager().resourceManager().resourceGroups().define(rgName).withRegion(Region.US_EAST);
// Prepare the virtual network definition [shared by primary and secondary network interfaces]
final String vnetName = "vnet" + this.testId;
Creatable<Network> networkCreatable = this.networkManager.networks().define(vnetName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withAddressSpace("10.0.0.0/28");
// Prepare the secondary network interface definition
final String secondaryNicName = "nic" + this.testId;
Creatable<NetworkInterface> secondaryNetworkInterfaceCreatable = this.networkManager.networkInterfaces().define(secondaryNicName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.5");
// .withNewPrimaryPublicIPAddress();
// [Secondary NIC cannot have PublicIP - Only primary network interface can reference a public IP address]
// Prepare the secondary network interface definition
final String secondaryNicName2 = "nic2" + this.testId;
Creatable<NetworkInterface> secondaryNetworkInterfaceCreatable2 = this.networkManager.networkInterfaces().define(secondaryNicName2).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.6");
// Create Virtual Machine
final String vmName = "vm" + this.testId;
final String primaryPipName = "pip" + vmName;
VirtualMachine virtualMachine = virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.4").withNewPrimaryPublicIPAddress(primaryPipName).withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS).withRootUsername("testuser").withRootPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_A9).withNewSecondaryNetworkInterface(secondaryNetworkInterfaceCreatable).withNewSecondaryNetworkInterface(secondaryNetworkInterfaceCreatable2).create();
Assert.assertTrue(virtualMachine.networkInterfaceIds().size() == 3);
NetworkInterface primaryNetworkInterface = virtualMachine.getPrimaryNetworkInterface();
Assert.assertEquals(primaryNetworkInterface.primaryPrivateIP(), "10.0.0.4");
PublicIPAddress primaryPublicIPAddress = primaryNetworkInterface.primaryIPConfiguration().getPublicIPAddress();
Assert.assertTrue(primaryPublicIPAddress.fqdn().startsWith(primaryPipName));
return virtualMachine;
}
use of com.microsoft.azure.management.compute.VirtualMachine in project azure-sdk-for-java by Azure.
the class TestVirtualMachineSsh method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
final String sshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfSPC2K7LZcFKEO+/t3dzmQYtrJFZNxOsbVgOVKietqHyvmYGHEC0J2wPdAqQ/63g/hhAEFRoyehM+rbeDri4txB3YFfnOK58jqdkyXzupWqXzOrlKY4Wz9SKjjN765+dqUITjKRIaAip1Ri137szRg71WnrmdP3SphTRlCx1Bk2nXqWPsclbRDCiZeF8QOTi4JqbmJyK5+0UqhqYRduun8ylAwKKQJ1NJt85sYIHn9f1Rfr6Tq2zS0wZ7DHbZL+zB5rSlAr8QyUdg/GQD+cmSs6LvPJKL78d6hMGk84ARtFo4A79ovwX/Fj01znDQkU6nJildfkaolH2rWFG/qttD azjava@javalib.com";
final String publicIpDnsLabel = vmName;
PublicIPAddress pip = pips.define(publicIpDnsLabel).withRegion(Region.US_EAST).withNewResourceGroup().withLeafDomainLabel(publicIpDnsLabel).create();
VirtualMachine vm = virtualMachines.define(vmName).withRegion(pip.regionName()).withExistingResourceGroup(pip.resourceGroupName()).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withExistingPrimaryPublicIPAddress(pip).withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS).withRootUsername("testuser").withRootPassword("12NewPA$$w0rd!").withSsh(sshKey).withSize(VirtualMachineSizeTypes.STANDARD_D3_V2).create();
pip.refresh();
Assert.assertTrue(pip.hasAssignedNetworkInterface());
JSch jsch = new JSch();
Session session = null;
if (!MockIntegrationTestBase.IS_MOCKED) {
try {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
// jsch.addIdentity(sshFile, filePassword);
session = jsch.getSession("testuser", publicIpDnsLabel + "." + "eastus.cloudapp.azure.com", 22);
session.setPassword("12NewPA$$w0rd!");
session.setConfig(config);
session.connect();
} catch (Exception e) {
Assert.fail("SSH connection failed" + e.getMessage());
} finally {
if (session != null) {
session.disconnect();
}
}
Assert.assertNotNull(vm.inner().osProfile().linuxConfiguration().ssh());
Assert.assertTrue(vm.inner().osProfile().linuxConfiguration().ssh().publicKeys().size() > 0);
}
return vm;
}
use of com.microsoft.azure.management.compute.VirtualMachine in project azure-sdk-for-java by Azure.
the class TestVirtualMachineCustomData method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
final String publicIpDnsLabel = SdkContext.randomResourceName("abc", 16);
// Prepare the custom data
//
String cloudInitFilePath = getClass().getClassLoader().getResource("cloud-init").getPath();
// In Windows remove leading slash
cloudInitFilePath = cloudInitFilePath.replaceFirst("^/(.:/)", "$1");
byte[] cloudInitAsBytes = Files.readAllBytes(Paths.get(cloudInitFilePath));
byte[] cloudInitEncoded = Base64.encodeBase64(cloudInitAsBytes);
String cloudInitEncodedString = new String(cloudInitEncoded);
PublicIPAddress pip = pips.define(publicIpDnsLabel).withRegion(Region.US_EAST).withNewResourceGroup().withLeafDomainLabel(publicIpDnsLabel).create();
VirtualMachine vm = virtualMachines.define(vmName).withRegion(pip.regionName()).withExistingResourceGroup(pip.resourceGroupName()).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withExistingPrimaryPublicIPAddress(pip).withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername("testuser").withRootPassword("12NewPA$$w0rd!").withCustomData(cloudInitEncodedString).withSize(VirtualMachineSizeTypes.STANDARD_D3_V2).create();
pip.refresh();
Assert.assertTrue(pip.hasAssignedNetworkInterface());
if (!MockIntegrationTestBase.IS_MOCKED) {
JSch jsch = new JSch();
Session session = null;
ChannelExec channel = null;
try {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session = jsch.getSession("testuser", publicIpDnsLabel + "." + "eastus.cloudapp.azure.com", 22);
session.setPassword("12NewPA$$w0rd!");
session.setConfig(config);
session.connect();
// Try running the package installed via init script
//
channel = (ChannelExec) session.openChannel("exec");
BufferedReader in = new BufferedReader(new InputStreamReader(channel.getInputStream()));
channel.setCommand("pwgen;");
channel.connect();
String msg;
while ((msg = in.readLine()) != null) {
Assert.assertFalse(msg.startsWith("The program 'pwgen' is currently not installed"));
}
} catch (Exception e) {
Assert.fail("SSH connection failed" + e.getMessage());
} finally {
if (channel != null) {
channel.disconnect();
}
if (session != null) {
session.disconnect();
}
}
}
return vm;
}
use of com.microsoft.azure.management.compute.VirtualMachine in project azure-sdk-for-java by Azure.
the class TestVirtualMachineDataDisk method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
VirtualMachine virtualMachine = virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup().withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress().withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withUnmanagedDisks().withNewUnmanagedDataDisk(30).defineUnmanagedDataDisk("disk2").withNewVhd(20).withCaching(CachingTypes.READ_ONLY).attach().withSize(VirtualMachineSizeTypes.STANDARD_A8).create();
Assert.assertTrue(virtualMachine.size().equals(VirtualMachineSizeTypes.STANDARD_A8));
Assert.assertTrue(virtualMachine.unmanagedDataDisks().size() == 2);
VirtualMachineUnmanagedDataDisk disk2 = null;
for (VirtualMachineUnmanagedDataDisk dataDisk : virtualMachine.unmanagedDataDisks().values()) {
if (dataDisk.name().equalsIgnoreCase("disk2")) {
disk2 = dataDisk;
break;
}
}
Assert.assertNotNull(disk2);
Assert.assertTrue(disk2.cachingType() == CachingTypes.READ_ONLY);
Assert.assertTrue(disk2.size() == 20);
return virtualMachine;
}
Aggregations