當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。