public static VirtualMachine getVM(Azure azureClient, String resourceGroup, String hostName) throws AzureDockerException { try { return azureClient.virtualMachines().getByResourceGroup(resourceGroup, hostName); } catch (Exception e) { throw new AzureDockerException(e.getMessage(), e); } }
/** * Determines whether a virtual machine exists. * * @param vmName Name of the VM. * @param resourceGroupName Resource group of the VM. * @return If the virtual machine exists */ private boolean virtualMachineExists( String vmName, String resourceGroupName) throws AzureCloudException { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: virtualMachineExists: check for {0}", vmName); VirtualMachine vm = null; try { vm = azureClient.virtualMachines().getByResourceGroup(resourceGroupName, vmName); } catch (Exception e) { throw AzureCloudException.create(e); } if (vm != null) { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: virtualMachineExists: {0} exists", vmName); return true; } else { LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: virtualMachineExists: {0} doesn't exist", vmName); return false; } }
@Override protected void refreshItems() throws AzureCmdException { try { Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient; VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name); if (vm != null) { refreshDockerHostInstance(vm); } } catch (Exception e) { DefaultLoader.getUIHelper().logError(e.getMessage(), e); } }
public static AzureDockerVM getDockerVM(Azure azureClient, String resourceGroup, String hostName) { try { AzureDockerVM azureDockerVM = getDockerVM(azureClient.virtualMachines().getByResourceGroup(resourceGroup, hostName)); azureDockerVM.sid = azureClient.subscriptionId(); return azureDockerVM; } catch (Exception e) { throw new AzureDockerException(e.getMessage(), e); } }
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 deleteDockerHost(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 { azureClient.virtualMachines().deleteById(vm.id()); } catch (Exception e) { throw new AzureDockerException(String.format("Unexpected error while deleting VM %s and its associated resources", vmName)); } }
/** * 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}); } }
/** * 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()); } }
/** * Restarts Azure virtual machine. * * @param agent * @throws AzureCloudException */ public void restartVirtualMachine(AzureVMAgent agent) throws AzureCloudException { try { azureClient.virtualMachines() .getByResourceGroup(agent.getResourceGroupName(), agent.getNodeName()).restart(); } catch (Exception e) { throw AzureCloudException.create(e); } }
List<URI> diskUrisToRemove = new ArrayList<>(); List<String> diskIdToRemove = new ArrayList<>(); if (!azureClient.virtualMachines().getByResourceGroup(resourceGroupName, vmName).isManagedDiskEnabled()) { .getByResourceGroup(resourceGroupName, vmName) .osUnmanagedDiskVhdUri())); } else { diskIdToRemove.add(azureClient.virtualMachines().getByResourceGroup(resourceGroupName, vmName).osDiskId());
@Override protected void azureNodeAction(NodeActionEvent e) throws AzureCmdException { try { removeAllChildNodes(); setIconPath(DOCKERHOST_WAIT_ICON_PATH); Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient; VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name); if (vm != null) { vm.restart(); setIconPath(DOCKERHOST_RUN_ICON_PATH); refreshDockerHostInstance(vm); } } catch (Exception ee) { DefaultLoader.getUIHelper().logError(ee.getMessage(), ee); } }
azureClient.virtualMachines().getByResourceGroup(agent.getResourceGroupName(), agent.getNodeName()).start(); successful = true; // may be we can just return } catch (Exception e) {
public static VirtualMachine updateDockerHostVM(Azure azureClient, DockerHost dockerHost) throws AzureDockerException { try { VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name); HashMap<String, Object> protectedSettings = new HashMap<>(); protectedSettings.put("username", dockerHost.certVault.vmUsername);
.getByResourceGroup(resourceGroupName, resource); final OperatingSystemTypes osType = vm.storageProfile().osDisk().osType();
@Override protected void azureNodeAction(NodeActionEvent e) throws AzureCmdException { try { removeAllChildNodes(); setIconPath(DOCKERHOST_STOP_ICON_PATH); for (NodeAction nodeAction : getNodeActions()) { nodeAction.setEnabled(false); } getNodeActionByName(ACTION_START).setEnabled(true); getNodeActionByName(ACTION_RESTART).setEnabled(true); Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient; VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name); if (vm != null) { vm.powerOff(); refreshDockerHostInstance(vm); } for (NodeAction nodeAction : getNodeActions()) { nodeAction.setEnabled(true); } } catch (Exception ee) { DefaultLoader.getUIHelper().logError(ee.getMessage(), ee); } }
azureClient.virtualMachines().getByResourceGroup(template.getResourceGroupName(), vmname);
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)); } }
azureClient.virtualMachines().getByResourceGroup(template.getResourceGroupName(), azureAgent.getNodeName());
vm = azureClient.virtualMachines().getByResourceGroup(template.getResourceGroupName(), azureAgent.getNodeName()); } catch (Exception e) { throw AzureCloudException.create(e);