@Override public Observable<DiskVolumeEncryptionMonitor> getMonitorAsync() { if (this.virtualMachine.osType() == OperatingSystemTypes.LINUX) { return new LinuxDiskVolumeEncryptionMonitorImpl(virtualMachine.id(), virtualMachine.manager()).refreshAsync(); } else { return new WindowsVolumeEncryptionMonitorImpl(virtualMachine.id(), virtualMachine.manager()).refreshAsync(); } }
@Override public boolean startIfStopped(final String id, final Timeout timeout) throws InterruptedException { VirtualMachine vm = getById(id); switch (vm.powerState()) { case RUNNING: case DEALLOCATING: case STARTING: return false; case DEALLOCATED: log.info(vm.resourceGroupName() + " - " + vm.name() + " is deallocated, starting"); start(id, timeout); return true; default: throw new IllegalArgumentException("Unknown power state"); } }
@Override public Void call() throws Exception { try { vm.restart(); } catch (CloudException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error restarting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } }));
@Override public Void call() throws Exception { try { vm.deallocate(); } catch (CloudException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error deallocating " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } }));
public static AzureDockerVM getDockerVM(VirtualMachine vm) { try { NicIPConfiguration nicIPConfiguration = vm.getPrimaryNetworkInterface().primaryIPConfiguration(); PublicIPAddress publicIp = nicIPConfiguration.getPublicIPAddress(); Network vnet = nicIPConfiguration.getNetwork(); AzureDockerVM dockerVM = new AzureDockerVM(); dockerVM.name = vm.name(); dockerVM.resourceGroupName = vm.resourceGroupName().toLowerCase(); dockerVM.region = vm.regionName(); dockerVM.availabilitySet = (vm.availabilitySetId() != null) ? ResourceUtils.nameFromResourceId(vm.availabilitySetId()) : null; dockerVM.privateIp = nicIPConfiguration.privateIPAddress(); if (publicIp != null) { dockerVM.nicName = vm.getPrimaryNetworkInterface().name(); dockerVM.vnetName = vnet.name(); dockerVM.vnetAddressSpace = vnet.addressSpaces().get(0); dockerVM.subnetAddressRange = vnet.subnets().get(dockerVM.subnetName).addressPrefix(); dockerVM.networkSecurityGroupName = (nicIPConfiguration.parent().networkSecurityGroupId() != null) ? ResourceUtils.nameFromResourceId(nicIPConfiguration.parent().networkSecurityGroupId()) : null; dockerVM.vmSize = vm.size().toString(); dockerVM.osDiskName = vm.storageProfile().osDisk().name(); if (vm.storageProfile().imageReference() != null) { dockerVM.osHost = new AzureOSHost(vm.storageProfile().imageReference()); if (vm.storageProfile().osDisk().managedDisk() != null) { dockerVM.storageAccountName = vm.storageProfile().osDisk().name(); dockerVM.storageAccountType = "Managed disk"; } else {
@Override public Future<Void> stopAsync(final String id) { final VirtualMachine vm = getById(id); final String threadName = "Azure Async Call - " + vm.resourceGroupName() + " - " + vm.name(); ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() { @Override public Void call() throws Exception { stop(vm, Timeout.THIRTY_MINUTES); return null; } }); return asynchronous.submit(call); }
@Override public Void call() throws Exception { try { vm.start(); } catch (CloudException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error starting " + vm.resourceGroupName() + " " + vm.name() + ": " + e.getMessage(), e); throw new RuntimeException(e); } return null; } }));
public static boolean isDeletingDockerHostAllSafe(Azure azureClient, String resourceGroup, String vmName) { if (azureClient == null || resourceGroup == null || vmName == null ) { return false; } VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName); if (vm == null) { return false; } PublicIPAddress publicIp = vm.getPrimaryPublicIPAddress(); NicIPConfiguration nicIPConfiguration = publicIp.getAssignedNetworkInterfaceIPConfiguration(); Network vnet = nicIPConfiguration.getNetwork(); NetworkInterface nic = vm.getPrimaryNetworkInterface(); return nic.ipConfigurations().size() == 1 && vnet.subnets().size() == 1 && vnet.subnets().values().toArray(new Subnet[1])[0].inner().ipConfigurations().size() == 1; }
public static void deleteDockerHostAll(Azure azureClient, String resourceGroup, String vmName) { if (azureClient == null || resourceGroup == null || vmName == null ) { throw new AzureDockerException("Unexpected param values; Azure instance, resource group and VM name cannot be null"); } VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName); if (vm == null) { throw new AzureDockerException(String.format("Unexpected error retrieving VM %s from Azure", vmName)); } try { PublicIPAddress publicIp = vm.getPrimaryPublicIPAddress(); NicIPConfiguration nicIPConfiguration = publicIp.getAssignedNetworkInterfaceIPConfiguration(); Network vnet = nicIPConfiguration.getNetwork(); NetworkInterface nic = vm.getPrimaryNetworkInterface(); azureClient.virtualMachines().deleteById(vm.id()); azureClient.networkInterfaces().deleteById(nic.id()); azureClient.publicIPAddresses().deleteById(publicIp.id()); azureClient.networks().deleteById(vnet.id()); } catch (Exception e) { throw new AzureDockerException(String.format("Unexpected error while deleting VM %s and its associated resources", vmName)); } }
public VMNode(Node parent, String subscriptionId, VirtualMachine virtualMachine) throws AzureCmdException { super(virtualMachine.id(), virtualMachine.name(), parent, WAIT_ICON_PATH, true); this.virtualMachine = virtualMachine; this.subscriptionId = subscriptionId; loadActions(); // update vm icon based on vm status refreshItemsInternal(); }
@Override public VirtualMachineCustomImageImpl fromVirtualMachine(VirtualMachine virtualMachine) { return this.fromVirtualMachine(virtualMachine.id()); }
/** * Gets status object that describes the current status of the volume encryption or decryption process. * * @param virtualMachine the virtual machine on which encryption or decryption is running * @return an observable that emits current encrypt or decrypt status */ private Observable<DiskVolumeEncryptionMonitor> getDiskVolumeEncryptDecryptStatusAsync(VirtualMachine virtualMachine) { if (osType == OperatingSystemTypes.LINUX) { return new LinuxDiskVolumeEncryptionMonitorImpl(virtualMachine.id(), virtualMachine.manager()).refreshAsync(); } else { return new WindowsVolumeEncryptionMonitorImpl(virtualMachine.id(), virtualMachine.manager()).refreshAsync(); } }
@Override public Map<String, String> toProperties() { final Map<String, String> properties = new HashMap<>(); properties.put(AppInsightsConstants.SubscriptionId, ResourceId.fromString(this.virtualMachine.id()).subscriptionId()); properties.put(AppInsightsConstants.Region, this.virtualMachine.regionName()); return properties; }
@Override protected void azureNodeAction(NodeActionEvent e) throws AzureCmdException { virtualMachine.restart(); refreshItems(); }
/** * Gets current status of virtual machine. * * @param vmName Virtual machine name. * @param resourceGroupName Resource group name. * @return Virtual machine status. * @throws AzureCloudException */ private VMStatus getVirtualMachineStatus( String vmName, String resourceGroupName) throws AzureCloudException { VirtualMachine vm; try { vm = azureClient.virtualMachines().getByResourceGroup(resourceGroupName, vmName); } catch (Exception e) { throw AzureCloudException.create(e); } final String provisioningState = vm.provisioningState(); if (!provisioningState.equalsIgnoreCase("succeeded")) { if (provisioningState.equalsIgnoreCase("updating")) { return VMStatus.UPDATING; } else { return VMStatus.PROVISIONING_OR_DEPROVISIONING; } } else { return VMStatus.fromPowerState(vm.powerState()); } }
@Override protected void azureNodeAction(NodeActionEvent e) throws AzureCmdException { virtualMachine.start(); refreshItems(); }
@Override public PowerState getPowerState(final String id) { try { VirtualMachine vm = virtualMachines.getById(id); return vm.powerState(); } catch (CloudException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
public DeleteVMAction() { super(VMNode.this, String.format("This operation will delete virtual machine %s.\nThe associated disks will not be deleted " + "from your storage account.\n\nAre you sure you want to continue?", virtualMachine.name()), "Deleting VM"); }
/** * Shutdowns Azure virtual machine. * * @param agent * @throws Exception */ public void shutdownVirtualMachine(AzureVMAgent agent) { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: shutdownVirtualMachine: called for {0}", agent.getNodeName()); try { azureClient.virtualMachines() .getByResourceGroup(agent.getResourceGroupName(), agent.getNodeName()).deallocate(); } catch (Exception e) { LOGGER.log(Level.WARNING, "AzureVMManagementServiceDelegate: provision: could not terminate or shutdown {0}, {1}", new Object[]{agent.getNodeName(), e}); } }
final OperatingSystemTypes osType = vm.storageProfile().osDisk().osType();