本文整理汇总了Java中org.openstack4j.model.compute.IPProtocol类的典型用法代码示例。如果您正苦于以下问题:Java IPProtocol类的具体用法?Java IPProtocol怎么用?Java IPProtocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IPProtocol类属于org.openstack4j.model.compute包,在下文中一共展示了IPProtocol类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRule
import org.openstack4j.model.compute.IPProtocol; //导入依赖的package包/类
private SecGroupExtension.Rule createRule(String cidr, String ipProtocol, int from, int to,
String securityGroupId) {
final IdScopedByLocation scopedByLocation = IdScopeByLocations.from(securityGroupId);
SecurityGroup securityGroup = securityGroupSupplier.get().stream().filter(
securityGroupCandidate -> securityGroupCandidate.id().equals(scopedByLocation.getId()))
.findAny().orElseThrow(() -> new IllegalStateException(
String.format("Could not find security group with id %s.", securityGroupId)));
Location region = LocationHierarchy.of(securityGroup.location().get())
.firstParentLocationWithScope(LocationScope.REGION).orElseThrow(
() -> new IllegalStateException(String
.format("Could not find parent region of location %s",
securityGroup.location().get())));
SecGroupExtension.Rule rule =
Builders.secGroupRule().cidr(cidr).protocol(IPProtocol.valueOf(ipProtocol))
.range(from, to).parentGroupId(securityGroup.providerId()).build();
return osClient.useRegion(region.providerId()).compute().securityGroups().createRule(rule);
}
示例2: apply
import org.openstack4j.model.compute.IPProtocol; //导入依赖的package包/类
@Override
public IpProtocol apply(IPProtocol ipProtocol) {
checkNotNull(ipProtocol, "ipProtocol is null.");
switch (ipProtocol) {
case ICMP:
return IpProtocol.ICMP;
case TCP:
return IpProtocol.TCP;
case UDP:
return IpProtocol.UDP;
default:
throw new IllegalStateException(ipProtocol + "is unknown.");
}
}
示例3: build
import org.openstack4j.model.compute.IPProtocol; //导入依赖的package包/类
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Group group, Network network, Security security,
CloudResource resource)
throws Exception {
try {
OSClient osClient = createOSClient(auth);
ComputeSecurityGroupService securityGroupService = osClient.compute().securityGroups();
SecGroupExtension securityGroup = securityGroupService.create(resource.getName(), "");
String securityGroupId = securityGroup.getId();
for (SecurityRule rule : security.getRules()) {
IPProtocol osProtocol = getProtocol(rule.getProtocol());
String cidr = rule.getCidr();
for (PortDefinition portStr : rule.getPorts()) {
int from = Integer.parseInt(portStr.getFrom());
int to = Integer.parseInt(portStr.getTo());
securityGroupService.createRule(createRule(securityGroupId, osProtocol, cidr, from, to));
}
}
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetCidr = neutronView.isExistingSubnet() ? utils.getExistingSubnetCidr(auth, neutronView) : network.getSubnet().getCidr();
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.TCP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.UDP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.ICMP, "0.0.0.0/0"));
return createPersistedResource(resource, group.getName(), securityGroup.getId());
} catch (OS4JException ex) {
throw new OpenStackResourceException("SecurityGroup creation failed", resourceType(), resource.getName(), ex);
}
}
示例4: createRule
import org.openstack4j.model.compute.IPProtocol; //导入依赖的package包/类
private Rule createRule(String securityGroupId, IPProtocol protocol, String cidr, int fromPort, int toPort) {
return Builders.secGroupRule()
.parentGroupId(securityGroupId)
.protocol(protocol)
.cidr(cidr)
.range(fromPort, toPort)
.build();
}
示例5: getProtocol
import org.openstack4j.model.compute.IPProtocol; //导入依赖的package包/类
private IPProtocol getProtocol(String protocolStr) {
return IPProtocol.value(protocolStr);
}