예제 #1
0
  private void checkSecurityGroupCapacity(Reservation reservation, SecurityGroup securityGroup) {
    LOG.debug(String.format("checking security group: %s", securityGroup));

    int numberOfInstancesInSecurityGroup = securityGroup.getInstances().size();

    if (numberOfInstancesInSecurityGroup == 0) {
      LOG.debug(String.format("No instances in security group: %s", securityGroup));
      return;
    }

    if (securityGroup.getNetmask() == null) {
      LOG.debug(String.format("Unable to get the netmask for security group: %s", securityGroup));
      return;
    }

    int availableNumberOfInstancesInSecurityGroup = getSecurityGroupCapacity(securityGroup);

    LOG.debug(
        String.format(
            "SecurityGroup: %s - Number of Instances: %d - Capacity in SecurityGroup: %d",
            securityGroup.getUrl(),
            numberOfInstancesInSecurityGroup,
            availableNumberOfInstancesInSecurityGroup));

    if (numberOfInstancesInSecurityGroup + reservation.getMinCount()
        > availableNumberOfInstancesInSecurityGroup
            - NUMBER_OF_RESERVED_ADDRESSES_IN_SECURITY_GROUP)
      throw new IllegalStateException(
          "unable to run instances as no more capacity in security group");
  }
예제 #2
0
  private boolean validateSecurityGroup(SecurityGroup securityGroup) {
    if (null == securityGroup.getNetmask() || null == securityGroup.getVlanId()) return false;

    return true;
  }
예제 #3
0
 private int getSecurityGroupCapacity(SecurityGroup securityGroup) {
   String netmask = securityGroup.getNetmask();
   int addrsInSlashnet = IpAddressUtils.addrsInSlashnet(IpAddressUtils.netmaskToSlashnet(netmask));
   return addrsInSlashnet;
 }