use of com.amazonaws.services.ec2.model.DetachNetworkInterfaceRequest in project photon-model by vmware.
the class TestAWSSetupUtils method detachNICDirectlyWithEC2Client.
/**
* 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;
});
}
use of com.amazonaws.services.ec2.model.DetachNetworkInterfaceRequest in project eureka by Netflix.
the class ElasticNetworkInterfaceBinder method unbind.
/**
* Unbind the IP that this instance is associated with.
*/
public void unbind() throws Exception {
InstanceInfo myInfo = applicationInfoManager.getInfo();
String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.instanceId);
AmazonEC2 ec2 = getEC2Service();
List<InstanceNetworkInterface> result = instanceData(myInstanceId, ec2).getNetworkInterfaces();
List<String> ips = getCandidateIps();
for (InstanceNetworkInterface networkInterface : result) {
if (ips.contains(networkInterface.getPrivateIpAddress())) {
String attachmentId = networkInterface.getAttachment().getAttachmentId();
ec2.detachNetworkInterface(new DetachNetworkInterfaceRequest().withAttachmentId(attachmentId));
break;
}
}
}
Aggregations