private VirtualMachine getById(final String id) { try { return virtualMachines.getById(id); } catch (CloudException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
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); } }
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)); } }
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()); + "Removing virtual machine {0}", vmName); azureClient.virtualMachines().deleteByResourceGroup(resourceGroupName, vmName);
@Override protected void azureNodeAction(NodeActionEvent e) throws AzureCmdException { try { AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); // not signed in if (azureManager == null) { return; } azureManager.getAzure(subscriptionId).virtualMachines().deleteByResourceGroup(virtualMachine.resourceGroupName(), virtualMachine.name()); } catch (Exception ex) { } DefaultLoader.getIdeHelper().invokeLater(new Runnable() { @Override public void run() { // instruct parent node to remove this node getParent().removeDirectChildNode(VMNode.this); } }); }
@Override public Observable<RunCommandResult> runCommandAsync(RunCommandInput inputCommand) { return this.manager().virtualMachines().runCommandAsync(this.resourceGroupName(), this.name(), inputCommand); }
public static Map<String, DockerHost> getDockerHosts(Azure azureClient, Map<String, AzureDockerCertVault> dockerVaultsMap) { Map<String, DockerHost> dockerHostMap = getDockerHosts(azureClient.virtualMachines().list(), dockerVaultsMap); for (DockerHost dockerHost : dockerHostMap.values()) { dockerHost.sid = azureClient.subscriptionId(); if (dockerHost.hostVM != null) dockerHost.hostVM.sid = azureClient.subscriptionId(); } return dockerHostMap; }
@Override public RunCommandResult runCommand(RunCommandInput inputCommand) { return this.manager().virtualMachines().runCommand(this.resourceGroupName(), this.name(), inputCommand); }
.define(newHost.hostVM.name) .withRegion(newHost.hostVM.region) .withExistingResourceGroup(resourceGroupName)
@Override public String getIdFromName(final String group, final String name) { try { final VirtualMachine vm = virtualMachines.getByGroup(group, name); return vm.id(); } catch (CloudException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
final PagedList<VirtualMachine> vms = azureClient.virtualMachines().listByResourceGroup(resourceGroupName); int count = 0; final AzureUtil.DeploymentTag deployTag = new AzureUtil.DeploymentTag();
@Override public Observable<RunCommandResult> runCommandAsync(RunCommandInput inputCommand) { return this.manager().virtualMachines().runCommandAsync(this.resourceGroupName(), this.name(), inputCommand); }
try { Azure azure = azureManager.getAzure(sid); List<VirtualMachine> virtualMachines = azure.virtualMachines().list();
@Override public RunCommandResult runCommand(RunCommandInput inputCommand) { return this.manager().virtualMachines().runCommand(this.resourceGroupName(), this.name(), inputCommand); }
VirtualMachine.DefinitionStages.WithGroup withGroup = azure.virtualMachines().define(name) .withRegion(region); Creatable<ResourceGroup> newResourceGroup = null;
/** * 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; } }
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)); } }
@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); } }
@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); } }
String managedOsDiskId = null; if (StringUtils.containsIgnoreCase(resource.type(), "virtualMachine")) { if (!azureClient.virtualMachines().getById(resource.id()).isManagedDiskEnabled()) { osDiskURI = new URI( azureClient.virtualMachines().getById(resource.id()).osUnmanagedDiskVhdUri()); } else { managedOsDiskId = azureClient.virtualMachines().getById(resource.id()).osDiskId();