@Test(dependsOnMethods = "testCreateAndStartServer")
 public void testConnectivity() throws Exception {
   HostAndPort vncsocket = HostAndPort.fromParts(server.getVnc().getIp(), 5900);
   Logger.getAnonymousLogger().info("awaiting vnc: " + vncsocket);
   assert socketTester.apply(vncsocket) : server;
   HostAndPort sshsocket = HostAndPort.fromParts(server.getNics().get(0).getDhcp(), 22);
   Logger.getAnonymousLogger().info("awaiting ssh: " + sshsocket);
   assert socketTester.apply(sshsocket) : server;
   doConnectViaSsh(server, getSshCredentials(server));
 }
  @Test(dependsOnMethods = "testSetDriveData")
  public void testCreateAndStartServer() throws Exception {
    Logger.getAnonymousLogger().info("preparing drive");
    prepareDrive();

    Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build();

    Logger.getAnonymousLogger().info("starting server");
    server = client.createServer(serverRequest);
    client.startServer(server.getUuid());
    server = client.getServerInfo(server.getUuid());
    checkStartedServer();

    Server newInfo = client.getServerInfo(server.getUuid());
    checkServerMatchesGet(newInfo);
  }
 protected void checkStartedServer() {
   System.out.println(new Gson().toJson(server));
   assertNotNull(server.getUuid());
   assertNotNull(server.getUser());
   assertEquals(server.getName(), prefix);
   assertEquals(server.isPersistent(), true);
   assertEquals(
       server.getDevices(),
       ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()));
   assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0"));
   assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp());
   assertEquals(server.getNics().get(0).getModel(), Model.E1000);
   assertEquals(server.getStatus(), ServerStatus.ACTIVE);
 }
  @Test(dependsOnMethods = "testConnectivity")
  public void testLifeCycle() throws Exception {
    client.stopServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);

    client.startServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);

    client.resetServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);

    client.shutdownServer(server.getUuid());
    // behavior on shutdown depends on how your server OS is set up to respond to an ACPI power
    // button signal
    assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE
        || client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.STOPPED);
  }
  @AfterGroups(groups = "live")
  @Override
  protected void tearDownContext() {
    try {
      client.destroyServer(server.getUuid());
    } catch (Exception e) {
      // no need to check null or anything as we swallow all
    }
    try {
      client.destroyDrive(drive.getUuid());
    } catch (Exception e) {

    }
    super.tearDownContext();
  }
  @Test(dependsOnMethods = "testLifeCycle")
  public void testSetServerConfiguration() throws Exception {
    client.stopServer(server.getUuid());
    assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);

    ServerInfo server2 =
        client.setServerConfiguration(
            server.getUuid(),
            Server.Builder.fromServer(server)
                .name("rediculous")
                .tags(ImmutableSet.of("networking", "security", "gateway"))
                .userMetadata(ImmutableMap.of("foo", "bar"))
                .build());

    assertNotNull(server2.getUuid(), server.getUuid());
    assertEquals(server2.getName(), "rediculous");
    checkTagsAndMetadata(server2);
    server = server2;
  }
 @Test(dependsOnMethods = "testSetServerConfiguration")
 public void testDestroyServer() throws Exception {
   client.destroyServer(server.getUuid());
   assertEquals(client.getServerInfo(server.getUuid()), null);
 }
 protected void checkTagsAndMetadata(ServerInfo server2) {
   assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
   assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
 }
 protected void checkServerMatchesGet(Server newInfo) {
   assertEquals(newInfo.getUuid(), server.getUuid());
 }