gpt4 book ai didi

org.jclouds.cloudstack.features.ZoneClient.listZones()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-20 20:04:31 26 4
gpt4 key购买 nike

本文整理了Java中org.jclouds.cloudstack.features.ZoneClient.listZones()方法的一些代码示例,展示了ZoneClient.listZones()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneClient.listZones()方法的具体详情如下:
包路径:org.jclouds.cloudstack.features.ZoneClient
类名称:ZoneClient
方法名:listZones

ZoneClient.listZones介绍

[英]Lists zones
[中]列出区域

代码示例

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public Iterable<Zone> listLocations() {
 // TODO: we may need to filter these
 return client.getZoneClient().listZones();
}

代码示例来源:origin: org.jclouds.api/cloudstack

@Override
public Iterable<Zone> listLocations() {
 // TODO: we may need to filter these
 return client.getZoneClient().listZones();
}

代码示例来源:origin: org.apache.provisionr/provisionr-cloudstack

@Override
  public Object doExecuteWithContext(CloudStackClient client, PrintStream out) throws Exception {
    out.printf("CloudStack zones for provider %s\n", getProvider().getId());
    for (Zone zone : client.getZoneClient().listZones()) {
      out.printf("---\n%s\n", zone.toString());
    }
    out.println();
    return null;
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
 public Map<String, Set<String>> apply(CloudStackClient client) {
   checkNotNull(client, "client");
   Builder<String, Set<String>> builder = ImmutableMap.builder();
   for (Zone zone : client.getZoneClient().listZones()) {
    builder.put(zone.getId(), client.getHypervisorClient().listHypervisorsInZone(zone.getId()));
   }
   return builder.build();
 }
}

代码示例来源:origin: org.apache.provisionr/provisionr-cloudstack

public static boolean hasSecurityGroupEnabled(final CloudStackClient cloudStackClient, final String zoneName) {
    Set<Zone> ourZone = Sets.filter(cloudStackClient.getZoneClient().listZones(), new Predicate<Zone>() {
      @Override
      public boolean apply(Zone input) {
        return input.getName().equals(zoneName);
      }
    });
    return Iterables.getOnlyElement(ourZone).isSecurityGroupsEnabled();
  }
}

代码示例来源:origin: org.jclouds.api/cloudstack

@Override
 public Map<String, Set<String>> apply(CloudStackClient client) {
   checkNotNull(client, "client");
   Builder<String, Set<String>> builder = ImmutableMap.builder();
   for (Zone zone : client.getZoneClient().listZones()) {
    builder.put(zone.getId(), client.getHypervisorClient().listHypervisorsInZone(zone.getId()));
   }
   return builder.build();
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@BeforeMethod(groups = "live")
public void setZoneId() {
 Set<Zone> zones = client.getZoneClient().listZones();
 assertNotNull(zones);
 assertFalse(zones.isEmpty());
 zoneId = Iterables.get(zones, 0).getId();
}

代码示例来源:origin: jclouds/legacy-jclouds

@BeforeGroups(groups = "live")
public void setupContext() {
 super.setupContext();
 try {
   zone = find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
   networksSupported = true;
 } catch (NoSuchElementException e) {
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testListHypervisors() throws Exception {
 Set<String> response = client.getHypervisorClient().listHypervisors();
 assert null != response;
 assertTrue(response.size() >= 0);
 for (Zone zone : client.getZoneClient().listZones()) {
   Set<String> zoneHype = client.getHypervisorClient().listHypervisorsInZone(zone.getId());
   assert response.containsAll(zoneHype);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testRegisterISO() throws Exception {
 Optional<OSType> guestOSTypeOptional = Iterables.tryFind(client.getGuestOSClient().listOSTypes(), Predicates.notNull());
 Optional<Zone> zoneOptional = Iterables.tryFind(client.getZoneClient().listZones(available(true)), Predicates.notNull());
 if(guestOSTypeOptional.isPresent() && zoneOptional.isPresent()) {
   String osTypeId = guestOSTypeOptional.get().getId();
   String zoneId = zoneOptional.get().getId();
   ISO iso = client.getISOClient().registerISO(isoName, "", url, zoneId, RegisterISOOptions.Builder.isPublic(true).osTypeId(osTypeId));
     assertNotNull(iso);
     assertNotNull(iso.getId());
     assertEquals(iso.getName(), isoName);
 } else {
   String skipMessage = String.format("Cannot register the iso with url: %s", url);
   if(zoneOptional.isPresent())
     skipMessage += " without a valid zone";
   else
     skipMessage += " without a valid guest OS type";
   throw new SkipException(skipMessage);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testListZonesWhenResponseIs404() {
 ZoneClient client = requestSendsResponse(
   HttpRequest.builder()
    .method("GET")
    .endpoint(
      URI.create("http://localhost:8080/client/api?response=json&" +
       "command=listZones&listAll=true&apiKey=identity&signature=8iHCtck0qfxFTqJ8reyAObRf31I%3D"))
    .addHeader("Accept", "application/json")
    .build(),
   HttpResponse.builder()
    .statusCode(404)
    .build());
 assertEquals(client.listZones(), ImmutableSet.of());
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testListZones() throws Exception {
 Set<Zone> response = client.getZoneClient().listZones();
 assert null != response;
 long zoneCount = response.size();
 assertTrue(zoneCount >= 0);
 for (Zone zone : response) {
   Zone newDetails = Iterables.getOnlyElement(client.getZoneClient().listZones(
      ListZonesOptions.Builder.id(zone.getId())));
   assertEquals(zone, newDetails);

代码示例来源:origin: jclouds/legacy-jclouds

@Test(enabled = true)
public void testRegisterTemplate() throws Exception {
 Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
 assertNotNull(zone);
 Iterable<Network> networks = client.getNetworkClient().listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));

代码示例来源:origin: jclouds/legacy-jclouds

@Test(enabled = true)
public void testCreateTemplate() throws Exception {
 Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
 assertNotNull(zone);
 Iterable<Network> networks = client.getNetworkClient().listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
 networks = Iterables.filter(networks, new Predicate<Network>() {
   @Override
   public boolean apply(Network network) {
    return network != null && network.getState().equals("Implemented");
   }
 });
 assertTrue(Iterables.size(networks) >= 1);
 Network network = Iterables.get(networks, 0);
 assertNotNull(network);
 // Create a VM and stop it
 String defaultTemplate = template != null ? template.getImageId() : null;
 vmForCreation = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, defaultTemplate, client, jobComplete, virtualMachineRunning);
 assertTrue(jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())), vmForCreation.toString());
 // Work out the VM's volume
 Set<Volume> volumes = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.virtualMachineId(vmForCreation.getId()));
 assertEquals(volumes.size(), 1);
 Volume volume = Iterables.getOnlyElement(volumes);
 // Create a template
 CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
 AsyncCreateResponse response = client.getTemplateClient().createTemplate(TemplateMetadata.builder().name(prefix+"-createTemplate").osTypeId(vmForCreation.getGuestOSId()).displayText("jclouds live testCreateTemplate").build(), options);
 assertTrue(jobComplete.apply(response.getJobId()), vmForCreation.toString());
 createdTemplate = client.getTemplateClient().getTemplateInZone(response.getId(), vmForCreation.getZoneId());
 // Assertions
 assertNotNull(createdTemplate);
}

代码示例来源:origin: jclouds/legacy-jclouds

public static VirtualMachine createVirtualMachine(CloudStackClient client, String defaultTemplate,
   Predicate<String> jobComplete, Predicate<VirtualMachine> virtualMachineRunning) {
 Set<Network> networks = client.getNetworkClient().listNetworks(isDefault(true));
 if (networks.size() > 0) {
   Network network = get(filter(networks, new Predicate<Network>() {
    @Override
    public boolean apply(Network network) {
      return network != null && network.getState().equals("Implemented");
    }
   }), 0);
   return createVirtualMachineInNetwork(network,
      defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
      virtualMachineRunning);
 } else {
   String zoneId = find(client.getZoneClient().listZones(), new Predicate<Zone>() {
    @Override
    public boolean apply(Zone arg0) {
      return arg0.isSecurityGroupsEnabled();
    }
   }).getId();
   return createVirtualMachineWithSecurityGroupInZone(zoneId,
      defaultTemplateOrPreferredInZone(defaultTemplate, client, zoneId),
      get(client.getSecurityGroupClient().listSecurityGroups(), 0).getId(), client, jobComplete,
      virtualMachineRunning);
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testCreateDestroySecurityGroup() {
 try {
   zone = Iterables.find(client.getZoneClient().listZones(), new Predicate<Zone>() {
    @Override
    public boolean apply(Zone arg0) {
      return arg0.isSecurityGroupsEnabled();
    }
   });
   securityGroupsSupported = true;
   for (SecurityGroup securityGroup : client.getSecurityGroupClient().listSecurityGroups(
      ListSecurityGroupsOptions.Builder.named(prefix))) {
    for (IngressRule rule : securityGroup.getIngressRules())
      assertTrue(jobComplete.apply(client.getSecurityGroupClient().revokeIngressRule(rule.getId())), rule.toString());
    client.getSecurityGroupClient().deleteSecurityGroup(securityGroup.getId());
   }
   group = client.getSecurityGroupClient().createSecurityGroup(prefix);
   assertEquals(group.getName(), prefix);
   checkGroup(group);
   try {
    client.getSecurityGroupClient().createSecurityGroup(prefix);
    fail("Expected IllegalStateException");
   } catch (IllegalStateException e) {
   }
 } catch (NoSuchElementException e) {
   e.printStackTrace();
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

skipIfNotGlobalAdmin();
final Zone zone = Iterables.find(client.getZoneClient().listZones(), ZonePredicates.supportsAdvancedNetworks());
final NetworkOffering offering = find(client.getOfferingClient().listNetworkOfferings(),
  NetworkOfferingPredicates.supportsGuestVirtualNetworks());

代码示例来源:origin: jclouds/legacy-jclouds

public void testListZonesWhenResponseIs2xx() {
 ZoneClient client = requestSendsResponse(
   HttpRequest.builder().method("GET")
        .endpoint("http://localhost:8080/client/api")
        .addQueryParam("response", "json")
        .addQueryParam("command", "listZones")
        .addQueryParam("listAll", "true")
        .addQueryParam("apiKey", "identity")
        .addQueryParam("signature", "8iHCtck0qfxFTqJ8reyAObRf31I%3D")
        .addHeader("Accept", "application/json")
        .build(),
   HttpResponse.builder()
         .statusCode(200)
         .payload(payloadFromResource("/listzonesresponse.json"))
         .build());
 assertEquals(client.listZones(),
   ImmutableSet.of(
    Zone.builder()
      .id("1")
      .name("San Jose 1")
      .networkType(NetworkType.ADVANCED)
      .securityGroupsEnabled(false).build(),
    Zone.builder()
      .id("2")
      .name("Chicago")
      .networkType(NetworkType.ADVANCED)
      .securityGroupsEnabled(true).build()));
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com