public static void applyNetworkRules(CloudStackClient cloudStackClient, SecurityGroup securityGroup, Network network) { SecurityGroupClient securityGroupClient = cloudStackClient.getSecurityGroupClient(); for (Rule rule : network.getIngress()) { if (rule.getProtocol() == Protocol.ICMP) { securityGroupClient.authorizeIngressICMPToCIDRs(securityGroup.getId(), DEFAULT_ICMP_CODE, DEFAULT_ICMP_TYPE, ImmutableList.of(rule.getCidr())); } else { securityGroupClient.authorizeIngressPortsToCIDRs(securityGroup.getId(), rule.getProtocol().name(), rule.getPorts().lowerEndpoint(), rule.getPorts().upperEndpoint(), Lists.newArrayList(rule.getCidr())); } } } }
String cidr = getCurrentCIDR(); ImmutableSet<String> cidrs = ImmutableSet.of(cidr); assertTrue(jobComplete.apply(client.getSecurityGroupClient().authorizeIngressICMPToCIDRs(group.getId(), 0, 8, cidrs)), group.toString()); assertTrue(jobComplete.apply(client.getSecurityGroupClient().authorizeIngressPortsToCIDRs(group.getId(), "TCP", 22, 22, cidrs)), group.toString());