public String getDockerDaemonIpAddress(@NonNull String machineName) { return runShellCommand(executableName, "ip", machineName); }
public boolean isMachineRunning(String machineName) { String status = runShellCommand("docker-machine", "status", machineName); return status.trim().equalsIgnoreCase("running"); }
public void ensureMachineRunning(@NonNull String machineName) { if (!isMachineRunning(machineName)) { LOGGER.info("Docker-machine '{}' is not running. Will start it now", machineName); runShellCommand("docker-machine", "start", machineName); } }
public Optional<String> getDefaultMachine() { String ls = runShellCommand(executableName, "ls", "-q"); List<String> machineNames = asList(ls.split("\n")); String envMachineName = System.getenv("DOCKER_MACHINE_NAME"); if (machineNames.contains(envMachineName)) { LOGGER.debug("Using docker-machine set in DOCKER_MACHINE_NAME: {}", envMachineName); return Optional.of(envMachineName); } else if (machineNames.contains("default")) { LOGGER.debug("DOCKER_MACHINE_NAME is not set; Using 'default' docker-machine", envMachineName); return Optional.of("default"); } else if (machineNames.size() > 0) { LOGGER.debug("DOCKER_MACHINE_NAME is not set and no machine named 'default' found; Using first machine found with `docker-machine ls`: {}", machineNames.get(0)); return Optional.of(machineNames.get(0)); } else { return Optional.empty(); } }
/** * {@inheritDoc} */ @Override public String getTestHostIpAddress() { if (DockerMachineClient.instance().isInstalled()) { try { Optional<String> defaultMachine = DockerMachineClient.instance().getDefaultMachine(); if (!defaultMachine.isPresent()) { throw new IllegalStateException("Could not find a default docker-machine instance"); } String sshConnectionString = runShellCommand("docker-machine", "ssh", defaultMachine.get(), "echo $SSH_CONNECTION").trim(); if (Strings.isNullOrEmpty(sshConnectionString)) { throw new IllegalStateException("Could not obtain SSH_CONNECTION environment variable for docker machine " + defaultMachine.get()); } String[] sshConnectionParts = sshConnectionString.split("\\s"); if (sshConnectionParts.length != 4) { throw new IllegalStateException("Unexpected pattern for SSH_CONNECTION for docker machine - expected 'IP PORT IP PORT' pattern but found '" + sshConnectionString + "'"); } return sshConnectionParts[0]; } catch (Exception e) { throw new RuntimeException(e); } } else { throw new UnsupportedOperationException("getTestHostIpAddress() is only implemented for docker-machine right now"); } }
public String getDockerDaemonIpAddress(@NonNull String machineName) { if (machineName == null) { throw new java.lang.NullPointerException("machineName is marked @NonNull but is null"); } return runShellCommand(executableName, "ip", machineName); }
public boolean isMachineRunning(String machineName) { String status = runShellCommand("docker-machine", "status", machineName); return status.trim().equalsIgnoreCase("running"); }
public void ensureMachineRunning(@NonNull String machineName) { if (machineName == null) { throw new java.lang.NullPointerException("machineName is marked @NonNull but is null"); } if (!isMachineRunning(machineName)) { LOGGER.info("Docker-machine \'{}\' is not running. Will start it now", machineName); runShellCommand("docker-machine", "start", machineName); } }
public Optional<String> getDefaultMachine() { String ls = runShellCommand(executableName, "ls", "-q"); List<String> machineNames = asList(ls.split("\n")); String envMachineName = System.getenv("DOCKER_MACHINE_NAME"); if (machineNames.contains(envMachineName)) { LOGGER.debug("Using docker-machine set in DOCKER_MACHINE_NAME: {}", envMachineName); return Optional.of(envMachineName); } else if (machineNames.contains("default")) { LOGGER.debug("DOCKER_MACHINE_NAME is not set; Using \'default\' docker-machine", envMachineName); return Optional.of("default"); } else if (machineNames.size() > 0) { LOGGER.debug("DOCKER_MACHINE_NAME is not set and no machine named \'default\' found; Using first machine found with `docker-machine ls`: {}", machineNames.get(0)); return Optional.of(machineNames.get(0)); } else { return Optional.empty(); } }
/** * {@inheritDoc} */ @Override public String getTestHostIpAddress() { if (DockerMachineClient.instance().isInstalled()) { try { Optional<String> defaultMachine = DockerMachineClient.instance().getDefaultMachine(); if (!defaultMachine.isPresent()) { throw new IllegalStateException("Could not find a default docker-machine instance"); } String sshConnectionString = runShellCommand("docker-machine", "ssh", defaultMachine.get(), "echo $SSH_CONNECTION").trim(); if (Strings.isNullOrEmpty(sshConnectionString)) { throw new IllegalStateException("Could not obtain SSH_CONNECTION environment variable for docker machine " + defaultMachine.get()); } String[] sshConnectionParts = sshConnectionString.split("\\s"); if (sshConnectionParts.length != 4) { throw new IllegalStateException("Unexpected pattern for SSH_CONNECTION for docker machine - expected \'IP PORT IP PORT\' pattern but found \'" + sshConnectionString + "\'"); } return sshConnectionParts[0]; } catch (Exception e) { throw new RuntimeException(e); } } else { throw new UnsupportedOperationException("getTestHostIpAddress() is only implemented for docker-machine right now"); } }