@Test public void testCreateDeleteSSHKeyPair() { sshKeyPair = client.getSSHKeyPairApi().createSSHKeyPair(keyPairName); assertNotNull(sshKeyPair.getPrivateKey()); checkSSHKeyPair(sshKeyPair); client.getSSHKeyPairApi().deleteSSHKeyPair(sshKeyPair.getName()); assertEquals(client.getSSHKeyPairApi().getSSHKeyPair(sshKeyPair.getName()), null); assertEquals(SshKeys.fingerprintPrivateKey(sshKeyPair.getPrivateKey()), sshKeyPair.getFingerprint()); sshKeyPair = null; }
private void cleanupOrphanedKeyPairsInZone(Set<String> groups, String zoneId) { for (String group : groups) { for (SshKeyPair pair : Iterables.filter(client.getSSHKeyPairApi().listSSHKeyPairs(), nameMatches(namingConvention.create().containsGroup(group)))) { logger.debug(">> deleting keypair(%s)", pair.getName()); client.getSSHKeyPairApi().deleteSSHKeyPair(pair.getName()); // TODO: test this clear happens keyPairCache.invalidate(pair.getName()); logger.debug("<< deleted keypair(%s)", pair.getName()); } keyPairCache.invalidate(namingConvention.create().sharedNameForGroup(group)); } }
@Test public void testRegisterDeleteSSHKeyPair() { final Map<String, String> sshKey = SshKeys.generate(); final String publicKey = sshKey.get("public"); sshKeyPair = client.getSSHKeyPairApi().registerSSHKeyPair(keyPairName, publicKey); assertNull(sshKeyPair.getPrivateKey()); checkSSHKeyPair(sshKeyPair); client.getSSHKeyPairApi().deleteSSHKeyPair(keyPairName); assertEquals(client.getSSHKeyPairApi().getSSHKeyPair(sshKeyPair.getName()), null); assertEquals(SshKeys.fingerprintPublicKey(publicKey), sshKeyPair.getFingerprint()); sshKeyPair = null; }
@Test public void testListAndGetSSHKeyPairsWhenResponseIs2xx() { HttpResponse response = HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/listsshkeypairsresponse.json")) .build(); SSHKeyPairApi client = requestSendsResponse(HttpRequest.builder() .method("GET") .endpoint( URI.create("http://localhost:8080/client/api?response=json&" + "command=listSSHKeyPairs&listAll=true&apiKey=identity&signature=5d2J9u%2BdKpkQsadDbl9i9OcUSLQ%3D")) .addHeader("Accept", "application/json") .build(), response); assertEquals(client.listSSHKeyPairs(), ImmutableSet.of( SshKeyPair.builder().name("jclouds-keypair") .fingerprint("1c:06:74:52:3b:99:1c:95:5c:04:c2:f4:ba:77:6e:7b").build())); client = requestSendsResponse(HttpRequest.builder() .method("GET") .endpoint( URI.create("http://localhost:8080/client/api?response=json&command=listSSHKeyPairs&listAll=true&" + "name=jclouds-keypair&apiKey=identity&signature=hJIVCFOHhdOww3aq19tFHpeD2HI%3D")) .addHeader("Accept", "application/json") .build(), response); assertEquals(client.getSSHKeyPair("jclouds-keypair"), SshKeyPair.builder().name("jclouds-keypair") .fingerprint("1c:06:74:52:3b:99:1c:95:5c:04:c2:f4:ba:77:6e:7b").build()); }
@BeforeGroups(groups = { "live" }) public void setupContext() { super.setupContext(); adapter = context.utils().injector().getInstance( CloudStackComputeServiceAdapter.class); keyPairName = prefix + "-adapter-test-keypair"; keyPair = SshKeys.generate(); client.getSSHKeyPairApi().deleteSSHKeyPair(keyPairName); client.getSSHKeyPairApi().registerSSHKeyPair(keyPairName, keyPair.get("public")); }
@Override public SshKeyPair load(String input) { SshKeyPair keyPair = null; while (keyPair == null) { try { keyPair = client.getSSHKeyPairApi().createSSHKeyPair(input); logger.debug(">> creating SSH key pair with name %s", input); } catch (IllegalStateException e) { logger.error(e, "<< error creating SSH key pair with name %s: ", Throwables.getRootCause(e).getMessage()); throw Throwables.propagate(e); } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; }
protected void checkSSHKeyPair(SshKeyPair pair) { assert pair.getName() != null : pair; assertEquals(pair.getFingerprint(), client.getSSHKeyPairApi().getSSHKeyPair(pair.getName()).getFingerprint()); }
@BeforeMethod @AfterMethod public void removeExistingKey() { client.getSSHKeyPairApi().deleteSSHKeyPair(keyPairName); }
@Test public void testListSSHKeyPairs() { final Set<SshKeyPair> sshKeyPairs = client.getSSHKeyPairApi().listSSHKeyPairs(); for (SshKeyPair sshKeyPair : sshKeyPairs) { checkSSHKeyPair(sshKeyPair); } }
.build()); SshKeyPair actual = client.registerSSHKeyPair("jclouds-keypair", publicKey); SshKeyPair expected = SshKeyPair.builder().name("jclouds-keypair") .fingerprint(expectedFingerprint).build();
@Test public void testLoad() throws UnknownHostException { final CloudStackApi client = createMock(CloudStackApi.class); SSHKeyPairApi keyClient = createMock(SSHKeyPairApi.class); SshKeyPair pair = createMock(SshKeyPair.class); expect(client.getSSHKeyPairApi()).andReturn(keyClient); expect(keyClient.createSSHKeyPair("group-1")).andReturn(pair); replay(client, keyClient); CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(new TypeLiteral<Supplier<String>>() { }).toInstance(Suppliers.ofInstance("1")); bind(CloudStackApi.class).toInstance(client); } }).getInstance(CreateUniqueKeyPair.class); assertEquals(parser.load("group-1"), pair); verify(client, keyClient); }
keyPairCache.asMap().put(keyPair.getName(), keyPair); options.keyPair(keyPair.getName()); } else if (client.getSSHKeyPairApi().getSSHKeyPair(templateOptions.getKeyPair()) != null) { keyPair = client.getSSHKeyPairApi().getSSHKeyPair(templateOptions.getKeyPair());
.build()); SshKeyPair actual = client.createSSHKeyPair("jclouds-keypair"); SshKeyPair expected = SshKeyPair.builder().name("jclouds-keypair") .fingerprint("1c:06:74:52:3b:99:1c:95:5c:04:c2:f4:ba:77:6e:7b")