com.amazonaws.services.ec2.model.DescribeNetworkInterfacesResult Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.DescribeNetworkInterfacesResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InventoryUtil.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch network intefaces.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<NetworkInterface>> fetchNetworkIntefaces(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){

	Map<String,List<NetworkInterface>> niMap = new LinkedHashMap<>();
	AmazonEC2 ec2Client ;
	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Network Interface\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()) {
		try{
			if(!skipRegions.contains(region.getName())){
				ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				DescribeNetworkInterfacesResult  descNIRslt =  ec2Client.describeNetworkInterfaces();
				List<NetworkInterface> niList = descNIRslt.getNetworkInterfaces();
				if(!niList.isEmpty() ) {
					log.debug(InventoryConstants.ACCOUNT + accountId + " Type : Network Interface " +region.getName()+" >> " + niList.size());
					niMap.put(accountId+delimiter+accountName+delimiter+region.getName(),niList);
				}

			}
		}catch(Exception e){
			log.error("Exception fetching Network Interfaces for "+region.getName() + e);
			log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
			ErrorManageUtil.uploadError(accountId,region.getName(),"eni",e.getMessage());
		}
	}
	return niMap;
}
 
Example #2
Source File: InventoryUtilTest.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch network interfaces test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchNetworkInterfacesTest() throws Exception {
    
    mockStatic(AmazonEC2ClientBuilder.class);
    AmazonEC2 ec2Client = PowerMockito.mock(AmazonEC2.class);
    AmazonEC2ClientBuilder amazonEC2ClientBuilder = PowerMockito.mock(AmazonEC2ClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonEC2ClientBuilder.standard()).thenReturn(amazonEC2ClientBuilder);
    when(amazonEC2ClientBuilder.withCredentials(anyObject())).thenReturn(amazonEC2ClientBuilder);
    when(amazonEC2ClientBuilder.withRegion(anyString())).thenReturn(amazonEC2ClientBuilder);
    when(amazonEC2ClientBuilder.build()).thenReturn(ec2Client);
    
    DescribeNetworkInterfacesResult describeNetworkInterfacesResult = new DescribeNetworkInterfacesResult();
    List<NetworkInterface> niList = new ArrayList<>();
    niList.add(new NetworkInterface());
    describeNetworkInterfacesResult.setNetworkInterfaces(niList);
    when(ec2Client.describeNetworkInterfaces()).thenReturn(describeNetworkInterfacesResult);
    assertThat(inventoryUtil.fetchNetworkIntefaces(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
    
}
 
Example #3
Source File: NetworkInterfaceImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public boolean load(DescribeNetworkInterfacesRequest request,
        ResultCapture<DescribeNetworkInterfacesResult> extractor) {

    return resource.load(request, extractor);
}
 
Example #4
Source File: NetworkInterface.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Makes a call to the service to load this resource's attributes if they
 * are not loaded yet, and use a ResultCapture to retrieve the low-level
 * client response
 * The following request parameters will be populated from the data of this
 * <code>NetworkInterface</code> resource, and any conflicting parameter
 * value set in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>NetworkInterfaceIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return Returns {@code true} if the resource is not yet loaded when this
 *         method was invoked, which indicates that a service call has been
 *         made to retrieve the attributes.
 * @see DescribeNetworkInterfacesRequest
 */
boolean load(DescribeNetworkInterfacesRequest request,
        ResultCapture<DescribeNetworkInterfacesResult> extractor);