/** * Removes a specified AWS NIC from the VM it is currently attached to */ public static void detachNICDirectlyWithEC2Client(String instanceId, String nicAttachmentId, String nicId, AmazonEC2Client client, VerificationHost host) { // detach the new AWS NIC to the AWS VM DetachNetworkInterfaceRequest detachNic = new DetachNetworkInterfaceRequest(); detachNic.withAttachmentId(nicAttachmentId); host.log("Detaching NIC with id: %s and attachment id: %s", nicId, nicAttachmentId); client.detachNetworkInterface(detachNic); host.waitFor("Timeout waiting for AWS to detach a NIC from " + instanceId + " with attachment id: " + nicAttachmentId, () -> { DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest() .withFilters(new Filter("instance-id", Collections.singletonList(instanceId))); DescribeInstancesResult result = client.describeInstances(describeInstancesRequest); Instance currentInstance = result.getReservations().get(0).getInstances().get(0); for (InstanceNetworkInterface awsNic : currentInstance.getNetworkInterfaces()) { if (awsNic.getNetworkInterfaceId().equals(nicId)) { //Requested NIC was not detached from the instance return false; } } host.log("Detached NIC with attachment id: %s", nicAttachmentId); return true; }); }
@Override public void detachNetworkInterface(DetachNetworkInterfaceRequest detachNetworkInterfaceRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
@Override public void detach(DetachNetworkInterfaceRequest request) { detach(request, null); }
@Override public void detach(DetachNetworkInterfaceRequest request, ResultCapture<Void> extractor) { resource.performAction("Detach", request, extractor); }
/** * Performs the <code>Detach</code> action. * * <p> * * @see DetachNetworkInterfaceRequest */ void detach(DetachNetworkInterfaceRequest request);
/** * Performs the <code>Detach</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * * @see DetachNetworkInterfaceRequest */ void detach(DetachNetworkInterfaceRequest request, ResultCapture<Void> extractor);