public void testDescribeVolumesWithNovaEC2Status() {
    ElasticBlockStoreApi client =
        requestsSendResponses(
                describeAvailabilityZonesRequest,
                describeAvailabilityZonesResponse,
                HttpRequest.builder()
                    .method("POST")
                    .endpoint("http://localhost:8773/services/Cloud/")
                    .addHeader("Host", "localhost:8773")
                    .payload(
                        payloadFromStringWithContentType(
                            "Action=DescribeVolumes&Signature=AvRznSzGExM%2Buaj2JJj66wq4v4f%2BakicyLooRDtC0t0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity",
                            "application/x-www-form-urlencoded"))
                    .build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/nova_ec2_describe_volumes.xml"))
                    .build())
            .getElasticBlockStoreApi()
            .get();

    Set<Volume> expected =
        ImmutableSet.of(
            Volume.builder()
                .status(Volume.Status.AVAILABLE)
                .availabilityZone("nova")
                .region("nova")
                .id("vol-00000007")
                .size(1)
                .attachments(Attachment.builder().region("nova").build())
                .createTime(dateService.iso8601SecondsDateParse("2012-04-10T10:39:52Z"))
                .build());

    assertEquals(client.describeVolumesInRegion("nova"), expected);
  }
Ejemplo n.º 2
0
  @Override
  public void detachVolume(String instanceId, String volumeId) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    if (region == null) {
      log.fatal(
          "Cannot detach the volume [id]: "
              + volumeId
              + " from the instance [id]: "
              + instanceId
              + " of the [region] : "
              + region
              + " of Iaas : "
              + iaasInfo);
      return;
    }

    ElasticBlockStoreApi blockStoreApi =
        context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();
    Set<Volume> volumeDescriptions = blockStoreApi.describeVolumesInRegion(region, volumeId);
    Iterator<Volume> it = volumeDescriptions.iterator();

    while (it.hasNext()) {
      Volume.Status status = it.next().getStatus();
      if (status == Volume.Status.AVAILABLE) {
        log.warn(
            String.format(
                "Volume %s is already in AVAILABLE state. Volume seems to be detached somehow",
                volumeId));
        return;
      }
    }
    blockStoreApi.detachVolumeInRegion(
        region, volumeId, true, DetachVolumeOptions.Builder.fromInstance(instanceId));

    log.info(
        "Detachment of Volume [id]: "
            + volumeId
            + " from instance [id]: "
            + instanceId
            + " was successful. [region] : "
            + region
            + " of Iaas : "
            + iaasInfo);
  }
Ejemplo n.º 3
0
 private Volume.Status getVolumeStatus(
     ElasticBlockStoreApi blockStoreApi, String region, String volumeId) {
   Set<Volume> volumeDescriptions = blockStoreApi.describeVolumesInRegion(region, volumeId);
   Iterator<Volume> it = volumeDescriptions.iterator();
   return it.next().getStatus();
 }