本文整理汇总了Java中com.microsoft.azure.management.compute.VirtualMachine类的典型用法代码示例。如果您正苦于以下问题:Java VirtualMachine类的具体用法?Java VirtualMachine怎么用?Java VirtualMachine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VirtualMachine类属于com.microsoft.azure.management.compute包,在下文中一共展示了VirtualMachine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateEncryptionExtensionAsync
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
/**
* Updates the encryption extension in the virtual machine using provided configuration.
* If extension is not installed then this method return empty observable.
*
* @param encryptConfig the volume encryption configuration
* @return an observable that emits updated virtual machine
*/
private Observable<VirtualMachine> updateEncryptionExtensionAsync(final EnableDisableEncryptConfig encryptConfig) {
return getEncryptionExtensionInstalledInVMAsync()
.flatMap(new Func1<VirtualMachineExtension, Observable<VirtualMachine>>() {
@Override
public Observable<VirtualMachine> call(final VirtualMachineExtension encryptionExtension) {
final HashMap<String, Object> publicSettings = encryptConfig.extensionPublicSettings();
return virtualMachine.update()
.updateExtension(encryptionExtension.name())
.withPublicSettings(publicSettings)
.withProtectedSettings(encryptConfig.extensionProtectedSettings())
.parent()
.applyAsync();
}
});
}
示例2: installEncryptionExtensionAsync
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
/**
* Prepare encryption extension using provided configuration and install it in the virtual machine.
*
* @param encryptConfig the volume encryption configuration
* @return an observable that emits updated virtual machine
*/
private Observable<VirtualMachine> installEncryptionExtensionAsync(final EnableDisableEncryptConfig encryptConfig) {
return Observable.defer(new Func0<Observable<VirtualMachine>>() {
@Override
public Observable<VirtualMachine> call() {
final String extensionName = encryptionExtensionType();
return virtualMachine.update()
.defineNewExtension(extensionName)
.withPublisher(encryptionExtensionPublisher)
.withType(encryptionExtensionType())
.withVersion(encryptionExtensionVersion())
.withPublicSettings(encryptConfig.extensionPublicSettings())
.withProtectedSettings(encryptConfig.extensionProtectedSettings())
.withMinorVersionAutoUpgrade()
.attach()
.applyAsync();
}
});
}
示例3: createResource
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
final String newRgName = SdkContext.randomResourceName("rgVmInAvail", 10);
final String newAvailSetName = SdkContext.randomResourceName("avai", 10);
VirtualMachine vm = virtualMachines.define(vmName)
.withRegion(Region.US_EAST)
.withNewResourceGroup(newRgName)
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("testuser")
.withRootPassword("12NewPA$$w0rd!")
.withComputerName("myvm123")
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.withNewAvailabilitySet(newAvailSetName)
.create();
Assert.assertNotNull(vm.availabilitySetId());
Assert.assertNotNull(vm.computerName());
Assert.assertTrue(vm.computerName().equalsIgnoreCase("myvm123"));
return vm;
}
示例4: createResource
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
List<VirtualMachineSize> availableSizes = virtualMachines.sizes().listByRegion(Region.US_EAST);
Assert.assertTrue(availableSizes.size() > 0);
System.out.println("VM Sizes: " + availableSizes);
final String vmName = "vm" + this.testId;
VirtualMachine vm = 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!")
.withSize(availableSizes.get(0).name()) // Use the first size
.create();
Assert.assertTrue(vm.size().toString().equalsIgnoreCase(availableSizes.get(0).name()));
return vm;
}
示例5: updateResource
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public VirtualMachine updateResource(VirtualMachine virtualMachine) throws Exception {
List<VirtualMachineSize> resizableSizes = virtualMachine.availableSizes();
Assert.assertTrue(resizableSizes.size() > 1);
VirtualMachineSize newSize = null;
for (VirtualMachineSize resizableSize : resizableSizes) {
if (!resizableSize.name().equalsIgnoreCase(virtualMachine.size().toString())) {
newSize = resizableSize;
break;
}
}
Assert.assertNotNull(newSize);
virtualMachine = virtualMachine.update()
.withSize(newSize.name())
.apply();
Assert.assertTrue(virtualMachine.size().toString().equalsIgnoreCase(newSize.name()));
return virtualMachine;
}
示例6: updateResource
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public VirtualMachine updateResource(VirtualMachine virtualMachine) throws Exception {
virtualMachine = virtualMachine.update()
.withoutUnmanagedDataDisk("disk2")
.defineUnmanagedDataDisk("disk3")
.withNewVhd(10)
.withLun(2)
.attach()
.apply();
Assert.assertTrue(virtualMachine.unmanagedDataDisks().size() == 2);
VirtualMachineUnmanagedDataDisk disk3 = null;
for (VirtualMachineUnmanagedDataDisk dataDisk : virtualMachine.unmanagedDataDisks().values()) {
if (dataDisk.name().equalsIgnoreCase("disk3")) {
disk3 = dataDisk;
break;
}
}
Assert.assertNotNull(disk3);
Assert.assertTrue(disk3.cachingType() == CachingTypes.READ_WRITE);
Assert.assertTrue(disk3.size() == 10);
return virtualMachine;
}
示例7: assertAttachDiskToVM
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
private void assertAttachDiskToVM() {
ComputeService.ComputeState provisionedVM = this.host.getServiceState(null,
ComputeService.ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertEquals(this.computeVM.diskLinks.size() + 1, provisionedVM.diskLinks.size());
DiskService.DiskState attachedDisk = this.host.getServiceState(null,
DiskService.DiskState.class, UriUtils.buildUri(this.host, this.diskState.documentSelfLink));
assertEquals("Disk status is not matching", DiskService.DiskStatus.ATTACHED, attachedDisk.status);
if (!this.isMock) {
assertNotNull(attachedDisk.customProperties.get(DISK_CONTROLLER_NUMBER));
VirtualMachine vm = this.getAzureSdkClients().getComputeManager()
.virtualMachines().getById(provisionedVM.id);
this.host.log("Number of disks attached to VM is - " + vm.dataDisks().size());
}
}
示例8: assertDetachDiskFromVM
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
private void assertDetachDiskFromVM() {
ComputeService.ComputeState provisionedVM = this.host.getServiceState(null,
ComputeService.ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertEquals(this.computeVM.diskLinks.size() - 1, provisionedVM.diskLinks.size());
DiskService.DiskState detachedDisk = this.host.getServiceState(null,
DiskService.DiskState.class, UriUtils.buildUri(this.host, this.diskState.documentSelfLink));
assertEquals("Disk status is not matching", DiskService.DiskStatus.AVAILABLE, detachedDisk.status);
if (!this.isMock) {
assertNull("LUN number not removed from Detached Disk", detachedDisk.customProperties
.get(DISK_CONTROLLER_NUMBER));
VirtualMachine vm = this.getAzureSdkClients().getComputeManager()
.virtualMachines().getById(provisionedVM.id);
//Check total numbers of disk match previous count - 1 = current data disks + 1 os disk
assertEquals("Number of disks not correct on Azure", this.computeVM.diskLinks.size()
- 1, vm.dataDisks().size() + 1);
this.host.log("Number of disks attached to VM is - " + vm.dataDisks().size());
}
}
示例9: apply
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public de.uniulm.omi.cloudiator.sword.domain.VirtualMachine apply(
VirtualMachine virtualMachine) {
final String id = IdScopeByLocations
.from(virtualMachine.regionName(), virtualMachine.name()).getIdWithLocation();
return VirtualMachineBuilder.newBuilder()
.addIpString(virtualMachine.getPrimaryNetworkInterface().primaryPrivateIP())
.addIpString(virtualMachine.getPrimaryPublicIPAddress().ipAddress())
.name(virtualMachine.name()).id(id)
.providerId(virtualMachine.vmId())
.location(locationGetStrategy.get(virtualMachine.regionName()))
.hardware(hardwareGetStrategy.get(
IdScopeByLocations.from(virtualMachine.regionName(), virtualMachine.size().toString())
.getIdWithLocation())).build();
}
示例10: renderVmDefinition
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
/**
* Creates a VM definition from a given {@link VmSpec} and with a given
* network interface.
*
* @param vmSpec
* @param vmNetworkInterface
* @return
*/
public Creatable<VirtualMachine> renderVmDefinition(VmSpec vmSpec, NetworkInterface vmNetworkInterface) {
String vmName = vmSpec.getVmName();
Azure api = ApiUtils.acquireApiClient(this.apiAccess);
WithOS rawVmDef = api.virtualMachines().define(vmName) //
.withRegion(this.region) //
.withExistingResourceGroup(this.resourceGroup) //
.withExistingPrimaryNetworkInterface(vmNetworkInterface);
if (vmSpec.getLinuxSettings().isPresent()) {
return linuxVmDefinition(vmSpec, rawVmDef);
} else {
return windowsVmDefinition(vmSpec, rawVmDef);
}
}
示例11: attachMachine
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public void attachMachine(String machineId) throws NotFoundException, CloudPoolDriverException {
checkState(isConfigured(), "cannot use driver before being configured");
// verifies that VM exists
VirtualMachine vm = this.client.getVm(machineId);
// only attach VM if it belongs to the region and resource group that
// the cloudpool is configured to use
ensureRightRegionAndResouceGroup(vm);
try {
LOG.info("attaching VM {} ...", machineId);
this.client.tagVm(vm, cloudPoolTag());
} catch (Exception e) {
throw new CloudPoolDriverException("failed to attach vm " + machineId + ": " + e.getMessage(), e);
}
}
示例12: detachMachine
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public void detachMachine(String machineId) throws NotFoundException, CloudPoolDriverException {
checkState(isConfigured(), "cannot use driver before being configured");
// verifies that VM exists
VirtualMachine vm = this.client.getVm(machineId);
// only detach VM if it is a pool member
ensurePoolMember(vm);
try {
LOG.info("detaching VM {} ...", machineId);
this.client.untagVm(vm, Arrays.asList(Constants.CLOUD_POOL_TAG));
} catch (Exception e) {
throw new CloudPoolDriverException("failed to detach vm " + machineId + ": " + e.getMessage(), e);
}
}
示例13: setServiceState
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public void setServiceState(String machineId, ServiceState serviceState)
throws NotFoundException, CloudPoolDriverException {
checkState(isConfigured(), "cannot use driver before being configured");
// verifies that VM exists
VirtualMachine vm = this.client.getVm(machineId);
// only set status VM if it is a pool member
ensurePoolMember(vm);
try {
LOG.info("setting service state for VM {} ...", machineId);
Map<String, String> tags = ImmutableMap.of(Constants.SERVICE_STATE_TAG, serviceState.name());
this.client.tagVm(vm, tags);
} catch (Exception e) {
throw new CloudPoolDriverException(
"failed to set service state for vm " + machineId + ": " + e.getMessage(), e);
}
}
示例14: setMembershipStatus
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
@Override
public void setMembershipStatus(String machineId, MembershipStatus membershipStatus)
throws NotFoundException, CloudPoolDriverException {
checkState(isConfigured(), "cannot use driver before being configured");
// verifies that VM exists
VirtualMachine vm = this.client.getVm(machineId);
// only set status VM if it is a pool member
ensurePoolMember(vm);
try {
LOG.info("setting membership status for VM {} ...", machineId);
Map<String, String> tags = ImmutableMap.of(Constants.MEMBERSHIP_STATUS_TAG,
JsonUtils.toString(toJson(membershipStatus)));
this.client.tagVm(vm, tags);
} catch (Exception e) {
throw new CloudPoolDriverException(
"failed to set membership status for vm " + machineId + ": " + e.getMessage(), e);
}
}
示例15: allStarted
import com.microsoft.azure.management.compute.VirtualMachine; //导入依赖的package包/类
private boolean allStarted(List<String> expectedVmNames, List<VirtualMachine> actualVms) {
Map<String, VirtualMachine> actualVmsByName = actualVms.stream()
.collect(Collectors.toMap(VirtualMachine::name, vm -> vm));
for (String expectedVmName : expectedVmNames) {
if (!actualVmsByName.containsKey(expectedVmName)) {
return false;
}
VirtualMachine actualVm = actualVmsByName.get(expectedVmName);
MachineState vmState = new VmToMachineState().apply(actualVm);
if (vmState != MachineState.PENDING && vmState != MachineState.RUNNING) {
return false;
}
}
// all vms were found to be started
return true;
}