private void deleteNetworkInterfaces( AuthenticatedContext authenticatedContext, AzureRMClient client, String stackName, List<String> networkInterfacesNames) throws CloudConnectorException { for (String networkInterfacesName : networkInterfacesNames) { try { client.deleteNetworkInterface(stackName, networkInterfacesName); PollTask<Boolean> task = armPollTaskFactory.newNetworkInterfaceDeleteStatusCheckerTask( authenticatedContext, armClient, new NetworkInterfaceCheckerContext( new ArmCredentialView(authenticatedContext.getCloudCredential()), stackName, networkInterfacesName)); syncPollingScheduler.schedule(task); } catch (HttpResponseException e) { if (e.getStatusCode() != NOT_FOUND) { throw new CloudConnectorException(e.getResponse().getData().toString(), e); } } catch (Exception e) { throw new CloudConnectorException( String.format("Could not delete network interface: %s", networkInterfacesName), e); } } }
private void deallocateVirtualMachine( AuthenticatedContext authenticatedContext, AzureRMClient client, String stackName, String privateInstanceId) throws CloudConnectorException { try { client.deallocateVirtualMachine(stackName, privateInstanceId); PollTask<Boolean> task = armPollTaskFactory.newVirtualMachineStatusCheckerTask( authenticatedContext, armClient, new VirtualMachineCheckerContext( new ArmCredentialView(authenticatedContext.getCloudCredential()), stackName, privateInstanceId, "Succeeded")); syncPollingScheduler.schedule(task); } catch (HttpResponseException e) { if (e.getStatusCode() != NOT_FOUND) { throw new CloudConnectorException(e.getResponse().getData().toString(), e); } } catch (Exception e) { throw new CloudConnectorException( String.format("Could not deallocate machine: %s", privateInstanceId), e); } }
@Override public List<CloudResourceStatus> terminate( AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { AzureRMClient azureRMClient = armClient.createAccess(authenticatedContext.getCloudCredential()); for (CloudResource resource : resources) { try { azureRMClient.deleteResourceGroup(resource.getName()); PollTask<Boolean> task = armPollTaskFactory.newResourceGroupDeleteStatusCheckerTask( authenticatedContext, armClient, new ResourceGroupCheckerContext( new ArmCredentialView(authenticatedContext.getCloudCredential()), resource.getName())); Boolean statePollerResult = task.call(); if (!task.completed(statePollerResult)) { syncPollingScheduler.schedule(task); } if (armUtils.isPersistentStorage()) { CloudContext cloudCtx = authenticatedContext.getCloudContext(); String storageName = armUtils.getStorageName( authenticatedContext.getCloudCredential(), cloudCtx, stack.getRegion()); String imageStorageGroup = armUtils.getImageResourceGroupName(cloudCtx); String diskContainer = armUtils.getDiskContainerName(cloudCtx); deleteContainer(azureRMClient, imageStorageGroup, storageName, diskContainer); } } catch (HttpResponseException e) { if (e.getStatusCode() != NOT_FOUND) { throw new CloudConnectorException(e.getResponse().getData().toString(), e); } else { return check(authenticatedContext, new ArrayList<CloudResource>()); } } catch (Exception e) { throw new CloudConnectorException( String.format("Could not delete resource group: %s", resource.getName()), e); } } return check(authenticatedContext, resources); }