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


Java SecGroupExtension类代码示例

本文整理汇总了Java中org.openstack4j.model.compute.SecGroupExtension的典型用法代码示例。如果您正苦于以下问题:Java SecGroupExtension类的具体用法?Java SecGroupExtension怎么用?Java SecGroupExtension使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SecGroupExtension类属于org.openstack4j.model.compute包,在下文中一共展示了SecGroupExtension类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
@Override
public Set<SecurityGroup> get() {

  Set<SecurityGroupInRegion> securityGroups = new HashSet<>();
  for (Location location : regionSupplier.get()) {
    Set<NovaSecGroupExtension.Rule> rules = new HashSet<>();
    osClient.useRegion(location.id()).compute().securityGroups().list().stream().filter(
        (Predicate<SecGroupExtension>) secGroupExtension -> namingStrategy.belongsToNamingGroup()
            .test(secGroupExtension.getName()))
        .forEach((Consumer<SecGroupExtension>) secGroupExtension -> {
          rules.addAll(secGroupExtension.getRules());
          securityGroups
              .add(new SecurityGroupInRegion(secGroupExtension, location, rules));
        });
  }
  return securityGroups.stream().map(converter).collect(Collectors.toSet());
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:18,代码来源:SecurityGroupSupplier.java

示例2: assign

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
public SecurityGroup assign(SecurityGroupRule securityGroupRule, String securityGroupId) {
  checkNotNull(securityGroupRule, "securityGroupRule is null");
  checkNotNull(securityGroupId, "securityGroupId is null");
  checkArgument(!securityGroupId.isEmpty(), "securityGroupId is empty");

  SecGroupExtension.Rule createdRule;
  if (securityGroupRule.ipProtocol().equals(IpProtocol.ALL)) {
    createdRule = createRule(securityGroupRule.cidr().toString(), IpProtocol.TCP.toString(),
        securityGroupRule.fromPort(), securityGroupRule.toPort(), securityGroupId);
    createdRule = createRule(securityGroupRule.cidr().toString(), IpProtocol.UDP.toString(),
        securityGroupRule.fromPort(), securityGroupRule.toPort(), securityGroupId);
  } else {
    createdRule = createRule(securityGroupRule.cidr().toString(),
        securityGroupRule.ipProtocol().toString(), securityGroupRule.fromPort(),
        securityGroupRule.toPort(), securityGroupId);
  }

  SecGroupExtension.Rule finalCreatedRule = createdRule;
  final Optional<SecurityGroup> any = securityGroupSupplier.get().stream().filter(
      securityGroupRemote -> securityGroupRemote.providerId()
          .equals(finalCreatedRule.getParentGroupId())).findAny();
  checkState(any.isPresent(),
      String.format("Could not find security group %s.", securityGroupId));
  return any.get();
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:26,代码来源:AssignSecurityGroupRuleToSecurityGroupStrategy.java

示例3: createRule

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的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

示例4: create

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
public SecurityGroup create(final String name, final String locationId) {
  checkNotNull(name, "name is null");
  checkArgument(!name.isEmpty(), "name is empty");
  checkNotNull(locationId, "locationId is null");
  checkArgument(!locationId.isEmpty(), "locationId is empty");

  Location location = locationGetStrategy.get(locationId);

  checkNotNull(location, String.format("Could not retrieve location with id %s", locationId));

  Location region =
      LocationHierarchy.of(location).firstParentLocationWithScope(LocationScope.REGION)
          .orElseThrow(() -> new IllegalStateException(
              String.format("Could not find parent region of location %s", location)));

  final SecGroupExtension secGroupExtension =
      osClient.useRegion(region.id()).compute().securityGroups()
          .create(namingStrategy.generateNameBasedOnName(name), name);
  return securityGroupConverter
      .apply(new SecurityGroupInRegion(secGroupExtension, location, Collections.emptySet()));
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:22,代码来源:CreateSecurityGroupStrategy.java

示例5: securityGroups

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient osClient = openStackClient.createOSClient(cloudCredential);
    KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);

    Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
    List<? extends SecGroupExtension> osSecurityGroups = osClient.compute().securityGroups().list();
    LOGGER.info("security groups from openstack: {}", osSecurityGroups);
    for (SecGroupExtension secGroup : osSecurityGroups) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("tenantId", secGroup.getTenantId());
        properties.put("rules", secGroup.getRules());

        CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(secGroup.getName(), secGroup.getId(), properties);
        cloudSecurityGroups.add(cloudSecurityGroup);
    }

    Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
    result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSecurityGroups);
    LOGGER.info("openstack security groups result: {}", result);
    return new CloudSecurityGroups(result);
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:23,代码来源:OpenStackPlatformResources.java

示例6: configure

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
@Override
protected void configure() {
  super.configure();
  bind(OSClient.class).toProvider(Openstack4jClientProvider.class).in(Singleton.class);
  bind(KeyStoneVersion.class).toProvider(KeyStoneVersionProvider.class).in(Singleton.class);
  bind(OsClientFactory.class).toProvider(OsClientFactoryProvider.class).in(Singleton.class);
  bind(RegionSupplier.class).toProvider(RegionSupplierProvider.class).in(Singleton.class);
  bind(OpenstackNetworkStrategy.class).to(OpenstackConfiguredNetworkStrategy.class)
      .in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<FlavorInRegion, HardwareFlavor>>() {
  }).to(FlavorInRegionToHardwareFlavor.class).in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<ImageInRegion, Image>>() {
  }).to(ImageInRegionToImage.class).in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<AvailabilityZoneInRegion, Location>>() {
  }).to(AvailabilityZoneInRegionToLocation.class).in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<String, Location>>() {
  }).to(RegionToLocation.class).in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<ServerInRegion, VirtualMachine>>() {
  }).to(ServerInRegionToVirtualMachine.class).in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<SecGroupExtension.Rule, SecurityGroupRule>>() {
  }).to(RuleToSecurityGroupRuleConverter.class).in(Singleton.class);
  bind(new TypeLiteral<OneWayConverter<SecurityGroupInRegion, SecurityGroup>>() {
  }).to(SecurityGroupInRegionToSecurityGroup.class).in(Singleton.class);
  bind(new TypeLiteral<Supplier<Set<SecurityGroup>>>() {
  }).to(SecurityGroupSupplier.class).in(Singleton.class);
  bind(CreateSecurityGroupStrategy.class).in(Singleton.class);
  bind(AssignSecurityGroupRuleToSecurityGroupStrategy.class).in(Singleton.class);
  bind(CreateSecurityGroupFromTemplateOption.class).in(Singleton.class);
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:30,代码来源:Openstack4jComputeModule.java

示例7: SecurityGroupInRegion

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
public SecurityGroupInRegion(SecGroupExtension original, Location region,
    Set<NovaSecGroupExtension.Rule> rules) {

  checkNotNull(original, "original is null.");
  checkNotNull(region, "region is null");
  checkNotNull(rules, "rules are null");
  delegate = original;
  this.region = region;
  this.regionScopedId =
      IdScopeByLocations.from(region.id(), delegate.getId()).getIdWithLocation();
  this.rules = rules;
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:13,代码来源:SecurityGroupInRegion.java

示例8: build

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的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

示例9: SecurityGroupInRegionToSecurityGroup

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
@Inject
public SecurityGroupInRegionToSecurityGroup(
    OneWayConverter<SecGroupExtension.Rule, SecurityGroupRule> securityGroupRuleConverter) {
  checkNotNull(securityGroupRuleConverter, "securityGroupRuleConverter is null");
  this.securityGroupRuleConverter = securityGroupRuleConverter;
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:7,代码来源:SecurityGroupInRegionToSecurityGroup.java

示例10: apply

import org.openstack4j.model.compute.SecGroupExtension; //导入依赖的package包/类
@Override
public SecurityGroupRule apply(SecGroupExtension.Rule rule) {
  return SecurityGroupRuleBuilder.newBuilder().cidr(CidrImpl.of(rule.getRange().getCidr()))
      .ipProtocol(ipProtocolConverter.apply(rule.getIPProtocol()))
      .fromPort(rule.getFromPort()).toPort(rule.getToPort()).build();
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:7,代码来源:RuleToSecurityGroupRuleConverter.java


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