Example usage for com.amazonaws.services.ec2.model InstanceNetworkInterface getSubnetId

List of usage examples for com.amazonaws.services.ec2.model InstanceNetworkInterface getSubnetId

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model InstanceNetworkInterface getSubnetId.

Prototype


public String getSubnetId() 

Source Link

Document

The ID of the subnet.

Usage

From source file:dsmwatcher.DSMWatcher.java

License:Open Source License

public Boolean checkIfIsolated(Instance instance, AmazonEC2Client ec2) throws Exception {
    boolean inIRSubnet = false;
    boolean hasDenySG = false;
    //check for tags on other ENIs
    List<InstanceNetworkInterface> ienis = instance.getNetworkInterfaces();
    for (InstanceNetworkInterface ieni : ienis) {
        for (String IRSubnet : IRSubnets) {
            if (IRSubnet.compareTo(ieni.getSubnetId()) == 0) {
                inIRSubnet = true;// w w  w. j a v a2  s .c  o  m
            }
        }
        List<GroupIdentifier> inititalSecGroups = ieni.getGroups();
        for (GroupIdentifier secGroup : inititalSecGroups) {
            if (secGroup.getGroupId().equals(denyAllSG)) {
                DescribeNetworkInterfacesRequest netReq = new DescribeNetworkInterfacesRequest()
                        .withNetworkInterfaceIds(ieni.getNetworkInterfaceId());
                DescribeNetworkInterfacesResult netResult = ec2.describeNetworkInterfaces(netReq);
                List<com.amazonaws.services.ec2.model.NetworkInterface> enis = netResult.getNetworkInterfaces();
                for (com.amazonaws.services.ec2.model.NetworkInterface eni : enis) {
                    List<Tag> tagSet = eni.getTagSet();
                    for (Tag tag : tagSet) {
                        if (tag.getKey().compareTo("InIsolation") == 0) {
                            hasDenySG = true;
                        }
                    }
                }
            }
        }

    }
    return (inIRSubnet && hasDenySG);
}

From source file:org.occiware.clouddriver.util.InstanceDataFactory.java

License:Apache License

/**
 *
 * @param instance//from   w w  w  .j ava  2 s  .c  o  m
 * @return
 */
private static List<NetworkInterfaceDO> buildNetworkInterfacesDatas(Instance instance) {
    List<InstanceNetworkInterface> netInts = instance.getNetworkInterfaces();
    InstanceNetworkInterfaceAssociation netIntAsso;
    InstanceNetworkInterfaceAttachment netIntAttach;

    List<GroupIdentifier> groupIdentifiers;
    List<NetworkInterfaceDO> networkInterfaceDOs = new ArrayList<>();
    NetworkInterfaceDO netDO;
    List<InstancePrivateIpAddress> ipAddresses;
    List<InstanceIpv6Address> ipv6Addresses;
    for (InstanceNetworkInterface netInt : netInts) {
        netDO = new NetworkInterfaceDO();
        netDO.setDescription(netInt.getDescription());
        netDO.setMacAddress(netInt.getMacAddress());
        netDO.setNetworkInterfaceId(netInt.getNetworkInterfaceId());
        netDO.setOwnerId(netInt.getOwnerId());
        netDO.setPrivateDnsName(netInt.getPrivateDnsName());
        netDO.setPrivateIpAddress(netInt.getPrivateIpAddress());
        netDO.setSourceDestCheck(netInt.getSourceDestCheck());
        netDO.setStatus(netInt.getStatus());
        netDO.setSubnetId(netInt.getSubnetId());
        netDO.setVpcId(netInt.getVpcId());

        netIntAsso = netInt.getAssociation();
        if (netIntAsso != null) {
            NetAssociationDO associationDO = new NetAssociationDO();
            associationDO.setIpOwnerId(netIntAsso.getIpOwnerId());
            associationDO.setPublicDnsName(netIntAsso.getPublicDnsName());
            associationDO.setPublicIp(netIntAsso.getPublicIp());
            netDO.setNetAssociation(associationDO);
        }

        netIntAttach = netInt.getAttachment();
        if (netIntAttach != null) {
            netDO.setAttachmentId(netIntAttach.getAttachmentId());
            netDO.setAttachTime(netIntAttach.getAttachTime());
            netDO.setDeleteOnTermination(netIntAttach.getDeleteOnTermination());
            netDO.setDeviceIndex(netIntAttach.getDeviceIndex());
            netDO.setAttachmentStatus(netIntAttach.getStatus());
        }

        groupIdentifiers = netInt.getGroups();
        if (groupIdentifiers != null && !groupIdentifiers.isEmpty()) {
            List<GroupIdentifierDO> grpDOs = buildSecurityGroupsDatas(groupIdentifiers);
            netDO.setSecurityGroups(grpDOs);
        }

        ipv6Addresses = netInt.getIpv6Addresses();
        if (ipv6Addresses != null && !ipv6Addresses.isEmpty()) {
            List<String> ipv6AddressesStr = new ArrayList<>();
            for (InstanceIpv6Address ipv6Address : ipv6Addresses) {
                ipv6AddressesStr.add(ipv6Address.getIpv6Address());
            }
            netDO.setIpv6Addresses(ipv6AddressesStr);
        }

        ipAddresses = netInt.getPrivateIpAddresses();
        if (ipAddresses != null && !ipAddresses.isEmpty()) {
            List<IpAddressDO> ipAddressDOs = new ArrayList<>();
            IpAddressDO addressDO;
            InstanceNetworkInterfaceAssociation netAsso;
            for (InstancePrivateIpAddress ipAddress : ipAddresses) {
                addressDO = new IpAddressDO();
                addressDO.setPrimary(ipAddress.isPrimary());
                addressDO.setPrivateDnsName(ipAddress.getPrivateDnsName());
                addressDO.setPrivateIpAddress(ipAddress.getPrivateIpAddress());
                netAsso = ipAddress.getAssociation();
                if (netAsso != null) {
                    NetAssociationDO associationDO = new NetAssociationDO();
                    associationDO.setIpOwnerId(netAsso.getIpOwnerId());
                    associationDO.setPublicDnsName(netAsso.getPublicDnsName());
                    associationDO.setPublicIp(netAsso.getPublicIp());
                    addressDO.setNetAssociation(associationDO);
                }
                ipAddressDOs.add(addressDO);
            }
            netDO.setIpAddresses(ipAddressDOs);
        }

        networkInterfaceDOs.add(netDO);
    }
    return networkInterfaceDOs;
}