当前位置: 首页>>代码示例>>Java>>正文


Java IPProtocol类代码示例

本文整理汇总了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);

}
 
开发者ID:cloudiator,项目名称:sword,代码行数:24,代码来源:AssignSecurityGroupRuleToSecurityGroupStrategy.java

示例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.");
  }
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:15,代码来源:RuleToSecurityGroupRuleConverter.java

示例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);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:29,代码来源:OpenStackSecurityGroupResourceBuilder.java

示例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();
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:9,代码来源:OpenStackSecurityGroupResourceBuilder.java

示例5: getProtocol

import org.openstack4j.model.compute.IPProtocol; //导入依赖的package包/类
private IPProtocol getProtocol(String protocolStr) {
    return IPProtocol.value(protocolStr);
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:4,代码来源:OpenStackSecurityGroupResourceBuilder.java


注:本文中的org.openstack4j.model.compute.IPProtocol类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。