@Test
  public void testEnableDisableAccount() {
    skipIfNotGlobalAdmin();

    Account testAccount = null;
    try {
      testAccount = createTestAccount(globalAdminClient, prefix);

      AsyncCreateResponse response =
          domainAdminClient
              .getAccountClient()
              .disableAccount(testAccount.getName(), testAccount.getDomainId(), false);
      assertNotNull(response);
      assertTrue(jobComplete.apply(response.getJobId()));

      AsyncJob<Account> job =
          domainAdminClient.getAsyncJobClient().getAsyncJob(response.getJobId());
      assertEquals(job.getResult().getState(), Account.State.DISABLED);

      Account updated =
          domainAdminClient
              .getAccountClient()
              .enableAccount(testAccount.getName(), testAccount.getDomainId());
      assertNotNull(updated);
      assertEquals(updated.getState(), Account.State.ENABLED);

    } finally {
      if (testAccount != null) {
        globalAdminClient.getAccountClient().deleteAccount(testAccount.getId());
      }
    }
  }
  @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(@Nullable Network network) {
                return network != null && network.getState().equals("Implemented");
              }
            });
    assertEquals(Iterables.size(networks), 1);
    Network network = Iterables.getOnlyElement(networks, null);
    assertNotNull(network);

    // Create a VM and stop it
    Long templateId = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
    vmForCreation =
        VirtualMachineClientLiveTest.createVirtualMachineInNetwork(
            network, templateId, 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);
  }
  /** deployVirtualMachineInZone */
  private void deployVirtualMachineInZone() throws Exception {
    CommonUtil.beforeMsg();

    String zoneId = getFirstZoneId();
    String serviceOfferingId = getRandomServiceOfferingId();
    String templateId = getRandomTemplateId();

    AsyncCreateResponse deployVirtualMachineInZone =
        client
            .getVirtualMachineClient()
            .deployVirtualMachineInZone(zoneId, serviceOfferingId, templateId);

    System.out.println(deployVirtualMachineInZone.getJobId());
  }
 @AfterGroups(groups = "live")
 protected void tearDown() {
   if (vmForCreation != null) {
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())),
         vmForCreation.toString());
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().destroyVirtualMachine(vmForCreation.getId())),
         vmForCreation.toString());
     assertTrue(virtualMachineDestroyed.apply(vmForCreation));
   }
   if (vmForRegistration != null) {
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().stopVirtualMachine(vmForRegistration.getId())),
         vmForRegistration.toString());
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().destroyVirtualMachine(vmForRegistration.getId())),
         vmForRegistration.toString());
     assert virtualMachineDestroyed.apply(vmForRegistration);
   }
   if (createdTemplate != null) {
     AsyncCreateResponse deleteJob =
         client.getTemplateClient().deleteTemplate(createdTemplate.getId());
     assertTrue(jobComplete.apply(deleteJob.getJobId()));
   }
   if (registeredTemplate != null) {
     AsyncCreateResponse deleteJob =
         client.getTemplateClient().deleteTemplate(registeredTemplate.getId());
     assertTrue(jobComplete.apply(deleteJob.getJobId()));
   }
   super.tearDown();
 }
  @Test(enabled = true, dependsOnMethods = "testRegisterTemplate")
  public void testExtractTemplate() throws Exception {
    // Initiate the extraction and wait for it to complete
    AsyncCreateResponse response =
        client
            .getTemplateClient()
            .extractTemplate(
                registeredTemplate.getId(),
                ExtractMode.HTTP_DOWNLOAD,
                registeredTemplate.getZoneId());
    assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString());

    // Get the result
    AsyncJob<TemplateExtraction> asyncJob =
        client.getAsyncJobClient().getAsyncJob(response.getJobId());
    TemplateExtraction extract = asyncJob.getResult();
    assertNotNull(extract);

    // Check that the URL can be retrieved
    String extractUrl = extract.getUrl();
    assertNotNull(extractUrl);
    URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8"));
    assertTrue(context.utils().http().exists(uri), "does not exist: " + uri);
  }